classpath-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[cp-patches] FYI: Swing button cleanup


From: Roman Kennke
Subject: [cp-patches] FYI: Swing button cleanup
Date: Fri, 15 Jul 2005 13:41:24 +0200
User-agent: Mozilla Thunderbird 1.0.2 (X11/20050317)

Ok, I think I found the problem. Roberts patches have been 100% correct AFAICS. Only the button text is initialized with "" instead of null when no text is specified in the constructor (like JButton(Icon)). I cleaned this up a bit, removing the AbstractButton(String, Icon) constructor (we don't need this since we have init(String, Icon) and it leads to unnecessary confusion and decentralization of the initialization). All of Roberts Mauve tests now PASS again, as well as some new Mauve tests that I added regarding this button text thingy.

Also this includes a small fix for JToggleButton. The ToggleButtonModel must not fire ActionEvents when setSelected() is called. It does fire ActionEvents when setPressed() is called, but only if it was armed before. This is checked by some more Mauve tests that I added.

2005-07-15  Roman Kennke  <address@hidden>

       * javax/swing/AbstractButton.java
       (AbstractButton): Directly call init() and updateUI().
       (AbstractButton(String, Icon)): Removed. This is not necessary
       since we have init(String, Icon) for that purpose.
       (getActionCommand): Reverted to previous behaviour: If
       actionCommand is set, return this, otherwise return text, even
       if text is null.
       * javax/swing/JButton.java
       (JButton(String, Icon)): Call super() and init(String, Icon)
       instead of super(String, Icon).
       * javax/swing/JMenuItem.java
       (JMenuItem): Call super() instead of super(String, Icon).
       (JMenuItem(Icon)): Call this(String, Icon) instead of
       super(String, Icon).
       (JMenuItem(String)): Call this(String, Icon) instead of
       super(String, Icon).
       (JMenuItem(Action)): Call super() instead of
       super(String, Icon).
       (JMenuItem(String, Icon)): Call super() and init(String, Icon)
       instead of super(String, Icon).
       (JMenuItem(String, int)): Call this(String, Icon) instead of
       super(String, Icon).
       * javax/swing/JToggleButton.java
       (ToggleButtonModel.setPressed): Fire an ActionEvent if button
       is released. According to my Mauve tests, it seems that this
       is what the JDK does, so do we.
       (ToggleButtonModel.setSelected): Removed.
       (JToggleButton): Call super() and init(String, Icon) instead
       of super(String, Icon).

/Roman

Index: javax/swing/AbstractButton.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/AbstractButton.java,v
retrieving revision 1.37
diff -u -r1.37 AbstractButton.java
--- javax/swing/AbstractButton.java     14 Jul 2005 15:15:15 -0000      1.37
+++ javax/swing/AbstractButton.java     15 Jul 2005 11:34:25 -0000
@@ -517,18 +517,7 @@
    */
   public AbstractButton()
   {
-    this("",null);
-  }
-
-  /**
-   * Creates a new AbstractButton object.
-   *
-   * @param txt Value to use for the button's "text" property
-   * @param icon Value to use for the button's "defaultIcon" property
-   */
-  AbstractButton(String txt, Icon icon)
-  {
-    init (txt, icon);
+    init("", null);
     updateUI();
   }
 
@@ -610,10 +599,8 @@
     String ac = model.getActionCommand();
     if (ac != null)
       return ac;
-    else if (text != null)
-      return text;
     else
-      return "";
+      return text;
   }
 
   /**
Index: javax/swing/JButton.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/JButton.java,v
retrieving revision 1.17
diff -u -r1.17 JButton.java
--- javax/swing/JButton.java    13 Jul 2005 01:18:42 -0000      1.17
+++ javax/swing/JButton.java    15 Jul 2005 11:34:25 -0000
@@ -77,7 +77,8 @@
 
   public JButton(String text, Icon icon)
   {
-    super(text, icon);
+    super();
+    init(text, icon);
     setModel(new DefaultButtonModel());
   }
 
Index: javax/swing/JMenuItem.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/JMenuItem.java,v
retrieving revision 1.17
diff -u -r1.17 JMenuItem.java
--- javax/swing/JMenuItem.java  2 Jul 2005 20:32:47 -0000       1.17
+++ javax/swing/JMenuItem.java  15 Jul 2005 11:34:25 -0000
@@ -83,7 +83,7 @@
    */
   public JMenuItem()
   {
-    super(null, null);
+    super();
   }
 
   /**
@@ -95,7 +95,8 @@
   {
     // FIXME: The requestedFocusEnabled property should
     // be set to false, when only icon is set for menu item.
-    super(null, icon);
+    super();
+    init(null, icon);
   }
 
   /**
@@ -105,7 +106,7 @@
    */
   public JMenuItem(String text)
   {
-    super(text, null);
+    this(text, null);
   }
 
   /**
@@ -115,7 +116,7 @@
    */
   public JMenuItem(Action action)
   {
-    super(null, null);
+    super();
     super.setAction(action);
   }
 
@@ -128,7 +129,8 @@
    */
   public JMenuItem(String text, Icon icon)
   {
-    super(text, icon);
+    super();
+    init(text, icon);
   }
 
   /**
@@ -141,7 +143,7 @@
    */
   public JMenuItem(String text, int mnemonic)
   {
-    super(text, null);
+    this(text, null);
     setMnemonic(mnemonic);
   }
 
Index: javax/swing/JToggleButton.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/JToggleButton.java,v
retrieving revision 1.22
diff -u -r1.22 JToggleButton.java
--- javax/swing/JToggleButton.java      13 Jul 2005 15:30:54 -0000      1.22
+++ javax/swing/JToggleButton.java      15 Jul 2005 11:34:25 -0000
@@ -133,7 +133,6 @@
     /**
      * Sets the pressed state of the button.  The selected state
      * of the button also changes follwing the button being pressed.
-     * Unlike DefaultButtonModel, does not fire an ActionEvent.
      *
      * @param b true if the button is pressed down.
      */
@@ -159,20 +158,12 @@
       // setPressed(false) == mouse release on us,
       // if we were armed, we flip the selected state.
       if (!p && isArmed())
-        setSelected(! isSelected());
-    }
-
-    /**
-     * Sets the selected state of the button.  Unlike DefaultButtonModel,
-     * fires an ActionEvent.
-     *
-     * @param s true if button is selected
-     */
-    public void setSelected(boolean s)
-    {
-      super.setSelected(s);
-      fireActionPerformed(new ActionEvent(this, ActionEvent.ACTION_PERFORMED,
-                                          actionCommand));
+        {
+          fireActionPerformed(new ActionEvent(this,
+                                              ActionEvent.ACTION_PERFORMED,
+                                              actionCommand));
+          setSelected(! isSelected());
+        }
     }
   }
 
@@ -269,7 +260,8 @@
    */
   public JToggleButton (String text, Icon icon, boolean selected) 
   {
-    super(text, icon);
+    super();
+    init(text, icon);
 
     setModel(new ToggleButtonModel()); 
     model.setSelected(selected);

reply via email to

[Prev in Thread] Current Thread [Next in Thread]