diff options
Diffstat (limited to 'libjava/javax/swing/JLabel.java')
-rw-r--r-- | libjava/javax/swing/JLabel.java | 107 |
1 files changed, 30 insertions, 77 deletions
diff --git a/libjava/javax/swing/JLabel.java b/libjava/javax/swing/JLabel.java index b3d7225..c01d811 100644 --- a/libjava/javax/swing/JLabel.java +++ b/libjava/javax/swing/JLabel.java @@ -1,5 +1,5 @@ /* JLabel.java -- - Copyright (C) 2002, 2004 Free Software Foundation, Inc. + Copyright (C) 2002, 2004, 2005 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -92,59 +92,6 @@ public class JLabel extends JComponent implements Accessible, SwingConstants private transient int iconTextGap = 4; /** - * Fired in a PropertyChangeEvent when the "disabledIcon" property changes. - */ - public static final String DISABLED_ICON_CHANGED_PROPERTY = "disabledIcon"; - - /** - * Fired in a PropertyChangeEvent when the "displayedMnemonic" property - * changes. - */ - public static final String DISPLAYED_MNEMONIC_CHANGED_PROPERTY = "displayedMnemonic"; - - /** - * Fired in a PropertyChangeEvent when the "displayedMnemonicIndex" property - * changes. - */ - public static final String DISPLAYED_MNEMONIC_INDEX_CHANGED_PROPERTY = "displayedMnemonicIndex"; - - /** - * Fired in a PropertyChangeEvent when the "horizontalAlignment" property - * changes. - */ - public static final String HORIZONTAL_ALIGNMENT_CHANGED_PROPERTY = "horizontalAlignment"; - - /** - * Fired in a PropertyChangeEvent when the "horizontalTextPosition" property - * changes. - */ - public static final String HORIZONTAL_TEXT_POSITION_CHANGED_PROPERTY = "horizontalTextPosition"; - - /** Fired in a PropertyChangeEvent when the "icon" property changes. */ - public static final String ICON_CHANGED_PROPERTY = "icon"; - - /** Fired in a PropertyChangeEvent when the "iconTextGap" property changes. */ - public static final String ICON_TEXT_GAP_CHANGED_PROPERTY = "iconTextGap"; - - /** Fired in a PropertyChangeEvent when the "labelFor" property changes. */ - public static final String LABEL_FOR_CHANGED_PROPERTY = "labelFor"; - - /** Fired in a PropertyChangeEvent when the "text" property changes. */ - public static final String TEXT_CHANGED_PROPERTY = "text"; - - /** - * Fired in a PropertyChangeEvent when the "verticalAlignment" property - * changes. - */ - public static final String VERTICAL_ALIGNMENT_CHANGED_PROPERTY = "verticalAlignment"; - - /** - * Fired in a PropertyChangeEvent when the "verticalTextPosition" property - * changes. - */ - public static final String VERTICAL_TEXT_POSITION_CHANGED_PROPERTY = "verticalTextPosition"; - - /** * Creates a new horizontally and vertically centered JLabel object with no * text and no icon. */ @@ -289,7 +236,7 @@ public class JLabel extends JComponent implements Accessible, SwingConstants { String oldText = text; text = newText; - firePropertyChange(TEXT_CHANGED_PROPERTY, oldText, newText); + firePropertyChange("text", oldText, newText); if (text != null && text.length() <= displayedMnemonicIndex) setDisplayedMnemonicIndex(text.length() - 1); @@ -319,7 +266,7 @@ public class JLabel extends JComponent implements Accessible, SwingConstants { Icon oldIcon = icon; icon = newIcon; - firePropertyChange(ICON_CHANGED_PROPERTY, oldIcon, newIcon); + firePropertyChange("icon", oldIcon, newIcon); } } @@ -352,7 +299,7 @@ public class JLabel extends JComponent implements Accessible, SwingConstants { Icon oldIcon = disabledIcon; disabledIcon = newIcon; - firePropertyChange(DISABLED_ICON_CHANGED_PROPERTY, oldIcon, newIcon); + firePropertyChange("disabledIcon", oldIcon, newIcon); } } @@ -367,12 +314,12 @@ public class JLabel extends JComponent implements Accessible, SwingConstants { if (displayedMnemonic != mnemonic) { - firePropertyChange(DISPLAYED_MNEMONIC_CHANGED_PROPERTY, + firePropertyChange("displayedMnemonic", displayedMnemonic, mnemonic); displayedMnemonic = mnemonic; if (text != null) - setDisplayedMnemonicIndex(text.indexOf(mnemonic)); + setDisplayedMnemonicIndex(text.toUpperCase().indexOf(mnemonic)); } } @@ -385,7 +332,7 @@ public class JLabel extends JComponent implements Accessible, SwingConstants */ public void setDisplayedMnemonic(char mnemonic) { - setDisplayedMnemonic((int) mnemonic); + setDisplayedMnemonic((int) Character.toUpperCase(mnemonic)); } /** @@ -399,7 +346,7 @@ public class JLabel extends JComponent implements Accessible, SwingConstants } /** - * This method sets which character in the text will be the underlined + * This method sets which character in the text will be the underlined * character. If the given index is -1, then this indicates that there is * no mnemonic. If the index is less than -1 or if the index is equal to * the length, this method will throw an IllegalArgumentException. @@ -410,19 +357,22 @@ public class JLabel extends JComponent implements Accessible, SwingConstants * length. */ public void setDisplayedMnemonicIndex(int newIndex) - throws IllegalArgumentException + throws IllegalArgumentException { if (newIndex < -1 || (text != null && newIndex >= text.length())) throw new IllegalArgumentException(); - if (text == null || text.charAt(newIndex) != displayedMnemonic) + if (newIndex == -1 + || text == null + || text.charAt(newIndex) != displayedMnemonic) newIndex = -1; if (newIndex != displayedMnemonicIndex) { - firePropertyChange(DISPLAYED_MNEMONIC_INDEX_CHANGED_PROPERTY, - displayedMnemonicIndex, newIndex); + int oldIndex = displayedMnemonicIndex; displayedMnemonicIndex = newIndex; + firePropertyChange("displayedMnemonicIndex", + oldIndex, newIndex); } } @@ -498,7 +448,7 @@ public class JLabel extends JComponent implements Accessible, SwingConstants { if (iconTextGap != newGap) { - firePropertyChange(ICON_TEXT_GAP_CHANGED_PROPERTY, iconTextGap, newGap); + firePropertyChange("iconTextGap", iconTextGap, newGap); iconTextGap = newGap; } } @@ -523,13 +473,12 @@ public class JLabel extends JComponent implements Accessible, SwingConstants */ public void setVerticalAlignment(int alignment) { - if (alignment != verticalAlignment) - { - int oldAlignment = verticalAlignment; - verticalAlignment = checkVerticalKey(alignment, "verticalAlignment"); - firePropertyChange(VERTICAL_ALIGNMENT_CHANGED_PROPERTY, oldAlignment, - verticalAlignment); - } + if (alignment == verticalAlignment) + return; + + int oldAlignment = verticalAlignment; + verticalAlignment = checkVerticalKey(alignment, "verticalAlignment"); + firePropertyChange("verticalAlignment", oldAlignment, verticalAlignment); } /** @@ -550,9 +499,12 @@ public class JLabel extends JComponent implements Accessible, SwingConstants */ public void setHorizontalAlignment(int alignment) { + if (horizontalAlignment == alignment) + return; + int oldAlignment = horizontalAlignment; horizontalAlignment = checkHorizontalKey(alignment, "horizontalAlignment"); - firePropertyChange(HORIZONTAL_ALIGNMENT_CHANGED_PROPERTY, oldAlignment, + firePropertyChange("horizontalAlignment", oldAlignment, horizontalAlignment); } @@ -580,7 +532,7 @@ public class JLabel extends JComponent implements Accessible, SwingConstants int oldPos = verticalTextPosition; verticalTextPosition = checkVerticalKey(textPosition, "verticalTextPosition"); - firePropertyChange(VERTICAL_TEXT_POSITION_CHANGED_PROPERTY, oldPos, + firePropertyChange("verticalTextPosition", oldPos, verticalTextPosition); } } @@ -609,7 +561,7 @@ public class JLabel extends JComponent implements Accessible, SwingConstants int oldPos = horizontalTextPosition; horizontalTextPosition = checkHorizontalKey(textPosition, "horizontalTextPosition"); - firePropertyChange(HORIZONTAL_TEXT_POSITION_CHANGED_PROPERTY, oldPos, + firePropertyChange("horizontalTextPosition", oldPos, horizontalTextPosition); } } @@ -665,8 +617,9 @@ public class JLabel extends JComponent implements Accessible, SwingConstants { if (c != labelFor) { - firePropertyChange(LABEL_FOR_CHANGED_PROPERTY, labelFor, c); + Component oldLabelFor = labelFor; labelFor = c; + firePropertyChange("labelFor", oldLabelFor, labelFor); } } |