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]

Patch: javax.swing.AbstractButton


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

Hi list,


I just commited the attached patch to improve 
javax.swing.AbstractButton.


Michael


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

	* javax/swing/AbstractButton.java:
	Little re-formatting.
	(changeEvent): Made protected.
	(fireStateChanged): Removed argument.
	(setHorizontalAlignment): Abort method when old value is equal too 
new
	value.
	(setHorizontalTextPosition): Likewise.
	(setVerticalAlignment): Likewise.
	(setVerticalTextPosition): Likewise.
	(setBorderPainted): Likewise.
	(setIcon): Likewise.
	(setText): Likewise.
	(setIconTextGap): Likewise.
	(setMargin): Likewise.
	(setPressedIcon): Likewise.
	(setFocusPainted): Likewise.
	(setDisabledSelectedIcon): Likewise.
	(setRolloverIcon): Likewise.
	(setRolloverSelectedIcon): Likewise.
	(setSelectedIcon): Likewise.
	(setContentAreaFilled): Likewise.


- -- 
Homepage: http://www.worldforge.org/
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)

iD8DBQFBRI8aWSOgCCdjSDsRAhznAJ9XbqGDEarTzllnYAjFSkeVgzBlzgCfYbYl
yOU0wWNDAC4UtcNGzdbT3Ko=
=06An
-----END PGP SIGNATURE-----
Index: javax/swing/AbstractButton.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/javax/swing/AbstractButton.java,v
retrieving revision 1.5.2.16
diff -u -r1.5.2.16 AbstractButton.java
--- javax/swing/AbstractButton.java	24 Aug 2004 22:00:26 -0000	1.5.2.16
+++ javax/swing/AbstractButton.java	12 Sep 2004 17:42:01 -0000
@@ -240,7 +240,7 @@
   PropertyChangeListener actionPropertyChangeListener;
   
   /** ChangeEvent that is fired to button's ChangeEventListeners  */  
-  private ChangeEvent changeEvent = new ChangeEvent(this);
+  protected ChangeEvent changeEvent = new ChangeEvent(this);
   
   /** Fired in a PropertyChangeEvent when the "borderPainted" property changes. */
   public static final String BORDER_PAINTED_CHANGED_PROPERTY = "borderPainted";
@@ -441,8 +441,7 @@
     {
       return null; // TODO
     }
-    }
-
+  }
 
   /**
    * Creates a new AbstractButton object.
@@ -691,11 +690,8 @@
   /**
    * Calls {@link ChangeEvent.stateChanged} on each {@link ChangeListener}
    * in the button's listener list.
-   *
-   * @param e The event signifying a change in one of the (non-bound)
-   * properties of the button's model.
    */
-  public void fireStateChanged(ChangeEvent e)
+  public void fireStateChanged()
   {
     ChangeListener[] listeners = getChangeListeners();
 
@@ -785,8 +781,8 @@
   {
     if (index < -1 || (text != null && index >= text.length()))
       throw new IllegalArgumentException();
-    else
-      mnemonicIndex = index;
+  
+    mnemonicIndex = index;
   }
   
   /** 
@@ -892,14 +888,14 @@
    */
   public void setHorizontalAlignment(int a)
   {
+    if (horizontalAlignment == a)
+      return;
+
     int old = horizontalAlignment;
     horizontalAlignment = a;
-    if (old != a)
-      {
-        firePropertyChange(HORIZONTAL_ALIGNMENT_CHANGED_PROPERTY, old, a);
-        revalidate();
-        repaint();
-      }
+    firePropertyChange(HORIZONTAL_ALIGNMENT_CHANGED_PROPERTY, old, a);
+    revalidate();
+    repaint();
   }
 
   /**
@@ -929,14 +925,14 @@
    */
   public void setHorizontalTextPosition(int t)
   {
+    if (horizontalTextPosition == t)
+      return;
+
     int old = horizontalTextPosition;
     horizontalTextPosition = t;
-    if (old != t)
-      {
-        firePropertyChange(HORIZONTAL_TEXT_POSITION_CHANGED_PROPERTY, old, t);
-        revalidate();
-        repaint();
-      }
+    firePropertyChange(HORIZONTAL_TEXT_POSITION_CHANGED_PROPERTY, old, t);
+    revalidate();
+    repaint();
   }
 
   /**
@@ -964,14 +960,14 @@
    */
   public void setVerticalAlignment(int a)
   {
+    if (verticalAlignment == a)
+      return;
+    
     int old = verticalAlignment;
     verticalAlignment = a;
-    if (old != a)
-      {
-        firePropertyChange(VERTICAL_ALIGNMENT_CHANGED_PROPERTY, old, a);
-        revalidate();
-        repaint();
-      }
+    firePropertyChange(VERTICAL_ALIGNMENT_CHANGED_PROPERTY, old, a);
+    revalidate();
+    repaint();
   }
 
   /**
@@ -1001,14 +997,14 @@
    */
   public void setVerticalTextPosition(int t)
   {
+    if (verticalTextPosition == t)
+      return;
+    
     int old = verticalTextPosition;
     verticalTextPosition = t;
-    if (old != t)
-      {
-        firePropertyChange(VERTICAL_TEXT_POSITION_CHANGED_PROPERTY, old, t);
-        revalidate();
-        repaint();
-      }
+    firePropertyChange(VERTICAL_TEXT_POSITION_CHANGED_PROPERTY, old, t);
+    revalidate();
+    repaint();
   }
 
   /**
@@ -1032,14 +1028,14 @@
    */
   public void setBorderPainted(boolean b)
   {
+    if (borderPainted == b)
+      return;
+    
     boolean old = borderPainted;
-        borderPainted = b;
-    if (b != old)
-      {
-        firePropertyChange(BORDER_PAINTED_CHANGED_PROPERTY, old, b);
-        revalidate();
-        repaint();
-      }
+    borderPainted = b;
+    firePropertyChange(BORDER_PAINTED_CHANGED_PROPERTY, old, b);
+    revalidate();
+    repaint();
   }
 
   /**
@@ -1078,10 +1074,7 @@
             action.removePropertyChangeListener(actionPropertyChangeListener);
             actionPropertyChangeListener = null;
           }
-
-
-  }
-  
+      }
 
     Action old = action;
     action = a;
@@ -1112,14 +1105,14 @@
    */
   public void setIcon(Icon i)
   {
-    if (default_icon != i)
-      {
+    if (default_icon == i)
+      return;
+    
     Icon old = default_icon;      
     default_icon = i;      
     firePropertyChange(ICON_CHANGED_PROPERTY, old, i);
     revalidate();
     repaint();
-      }
   }
 
   /**
@@ -1163,14 +1156,14 @@
    */
   public void setText(String t)
   {
+    if (text == t)
+      return;
+    
     String old = text;
     text = t;
-    if (t != old)
-      {
-        firePropertyChange(TEXT_CHANGED_PROPERTY, old, t);
-        revalidate();
-        repaint();
-      }
+    firePropertyChange(TEXT_CHANGED_PROPERTY, old, t);
+    revalidate();
+    repaint();
   }
 
   /**
@@ -1180,14 +1173,14 @@
    */
   public void setIconTextGap(int i)
   {
+    if (iconTextGap == i)
+      return;
+    
     int old = iconTextGap;
     iconTextGap = i;
-    if (old != i)
-      {
-        fireStateChanged(new ChangeEvent(this));
-        revalidate();
-        repaint();
-      }
+    fireStateChanged();
+    revalidate();
+    repaint();
   }
 
   /**
@@ -1207,7 +1200,7 @@
    *
    * @return The current "margin" property
    */
-  public 	Insets getMargin()
+  public Insets getMargin()
   {
     return margin;
   }
@@ -1221,15 +1214,15 @@
    */
   public void setMargin(Insets m)
   {
+    if (margin == m)
+      return;
+    
     Insets old = margin;
     margin = m;
-    if (m != old)
-      {
-        firePropertyChange(MARGIN_CHANGED_PROPERTY, old, m);
-        revalidate();
+    firePropertyChange(MARGIN_CHANGED_PROPERTY, old, m);
+    revalidate();
     repaint();
   }
-  }
 
   /**
    * Return the button's "pressedIcon" property. The look and feel class
@@ -1254,15 +1247,15 @@
    */
   public void setPressedIcon(Icon pressedIcon)
   {
+    if (pressed_icon == pressedIcon)
+      return;
+    
     Icon old = pressed_icon;
     pressed_icon = pressedIcon;
-    if (pressed_icon != old)
-      {
-        firePropertyChange(PRESSED_ICON_CHANGED_PROPERTY, old, pressed_icon);
+    firePropertyChange(PRESSED_ICON_CHANGED_PROPERTY, old, pressed_icon);
     revalidate();
     repaint();
   }
-  }
 
   /**
    * Return the button's "disabledIcon" property. The look and feel class
@@ -1323,15 +1316,14 @@
    */
   public void setFocusPainted(boolean p)
   {
+    if (focusPainted == p)
+      return;
+    
     boolean old = focusPainted;
     focusPainted = p;
-
-    if (old != focusPainted)
-      {
-        firePropertyChange(FOCUS_PAINTED_CHANGED_PROPERTY, old, p);
-        revalidate();
-        repaint();
-      }
+    firePropertyChange(FOCUS_PAINTED_CHANGED_PROPERTY, old, p);
+    revalidate();
+    repaint();
   }
 
   /**
@@ -1554,7 +1546,7 @@
       {
         public void stateChanged(ChangeEvent e)
         {
-          AbstractButton.this.fireStateChanged(e);
+          AbstractButton.this.fireStateChanged();
           AbstractButton.this.repaint();          
         }
       };
@@ -1612,13 +1604,13 @@
     getModel().setArmed(true);
     getModel().setPressed(true);
     try
-  {
+      {
         java.lang.Thread.sleep(pressTime);
-  }
+      }
     catch (java.lang.InterruptedException e)
-  {
+      {
         // probably harmless
-  }
+      }
     getModel().setPressed(false);
     getModel().setArmed(false);
   }
@@ -1644,22 +1636,20 @@
    * <code>true</code>. This icon can be <code>null</code>, in which case
    * it is synthesized from the button's selected icon.
    *
-   * @param disabledSelectedIcon The new disabled selected icon
+   * @param icon The new disabled selected icon
    */
-  public void setDisabledSelectedIcon(Icon disabledSelectedIcon)
+  public void setDisabledSelectedIcon(Icon icon)
   {
+    if (disabledSelectedIcon == icon)
+      return;
+    
     Icon old = disabledSelectedIcon;
-    disabledSelectedIcon = disabledSelectedIcon;
-    if (old != disabledSelectedIcon)
-  {
-        firePropertyChange(DISABLED_SELECTED_ICON_CHANGED_PROPERTY, old, 
-                           disabledSelectedIcon);
-        revalidate();
-        repaint();        
-  }
+    disabledSelectedIcon = icon;
+    firePropertyChange(DISABLED_SELECTED_ICON_CHANGED_PROPERTY, old, icon);
+    revalidate();
+    repaint();        
   }
 
-
   /**
    * Return the button's rollover icon. The look and feel class should
    * paint this icon when the "rolloverEnabled" property of the button is
@@ -1681,15 +1671,14 @@
    */
   public void setRolloverIcon(Icon r)
   {
+    if (rolloverIcon == r)
+      return;
+    
     Icon old = rolloverIcon;
     rolloverIcon = r;
-    if (old != rolloverIcon)
-  {
-        firePropertyChange(ROLLOVER_ICON_CHANGED_PROPERTY, old, 
-                           rolloverIcon);
-        revalidate();
-        repaint();
-      }
+    firePropertyChange(ROLLOVER_ICON_CHANGED_PROPERTY, old, rolloverIcon);
+    revalidate();
+    repaint();
   }
 
   /**
@@ -1715,18 +1704,16 @@
    */
   public void setRolloverSelectedIcon(Icon r)
   {
+    if (rolloverSelectedIcon == r)
+      return;
+    
     Icon old = rolloverSelectedIcon;
     rolloverSelectedIcon = r;
-    if (old != rolloverSelectedIcon)
-  {
-        firePropertyChange(ROLLOVER_SELECTED_ICON_CHANGED_PROPERTY, old, 
-                           rolloverSelectedIcon);
-        revalidate();
-        repaint();
-  }
+    firePropertyChange(ROLLOVER_SELECTED_ICON_CHANGED_PROPERTY, old, r);
+    revalidate();
+    repaint();
   }
 
-
   /**
    * Return the button's selected icon. The look and feel class should
    * paint this icon when the "selected" property of the button's model is
@@ -1752,15 +1739,14 @@
    */
   public void setSelectedIcon(Icon s)
   {
+    if (selectedIcon == s)
+      return;
+    
     Icon old = selectedIcon;
     selectedIcon = s;
-    if (old != selectedIcon)
-    {
-        firePropertyChange(SELECTED_ICON_CHANGED_PROPERTY, old, 
-                           selectedIcon);
-        revalidate();
-        repaint();
-    }
+    firePropertyChange(SELECTED_ICON_CHANGED_PROPERTY, old, s);
+    revalidate();
+    repaint();
   }
 
   /**
@@ -1777,9 +1763,9 @@
         Object[] objs = new Object[1];
         objs[0] = getText();
         return objs;
-  }
+      }
     else
-  {
+     {
         return null;
       }
   }
@@ -1800,9 +1786,9 @@
    */
   public boolean imageUpdate(Image img, int infoflags, int x, int y, int w,
                              int h)
-        {
+  {
     return current_icon == img;
-        }
+  }
 
   /**
    * Returns the value of the button's "contentAreaFilled" property. This
@@ -1814,9 +1800,9 @@
    * @return The current value of the "contentAreaFilled" property
    */
   public boolean isContentAreaFilled()
-            {
+  {
     return contentAreaFilled;
-            }
+  }
 
   /**
    * Sets the value of the button's "contentAreaFilled" property. This
@@ -1828,16 +1814,16 @@
    * @param b The new value of the "contentAreaFilled" property
    */
   public void setContentAreaFilled(boolean b)
-            {
+  {
+    if (contentAreaFilled == b)
+      return;
+    
     boolean old = contentAreaFilled;
     contentAreaFilled = b;
-    if (b != old)
-      {
-        firePropertyChange(CONTENT_AREA_FILLED_CHANGED_PROPERTY, old, b);
-        revalidate();
-              repaint();
-            }
-        }
+    firePropertyChange(CONTENT_AREA_FILLED_CHANGED_PROPERTY, old, b);
+    revalidate();
+    repaint();
+   }
 
   /**
    * Paints the button's border, if the button's "borderPainted" property is
@@ -1846,10 +1832,10 @@
    * @param g The graphics context used to paint the border
    */
   protected void paintBorder(Graphics g)
-            {
+  {
     if (isBorderPainted())
       super.paintBorder(g);
-            }
+  }
 
   /**
    * Returns a string, used only for debugging, which identifies or somehow
@@ -1862,7 +1848,6 @@
     return "AbstractButton";
   }
 
-
   /**
    * Set the "UI" property of the button, which is a look and feel class
    * responsible for handling the button's input events and painting it.
@@ -1870,9 +1855,9 @@
    * @param ui The new "UI" property
    */
   public void setUI(ButtonUI ui)
-        {
+  {
     super.setUI(ui);
-        }
+  }
   
   /**
    * Set the "UI" property of the button, which is a look and feel class
@@ -1883,7 +1868,7 @@
   public ButtonUI getUI()
   {
     return (ButtonUI) ui;
-      }
+  }
   
   /**
    * Set the "UI" property to a class constructed, via the {@link

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