jdk/src/share/classes/javax/swing/text/EditorKit.java
author malenkov
Fri, 04 Apr 2014 20:18:53 +0400
changeset 24158 6afb40c4e9f8
parent 24148 d6e18bb8a7f0
permissions -rw-r--r--
8039137: KSS: JTextComponent.isProcessInputMethodEventOverridden Reviewed-by: alexsch, serb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
23697
e556a715949f 8034169: Fix serial lint warnings in javax.swing
darcy
parents: 23010
diff changeset
     2
 * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
package javax.swing.text;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
import java.io.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import javax.swing.Action;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import javax.swing.JEditorPane;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 * Establishes the set of things needed by a text component
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * to be a reasonably functioning editor for some <em>type</em>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * of text content.  The EditorKit acts as a factory for some
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * kind of policy.  For example, an implementation
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * of html and rtf can be provided that is replaceable
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * with other implementations.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * A kit can safely store editing state as an instance
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * of the kit will be dedicated to a text component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * New kits will normally be created by cloning a
24148
d6e18bb8a7f0 7052708: Grammar error in EditorKit documentation
alexsch
parents: 23697
diff changeset
    42
 * prototype kit.  The kit will have its
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * <code>setComponent</code> method called to establish
24148
d6e18bb8a7f0 7052708: Grammar error in EditorKit documentation
alexsch
parents: 23697
diff changeset
    44
 * its relationship with a JTextComponent.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * @author  Timothy Prinzing
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 */
23697
e556a715949f 8034169: Fix serial lint warnings in javax.swing
darcy
parents: 23010
diff changeset
    48
@SuppressWarnings("serial") // Same-version serialization only
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
public abstract class EditorKit implements Cloneable, Serializable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
     * Construct an EditorKit.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    public EditorKit() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
     * Creates a copy of the editor kit.  This is implemented
20158
1c5d22e5b898 8025117: [cleanup] Eliminate doclint errors in javax/swing/text classes
yan
parents: 5506
diff changeset
    59
     * to use <code>Object.clone()</code>.  If the kit cannot be cloned,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
     * null is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
     * @return the copy
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    public Object clone() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
        Object o;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
            o = super.clone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
        } catch (CloneNotSupportedException cnse) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
            o = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
        return o;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
     * Called when the kit is being installed into the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
     * a JEditorPane.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
     * @param c the JEditorPane
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    public void install(JEditorPane c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
     * Called when the kit is being removed from the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
     * JEditorPane.  This is used to unregister any
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
     * listeners that were attached.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
     * @param c the JEditorPane
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    public void deinstall(JEditorPane c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     * Gets the MIME type of the data that this
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
     * kit represents support for.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     * @return the type
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    public abstract String getContentType();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     * Fetches a factory that is suitable for producing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     * views of any models that are produced by this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     * kit.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     * @return the factory
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    public abstract ViewFactory getViewFactory();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     * Fetches the set of commands that can be used
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     * on a text component that is using a model and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     * view produced by this kit.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     * @return the set of actions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    public abstract Action[] getActions();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     * Fetches a caret that can navigate through views
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     * produced by the associated ViewFactory.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     * @return the caret
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    public abstract Caret createCaret();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     * Creates an uninitialized text storage model
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     * that is appropriate for this type of editor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     * @return the model
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    public abstract Document createDefaultDocument();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     * Inserts content from the given stream which is expected
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     * to be in a format appropriate for this kind of content
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     * handler.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     * @param in  The stream to read from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     * @param doc The destination for the insertion.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     * @param pos The location in the document to place the
20158
1c5d22e5b898 8025117: [cleanup] Eliminate doclint errors in javax/swing/text classes
yan
parents: 5506
diff changeset
   143
     *   content &gt;= 0.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     * @exception IOException on any I/O error
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     * @exception BadLocationException if pos represents an invalid
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     *   location within the document.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
    public abstract void read(InputStream in, Document doc, int pos)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        throws IOException, BadLocationException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
     * Writes content from a document to the given stream
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     * in a format appropriate for this kind of content handler.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     * @param out  The stream to write to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
     * @param doc The source for the write.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
     * @param pos The location in the document to fetch the
20158
1c5d22e5b898 8025117: [cleanup] Eliminate doclint errors in javax/swing/text classes
yan
parents: 5506
diff changeset
   158
     *   content from &gt;= 0.
1c5d22e5b898 8025117: [cleanup] Eliminate doclint errors in javax/swing/text classes
yan
parents: 5506
diff changeset
   159
     * @param len The amount to write out &gt;= 0.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     * @exception IOException on any I/O error
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
     * @exception BadLocationException if pos represents an invalid
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
     *   location within the document.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
    public abstract void write(OutputStream out, Document doc, int pos, int len)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        throws IOException, BadLocationException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
     * Inserts content from the given stream which is expected
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
     * to be in a format appropriate for this kind of content
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     * handler.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     * Since actual text editing is unicode based, this would
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     * generally be the preferred way to read in the data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
     * Some types of content are stored in an 8-bit form however,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     * and will favor the InputStream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     * @param in  The stream to read from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     * @param doc The destination for the insertion.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     * @param pos The location in the document to place the
20158
1c5d22e5b898 8025117: [cleanup] Eliminate doclint errors in javax/swing/text classes
yan
parents: 5506
diff changeset
   180
     *   content &gt;= 0.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     * @exception IOException on any I/O error
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
     * @exception BadLocationException if pos represents an invalid
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
     *   location within the document.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
    public abstract void read(Reader in, Document doc, int pos)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        throws IOException, BadLocationException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
     * Writes content from a document to the given stream
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
     * in a format appropriate for this kind of content handler.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
     * Since actual text editing is unicode based, this would
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     * generally be the preferred way to write the data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     * Some types of content are stored in an 8-bit form however,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     * and will favor the OutputStream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     * @param out  The stream to write to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     * @param doc The source for the write.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     * @param pos The location in the document to fetch the
20158
1c5d22e5b898 8025117: [cleanup] Eliminate doclint errors in javax/swing/text classes
yan
parents: 5506
diff changeset
   200
     *   content &gt;= 0.
1c5d22e5b898 8025117: [cleanup] Eliminate doclint errors in javax/swing/text classes
yan
parents: 5506
diff changeset
   201
     * @param len The amount to write out &gt;= 0.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
     * @exception IOException on any I/O error
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
     * @exception BadLocationException if pos represents an invalid
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
     *   location within the document.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
    public abstract void write(Writer out, Document doc, int pos, int len)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
        throws IOException, BadLocationException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
}