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