Module java.desktop

Class DefaultEditorKit

java.lang.Object
javax.swing.text.EditorKit
javax.swing.text.DefaultEditorKit
All Implemented Interfaces:
Serializable, Cloneable
Direct Known Subclasses:
StyledEditorKit

public class DefaultEditorKit extends EditorKit
This is the set of things needed by a text component to be a reasonably functioning editor for some type of text document. This implementation provides a default implementation which treats text as plain text and provides a minimal set of actions for a simple editor.
Newlines
There are two properties which deal with newlines. The system property, line.separator, is defined to be platform-dependent, either "\n", "\r", or "\r\n". There is also a property defined in DefaultEditorKit, called EndOfLineStringProperty, which is defined automatically when a document is loaded, to be the first occurrence of any of the newline characters. When a document is loaded, EndOfLineStringProperty is set appropriately, and when the document is written back out, the EndOfLineStringProperty is used. But while the document is in memory, the "\n" character is used to define a newline, regardless of how the newline is defined when the document is on disk. Therefore, for searching purposes, "\n" should always be used. When a new document is created, and the EndOfLineStringProperty has not been defined, it will use the System property when writing out the document.

Note that EndOfLineStringProperty is set on the Document using the get/putProperty methods. Subclasses may override this behavior.

  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static class 
    Creates a beep.
    static class 
    Copies the selected region and place its contents into the system clipboard.
    static class 
    Cuts the selected region and place its contents into the system clipboard.
    static class 
    The action that is executed by default if a key typed event is received and there is no keymap entry.
    static class 
    Places a line/paragraph break into the document.
    static class 
    Places content into the associated document.
    static class 
    Places a tab character into the document.
    static class 
    Pastes the contents of the system clipboard into the selected region, or before the caret if nothing is selected.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
    Name of the Action for moving the caret logically backward one position.
    static final String
    Name of the action to create a beep.
    static final String
    Name of the Action for moving the caret to the beginning of the document.
    static final String
    Name of the Action for moving the caret to the beginning of a line.
    static final String
    Name of the Action for moving the caret to the beginning of the current line or up to the beginning of the previous line if the caret is already at the beginning of the line.
    static final String
    Name of the Action for moving the caret to the beginning of a paragraph.
    static final String
    Name of the Action for moving the caret to the beginning of a word.
    static final String
    Name of the action to copy the selected region and place the contents into the system clipboard.
    static final String
    Name of the action to cut the selected region and place the contents into the system clipboard.
    static final String
    Name of the action that is executed by default if a key typed event is received and there is no keymap entry.
    static final String
    Name of the action to delete the character of content that follows the current caret position.
    static final String
    Name of the action to delete the word that follows the beginning of the selection.
    static final String
    Name of the action to delete the character of content that precedes the current caret position.
    static final String
    Name of the action to delete the word that precedes the beginning of the selection.
    static final String
    Name of the Action for moving the caret logically downward one position.
    static final String
    Name of the Action for moving the caret to the end of the document.
    static final String
    Name of the Action for moving the caret to the end of a line.
    static final String
    Name of the Action for moving the caret to the end of the current line or down to the end of the next line if the caret is already at the end of the line.
    static final String
    When reading a document if a CRLF is encountered a property with this name is added and the value will be "\r\n".
    static final String
    Name of the Action for moving the caret to the end of a paragraph.
    static final String
    Name of the Action for moving the caret to the end of a word.
    static final String
    Name of the Action for moving the caret logically forward one position.
    static final String
    Name of the action to place a line/paragraph break into the document.
    static final String
    Name of the action to place content into the associated document.
    static final String
    Name of the action to place a tab character into the document.
    static final String
    Name of the Action for moving the caret to the beginning of the next word.
    static final String
    Name of the action to page down vertically.
    static final String
    Name of the action to page up vertically.
    static final String
    Name of the action to paste the contents of the system clipboard into the selected region, or before the caret if nothing is selected.
    static final String
    Name of the Action for moving the caret to the beginning of the previous word.
    static final String
    Name of the action to set the editor into read-only mode.
    static final String
    Name of the Action for selecting the entire document
    static final String
    Name of the Action for extending the selection by moving the caret logically backward one position.
    static final String
    Name of the Action for moving the caret to the beginning of the document.
    static final String
    Name of the Action for moving the caret to the beginning of a line, extending the selection.
    static final String
    Name of the Action for moving the caret to the beginning of a paragraph, extending the selection.
    static final String
    Name of the Action for moving the caret to the beginning of a word, extending the selection.
    static final String
    Name of the Action for moving the caret logically downward one position, extending the selection.
    static final String
    Name of the Action for moving the caret to the end of the document.
    static final String
    Name of the Action for moving the caret to the end of a line, extending the selection.
    static final String
    Name of the Action for moving the caret to the end of a paragraph, extending the selection.
    static final String
    Name of the Action for moving the caret to the end of a word, extending the selection.
    static final String
    Name of the Action for extending the selection by moving the caret logically forward one position.
    static final String
    Name of the Action for moving the selection to the beginning of the next word, extending the selection.
    static final String
    Name of the Action for moving the selection to the beginning of the previous word, extending the selection.
    static final String
    Name of the Action for moving the caret logically upward one position, extending the selection.
    static final String
    Name of the Action for selecting a line around the caret.
    static final String
    Name of the Action for selecting a paragraph around the caret.
    static final String
    Name of the Action for selecting a word around the caret.
    static final String
    Name of the Action for moving the caret logically upward one position.
    static final String
    Name of the action to set the editor into writeable mode.
  • Constructor Summary

    Constructors
    Constructor
    Description
    default constructor for DefaultEditorKit
  • Method Summary

    Modifier and Type
    Method
    Description
    Fetches a caret that can navigate through views produced by the associated ViewFactory.
    Creates an uninitialized text storage model (PlainDocument) that is appropriate for this type of editor.
    Fetches the set of commands that can be used on a text component that is using a model and view produced by this kit.
    Gets the MIME type of the data that this kit represents support for.
    Fetches a factory that is suitable for producing views of any models that are produced by this kit.
    void
    read(InputStream in, Document doc, int pos)
    Inserts content from the given stream which is expected to be in a format appropriate for this kind of content handler.
    void
    read(Reader in, Document doc, int pos)
    Inserts content from the given stream, which will be treated as plain text.
    void
    write(OutputStream out, Document doc, int pos, int len)
    Writes content from a document to the given stream in a format appropriate for this kind of content handler.
    void
    write(Writer out, Document doc, int pos, int len)
    Writes content from a document to the given stream as plain text.

    Methods declared in class javax.swing.text.EditorKit

    clone, deinstall, install

    Methods declared in class java.lang.Object

    equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • Constructor Details

    • DefaultEditorKit

      public DefaultEditorKit()
      default constructor for DefaultEditorKit
  • Method Details

    • getContentType

      public String getContentType()
      Gets the MIME type of the data that this kit represents support for. The default is text/plain.
      Specified by:
      getContentType in class EditorKit
      Returns:
      the type
    • getViewFactory

      public ViewFactory getViewFactory()
      Fetches a factory that is suitable for producing views of any models that are produced by this kit. The default is to have the UI produce the factory, so this method has no implementation.
      Specified by:
      getViewFactory in class EditorKit
      Returns:
      the view factory
    • getActions

      public Action[] getActions()
      Fetches the set of commands that can be used on a text component that is using a model and view produced by this kit.
      Specified by:
      getActions in class EditorKit
      Returns:
      the command list
    • createCaret

      public Caret createCaret()
      Fetches a caret that can navigate through views produced by the associated ViewFactory.
      Specified by:
      createCaret in class EditorKit
      Returns:
      the caret
    • createDefaultDocument

      public Document createDefaultDocument()
      Creates an uninitialized text storage model (PlainDocument) that is appropriate for this type of editor.
      Specified by:
      createDefaultDocument in class EditorKit
      Returns:
      the model
    • read

      public void read(InputStream in, Document doc, int pos) throws IOException, BadLocationException
      Inserts content from the given stream which is expected to be in a format appropriate for this kind of content handler.
      Specified by:
      read in class EditorKit
      Parameters:
      in - The stream to read from
      doc - The destination for the insertion.
      pos - The location in the document to place the content >=0.
      Throws:
      IOException - on any I/O error
      BadLocationException - if pos represents an invalid location within the document.
    • write

      public void write(OutputStream out, Document doc, int pos, int len) throws IOException, BadLocationException
      Writes content from a document to the given stream in a format appropriate for this kind of content handler.
      Specified by:
      write in class EditorKit
      Parameters:
      out - The stream to write to
      doc - The source for the write.
      pos - The location in the document to fetch the content >=0.
      len - The amount to write out >=0.
      Throws:
      IOException - on any I/O error
      BadLocationException - if pos represents an invalid location within the document.
    • read

      public void read(Reader in, Document doc, int pos) throws IOException, BadLocationException
      Inserts content from the given stream, which will be treated as plain text.
      Specified by:
      read in class EditorKit
      Parameters:
      in - The stream to read from
      doc - The destination for the insertion.
      pos - The location in the document to place the content >=0.
      Throws:
      IOException - on any I/O error
      BadLocationException - if pos represents an invalid location within the document.
    • write

      public void write(Writer out, Document doc, int pos, int len) throws IOException, BadLocationException
      Writes content from a document to the given stream as plain text.
      Specified by:
      write in class EditorKit
      Parameters:
      out - The stream to write to
      doc - The source for the write.
      pos - The location in the document to fetch the content from >=0.
      len - The amount to write out >=0.
      Throws:
      IOException - on any I/O error
      BadLocationException - if pos is not within 0 and the length of the document.