1. /*
  2. * @(#)EditorKit.java 1.15 01/11/29
  3. *
  4. * Copyright 2002 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. package javax.swing.text;
  8. import java.io.*;
  9. import javax.swing.Action;
  10. import javax.swing.JEditorPane;
  11. /**
  12. * Establishes the set of things needed by a text component
  13. * to be a reasonably functioning editor for some <em>type</em>
  14. * of text content. The EditorKit acts as a factory for some
  15. * kind of policy. For example, an implementation
  16. * of html and rtf can be provided that is replaceable
  17. * with other implementations.
  18. * <p>
  19. * A kit can safely store editing state as an instance
  20. * of the kit will be dedicated to a text component.
  21. * New kits will normally be created by cloning a
  22. * prototype kit. The kit will have it's
  23. * <code>setComponent</code> method called to establish
  24. * it's relationship with a JTextComponent.
  25. *
  26. * @author Timothy Prinzing
  27. * @version 1.15 11/29/01
  28. */
  29. public abstract class EditorKit implements Cloneable, Serializable {
  30. /**
  31. * Construct an EditorKit.
  32. */
  33. public EditorKit() {
  34. }
  35. /**
  36. * Creates a copy of the editor kit. This
  37. * allows an implementation to serve as a prototype
  38. * for others, so that they can be quickly created.
  39. * <em>In a future release this method will be implemented
  40. * to use Object.clone</em>
  41. *
  42. * @return the copy
  43. */
  44. public abstract Object clone();
  45. /*
  46. public Object clone() {
  47. Object o;
  48. try {
  49. o = super.clone();
  50. } catch (CloneNotSupportedException 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 c) {
  63. }
  64. /**
  65. * Called when the kit is being removed from the
  66. * JEditorPane. This is used to unregister any
  67. * listeners that were attached.
  68. *
  69. * @param c the JEditorPane
  70. */
  71. public void deinstall(JEditorPane c) {
  72. }
  73. /**
  74. * Gets the MIME type of the data that this
  75. * kit represents support for.
  76. *
  77. * @return the type
  78. */
  79. public abstract String getContentType();
  80. /**
  81. * Fetches a factory that is suitable for producing
  82. * views of any models that are produced by this
  83. * kit.
  84. *
  85. * @return the factory
  86. */
  87. public abstract ViewFactory getViewFactory();
  88. /**
  89. * Fetches the set of commands that can be used
  90. * on a text component that is using a model and
  91. * view produced by this kit.
  92. *
  93. * @return the set of actions
  94. */
  95. public abstract Action[] getActions();
  96. /**
  97. * Fetches a caret that can navigate through views
  98. * produced by the associated ViewFactory.
  99. *
  100. * @return the caret
  101. */
  102. public abstract Caret createCaret();
  103. /**
  104. * Creates an uninitialized text storage model
  105. * that is appropriate for this type of editor.
  106. *
  107. * @return the model
  108. */
  109. public abstract Document createDefaultDocument();
  110. /**
  111. * Inserts content from the given stream which is expected
  112. * to be in a format appropriate for this kind of content
  113. * handler.
  114. *
  115. * @param in The stream to read from
  116. * @param doc The destination for the insertion.
  117. * @param pos The location in the document to place the
  118. * content >= 0.
  119. * @exception IOException on any I/O error
  120. * @exception BadLocationException if pos represents an invalid
  121. * location within the document.
  122. */
  123. public abstract void read(InputStream in, Document doc, int pos)
  124. throws IOException, BadLocationException;
  125. /**
  126. * Writes content from a document to the given stream
  127. * in a format appropriate for this kind of content handler.
  128. *
  129. * @param out The stream to write to
  130. * @param doc The source for the write.
  131. * @param pos The location in the document to fetch the
  132. * content from >= 0.
  133. * @param len The amount to write out >= 0.
  134. * @exception IOException on any I/O error
  135. * @exception BadLocationException if pos represents an invalid
  136. * location within the document.
  137. */
  138. public abstract void write(OutputStream out, Document doc, int pos, int len)
  139. throws IOException, BadLocationException;
  140. /**
  141. * Inserts content from the given stream which is expected
  142. * to be in a format appropriate for this kind of content
  143. * handler.
  144. * <p>
  145. * Since actual text editing is unicode based, this would
  146. * generally be the preferred way to read in the data.
  147. * Some types of content are stored in an 8-bit form however,
  148. * and will favor the InputStream.
  149. *
  150. * @param in The stream to read from
  151. * @param doc The destination for the insertion.
  152. * @param pos The location in the document to place the
  153. * content >= 0.
  154. * @exception IOException on any I/O error
  155. * @exception BadLocationException if pos represents an invalid
  156. * location within the document.
  157. */
  158. public abstract void read(Reader in, Document doc, int pos)
  159. throws IOException, BadLocationException;
  160. /**
  161. * Writes content from a document to the given stream
  162. * in a format appropriate for this kind of content handler.
  163. * <p>
  164. * Since actual text editing is unicode based, this would
  165. * generally be the preferred way to write the data.
  166. * Some types of content are stored in an 8-bit form however,
  167. * and will favor the OutputStream.
  168. *
  169. * @param out The stream to write to
  170. * @param doc The source for the write.
  171. * @param pos The location in the document to fetch the
  172. * content >= 0.
  173. * @param len The amount to write out >= 0.
  174. * @exception IOException on any I/O error
  175. * @exception BadLocationException if pos represents an invalid
  176. * location within the document.
  177. */
  178. public abstract void write(Writer out, Document doc, int pos, int len)
  179. throws IOException, BadLocationException;
  180. }