KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > javax > swing > text > EditorKit


1 /*
2  * @(#)EditorKit.java 1.19 03/12/19
3  *
4  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7 package javax.swing.text;
8
9 import java.io.*;
10 import javax.swing.Action JavaDoc;
11 import javax.swing.JEditorPane JavaDoc;
12
13 /**
14  * Establishes the set of things needed by a text component
15  * to be a reasonably functioning editor for some <em>type</em>
16  * of text content. The EditorKit acts as a factory for some
17  * kind of policy. For example, an implementation
18  * of html and rtf can be provided that is replaceable
19  * with other implementations.
20  * <p>
21  * A kit can safely store editing state as an instance
22  * of the kit will be dedicated to a text component.
23  * New kits will normally be created by cloning a
24  * prototype kit. The kit will have it's
25  * <code>setComponent</code> method called to establish
26  * it's relationship with a JTextComponent.
27  *
28  * @author Timothy Prinzing
29  * @version 1.19 12/19/03
30  */

31 public abstract class EditorKit implements Cloneable JavaDoc, Serializable {
32
33     /**
34      * Construct an EditorKit.
35      */

36     public EditorKit() {
37     }
38
39     /**
40      * Creates a copy of the editor kit. This is implemented
41      * to use Object.clone</em>. If the kit cannot be cloned,
42      * null is returned.
43      *
44      * @return the copy
45      */

46     public Object JavaDoc clone() {
47     Object JavaDoc o;
48     try {
49         o = super.clone();
50     } catch (CloneNotSupportedException JavaDoc cnse) {
51         o = null;
52     }
53     return o;
54     }
55
56     /**
57      * Called when the kit is being installed into the
58      * a JEditorPane.
59      *
60      * @param c the JEditorPane
61      */

62     public void install(JEditorPane JavaDoc c) {
63     }
64
65     /**
66      * Called when the kit is being removed from the
67      * JEditorPane. This is used to unregister any
68      * listeners that were attached.
69      *
70      * @param c the JEditorPane
71      */

72     public void deinstall(JEditorPane JavaDoc c) {
73     }
74
75     /**
76      * Gets the MIME type of the data that this
77      * kit represents support for.
78      *
79      * @return the type
80      */

81     public abstract String JavaDoc getContentType();
82
83     /**
84      * Fetches a factory that is suitable for producing
85      * views of any models that are produced by this
86      * kit.
87      *
88      * @return the factory
89      */

90     public abstract ViewFactory JavaDoc getViewFactory();
91
92     /**
93      * Fetches the set of commands that can be used
94      * on a text component that is using a model and
95      * view produced by this kit.
96      *
97      * @return the set of actions
98      */

99     public abstract Action JavaDoc[] getActions();
100
101     /**
102      * Fetches a caret that can navigate through views
103      * produced by the associated ViewFactory.
104      *
105      * @return the caret
106      */

107     public abstract Caret JavaDoc createCaret();
108
109     /**
110      * Creates an uninitialized text storage model
111      * that is appropriate for this type of editor.
112      *
113      * @return the model
114      */

115     public abstract Document JavaDoc createDefaultDocument();
116
117     /**
118      * Inserts content from the given stream which is expected
119      * to be in a format appropriate for this kind of content
120      * handler.
121      *
122      * @param in The stream to read from
123      * @param doc The destination for the insertion.
124      * @param pos The location in the document to place the
125      * content >= 0.
126      * @exception IOException on any I/O error
127      * @exception BadLocationException if pos represents an invalid
128      * location within the document.
129      */

130     public abstract void read(InputStream in, Document JavaDoc doc, int pos)
131     throws IOException, BadLocationException JavaDoc;
132
133     /**
134      * Writes content from a document to the given stream
135      * in a format appropriate for this kind of content handler.
136      *
137      * @param out The stream to write to
138      * @param doc The source for the write.
139      * @param pos The location in the document to fetch the
140      * content from >= 0.
141      * @param len The amount to write out >= 0.
142      * @exception IOException on any I/O error
143      * @exception BadLocationException if pos represents an invalid
144      * location within the document.
145      */

146     public abstract void write(OutputStream out, Document JavaDoc doc, int pos, int len)
147     throws IOException, BadLocationException JavaDoc;
148
149     /**
150      * Inserts content from the given stream which is expected
151      * to be in a format appropriate for this kind of content
152      * handler.
153      * <p>
154      * Since actual text editing is unicode based, this would
155      * generally be the preferred way to read in the data.
156      * Some types of content are stored in an 8-bit form however,
157      * and will favor the InputStream.
158      *
159      * @param in The stream to read from
160      * @param doc The destination for the insertion.
161      * @param pos The location in the document to place the
162      * content >= 0.
163      * @exception IOException on any I/O error
164      * @exception BadLocationException if pos represents an invalid
165      * location within the document.
166      */

167     public abstract void read(Reader in, Document JavaDoc doc, int pos)
168     throws IOException, BadLocationException JavaDoc;
169
170     /**
171      * Writes content from a document to the given stream
172      * in a format appropriate for this kind of content handler.
173      * <p>
174      * Since actual text editing is unicode based, this would
175      * generally be the preferred way to write the data.
176      * Some types of content are stored in an 8-bit form however,
177      * and will favor the OutputStream.
178      *
179      * @param out The stream to write to
180      * @param doc The source for the write.
181      * @param pos The location in the document to fetch the
182      * content >= 0.
183      * @param len The amount to write out >= 0.
184      * @exception IOException on any I/O error
185      * @exception BadLocationException if pos represents an invalid
186      * location within the document.
187      */

188     public abstract void write(Writer out, Document JavaDoc doc, int pos, int len)
189     throws IOException, BadLocationException JavaDoc;
190
191 }
192
Popular Tags