I implemented the hook method
javax.swing.plaf.basic.BasicTextUI.propertyChange and moved some code to
BasicTextFieldUI.

2005-09-20  Roman Kennke  <[EMAIL PROTECTED]>

        * javax/swing/plaf/basic/BasicTextUI.java
        (UpdateHandler): Renamed to PropertyChangeHandler. This name is
        closer to the purpose of this class.
        (PropertyChangeHandler.propertyChange): Delegate property change
        to propertyChange hook method in the enclosing BasicTextUI.
        (propertyChange): New protected method. This serves as a hook
        for subclasses to handle property changes in the text component.
        * javax/swing/plaf/basic/BasicTextUI.java
        (properyChange): Handle editable property here and adjust background
        accordingly.

/Roman
Index: javax/swing/plaf/basic/BasicTextUI.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/plaf/basic/BasicTextUI.java,v
retrieving revision 1.39
diff -u -r1.39 BasicTextUI.java
--- javax/swing/plaf/basic/BasicTextUI.java	19 Sep 2005 14:17:09 -0000	1.39
+++ javax/swing/plaf/basic/BasicTextUI.java	20 Sep 2005 17:58:09 -0000
@@ -74,7 +74,6 @@
 import javax.swing.text.Highlighter;
 import javax.swing.text.JTextComponent;
 import javax.swing.text.Keymap;
-import javax.swing.text.PlainView;
 import javax.swing.text.Position;
 import javax.swing.text.View;
 import javax.swing.text.ViewFactory;
@@ -333,7 +332,7 @@
   /**
    * Receives notifications when properties of the text component change.
    */
-  class UpdateHandler implements PropertyChangeListener
+  class PropertyChangeHandler implements PropertyChangeListener
   {
     /**
      * Notifies when a property of the text component changes.
@@ -347,13 +346,8 @@
           // Document changed.
 	      modelChanged();
         }
-      else if (event.getPropertyName().equals("editable"))
-        {
-          if (textComponent.isEditable())
-            textComponent.setBackground(background);
-          else 
-            textComponent.setBackground(inactiveBackground);
-        }
+
+      BasicTextUI.this.propertyChange(event);
     }
   }
 
@@ -376,7 +370,7 @@
       rootView.changedUpdate(ev, new Rectangle(0, 0, size.width, size.height),
                              rootView.getViewFactory());
     }
-    
+
     /**
      * Notification about a document insert event.
      *
@@ -427,7 +421,7 @@
   /**
    * Receives notification when the model changes.
    */
-  UpdateHandler updateHandler = new UpdateHandler();
+  PropertyChangeHandler updateHandler = new PropertyChangeHandler();
 
   /** The DocumentEvent handler. */
   DocumentHandler documentHandler = new DocumentHandler();
@@ -1069,5 +1063,18 @@
       return;
     View view = factory.create(elem);
     setView(view);
+  }
+
+  /**
+   * Receives notification whenever one of the text component's bound
+   * properties changes. This default implementation does nothing.
+   * It is a hook that enables subclasses to react to property changes
+   * on the text component.
+   *
+   * @param ev the property change event
+   */
+  protected void propertyChange(PropertyChangeEvent ev)
+  {
+    // The default implementation does nothing.
   }
 }
Index: javax/swing/plaf/basic/BasicTextFieldUI.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/plaf/basic/BasicTextFieldUI.java,v
retrieving revision 1.4
diff -u -r1.4 BasicTextFieldUI.java
--- javax/swing/plaf/basic/BasicTextFieldUI.java	14 Sep 2005 07:58:07 -0000	1.4
+++ javax/swing/plaf/basic/BasicTextFieldUI.java	20 Sep 2005 17:58:09 -0000
@@ -79,8 +79,21 @@
     super.installUI(c);
   }
 
+  /**
+   * Receives notification whenever one of the text component's bound
+   * properties changes. Here we check for the editable and enabled
+   * properties and adjust the background color accordingly.
+   *
+   * @param event the property change event
+   */
   protected void propertyChange(PropertyChangeEvent event)
   {
-    // Does nothing by default.
+    if (event.getPropertyName().equals("editable"))
+      {
+        if (textComponent.isEditable())
+          textComponent.setBackground(background);
+        else 
+          textComponent.setBackground(inactiveBackground);
+      }
   }
 }
_______________________________________________
Classpath-patches mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/classpath-patches

Reply via email to