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: some swing fixes


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

Hi list,


I just commited the attached patch to fix some issues with Swing in 
gui branch.


Michael


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

	* javax/swing/JComponent.java
	(setUI): Fire PropertyChange.
	* javax/swing/JLabel.java
	(text): Renamed from labelText.
	(horizontalAlignment): New default vlaue.
	(icon): Renamed from activeIcon.
	(displayedMnemonic): Renamed from mnemonicKey, added default value.
	(displayedMnemonicIndex): Renamed from underlineChar.
	(setDisplayedMnemonic): Reimplemented.
	* javax/swing/JRadioButton.java
	(JRadioButton): New constructors.
	* javax/swing/JTextField.java
	(JTextField): Throw exception if colums < 0, initialitialz
	this.columns directly and initialize document with text 
conditionally.
- -- 
Homepage: http://www.worldforge.org/
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)

iD8DBQFBGicTWSOgCCdjSDsRAtdUAJsH9mOW4ilsinsZb46Hagx4k9/M2QCbBrFV
lIP7zw33TR/xE5nCLGWgo3U=
=Wb0B
-----END PGP SIGNATURE-----
Index: javax/swing/JComponent.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/javax/swing/JComponent.java,v
retrieving revision 1.7.2.14
diff -u -b -B -r1.7.2.14 JComponent.java
--- javax/swing/JComponent.java	29 Jul 2004 16:02:27 -0000	1.7.2.14
+++ javax/swing/JComponent.java	11 Aug 2004 13:53:42 -0000
@@ -1878,11 +1878,14 @@
     if (ui != null)
       ui.uninstallUI(this);
 
+    ComponentUI oldUI = ui;
     ui = newUI;
 
     if (ui != null)
       ui.installUI(this);
 
+    firePropertyChange("UI", oldUI, newUI);
+    
     revalidate();
     repaint();
   }
Index: javax/swing/JLabel.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/javax/swing/JLabel.java,v
retrieving revision 1.4.2.6
diff -u -b -B -r1.4.2.6 JLabel.java
--- javax/swing/JLabel.java	10 Jun 2004 07:42:15 -0000	1.4.2.6
+++ javax/swing/JLabel.java	11 Aug 2004 13:53:42 -0000
@@ -40,6 +40,7 @@
 import java.awt.Component;
 import java.awt.Image;
 import java.awt.Font;
+import java.awt.event.KeyEvent;
 import javax.accessibility.Accessible;
 import javax.accessibility.AccessibleContext;
 import javax.swing.Icon;
@@ -63,10 +64,10 @@
   protected Component labelFor;
 
   /** The label's text. */
-  private transient String labelText;
+  private transient String text;
 
   /** Where the label will be positioned horizontally. */
-  private transient int horizontalAlignment = CENTER;
+  private transient int horizontalAlignment = LEADING;
 
   /** Where the label text will be placed horizontally relative to the icon. */
   private transient int horizontalTextPosition = TRAILING;
@@ -78,16 +79,16 @@
   private transient int verticalTextPosition = CENTER;
 
   /** The icon painted when the label is enabled. */
-  private transient Icon activeIcon;
+  private transient Icon icon;
 
   /** The icon painted when the label is disabled. */
   private transient Icon disabledIcon;
 
   /** The label's mnemnonic key. */
-  private transient char mnemonicKey;
+  private transient int displayedMnemonic = KeyEvent.VK_UNDEFINED;
 
   /** The index of the menemonic character in the text. */
-  private transient int underlinedChar = -1;
+  private transient int displayedMnemonicIndex = -1;
 
   /** The gap between the icon and the text. */
   private transient int iconTextGap = 4;
@@ -209,8 +210,8 @@
    */
   public JLabel(String text, Icon icon, int horizontalAlignment)
   {
-    labelText = text;
-    activeIcon = icon;
+    this.text = text;
+    this.icon = icon;
     this.horizontalAlignment = horizontalAlignment;
     updateUI();
   }
@@ -273,24 +274,26 @@
    */
   public String getText()
   {
-    return labelText;
+    return text;
   }
 
   /**
    * This method changes the "text" property. The given text will be painted
    * in the label.
    *
-   * @param text The label's text.
+   * @param newText The label's text.
    */
-  public void setText(String text)
+  public void setText(String newText)
   {
-    if (text != labelText)
+    if (text != newText)
       {
-	String oldText = labelText;
-	labelText = text;
-	firePropertyChange(TEXT_CHANGED_PROPERTY, oldText, labelText);
-	if (labelText != null && labelText.length() <= underlinedChar)
-	  setDisplayedMnemonicIndex(labelText.length() - 1);
+	String oldText = text;
+	text = newText;
+	firePropertyChange(TEXT_CHANGED_PROPERTY, oldText, newText);
+        
+	if (text != null
+            && text.length() <= displayedMnemonicIndex)
+	  setDisplayedMnemonicIndex(text.length() - 1);
       }
   }
 
@@ -302,22 +305,22 @@
    */
   public Icon getIcon()
   {
-    return activeIcon;
+    return icon;
   }
 
   /**
    * This method changes the "icon" property. This icon (the active icon) will
    * be the one displayed when the label is enabled.
    *
-   * @param icon The active icon.
+   * @param newIcon The active icon.
    */
-  public void setIcon(Icon icon)
+  public void setIcon(Icon newIcon)
   {
-    if (icon != activeIcon)
+    if (icon != newIcon)
       {
-	Icon oldIcon = activeIcon;
-	activeIcon = icon;
-	firePropertyChange(ICON_CHANGED_PROPERTY, oldIcon, activeIcon);
+	Icon oldIcon = icon;
+	icon = newIcon;
+	firePropertyChange(ICON_CHANGED_PROPERTY, oldIcon, newIcon);
       }
   }
 
@@ -331,8 +334,9 @@
    */
   public Icon getDisabledIcon()
   {
-    if (disabledIcon == null && activeIcon instanceof ImageIcon)
-      disabledIcon = new ImageIcon(GrayFilter.createDisabledImage(((ImageIcon) activeIcon).getImage()));
+    if (disabledIcon == null && icon instanceof ImageIcon)
+      disabledIcon = new ImageIcon(GrayFilter.createDisabledImage(((ImageIcon) icon).getImage()));
+    
     return disabledIcon;
   }
 
@@ -340,16 +344,15 @@
    * This method changes the "disabledIcon" property. This icon (the disabled
    * icon) will be the one displayed when the label is disabled.
    *
-   * @param disabledIcon The disabled icon.
+   * @param newIcon The disabled icon.
    */
-  public void setDisabledIcon(Icon disabledIcon)
+  public void setDisabledIcon(Icon newIcon)
   {
-    if (disabledIcon != this.disabledIcon)
+    if (disabledIcon != newIcon)
       {
-	Icon oldDisabledIcon = this.disabledIcon;
-	this.disabledIcon = disabledIcon;
-	firePropertyChange(DISABLED_ICON_CHANGED_PROPERTY, oldDisabledIcon,
-	                   this.disabledIcon);
+	Icon oldIcon = disabledIcon;
+	disabledIcon = newIcon;
+	firePropertyChange(DISABLED_ICON_CHANGED_PROPERTY, oldIcon, newIcon);
       }
   }
 
@@ -358,13 +361,22 @@
    * label is used as a label for another component, the label will give
    * focus to that component when the mnemonic is activated.
    *
-   * @param key The keycode to use for the mnemonic.
+   * @param mnemonic The keycode to use for the mnemonic.
    */
-  public void setDisplayedMnemonic(int key)
+  public void setDisplayedMnemonic(int mnemonic)
+  {
+    if (displayedMnemonic != mnemonic)
   {
-    setDisplayedMnemonic((char) key);
+	firePropertyChange(DISPLAYED_MNEMONIC_CHANGED_PROPERTY,
+                           displayedMnemonic, mnemonic);
+	displayedMnemonic = mnemonic;
+        
+	if (text != null)
+	  setDisplayedMnemonicIndex(text.indexOf(mnemonic));
+      }
   }
 
+
   /**
    * This method sets the character that will be the mnemonic used. If the
    * label is used as a label for another component, the label will give
@@ -370,19 +382,11 @@
    * label is used as a label for another component, the label will give
    * focus to that component when the mnemonic is activated.
    *
-   * @param aChar The character to use for the mnemonic.
+   * @param menmonic The character to use for the mnemonic.
    */
-  public void setDisplayedMnemonic(char aChar)
-  {
-    if (aChar != mnemonicKey)
+  public void setDisplayedMnemonic(char mnemonic)
       {
-	char oldKey = mnemonicKey;
-	mnemonicKey = aChar;
-	firePropertyChange(DISPLAYED_MNEMONIC_CHANGED_PROPERTY, oldKey,
-	                   mnemonicKey);
-	if (labelText != null)
-	  setDisplayedMnemonicIndex(labelText.indexOf(mnemonicKey));
-      }
+    setDisplayedMnemonic((int) mnemonic);
   }
 
   /**
@@ -392,7 +396,7 @@
    */
   public int getDisplayedMnemonic()
   {
-    return (int) mnemonicKey;
+    return (int) displayedMnemonic;
   }
 
   /**
@@ -401,26 +405,25 @@
    * no mnemonic. If the index is less than -1 or if the index is equal to
    * the length, this method will throw an IllegalArgumentException.
    *
-   * @param index The index of the character to underline.
+   * @param newIndex The index of the character to underline.
    *
    * @throws IllegalArgumentException If index less than -1 or index equals
    *         length.
    */
-  public void setDisplayedMnemonicIndex(int index)
+  public void setDisplayedMnemonicIndex(int newIndex)
                                  throws IllegalArgumentException
   {
-    if (index < -1 || labelText != null && index >= labelText.length())
+    if (newIndex < -1 || (text != null && newIndex >= text.length()))
       throw new IllegalArgumentException();
       
-    if (labelText == null || labelText.charAt(index) != mnemonicKey)
-      index = -1;
+    if (text == null || text.charAt(newIndex) != displayedMnemonic)
+      newIndex = -1;
       
-    if (index != underlinedChar)
+    if (newIndex != displayedMnemonicIndex)
     {
-      int oldIndex = underlinedChar;  
-      underlinedChar = index;
       firePropertyChange(DISPLAYED_MNEMONIC_INDEX_CHANGED_PROPERTY,
-                         oldIndex, underlinedChar);
+                           displayedMnemonicIndex, newIndex);
+        displayedMnemonicIndex = newIndex;
     }
   }
 
@@ -432,7 +435,7 @@
    */
   public int getDisplayedMnemonicIndex()
   {
-    return underlinedChar;
+    return displayedMnemonicIndex;
   }
 
   /**
@@ -490,16 +493,15 @@
    * This method changes the "iconTextGap" property. The iconTextGap
    * determines how much space there is between the icon and the text.
    *
-   * @param iconTextGap The gap between the icon and the text.
+   * @param newGap The gap between the icon and the text.
    */
-  public void setIconTextGap(int iconTextGap)
+  public void setIconTextGap(int newGap)
   {
-    if (iconTextGap != this.iconTextGap)
+    if (iconTextGap != newGap)
       {
-	int oldIconTextGap = this.iconTextGap;
-	this.iconTextGap = iconTextGap;
-	firePropertyChange(ICON_TEXT_GAP_CHANGED_PROPERTY, oldIconTextGap,
-	                   iconTextGap);
+	firePropertyChange(ICON_TEXT_GAP_CHANGED_PROPERTY, iconTextGap,
+	                   newGap);
+	iconTextGap = newGap;
       }
   }
 
@@ -632,11 +634,12 @@
   public boolean imageUpdate(Image img, int infoflags, int x, int y, int w,
                              int h)
   {
-    Icon currIcon = (isEnabled()) ? activeIcon : disabledIcon;
+    Icon currIcon = isEnabled() ? icon : disabledIcon;
 
-    //Is this the correct way to check for image equality?
+    // XXX: Is this the correct way to check for image equality?
     if (currIcon != null && currIcon instanceof ImageIcon)
       return (((ImageIcon) currIcon).getImage() == img);
+    
     return false;
   }
 
@@ -664,9 +667,8 @@
   {
     if (c != labelFor)
       {
-	Component oldLabelFor = labelFor;
+	firePropertyChange(LABEL_FOR_CHANGED_PROPERTY, labelFor, c);
 	labelFor = c;
-	firePropertyChange(LABEL_FOR_CHANGED_PROPERTY, oldLabelFor, labelFor);
       }
   }
   
Index: javax/swing/JRadioButton.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/javax/swing/JRadioButton.java,v
retrieving revision 1.3.2.3
diff -u -b -B -r1.3.2.3 JRadioButton.java
--- javax/swing/JRadioButton.java	30 Jul 2004 21:34:34 -0000	1.3.2.3
+++ javax/swing/JRadioButton.java	11 Aug 2004 13:53:42 -0000
@@ -48,6 +48,7 @@
     {
 	this(null, null);
     }
+    
     public JRadioButton(Action a)
     {
 	this();
@@ -59,11 +60,21 @@
 	this(null, icon);
     }    
   
+  public JRadioButton(Icon icon, boolean selected)
+  { 
+    this(null, icon, selected);
+  }    
+  
     public JRadioButton(String text)
     {
 	this(text, null);
     }
       
+  public JRadioButton(String text, boolean selected)
+  {
+    this(text, null, selected);
+  }
+      
     public JRadioButton(String text, Icon icon)
     {
 	super(text, icon);
@@ -71,6 +82,9 @@
         contentAreaFilled = false;
     }
 
+  public JRadioButton(String text, Icon icon, boolean selected)
+  {
+  }
     
     public AccessibleContext getAccessibleContext()
     {
Index: javax/swing/JTextField.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/javax/swing/JTextField.java,v
retrieving revision 1.2.18.6
diff -u -b -B -r1.2.18.6 JTextField.java
--- javax/swing/JTextField.java	20 Jul 2004 19:36:47 -0000	1.2.18.6
+++ javax/swing/JTextField.java	11 Aug 2004 13:53:42 -0000
@@ -138,9 +138,15 @@
    */
   public JTextField(Document doc, String text, int columns)
   {
+    if (columns < 0)
+      throw new IllegalArgumentException();
+    
+    this.columns = columns;
+    
     setDocument(doc == null ? createDefaultModel() : doc);
+
+    if (text != null)
     setText(text);
-    setColumns(columns);
   }
 
   /**

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