This is the mail archive of the java-patches@gcc.gnu.org mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[gui] Patch: javax.swing.text


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi list,


I just commited the attached patch to improve javax.swing.text a bit.


Michael


2004-08-12  Michael Koch  <konqueror@gmx.de>

	* javax/swing/plaf/basic/BasicTextUI.java
	(RootView.textComponent): Removed.
	(RootView.RootView): Don't initialize textComponent.
	(RootView.getViewFactory): New method.
	(EventHandler): New inner class.
	(rootView): Initialize at instance creation.
	(eventHandler): New field.
	(installUI): Don't create view hierarchy directly,
	call modelChanged() instead.
	(modelChanged): New method.
	* javax/swing/text/JTextComponent.java
	(setDocument): Fire property change event.
- -- 
Homepage: http://www.worldforge.org/
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)

iD8DBQFBG0F9WSOgCCdjSDsRAktdAJ4un0NGm0a1SqYTbbHO8CUtNq0LnwCeNwDl
JayUkMIrrfazUHNUAxfqMa0=
=0fxC
-----END PGP SIGNATURE-----
Index: javax/swing/plaf/basic/BasicTextUI.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/javax/swing/plaf/basic/BasicTextUI.java,v
retrieving revision 1.4.16.8
diff -u -r1.4.16.8 BasicTextUI.java
--- javax/swing/plaf/basic/BasicTextUI.java	12 Aug 2004 08:57:40 -0000	1.4.16.8
+++ javax/swing/plaf/basic/BasicTextUI.java	12 Aug 2004 09:57:47 -0000
@@ -46,6 +46,8 @@
 import java.awt.Point;
 import java.awt.Rectangle;
 import java.awt.Shape;
+import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
 
 import javax.swing.JComponent;
 import javax.swing.plaf.ComponentUI;
@@ -88,13 +90,17 @@
   
   private class RootView extends View
   {
-    private JTextComponent textComponent;
     private View view;
     
-    public RootView(JTextComponent parent)
+    public RootView()
     {
       super(null);
-      textComponent = parent;
+    }
+
+    public ViewFactory getViewFactory()
+    {
+      // FIXME: Handle EditorKit somehow.
+      return BasicTextUI.this;
     }
 
     public void setView(View v)
@@ -127,11 +133,24 @@
 	view.paint(g, s);
     }
   }
+
+  class EventHandler implements PropertyChangeListener
+  {
+    public void propertyChange(PropertyChangeEvent event)
+    {
+      if (event.getPropertyName().equals("document"))
+	{
+          // Document changed.
+	  modelChanged();
+	}
+    }
+  }
   
-  RootView rootView;
+  RootView rootView = new RootView();
   JTextComponent textComponent;
   int gap = 3;
   EditorKit kit = new DefaultEditorKit();
+  EventHandler eventHandler = new EventHandler();
 
   public BasicTextUI()
   {
@@ -166,8 +185,7 @@
 	textComponent.setDocument(doc);
       }
     
-    rootView = new RootView(textComponent);
-    setView(create(doc.getDefaultRootElement()));
+    modelChanged();
     
     installDefaults();
     installListeners();
@@ -329,4 +347,11 @@
     rootView.setView(view);
     view.setParent(rootView);
   }
+
+  protected void modelChanged()
+  {
+    ViewFactory factory = rootView.getViewFactory();
+    Element elem = textComponent.getDocument().getDefaultRootElement();
+    setView(factory.create(elem));
+  }
 }
Index: javax/swing/text/JTextComponent.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/javax/swing/text/JTextComponent.java,v
retrieving revision 1.4.2.16
diff -u -r1.4.2.16 JTextComponent.java
--- javax/swing/text/JTextComponent.java	30 Jul 2004 21:34:35 -0000	1.4.2.16
+++ javax/swing/text/JTextComponent.java	12 Aug 2004 09:57:47 -0000
@@ -306,9 +306,11 @@
     updateUI();
   }
 
-  public void setDocument(Document s)
+  public void setDocument(Document newDoc)
   {
-    doc = s;
+    Document oldDoc = doc;
+    doc = newDoc;
+    firePropertyChange("document", oldDoc, newDoc);
     revalidate();
     repaint();
   }

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]