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