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] FYI: fixes to JLabel


Hi,

Committing this to gui branch.

Cheers,

Kim

2004-02-17  Kim Ho  <kho@redhat.com>

	* javax/swing/JLabel.java: Changed 
	property strings to constants.
	(DISPLAYED_MNEMONIC_INDEX_CHANGED_PROPERTY):
	New property.
	(setText): Change mnemonic index if
	text is too short.
	(setDisplayedMnemonicIndex): Fire property
	change event.
	(getDisplayedMnemonicIndex): Remove check
	against short text.
Index: javax/swing/JLabel.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/javax/swing/JLabel.java,v
retrieving revision 1.4.2.1
diff -u -r1.4.2.1 JLabel.java
--- javax/swing/JLabel.java	16 Feb 2004 17:04:38 -0000	1.4.2.1
+++ javax/swing/JLabel.java	17 Feb 2004 17:06:12 -0000
@@ -95,49 +95,54 @@
   /**
    * Fired in a PropertyChangeEvent when the "disabledIcon" property changes.
    */
-  public static String DISABLED_ICON_CHANGED_PROPERTY = "disabledIcon";
+  public final static String DISABLED_ICON_CHANGED_PROPERTY = "disabledIcon";
 
   /**
    * Fired in a PropertyChangeEvent when the "displayedMnemonic" property
    * changes.
    */
-  public static String DISPLAYED_MNEMONIC_CHANGED_PROPERTY = "displayedMnemonic";
+  public final static String DISPLAYED_MNEMONIC_CHANGED_PROPERTY = "displayedMnemonic";
+  
+  /**
+   * Fired in a PropertyChangeEvent when the "displayedMnemonicIndex"
+   * property changes. */
+  public final static String DISPLAYED_MNEMONIC_INDEX_CHANGED_PROPERTY = "displayedMnemonicIndex";
 
   /**
    * Fired in a PropertyChangeEvent when the "horizontalAlignment" property
    * changes.
    */
-  public static String HORIZONTAL_ALIGNMENT_CHANGED_PROPERTY = "horizontalAlignment";
+  public final static String HORIZONTAL_ALIGNMENT_CHANGED_PROPERTY = "horizontalAlignment";
 
   /**
    * Fired in a PropertyChangeEvent when the "horizontalTextPosition" property
    * changes.
    */
-  public static String HORIZONTAL_TEXT_POSITION_CHANGED_PROPERTY = "horizontalTextPosition";
+  public final static String HORIZONTAL_TEXT_POSITION_CHANGED_PROPERTY = "horizontalTextPosition";
 
   /** Fired in a PropertyChangeEvent when the "icon" property changes. */
-  public static String ICON_CHANGED_PROPERTY = "icon";
+  public final static String ICON_CHANGED_PROPERTY = "icon";
 
   /** Fired in a PropertyChangeEvent when the "iconTextGap" property changes. */
-  public static String ICON_TEXT_GAP_CHANGED_PROPERTY = "iconTextGap";
+  public final static String ICON_TEXT_GAP_CHANGED_PROPERTY = "iconTextGap";
 
   /** Fired in a PropertyChangeEvent when the "labelFor" property changes. */
-  public static String LABEL_FOR_CHANGED_PROPERTY = "labelFor";
+  public final static String LABEL_FOR_CHANGED_PROPERTY = "labelFor";
 
   /** Fired in a PropertyChangeEvent when the "text" property changes. */
-  public static String TEXT_CHANGED_PROPERTY = "text";
+  public final static String TEXT_CHANGED_PROPERTY = "text";
 
   /**
    * Fired in a PropertyChangeEvent when the "verticalAlignment" property
    * changes.
    */
-  public static String VERTICAL_ALIGNMENT_CHANGED_PROPERTY = "verticalAlignment";
+  public final static String VERTICAL_ALIGNMENT_CHANGED_PROPERTY = "verticalAlignment";
 
   /**
    * Fired in a PropertyChangeEvent when the "verticalTextPosition" property
    * changes.
    */
-  public static String VERTICAL_TEXT_POSITION_CHANGED_PROPERTY = "verticalTextPosition";
+  public final static String VERTICAL_TEXT_POSITION_CHANGED_PROPERTY = "verticalTextPosition";
 
   /**
    * Creates a new horizontally and vertically centered JLabel object with no text and no
@@ -284,6 +289,8 @@
 	String oldText = labelText;
 	labelText = text;
 	firePropertyChange(TEXT_CHANGED_PROPERTY, oldText, labelText);
+	if (labelText.length() <= underlinedChar)
+	  setDisplayedMnemonicIndex(labelText.length() - 1);
       }
   }
 
@@ -403,18 +410,19 @@
   public void setDisplayedMnemonicIndex(int index)
                                  throws IllegalArgumentException
   {
-    if (labelText == null)
-      {
-	underlinedChar = -1;
-	return;
-      }
-    if (index < -1 || index >= labelText.length())
+    if (index < -1 || labelText != null && index >= labelText.length())
       throw new IllegalArgumentException();
-
-    if (index == -1 || labelText.charAt(index) != mnemonicKey)
-      underlinedChar = -1;
-    else
+      
+    if (labelText == null || labelText.charAt(index) != mnemonicKey)
+      index = -1;
+      
+    if (index != underlinedChar)
+    {
+      int oldIndex = underlinedChar;  
       underlinedChar = index;
+      firePropertyChange(DISPLAYED_MNEMONIC_INDEX_CHANGED_PROPERTY,
+                         oldIndex, underlinedChar);
+    }
   }
 
   /**
@@ -425,8 +433,6 @@
    */
   public int getDisplayedMnemonicIndex()
   {
-    if (labelText.length() - 1 < underlinedChar)
-      underlinedChar = labelText.length() - 1;
     return underlinedChar;
   }
 

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