/* AbstractButton.java -- Provides basic button functionality.
- Copyright (C) 2002, 2004 Free Software Foundation, Inc.
+ Copyright (C) 2002, 2004, 2006, Free Software Foundation, Inc.
This file is part of GNU Classpath.
Icon pressed_icon;
/** The icon displayed when the button is disabled. */
- Icon disabeldIcon;
+ Icon disabledIcon;
/** The icon displayed when the button is selected. */
Icon selectedIcon;
protected ChangeListener changeListener;
/**
- * The time in miliseconds in which clicks get coalesced into a single
+ * The time in milliseconds in which clicks get coalesced into a single
* <code>ActionEvent</code>.
*/
long multiClickThreshhold;
* {@link AccessibleState#FOCUSED}, {@link AccessibleState#PRESSED} and
* {@link AccessibleState#CHECKED}.
*
- * @return the curren state of this accessible object
+ * @return the current state of this accessible object
*/
public AccessibleStateSet getAccessibleStateSet()
{
* Returns the minimum accessible value for the AccessibleAbstractButton,
* which is <code>0</code>.
*
- * @return the maxinimum accessible value for the AccessibleAbstractButton,
- * which is <code>1</code>
+ * @return the minimimum accessible value for the AccessibleAbstractButton,
+ * which is <code>0</code>
*/
public Number getMinimumAccessibleValue()
{
// constructor).
// This way the behavior of the JDK is matched.
if(text != null)
- this.text = text;
+ setText(text);
if (icon != null)
default_icon = icon;
* alignment is a numeric constant from {@link SwingConstants}. It must
* be one of: <code>RIGHT</code>, <code>LEFT</code>, <code>CENTER</code>,
* <code>LEADING</code> or <code>TRAILING</code>. The default is
- * <code>RIGHT</code>.
+ * <code>CENTER</code>.
*
* @return The current horizontal alignment
+ *
+ * @see #setHorizontalAlignment(int)
*/
public int getHorizontalAlignment()
{
* alignment is a numeric constant from {@link SwingConstants}. It must
* be one of: <code>RIGHT</code>, <code>LEFT</code>, <code>CENTER</code>,
* <code>LEADING</code> or <code>TRAILING</code>. The default is
- * <code>RIGHT</code>.
+ * <code>CENTER</code>.
*
* @param a The new horizontal alignment
* @throws IllegalArgumentException If alignment is not one of the legal
* constants.
+ *
+ * @see #getHorizontalAlignment()
*/
public void setHorizontalAlignment(int a)
{
if (horizontalAlignment == a)
return;
-
+ if (a != LEFT && a != CENTER && a != RIGHT && a != LEADING
+ && a != TRAILING)
+ throw new IllegalArgumentException("Invalid alignment.");
int old = horizontalAlignment;
horizontalAlignment = a;
firePropertyChange(HORIZONTAL_ALIGNMENT_CHANGED_PROPERTY, old, a);
{
if (horizontalTextPosition == t)
return;
+ if (t != LEFT && t != CENTER && t != RIGHT && t != LEADING
+ && t != TRAILING)
+ throw new IllegalArgumentException("Invalid alignment.");
int old = horizontalTextPosition;
horizontalTextPosition = t;
* <code>BOTTOM</code>. The default is <code>CENTER</code>.
*
* @return The current vertical alignment
+ *
+ * @see #setVerticalAlignment(int)
*/
public int getVerticalAlignment()
{
* @param a The new vertical alignment
* @throws IllegalArgumentException If alignment is not one of the legal
* constants.
+ *
+ * @see #getVerticalAlignment()
*/
public void setVerticalAlignment(int a)
{
if (verticalAlignment == a)
return;
-
+ if (a != TOP && a != CENTER && a != BOTTOM)
+ throw new IllegalArgumentException("Invalid alignment.");
+
int old = verticalAlignment;
verticalAlignment = a;
firePropertyChange(VERTICAL_ALIGNMENT_CHANGED_PROPERTY, old, a);
{
if (verticalTextPosition == t)
return;
+ if (t != TOP && t != CENTER && t != BOTTOM)
+ throw new IllegalArgumentException("Invalid alignment.");
int old = verticalTextPosition;
verticalTextPosition = t;
*/
public Icon getDisabledIcon()
{
- if (disabeldIcon == null && default_icon instanceof ImageIcon)
+ if (disabledIcon == null && default_icon instanceof ImageIcon)
{
Image iconImage = ((ImageIcon) default_icon).getImage();
Image grayImage = GrayFilter.createDisabledImage(iconImage);
- disabeldIcon = new ImageIcon(grayImage);
+ disabledIcon = new ImageIcon(grayImage);
}
- return disabeldIcon;
+ return disabledIcon;
}
/**
*/
public void setDisabledIcon(Icon d)
{
- disabeldIcon = d;
+ if (disabledIcon == d)
+ return;
+ Icon old = disabledIcon;
+ disabledIcon = d;
+ firePropertyChange(DISABLED_ICON_CHANGED_PROPERTY, old, d);
revalidate();
repaint();
}
}
/**
- * Set the button's rollover icon. The look and feel class should
+ * Set the button's rollover icon and sets the <code>rolloverEnabled</code>
+ * property to <code>true</code>. The look and feel class should
* paint this icon when the "rolloverEnabled" property of the button is
* <code>true</code> and the mouse rolls over the button.
*
Icon old = rolloverIcon;
rolloverIcon = r;
firePropertyChange(ROLLOVER_ICON_CHANGED_PROPERTY, old, rolloverIcon);
+ setRolloverEnabled(true);
revalidate();
repaint();
}
}
/**
- * Set the button's rollover selected icon. The look and feel class
- * should paint this icon when the "rolloverEnabled" property of the button
- * is <code>true</code>, the "selected" property of the button's model is
- * <code>true</code>, and the mouse rolls over the button.
+ * Set the button's rollover selected icon and sets the
+ * <code>rolloverEnabled</code> property to <code>true</code>. The look and
+ * feel class should paint this icon when the "rolloverEnabled" property of
+ * the button is <code>true</code>, the "selected" property of the button's
+ * model is <code>true</code>, and the mouse rolls over the button.
*
- * @param r The new rollover selected icon
+ * @param r The new rollover selected icon.
*/
public void setRolloverSelectedIcon(Icon r)
{
Icon old = rolloverSelectedIcon;
rolloverSelectedIcon = r;
firePropertyChange(ROLLOVER_SELECTED_ICON_CHANGED_PROPERTY, old, r);
+ setRolloverEnabled(true);
revalidate();
repaint();
}