This adds a default editor kit for JEditorPane and implements 2
previously stubbed methods. So now you can add icons and Components to
JTextPanes. If you are lucky, they are even rendered using the freshly
implemented ComponentView and IconView. Unfortunately, rendering styled
text components is still very broken...

2005-11-17  Roman Kennke  <[EMAIL PROTECTED]>

        * javax/swing/JEditorPane.java
        (PlainEditorKit): New inner class.
        (createDefaultEditorKit): Return an instance of PlainEditorKit.
        * javax/swing/JTextPane.java
        (insertComponent): Implemented previously stubbed method.
        (insertIcon): Implemented previously stubbed method.

/Roman
Index: javax/swing/JEditorPane.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/JEditorPane.java,v
retrieving revision 1.25
diff -u -r1.25 JEditorPane.java
--- javax/swing/JEditorPane.java	27 Oct 2005 20:28:37 -0000	1.25
+++ javax/swing/JEditorPane.java	17 Nov 2005 21:42:00 -0000
@@ -59,6 +59,9 @@
 import javax.swing.text.EditorKit;
 import javax.swing.text.Element;
 import javax.swing.text.JTextComponent;
+import javax.swing.text.View;
+import javax.swing.text.ViewFactory;
+import javax.swing.text.WrappedPlainView;
 import javax.swing.text.html.HTML;
 import javax.swing.text.html.HTMLDocument;
 import javax.swing.text.html.HTMLEditorKit;
@@ -466,6 +469,30 @@
     }
   }
 
+  /**
+   * An EditorKit used for plain text. This is the default editor kit for
+   * JEditorPanes.
+   *
+   * @author Roman Kennke ([EMAIL PROTECTED])
+   */
+  private static class PlainEditorKit extends DefaultEditorKit
+  {
+
+    /**
+     * Returns a ViewFactory that supplies WrappedPlainViews.
+     */
+    public ViewFactory getViewFactory()
+    {
+      return new ViewFactory()
+      {
+        public View create(Element el)
+        {
+          return new WrappedPlainView(el);
+        }
+      };
+    }
+  }
+
   private static final long serialVersionUID = 3140472492599046285L;
   
   private URL page;
@@ -497,12 +524,12 @@
 
   protected EditorKit createDefaultEditorKit()
   {
-    return new DefaultEditorKit();
+    return new PlainEditorKit();
   }
 
   public static EditorKit createEditorKitForContentType(String type)
   {
-    return new DefaultEditorKit();
+    return new PlainEditorKit();
   }
 
   /**
Index: javax/swing/JTextPane.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/JTextPane.java,v
retrieving revision 1.12
diff -u -r1.12 JTextPane.java
--- javax/swing/JTextPane.java	19 Oct 2005 15:45:04 -0000	1.12
+++ javax/swing/JTextPane.java	17 Nov 2005 21:42:00 -0000
@@ -47,7 +47,9 @@
 import javax.swing.text.EditorKit;
 import javax.swing.text.Element;
 import javax.swing.text.MutableAttributeSet;
+import javax.swing.text.SimpleAttributeSet;
 import javax.swing.text.Style;
+import javax.swing.text.StyleConstants;
 import javax.swing.text.StyledDocument;
 import javax.swing.text.StyledEditorKit;
 
@@ -192,9 +194,20 @@
    */
   public void insertComponent(Component component)
   {
-    // TODO: One space must be inserted here with attributes set to indicate
-    // that the component must be displayed here. Have to figure out the
-    // attributes.
+    SimpleAttributeSet atts = new SimpleAttributeSet();
+    atts.addAttribute(StyleConstants.ComponentAttribute, component);
+    atts.addAttribute(StyleConstants.NameAttribute,
+                      StyleConstants.ComponentElementName);
+    try
+      {
+        getDocument().insertString(getCaret().getDot(), " ", atts);
+      }
+    catch (BadLocationException ex)
+      {
+        AssertionError err = new AssertionError("Unexpected bad location");
+        err.initCause(ex);
+        throw err;
+      }
   }
 
   /**
@@ -204,9 +217,20 @@
    */
   public void insertIcon(Icon icon)
   {
-    // TODO: One space must be inserted here with attributes set to indicate
-    // that the icon must be displayed here. Have to figure out the
-    // attributes.
+    SimpleAttributeSet atts = new SimpleAttributeSet();
+    atts.addAttribute(StyleConstants.IconAttribute, icon);
+    atts.addAttribute(StyleConstants.NameAttribute,
+                      StyleConstants.IconElementName);
+    try
+      {
+        getDocument().insertString(getCaret().getDot(), " ", atts);
+      }
+    catch (BadLocationException ex)
+      {
+        AssertionError err = new AssertionError("Unexpected bad location");
+        err.initCause(ex);
+        throw err;
+      }
   }
 
   /**
_______________________________________________
Classpath-patches mailing list
Classpath-patches@gnu.org
http://lists.gnu.org/mailman/listinfo/classpath-patches

Reply via email to