Started working on HTMLEditorKit, very minor stuff.  Had to write
DefaultEditorKit.write to get a test app to work.  It's only partially
implemented for now, but I'll be working on these classes for the next
little while and will continue to update them.  Patch is attached.

2005-09-19  Anthony Balkissoon  <[EMAIL PROTECTED]>

        * javax/swing/text/DefaultEditorKit.java:
        (write): Partially Implemented and made slight correction to API docs.
        * javax/swing/text/html/HTMLEditorKit.java:
        (createDefaultDocument): Override parent method because we need to 
        return an HTMLDocument not a DefaultStyledDocument.

--Tony
Index: javax/swing/text/DefaultEditorKit.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/text/DefaultEditorKit.java,v
retrieving revision 1.20
diff -u -r1.20 DefaultEditorKit.java
--- javax/swing/text/DefaultEditorKit.java	13 Sep 2005 23:44:50 -0000	1.20
+++ javax/swing/text/DefaultEditorKit.java	20 Sep 2005 18:49:44 -0000
@@ -947,15 +947,23 @@
    * @param offset the beginning offset from where to write
    * @param len the length of the fragment to write
    *
-   * @throws BadLocationException if <code>offset</code> or
-   *         <code>offset + len</code>is an invalid location inside
-   *         <code>document</code>
+   * @throws BadLocationException if <code>offset</code> is an 
+   * invalid location inside <code>document</code>.
    * @throws IOException if something goes wrong while writing to
    *        <code>out</code>
    */
   public void write(Writer out, Document document, int offset, int len)
-    throws BadLocationException, IOException
+      throws BadLocationException, IOException
   {
-    // TODO: Implement this properly.
+    // Throw a BLE if offset is invalid
+    if (offset < 0 || offset > document.getLength())
+      throw new BadLocationException("Tried to write to invalid location",
+                                     offset);
+
+    // If they gave an overly large len, just adjust it
+    if (offset + len > document.getLength())
+      len = document.getLength() - offset;
+
+    out.write(document.getText(offset, len));
   }
 }
Index: javax/swing/text/html/HTMLEditorKit.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/text/html/HTMLEditorKit.java,v
retrieving revision 1.4
diff -u -r1.4 HTMLEditorKit.java
--- javax/swing/text/html/HTMLEditorKit.java	22 Jul 2005 08:18:36 -0000	1.4
+++ javax/swing/text/html/HTMLEditorKit.java	20 Sep 2005 18:49:44 -0000
@@ -43,6 +43,7 @@
 import java.io.Serializable;
 
 import javax.swing.text.BadLocationException;
+import javax.swing.text.Document;
 import javax.swing.text.MutableAttributeSet;
 import javax.swing.text.StyledEditorKit;
 
@@ -78,7 +79,7 @@
                               )
                         throws IOException;
   }
-
+  
   /**
    * The "hook" that receives all information about the HTML document
    * structure while parsing it. The methods are invoked by parser
@@ -247,4 +248,15 @@
    * The "ident paragraph right" action.
    */
   public static final String PARA_INDENT_RIGHT = "html-para-indent-right";
+  
+  /**
+   * Create a text storage model for this type of editor.
+   * 
+   * @return the model
+   */
+  public Document createDefaultDocument()
+  {
+    HTMLDocument document = new HTMLDocument();
+    return document;
+  }
 }
_______________________________________________
Classpath-patches mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/classpath-patches

Reply via email to