0N/A/*
3909N/A * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/Apackage javax.swing;
0N/A
0N/Aimport java.awt.*;
0N/Aimport java.awt.event.*;
0N/Aimport java.awt.image.*;
0N/Aimport java.text.*;
0N/Aimport java.awt.geom.*;
243N/Aimport java.beans.PropertyChangeEvent;
243N/Aimport java.beans.PropertyChangeListener;
243N/Aimport java.beans.Transient;
0N/Aimport java.util.Enumeration;
0N/Aimport java.util.Vector;
0N/Aimport java.io.Serializable;
0N/Aimport javax.swing.event.*;
0N/Aimport javax.swing.border.*;
0N/Aimport javax.swing.plaf.*;
0N/Aimport javax.accessibility.*;
0N/Aimport javax.swing.text.*;
0N/Aimport javax.swing.text.html.*;
0N/Aimport javax.swing.plaf.basic.*;
0N/Aimport java.util.*;
0N/A
0N/A/**
0N/A * Defines common behaviors for buttons and menu items.
0N/A * <p>
0N/A * Buttons can be configured, and to some degree controlled, by
0N/A * <code><a href="Action.html">Action</a></code>s. Using an
0N/A * <code>Action</code> with a button has many benefits beyond directly
0N/A * configuring a button. Refer to <a href="Action.html#buttonActions">
0N/A * Swing Components Supporting <code>Action</code></a> for more
0N/A * details, and you can find more information in <a
0N/A * href="http://java.sun.com/docs/books/tutorial/uiswing/misc/action.html">How
0N/A * to Use Actions</a>, a section in <em>The Java Tutorial</em>.
0N/A * <p>
0N/A * For further information see
0N/A * <a
0N/A href="http://java.sun.com/docs/books/tutorial/uiswing/components/button.html">How to Use Buttons, Check Boxes, and Radio Buttons</a>,
0N/A * a section in <em>The Java Tutorial</em>.
0N/A * <p>
0N/A * <strong>Warning:</strong>
0N/A * Serialized objects of this class will not be compatible with
0N/A * future Swing releases. The current serialization support is
0N/A * appropriate for short term storage or RMI between applications running
0N/A * the same version of Swing. As of 1.4, support for long term storage
0N/A * of all JavaBeans<sup><font size="-2">TM</font></sup>
0N/A * has been added to the <code>java.beans</code> package.
0N/A * Please see {@link java.beans.XMLEncoder}.
0N/A *
0N/A * @author Jeff Dinkins
0N/A */
0N/Apublic abstract class AbstractButton extends JComponent implements ItemSelectable, SwingConstants {
0N/A
0N/A // *********************************
0N/A // ******* Button properties *******
0N/A // *********************************
0N/A
0N/A /** Identifies a change in the button model. */
0N/A public static final String MODEL_CHANGED_PROPERTY = "model";
0N/A /** Identifies a change in the button's text. */
0N/A public static final String TEXT_CHANGED_PROPERTY = "text";
0N/A /** Identifies a change to the button's mnemonic. */
0N/A public static final String MNEMONIC_CHANGED_PROPERTY = "mnemonic";
0N/A
0N/A // Text positioning and alignment
0N/A /** Identifies a change in the button's margins. */
0N/A public static final String MARGIN_CHANGED_PROPERTY = "margin";
0N/A /** Identifies a change in the button's vertical alignment. */
0N/A public static final String VERTICAL_ALIGNMENT_CHANGED_PROPERTY = "verticalAlignment";
0N/A /** Identifies a change in the button's horizontal alignment. */
0N/A public static final String HORIZONTAL_ALIGNMENT_CHANGED_PROPERTY = "horizontalAlignment";
0N/A
0N/A /** Identifies a change in the button's vertical text position. */
0N/A public static final String VERTICAL_TEXT_POSITION_CHANGED_PROPERTY = "verticalTextPosition";
0N/A /** Identifies a change in the button's horizontal text position. */
0N/A public static final String HORIZONTAL_TEXT_POSITION_CHANGED_PROPERTY = "horizontalTextPosition";
0N/A
0N/A // Paint options
0N/A /**
0N/A * Identifies a change to having the border drawn,
0N/A * or having it not drawn.
0N/A */
0N/A public static final String BORDER_PAINTED_CHANGED_PROPERTY = "borderPainted";
0N/A /**
0N/A * Identifies a change to having the border highlighted when focused,
0N/A * or not.
0N/A */
0N/A public static final String FOCUS_PAINTED_CHANGED_PROPERTY = "focusPainted";
0N/A /**
0N/A * Identifies a change from rollover enabled to disabled or back
0N/A * to enabled.
0N/A */
0N/A public static final String ROLLOVER_ENABLED_CHANGED_PROPERTY = "rolloverEnabled";
0N/A /**
0N/A * Identifies a change to having the button paint the content area.
0N/A */
0N/A public static final String CONTENT_AREA_FILLED_CHANGED_PROPERTY = "contentAreaFilled";
0N/A
0N/A // Icons
0N/A /** Identifies a change to the icon that represents the button. */
0N/A public static final String ICON_CHANGED_PROPERTY = "icon";
0N/A
0N/A /**
0N/A * Identifies a change to the icon used when the button has been
0N/A * pressed.
0N/A */
0N/A public static final String PRESSED_ICON_CHANGED_PROPERTY = "pressedIcon";
0N/A /**
0N/A * Identifies a change to the icon used when the button has
0N/A * been selected.
0N/A */
0N/A public static final String SELECTED_ICON_CHANGED_PROPERTY = "selectedIcon";
0N/A
0N/A /**
0N/A * Identifies a change to the icon used when the cursor is over
0N/A * the button.
0N/A */
0N/A public static final String ROLLOVER_ICON_CHANGED_PROPERTY = "rolloverIcon";
0N/A /**
0N/A * Identifies a change to the icon used when the cursor is
0N/A * over the button and it has been selected.
0N/A */
0N/A public static final String ROLLOVER_SELECTED_ICON_CHANGED_PROPERTY = "rolloverSelectedIcon";
0N/A
0N/A /**
0N/A * Identifies a change to the icon used when the button has
0N/A * been disabled.
0N/A */
0N/A public static final String DISABLED_ICON_CHANGED_PROPERTY = "disabledIcon";
0N/A /**
0N/A * Identifies a change to the icon used when the button has been
0N/A * disabled and selected.
0N/A */
0N/A public static final String DISABLED_SELECTED_ICON_CHANGED_PROPERTY = "disabledSelectedIcon";
0N/A
0N/A
0N/A /** The data model that determines the button's state. */
0N/A protected ButtonModel model = null;
0N/A
0N/A private String text = ""; // for BeanBox
0N/A private Insets margin = null;
0N/A private Insets defaultMargin = null;
0N/A
0N/A // Button icons
0N/A // PENDING(jeff) - hold icons in an array
0N/A private Icon defaultIcon = null;
0N/A private Icon pressedIcon = null;
0N/A private Icon disabledIcon = null;
0N/A
0N/A private Icon selectedIcon = null;
0N/A private Icon disabledSelectedIcon = null;
0N/A
0N/A private Icon rolloverIcon = null;
0N/A private Icon rolloverSelectedIcon = null;
0N/A
0N/A // Display properties
0N/A private boolean paintBorder = true;
0N/A private boolean paintFocus = true;
0N/A private boolean rolloverEnabled = false;
0N/A private boolean contentAreaFilled = true;
0N/A
0N/A // Icon/Label Alignment
0N/A private int verticalAlignment = CENTER;
0N/A private int horizontalAlignment = CENTER;
0N/A
0N/A private int verticalTextPosition = CENTER;
0N/A private int horizontalTextPosition = TRAILING;
0N/A
0N/A private int iconTextGap = 4;
0N/A
0N/A private int mnemonic;
0N/A private int mnemonicIndex = -1;
0N/A
0N/A private long multiClickThreshhold = 0;
0N/A
0N/A private boolean borderPaintedSet = false;
0N/A private boolean rolloverEnabledSet = false;
0N/A private boolean iconTextGapSet = false;
0N/A private boolean contentAreaFilledSet = false;
0N/A
0N/A // Whether or not we've set the LayoutManager.
0N/A private boolean setLayout = false;
0N/A
0N/A // This is only used by JButton, promoted to avoid an extra
0N/A // boolean field in JButton
0N/A boolean defaultCapable = true;
0N/A
0N/A /**
0N/A * Combined listeners: ActionListener, ChangeListener, ItemListener.
0N/A */
0N/A private Handler handler;
0N/A
0N/A /**
0N/A * The button model's <code>changeListener</code>.
0N/A */
0N/A protected ChangeListener changeListener = null;
0N/A /**
0N/A * The button model's <code>ActionListener</code>.
0N/A */
0N/A protected ActionListener actionListener = null;
0N/A /**
0N/A * The button model's <code>ItemListener</code>.
0N/A */
0N/A protected ItemListener itemListener = null;
0N/A
0N/A /**
0N/A * Only one <code>ChangeEvent</code> is needed per button
0N/A * instance since the
0N/A * event's only state is the source property. The source of events
0N/A * generated is always "this".
0N/A */
0N/A protected transient ChangeEvent changeEvent;
0N/A
0N/A private boolean hideActionText = false;
0N/A
0N/A /**
0N/A * Sets the <code>hideActionText</code> property, which determines
0N/A * whether the button displays text from the <code>Action</code>.
0N/A * This is useful only if an <code>Action</code> has been
0N/A * installed on the button.
0N/A *
0N/A * @param hideActionText <code>true</code> if the button's
0N/A * <code>text</code> property should not reflect
0N/A * that of the <code>Action</code>; the default is
0N/A * <code>false</code>
0N/A * @see <a href="Action.html#buttonActions">Swing Components Supporting
0N/A * <code>Action</code></a>
0N/A * @since 1.6
0N/A * @beaninfo
0N/A * bound: true
0N/A * expert: true
0N/A * description: Whether the text of the button should come from
0N/A * the <code>Action</code>.
0N/A */
0N/A public void setHideActionText(boolean hideActionText) {
0N/A if (hideActionText != this.hideActionText) {
0N/A this.hideActionText = hideActionText;
0N/A if (getAction() != null) {
0N/A setTextFromAction(getAction(), false);
0N/A }
0N/A firePropertyChange("hideActionText", !hideActionText,
0N/A hideActionText);
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Returns the value of the <code>hideActionText</code> property, which
0N/A * determines whether the button displays text from the
0N/A * <code>Action</code>. This is useful only if an <code>Action</code>
0N/A * has been installed on the button.
0N/A *
0N/A * @return <code>true</code> if the button's <code>text</code>
0N/A * property should not reflect that of the
0N/A * <code>Action</code>; the default is <code>false</code>
0N/A * @since 1.6
0N/A */
0N/A public boolean getHideActionText() {
0N/A return hideActionText;
0N/A }
0N/A
0N/A /**
0N/A * Returns the button's text.
0N/A * @return the buttons text
0N/A * @see #setText
0N/A */
0N/A public String getText() {
0N/A return text;
0N/A }
0N/A
0N/A /**
0N/A * Sets the button's text.
0N/A * @param text the string used to set the text
0N/A * @see #getText
0N/A * @beaninfo
0N/A * bound: true
0N/A * preferred: true
0N/A * attribute: visualUpdate true
0N/A * description: The button's text.
0N/A */
0N/A public void setText(String text) {
0N/A String oldValue = this.text;
0N/A this.text = text;
0N/A firePropertyChange(TEXT_CHANGED_PROPERTY, oldValue, text);
0N/A updateDisplayedMnemonicIndex(text, getMnemonic());
0N/A
0N/A if (accessibleContext != null) {
0N/A accessibleContext.firePropertyChange(
0N/A AccessibleContext.ACCESSIBLE_VISIBLE_DATA_PROPERTY,
0N/A oldValue, text);
0N/A }
0N/A if (text == null || oldValue == null || !text.equals(oldValue)) {
0N/A revalidate();
0N/A repaint();
0N/A }
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Returns the state of the button. True if the
0N/A * toggle button is selected, false if it's not.
0N/A * @return true if the toggle button is selected, otherwise false
0N/A */
0N/A public boolean isSelected() {
0N/A return model.isSelected();
0N/A }
0N/A
0N/A /**
0N/A * Sets the state of the button. Note that this method does not
0N/A * trigger an <code>actionEvent</code>.
0N/A * Call <code>doClick</code> to perform a programatic action change.
0N/A *
0N/A * @param b true if the button is selected, otherwise false
0N/A */
0N/A public void setSelected(boolean b) {
0N/A boolean oldValue = isSelected();
0N/A
0N/A // TIGER - 4840653
0N/A // Removed code which fired an AccessibleState.SELECTED
0N/A // PropertyChangeEvent since this resulted in two
0N/A // identical events being fired since
0N/A // AbstractButton.fireItemStateChanged also fires the
0N/A // same event. This caused screen readers to speak the
0N/A // name of the item twice.
0N/A
0N/A model.setSelected(b);
0N/A }
0N/A
0N/A /**
0N/A * Programmatically perform a "click". This does the same
0N/A * thing as if the user had pressed and released the button.
0N/A */
0N/A public void doClick() {
0N/A doClick(68);
0N/A }
0N/A
0N/A /**
0N/A * Programmatically perform a "click". This does the same
0N/A * thing as if the user had pressed and released the button.
0N/A * The button stays visually "pressed" for <code>pressTime</code>
0N/A * milliseconds.
0N/A *
0N/A * @param pressTime the time to "hold down" the button, in milliseconds
0N/A */
0N/A public void doClick(int pressTime) {
0N/A Dimension size = getSize();
0N/A model.setArmed(true);
0N/A model.setPressed(true);
0N/A paintImmediately(new Rectangle(0,0, size.width, size.height));
0N/A try {
0N/A Thread.currentThread().sleep(pressTime);
0N/A } catch(InterruptedException ie) {
0N/A }
0N/A model.setPressed(false);
0N/A model.setArmed(false);
0N/A }
0N/A
0N/A /**
0N/A * Sets space for margin between the button's border and
0N/A * the label. Setting to <code>null</code> will cause the button to
0N/A * use the default margin. The button's default <code>Border</code>
0N/A * object will use this value to create the proper margin.
0N/A * However, if a non-default border is set on the button,
0N/A * it is that <code>Border</code> object's responsibility to create the
0N/A * appropriate margin space (else this property will
0N/A * effectively be ignored).
0N/A *
0N/A * @param m the space between the border and the label
0N/A *
0N/A * @beaninfo
0N/A * bound: true
0N/A * attribute: visualUpdate true
0N/A * description: The space between the button's border and the label.
0N/A */
0N/A public void setMargin(Insets m) {
0N/A // Cache the old margin if it comes from the UI
0N/A if(m instanceof UIResource) {
0N/A defaultMargin = m;
0N/A } else if(margin instanceof UIResource) {
0N/A defaultMargin = margin;
0N/A }
0N/A
0N/A // If the client passes in a null insets, restore the margin
0N/A // from the UI if possible
0N/A if(m == null && defaultMargin != null) {
0N/A m = defaultMargin;
0N/A }
0N/A
0N/A Insets old = margin;
0N/A margin = m;
0N/A firePropertyChange(MARGIN_CHANGED_PROPERTY, old, m);
0N/A if (old == null || !old.equals(m)) {
0N/A revalidate();
0N/A repaint();
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Returns the margin between the button's border and
0N/A * the label.
0N/A *
0N/A * @return an <code>Insets</code> object specifying the margin
0N/A * between the botton's border and the label
0N/A * @see #setMargin
0N/A */
0N/A public Insets getMargin() {
0N/A return (margin == null) ? null : (Insets) margin.clone();
0N/A }
0N/A
0N/A /**
0N/A * Returns the default icon.
0N/A * @return the default <code>Icon</code>
0N/A * @see #setIcon
0N/A */
0N/A public Icon getIcon() {
0N/A return defaultIcon;
0N/A }
0N/A
0N/A /**
0N/A * Sets the button's default icon. This icon is
0N/A * also used as the "pressed" and "disabled" icon if
0N/A * there is no explicitly set pressed icon.
0N/A *
0N/A * @param defaultIcon the icon used as the default image
0N/A * @see #getIcon
0N/A * @see #setPressedIcon
0N/A * @beaninfo
0N/A * bound: true
0N/A * attribute: visualUpdate true
0N/A * description: The button's default icon
0N/A */
0N/A public void setIcon(Icon defaultIcon) {
0N/A Icon oldValue = this.defaultIcon;
0N/A this.defaultIcon = defaultIcon;
0N/A
0N/A /* If the default icon has really changed and we had
0N/A * generated the disabled icon for this component,
0N/A * (i.e. setDisabledIcon() was never called) then
0N/A * clear the disabledIcon field.
0N/A */
0N/A if (defaultIcon != oldValue && (disabledIcon instanceof UIResource)) {
0N/A disabledIcon = null;
0N/A }
0N/A
0N/A firePropertyChange(ICON_CHANGED_PROPERTY, oldValue, defaultIcon);
0N/A if (accessibleContext != null) {
0N/A accessibleContext.firePropertyChange(
0N/A AccessibleContext.ACCESSIBLE_VISIBLE_DATA_PROPERTY,
0N/A oldValue, defaultIcon);
0N/A }
0N/A if (defaultIcon != oldValue) {
0N/A if (defaultIcon == null || oldValue == null ||
0N/A defaultIcon.getIconWidth() != oldValue.getIconWidth() ||
0N/A defaultIcon.getIconHeight() != oldValue.getIconHeight()) {
0N/A revalidate();
0N/A }
0N/A repaint();
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Returns the pressed icon for the button.
0N/A * @return the <code>pressedIcon</code> property
0N/A * @see #setPressedIcon
0N/A */
0N/A public Icon getPressedIcon() {
0N/A return pressedIcon;
0N/A }
0N/A
0N/A /**
0N/A * Sets the pressed icon for the button.
0N/A * @param pressedIcon the icon used as the "pressed" image
0N/A * @see #getPressedIcon
0N/A * @beaninfo
0N/A * bound: true
0N/A * attribute: visualUpdate true
0N/A * description: The pressed icon for the button.
0N/A */
0N/A public void setPressedIcon(Icon pressedIcon) {
0N/A Icon oldValue = this.pressedIcon;
0N/A this.pressedIcon = pressedIcon;
0N/A firePropertyChange(PRESSED_ICON_CHANGED_PROPERTY, oldValue, pressedIcon);
0N/A if (accessibleContext != null) {
0N/A accessibleContext.firePropertyChange(
0N/A AccessibleContext.ACCESSIBLE_VISIBLE_DATA_PROPERTY,
0N/A oldValue, pressedIcon);
0N/A }
0N/A if (pressedIcon != oldValue) {
0N/A if (getModel().isPressed()) {
0N/A repaint();
0N/A }
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Returns the selected icon for the button.
0N/A * @return the <code>selectedIcon</code> property
0N/A * @see #setSelectedIcon
0N/A */
0N/A public Icon getSelectedIcon() {
0N/A return selectedIcon;
0N/A }
0N/A
0N/A /**
0N/A * Sets the selected icon for the button.
0N/A * @param selectedIcon the icon used as the "selected" image
0N/A * @see #getSelectedIcon
0N/A * @beaninfo
0N/A * bound: true
0N/A * attribute: visualUpdate true
0N/A * description: The selected icon for the button.
0N/A */
0N/A public void setSelectedIcon(Icon selectedIcon) {
0N/A Icon oldValue = this.selectedIcon;
0N/A this.selectedIcon = selectedIcon;
0N/A
0N/A /* If the default selected icon has really changed and we had
0N/A * generated the disabled selected icon for this component,
0N/A * (i.e. setDisabledSelectedIcon() was never called) then
0N/A * clear the disabledSelectedIcon field.
0N/A */
0N/A if (selectedIcon != oldValue &&
0N/A disabledSelectedIcon instanceof UIResource) {
0N/A
0N/A disabledSelectedIcon = null;
0N/A }
0N/A
0N/A firePropertyChange(SELECTED_ICON_CHANGED_PROPERTY, oldValue, selectedIcon);
0N/A if (accessibleContext != null) {
0N/A accessibleContext.firePropertyChange(
0N/A AccessibleContext.ACCESSIBLE_VISIBLE_DATA_PROPERTY,
0N/A oldValue, selectedIcon);
0N/A }
0N/A if (selectedIcon != oldValue) {
0N/A if (isSelected()) {
0N/A repaint();
0N/A }
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Returns the rollover icon for the button.
0N/A * @return the <code>rolloverIcon</code> property
0N/A * @see #setRolloverIcon
0N/A */
0N/A public Icon getRolloverIcon() {
0N/A return rolloverIcon;
0N/A }
0N/A
0N/A /**
0N/A * Sets the rollover icon for the button.
0N/A * @param rolloverIcon the icon used as the "rollover" image
0N/A * @see #getRolloverIcon
0N/A * @beaninfo
0N/A * bound: true
0N/A * attribute: visualUpdate true
0N/A * description: The rollover icon for the button.
0N/A */
0N/A public void setRolloverIcon(Icon rolloverIcon) {
0N/A Icon oldValue = this.rolloverIcon;
0N/A this.rolloverIcon = rolloverIcon;
0N/A firePropertyChange(ROLLOVER_ICON_CHANGED_PROPERTY, oldValue, rolloverIcon);
0N/A if (accessibleContext != null) {
0N/A accessibleContext.firePropertyChange(
0N/A AccessibleContext.ACCESSIBLE_VISIBLE_DATA_PROPERTY,
0N/A oldValue, rolloverIcon);
0N/A }
0N/A setRolloverEnabled(true);
0N/A if (rolloverIcon != oldValue) {
0N/A // No way to determine whether we are currently in
0N/A // a rollover state, so repaint regardless
0N/A repaint();
0N/A }
0N/A
0N/A }
0N/A
0N/A /**
0N/A * Returns the rollover selection icon for the button.
0N/A * @return the <code>rolloverSelectedIcon</code> property
0N/A * @see #setRolloverSelectedIcon
0N/A */
0N/A public Icon getRolloverSelectedIcon() {
0N/A return rolloverSelectedIcon;
0N/A }
0N/A
0N/A /**
0N/A * Sets the rollover selected icon for the button.
0N/A * @param rolloverSelectedIcon the icon used as the
0N/A * "selected rollover" image
0N/A * @see #getRolloverSelectedIcon
0N/A * @beaninfo
0N/A * bound: true
0N/A * attribute: visualUpdate true
0N/A * description: The rollover selected icon for the button.
0N/A */
0N/A public void setRolloverSelectedIcon(Icon rolloverSelectedIcon) {
0N/A Icon oldValue = this.rolloverSelectedIcon;
0N/A this.rolloverSelectedIcon = rolloverSelectedIcon;
0N/A firePropertyChange(ROLLOVER_SELECTED_ICON_CHANGED_PROPERTY, oldValue, rolloverSelectedIcon);
0N/A if (accessibleContext != null) {
0N/A accessibleContext.firePropertyChange(
0N/A AccessibleContext.ACCESSIBLE_VISIBLE_DATA_PROPERTY,
0N/A oldValue, rolloverSelectedIcon);
0N/A }
0N/A setRolloverEnabled(true);
0N/A if (rolloverSelectedIcon != oldValue) {
0N/A // No way to determine whether we are currently in
0N/A // a rollover state, so repaint regardless
0N/A if (isSelected()) {
0N/A repaint();
0N/A }
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Returns the icon used by the button when it's disabled.
0N/A * If no disabled icon has been set this will forward the call to
0N/A * the look and feel to construct an appropriate disabled Icon.
0N/A * <p>
0N/A * Some look and feels might not render the disabled Icon, in which
0N/A * case they will ignore this.
0N/A *
0N/A * @return the <code>disabledIcon</code> property
0N/A * @see #getPressedIcon
0N/A * @see #setDisabledIcon
0N/A * @see javax.swing.LookAndFeel#getDisabledIcon
0N/A */
243N/A @Transient
0N/A public Icon getDisabledIcon() {
0N/A if (disabledIcon == null) {
0N/A disabledIcon = UIManager.getLookAndFeel().getDisabledIcon(this, getIcon());
0N/A if (disabledIcon != null) {
0N/A firePropertyChange(DISABLED_ICON_CHANGED_PROPERTY, null, disabledIcon);
0N/A }
0N/A }
0N/A return disabledIcon;
0N/A }
0N/A
0N/A /**
0N/A * Sets the disabled icon for the button.
0N/A * @param disabledIcon the icon used as the disabled image
0N/A * @see #getDisabledIcon
0N/A * @beaninfo
0N/A * bound: true
0N/A * attribute: visualUpdate true
0N/A * description: The disabled icon for the button.
0N/A */
0N/A public void setDisabledIcon(Icon disabledIcon) {
0N/A Icon oldValue = this.disabledIcon;
0N/A this.disabledIcon = disabledIcon;
0N/A firePropertyChange(DISABLED_ICON_CHANGED_PROPERTY, oldValue, disabledIcon);
0N/A if (accessibleContext != null) {
0N/A accessibleContext.firePropertyChange(
0N/A AccessibleContext.ACCESSIBLE_VISIBLE_DATA_PROPERTY,
0N/A oldValue, disabledIcon);
0N/A }
0N/A if (disabledIcon != oldValue) {
0N/A if (!isEnabled()) {
0N/A repaint();
0N/A }
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Returns the icon used by the button when it's disabled and selected.
0N/A * If no disabled selection icon has been set, this will forward
0N/A * the call to the LookAndFeel to construct an appropriate disabled
0N/A * Icon from the selection icon if it has been set and to
0N/A * <code>getDisabledIcon()</code> otherwise.
0N/A * <p>
0N/A * Some look and feels might not render the disabled selected Icon, in
0N/A * which case they will ignore this.
0N/A *
0N/A * @return the <code>disabledSelectedIcon</code> property
0N/A * @see #getDisabledIcon
0N/A * @see #setDisabledSelectedIcon
0N/A * @see javax.swing.LookAndFeel#getDisabledSelectedIcon
0N/A */
0N/A public Icon getDisabledSelectedIcon() {
0N/A if (disabledSelectedIcon == null) {
0N/A if (selectedIcon != null) {
0N/A disabledSelectedIcon = UIManager.getLookAndFeel().
0N/A getDisabledSelectedIcon(this, getSelectedIcon());
0N/A } else {
0N/A return getDisabledIcon();
0N/A }
0N/A }
0N/A return disabledSelectedIcon;
0N/A }
0N/A
0N/A /**
0N/A * Sets the disabled selection icon for the button.
0N/A * @param disabledSelectedIcon the icon used as the disabled
0N/A * selection image
0N/A * @see #getDisabledSelectedIcon
0N/A * @beaninfo
0N/A * bound: true
0N/A * attribute: visualUpdate true
0N/A * description: The disabled selection icon for the button.
0N/A */
0N/A public void setDisabledSelectedIcon(Icon disabledSelectedIcon) {
0N/A Icon oldValue = this.disabledSelectedIcon;
0N/A this.disabledSelectedIcon = disabledSelectedIcon;
0N/A firePropertyChange(DISABLED_SELECTED_ICON_CHANGED_PROPERTY, oldValue, disabledSelectedIcon);
0N/A if (accessibleContext != null) {
0N/A accessibleContext.firePropertyChange(
0N/A AccessibleContext.ACCESSIBLE_VISIBLE_DATA_PROPERTY,
0N/A oldValue, disabledSelectedIcon);
0N/A }
0N/A if (disabledSelectedIcon != oldValue) {
0N/A if (disabledSelectedIcon == null || oldValue == null ||
0N/A disabledSelectedIcon.getIconWidth() != oldValue.getIconWidth() ||
0N/A disabledSelectedIcon.getIconHeight() != oldValue.getIconHeight()) {
0N/A revalidate();
0N/A }
0N/A if (!isEnabled() && isSelected()) {
0N/A repaint();
0N/A }
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Returns the vertical alignment of the text and icon.
0N/A *
0N/A * @return the <code>verticalAlignment</code> property, one of the
0N/A * following values:
0N/A * <ul>
0N/A * <li>{@code SwingConstants.CENTER} (the default)
0N/A * <li>{@code SwingConstants.TOP}
0N/A * <li>{@code SwingConstants.BOTTOM}
0N/A * </ul>
0N/A */
0N/A public int getVerticalAlignment() {
0N/A return verticalAlignment;
0N/A }
0N/A
0N/A /**
0N/A * Sets the vertical alignment of the icon and text.
0N/A * @param alignment one of the following values:
0N/A * <ul>
0N/A * <li>{@code SwingConstants.CENTER} (the default)
0N/A * <li>{@code SwingConstants.TOP}
0N/A * <li>{@code SwingConstants.BOTTOM}
0N/A * </ul>
0N/A * @throws IllegalArgumentException if the alignment is not one of the legal
0N/A * values listed above
0N/A * @beaninfo
0N/A * bound: true
0N/A * enum: TOP SwingConstants.TOP
0N/A * CENTER SwingConstants.CENTER
0N/A * BOTTOM SwingConstants.BOTTOM
0N/A * attribute: visualUpdate true
0N/A * description: The vertical alignment of the icon and text.
0N/A */
0N/A public void setVerticalAlignment(int alignment) {
0N/A if (alignment == verticalAlignment) return;
0N/A int oldValue = verticalAlignment;
0N/A verticalAlignment = checkVerticalKey(alignment, "verticalAlignment");
0N/A firePropertyChange(VERTICAL_ALIGNMENT_CHANGED_PROPERTY, oldValue, verticalAlignment); repaint();
0N/A }
0N/A
0N/A /**
0N/A * Returns the horizontal alignment of the icon and text.
0N/A * {@code AbstractButton}'s default is {@code SwingConstants.CENTER},
0N/A * but subclasses such as {@code JCheckBox} may use a different default.
0N/A *
0N/A * @return the <code>horizontalAlignment</code> property,
0N/A * one of the following values:
0N/A * <ul>
0N/A * <li>{@code SwingConstants.RIGHT}
0N/A * <li>{@code SwingConstants.LEFT}
0N/A * <li>{@code SwingConstants.CENTER}
0N/A * <li>{@code SwingConstants.LEADING}
0N/A * <li>{@code SwingConstants.TRAILING}
0N/A * </ul>
0N/A */
0N/A public int getHorizontalAlignment() {
0N/A return horizontalAlignment;
0N/A }
0N/A
0N/A /**
0N/A * Sets the horizontal alignment of the icon and text.
0N/A * {@code AbstractButton}'s default is {@code SwingConstants.CENTER},
0N/A * but subclasses such as {@code JCheckBox} may use a different default.
0N/A *
0N/A * @param alignment the alignment value, one of the following values:
0N/A * <ul>
0N/A * <li>{@code SwingConstants.RIGHT}
0N/A * <li>{@code SwingConstants.LEFT}
0N/A * <li>{@code SwingConstants.CENTER}
0N/A * <li>{@code SwingConstants.LEADING}
0N/A * <li>{@code SwingConstants.TRAILING}
0N/A * </ul>
0N/A * @throws IllegalArgumentException if the alignment is not one of the
0N/A * valid values
0N/A * @beaninfo
0N/A * bound: true
0N/A * enum: LEFT SwingConstants.LEFT
0N/A * CENTER SwingConstants.CENTER
0N/A * RIGHT SwingConstants.RIGHT
0N/A * LEADING SwingConstants.LEADING
0N/A * TRAILING SwingConstants.TRAILING
0N/A * attribute: visualUpdate true
0N/A * description: The horizontal alignment of the icon and text.
0N/A */
0N/A public void setHorizontalAlignment(int alignment) {
0N/A if (alignment == horizontalAlignment) return;
0N/A int oldValue = horizontalAlignment;
0N/A horizontalAlignment = checkHorizontalKey(alignment,
0N/A "horizontalAlignment");
0N/A firePropertyChange(HORIZONTAL_ALIGNMENT_CHANGED_PROPERTY,
0N/A oldValue, horizontalAlignment);
0N/A repaint();
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Returns the vertical position of the text relative to the icon.
0N/A * @return the <code>verticalTextPosition</code> property,
0N/A * one of the following values:
0N/A * <ul>
0N/A * <li>{@code SwingConstants.CENTER} (the default)
0N/A * <li>{@code SwingConstants.TOP}
0N/A * <li>{@code SwingConstants.BOTTOM}
0N/A * </ul>
0N/A */
0N/A public int getVerticalTextPosition() {
0N/A return verticalTextPosition;
0N/A }
0N/A
0N/A /**
0N/A * Sets the vertical position of the text relative to the icon.
0N/A * @param textPosition one of the following values:
0N/A * <ul>
0N/A * <li>{@code SwingConstants.CENTER} (the default)
0N/A * <li>{@code SwingConstants.TOP}
0N/A * <li>{@code SwingConstants.BOTTOM}
0N/A * </ul>
0N/A * @beaninfo
0N/A * bound: true
0N/A * enum: TOP SwingConstants.TOP
0N/A * CENTER SwingConstants.CENTER
0N/A * BOTTOM SwingConstants.BOTTOM
0N/A * attribute: visualUpdate true
0N/A * description: The vertical position of the text relative to the icon.
0N/A */
0N/A public void setVerticalTextPosition(int textPosition) {
0N/A if (textPosition == verticalTextPosition) return;
0N/A int oldValue = verticalTextPosition;
0N/A verticalTextPosition = checkVerticalKey(textPosition, "verticalTextPosition");
0N/A firePropertyChange(VERTICAL_TEXT_POSITION_CHANGED_PROPERTY, oldValue, verticalTextPosition);
0N/A revalidate();
0N/A repaint();
0N/A }
0N/A
0N/A /**
0N/A * Returns the horizontal position of the text relative to the icon.
0N/A * @return the <code>horizontalTextPosition</code> property,
0N/A * one of the following values:
0N/A * <ul>
0N/A * <li>{@code SwingConstants.RIGHT}
0N/A * <li>{@code SwingConstants.LEFT}
0N/A * <li>{@code SwingConstants.CENTER}
0N/A * <li>{@code SwingConstants.LEADING}
0N/A * <li>{@code SwingConstants.TRAILING} (the default)
0N/A * </ul>
0N/A */
0N/A public int getHorizontalTextPosition() {
0N/A return horizontalTextPosition;
0N/A }
0N/A
0N/A /**
0N/A * Sets the horizontal position of the text relative to the icon.
0N/A * @param textPosition one of the following values:
0N/A * <ul>
0N/A * <li>{@code SwingConstants.RIGHT}
0N/A * <li>{@code SwingConstants.LEFT}
0N/A * <li>{@code SwingConstants.CENTER}
0N/A * <li>{@code SwingConstants.LEADING}
0N/A * <li>{@code SwingConstants.TRAILING} (the default)
0N/A * </ul>
0N/A * @exception IllegalArgumentException if <code>textPosition</code>
0N/A * is not one of the legal values listed above
0N/A * @beaninfo
0N/A * bound: true
0N/A * enum: LEFT SwingConstants.LEFT
0N/A * CENTER SwingConstants.CENTER
0N/A * RIGHT SwingConstants.RIGHT
0N/A * LEADING SwingConstants.LEADING
0N/A * TRAILING SwingConstants.TRAILING
0N/A * attribute: visualUpdate true
0N/A * description: The horizontal position of the text relative to the icon.
0N/A */
0N/A public void setHorizontalTextPosition(int textPosition) {
0N/A if (textPosition == horizontalTextPosition) return;
0N/A int oldValue = horizontalTextPosition;
0N/A horizontalTextPosition = checkHorizontalKey(textPosition,
0N/A "horizontalTextPosition");
0N/A firePropertyChange(HORIZONTAL_TEXT_POSITION_CHANGED_PROPERTY,
0N/A oldValue,
0N/A horizontalTextPosition);
0N/A revalidate();
0N/A repaint();
0N/A }
0N/A
0N/A /**
0N/A * Returns the amount of space between the text and the icon
0N/A * displayed in this button.
0N/A *
0N/A * @return an int equal to the number of pixels between the text
0N/A * and the icon.
0N/A * @since 1.4
0N/A * @see #setIconTextGap
0N/A */
0N/A public int getIconTextGap() {
0N/A return iconTextGap;
0N/A }
0N/A
0N/A /**
0N/A * If both the icon and text properties are set, this property
0N/A * defines the space between them.
0N/A * <p>
0N/A * The default value of this property is 4 pixels.
0N/A * <p>
0N/A * This is a JavaBeans bound property.
0N/A *
0N/A * @since 1.4
0N/A * @see #getIconTextGap
0N/A * @beaninfo
0N/A * bound: true
0N/A * attribute: visualUpdate true
0N/A * description: If both the icon and text properties are set, this
0N/A * property defines the space between them.
0N/A */
0N/A public void setIconTextGap(int iconTextGap) {
0N/A int oldValue = this.iconTextGap;
0N/A this.iconTextGap = iconTextGap;
0N/A iconTextGapSet = true;
0N/A firePropertyChange("iconTextGap", oldValue, iconTextGap);
0N/A if (iconTextGap != oldValue) {
0N/A revalidate();
0N/A repaint();
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Verify that the {@code key} argument is a legal value for the
0N/A * {@code horizontalAlignment} and {@code horizontalTextPosition}
0N/A * properties. Valid values are:
0N/A * <ul>
0N/A * <li>{@code SwingConstants.RIGHT}
0N/A * <li>{@code SwingConstants.LEFT}
0N/A * <li>{@code SwingConstants.CENTER}
0N/A * <li>{@code SwingConstants.LEADING}
0N/A * <li>{@code SwingConstants.TRAILING}
0N/A * </ul>
0N/A *
0N/A * @param key the property value to check
0N/A * @param exception the message to use in the
0N/A * {@code IllegalArgumentException} that is thrown for an invalid
0N/A * value
0N/A * @exception IllegalArgumentException if key is not one of the legal
0N/A * values listed above
0N/A * @see #setHorizontalTextPosition
0N/A * @see #setHorizontalAlignment
0N/A */
0N/A protected int checkHorizontalKey(int key, String exception) {
0N/A if ((key == LEFT) ||
0N/A (key == CENTER) ||
0N/A (key == RIGHT) ||
0N/A (key == LEADING) ||
0N/A (key == TRAILING)) {
0N/A return key;
0N/A } else {
0N/A throw new IllegalArgumentException(exception);
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Verify that the {@code key} argument is a legal value for the
0N/A * vertical properties. Valid values are:
0N/A * <ul>
0N/A * <li>{@code SwingConstants.CENTER}
0N/A * <li>{@code SwingConstants.TOP}
0N/A * <li>{@code SwingConstants.BOTTOM}
0N/A * </ul>
0N/A *
0N/A * @param key the property value to check
0N/A * @param exception the message to use in the
0N/A * {@code IllegalArgumentException} that is thrown for an invalid
0N/A * value
0N/A * @exception IllegalArgumentException if key is not one of the legal
0N/A * values listed above
0N/A */
0N/A protected int checkVerticalKey(int key, String exception) {
0N/A if ((key == TOP) || (key == CENTER) || (key == BOTTOM)) {
0N/A return key;
0N/A } else {
0N/A throw new IllegalArgumentException(exception);
0N/A }
0N/A }
0N/A
0N/A /**
0N/A *{@inheritDoc}
0N/A *
0N/A * @since 1.6
0N/A */
0N/A public void removeNotify() {
0N/A super.removeNotify();
0N/A if(isRolloverEnabled()) {
0N/A getModel().setRollover(false);
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Sets the action command for this button.
0N/A * @param actionCommand the action command for this button
0N/A */
0N/A public void setActionCommand(String actionCommand) {
0N/A getModel().setActionCommand(actionCommand);
0N/A }
0N/A
0N/A /**
0N/A * Returns the action command for this button.
0N/A * @return the action command for this button
0N/A */
0N/A public String getActionCommand() {
0N/A String ac = getModel().getActionCommand();
0N/A if(ac == null) {
0N/A ac = getText();
0N/A }
0N/A return ac;
0N/A }
0N/A
0N/A private Action action;
0N/A private PropertyChangeListener actionPropertyChangeListener;
0N/A
0N/A /**
0N/A * Sets the <code>Action</code>.
0N/A * The new <code>Action</code> replaces any previously set
0N/A * <code>Action</code> but does not affect <code>ActionListeners</code>
0N/A * independently added with <code>addActionListener</code>.
0N/A * If the <code>Action</code> is already a registered
0N/A * <code>ActionListener</code> for the button, it is not re-registered.
0N/A * <p>
0N/A * Setting the <code>Action</code> results in immediately changing
0N/A * all the properties described in <a href="Action.html#buttonActions">
0N/A * Swing Components Supporting <code>Action</code></a>.
0N/A * Subsequently, the button's properties are automatically updated
0N/A * as the <code>Action</code>'s properties change.
0N/A * <p>
0N/A * This method uses three other methods to set
0N/A * and help track the <code>Action</code>'s property values.
0N/A * It uses the <code>configurePropertiesFromAction</code> method
0N/A * to immediately change the button's properties.
0N/A * To track changes in the <code>Action</code>'s property values,
0N/A * this method registers the <code>PropertyChangeListener</code>
0N/A * returned by <code>createActionPropertyChangeListener</code>. The
0N/A * default {@code PropertyChangeListener} invokes the
0N/A * {@code actionPropertyChanged} method when a property in the
0N/A * {@code Action} changes.
0N/A *
0N/A * @param a the <code>Action</code> for the <code>AbstractButton</code>,
0N/A * or <code>null</code>
0N/A * @since 1.3
0N/A * @see Action
0N/A * @see #getAction
0N/A * @see #configurePropertiesFromAction
0N/A * @see #createActionPropertyChangeListener
0N/A * @see #actionPropertyChanged
0N/A * @beaninfo
0N/A * bound: true
0N/A * attribute: visualUpdate true
0N/A * description: the Action instance connected with this ActionEvent source
0N/A */
0N/A public void setAction(Action a) {
0N/A Action oldValue = getAction();
0N/A if (action==null || !action.equals(a)) {
0N/A action = a;
0N/A if (oldValue!=null) {
0N/A removeActionListener(oldValue);
0N/A oldValue.removePropertyChangeListener(actionPropertyChangeListener);
0N/A actionPropertyChangeListener = null;
0N/A }
0N/A configurePropertiesFromAction(action);
0N/A if (action!=null) {
0N/A // Don't add if it is already a listener
0N/A if (!isListener(ActionListener.class, action)) {
0N/A addActionListener(action);
0N/A }
0N/A // Reverse linkage:
0N/A actionPropertyChangeListener = createActionPropertyChangeListener(action);
0N/A action.addPropertyChangeListener(actionPropertyChangeListener);
0N/A }
0N/A firePropertyChange("action", oldValue, action);
0N/A }
0N/A }
0N/A
0N/A private boolean isListener(Class c, ActionListener a) {
0N/A boolean isListener = false;
0N/A Object[] listeners = listenerList.getListenerList();
0N/A for (int i = listeners.length-2; i>=0; i-=2) {
0N/A if (listeners[i]==c && listeners[i+1]==a) {
0N/A isListener=true;
0N/A }
0N/A }
0N/A return isListener;
0N/A }
0N/A
0N/A /**
0N/A * Returns the currently set <code>Action</code> for this
0N/A * <code>ActionEvent</code> source, or <code>null</code>
0N/A * if no <code>Action</code> is set.
0N/A *
0N/A * @return the <code>Action</code> for this <code>ActionEvent</code>
0N/A * source, or <code>null</code>
0N/A * @since 1.3
0N/A * @see Action
0N/A * @see #setAction
0N/A */
0N/A public Action getAction() {
0N/A return action;
0N/A }
0N/A
0N/A /**
0N/A * Sets the properties on this button to match those in the specified
0N/A * <code>Action</code>. Refer to <a href="Action.html#buttonActions">
0N/A * Swing Components Supporting <code>Action</code></a> for more
0N/A * details as to which properties this sets.
0N/A *
0N/A * @param a the <code>Action</code> from which to get the properties,
0N/A * or <code>null</code>
0N/A * @since 1.3
0N/A * @see Action
0N/A * @see #setAction
0N/A */
0N/A protected void configurePropertiesFromAction(Action a) {
0N/A setMnemonicFromAction(a);
0N/A setTextFromAction(a, false);
0N/A AbstractAction.setToolTipTextFromAction(this, a);
0N/A setIconFromAction(a);
0N/A setActionCommandFromAction(a);
0N/A AbstractAction.setEnabledFromAction(this, a);
0N/A if (AbstractAction.hasSelectedKey(a) &&
0N/A shouldUpdateSelectedStateFromAction()) {
0N/A setSelectedFromAction(a);
0N/A }
0N/A setDisplayedMnemonicIndexFromAction(a, false);
0N/A }
0N/A
0N/A void clientPropertyChanged(Object key, Object oldValue,
0N/A Object newValue) {
0N/A if (key == "hideActionText") {
0N/A boolean current = (newValue instanceof Boolean) ?
0N/A (Boolean)newValue : false;
0N/A if (getHideActionText() != current) {
0N/A setHideActionText(current);
0N/A }
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Button subclasses that support mirroring the selected state from
0N/A * the action should override this to return true. AbstractButton's
0N/A * implementation returns false.
0N/A */
0N/A boolean shouldUpdateSelectedStateFromAction() {
0N/A return false;
0N/A }
0N/A
0N/A /**
0N/A * Updates the button's state in response to property changes in the
0N/A * associated action. This method is invoked from the
0N/A * {@code PropertyChangeListener} returned from
0N/A * {@code createActionPropertyChangeListener}. Subclasses do not normally
0N/A * need to invoke this. Subclasses that support additional {@code Action}
0N/A * properties should override this and
0N/A * {@code configurePropertiesFromAction}.
0N/A * <p>
0N/A * Refer to the table at <a href="Action.html#buttonActions">
0N/A * Swing Components Supporting <code>Action</code></a> for a list of
0N/A * the properties this method sets.
0N/A *
0N/A * @param action the <code>Action</code> associated with this button
0N/A * @param propertyName the name of the property that changed
0N/A * @since 1.6
0N/A * @see Action
0N/A * @see #configurePropertiesFromAction
0N/A */
0N/A protected void actionPropertyChanged(Action action, String propertyName) {
0N/A if (propertyName == Action.NAME) {
0N/A setTextFromAction(action, true);
0N/A } else if (propertyName == "enabled") {
0N/A AbstractAction.setEnabledFromAction(this, action);
0N/A } else if (propertyName == Action.SHORT_DESCRIPTION) {
0N/A AbstractAction.setToolTipTextFromAction(this, action);
0N/A } else if (propertyName == Action.SMALL_ICON) {
0N/A smallIconChanged(action);
0N/A } else if (propertyName == Action.MNEMONIC_KEY) {
0N/A setMnemonicFromAction(action);
0N/A } else if (propertyName == Action.ACTION_COMMAND_KEY) {
0N/A setActionCommandFromAction(action);
0N/A } else if (propertyName == Action.SELECTED_KEY &&
0N/A AbstractAction.hasSelectedKey(action) &&
0N/A shouldUpdateSelectedStateFromAction()) {
0N/A setSelectedFromAction(action);
0N/A } else if (propertyName == Action.DISPLAYED_MNEMONIC_INDEX_KEY) {
0N/A setDisplayedMnemonicIndexFromAction(action, true);
0N/A } else if (propertyName == Action.LARGE_ICON_KEY) {
0N/A largeIconChanged(action);
0N/A }
0N/A }
0N/A
0N/A private void setDisplayedMnemonicIndexFromAction(
0N/A Action a, boolean fromPropertyChange) {
0N/A Integer iValue = (a == null) ? null :
0N/A (Integer)a.getValue(Action.DISPLAYED_MNEMONIC_INDEX_KEY);
0N/A if (fromPropertyChange || iValue != null) {
0N/A int value;
0N/A if (iValue == null) {
0N/A value = -1;
0N/A } else {
0N/A value = iValue;
0N/A String text = getText();
0N/A if (text == null || value >= text.length()) {
0N/A value = -1;
0N/A }
0N/A }
0N/A setDisplayedMnemonicIndex(value);
0N/A }
0N/A }
0N/A
0N/A private void setMnemonicFromAction(Action a) {
0N/A Integer n = (a == null) ? null :
0N/A (Integer)a.getValue(Action.MNEMONIC_KEY);
0N/A setMnemonic((n == null) ? '\0' : n);
0N/A }
0N/A
0N/A private void setTextFromAction(Action a, boolean propertyChange) {
0N/A boolean hideText = getHideActionText();
0N/A if (!propertyChange) {
0N/A setText((a != null && !hideText) ?
0N/A (String)a.getValue(Action.NAME) : null);
0N/A }
0N/A else if (!hideText) {
0N/A setText((String)a.getValue(Action.NAME));
0N/A }
0N/A }
0N/A
0N/A void setIconFromAction(Action a) {
0N/A Icon icon = null;
0N/A if (a != null) {
0N/A icon = (Icon)a.getValue(Action.LARGE_ICON_KEY);
0N/A if (icon == null) {
0N/A icon = (Icon)a.getValue(Action.SMALL_ICON);
0N/A }
0N/A }
0N/A setIcon(icon);
0N/A }
0N/A
0N/A void smallIconChanged(Action a) {
0N/A if (a.getValue(Action.LARGE_ICON_KEY) == null) {
0N/A setIconFromAction(a);
0N/A }
0N/A }
0N/A
0N/A void largeIconChanged(Action a) {
0N/A setIconFromAction(a);
0N/A }
0N/A
0N/A private void setActionCommandFromAction(Action a) {
0N/A setActionCommand((a != null) ?
0N/A (String)a.getValue(Action.ACTION_COMMAND_KEY) :
0N/A null);
0N/A }
0N/A
0N/A /**
0N/A * Sets the seleted state of the button from the action. This is defined
0N/A * here, but not wired up. Subclasses like JToggleButton and
0N/A * JCheckBoxMenuItem make use of it.
0N/A *
0N/A * @param a the Action
0N/A */
0N/A private void setSelectedFromAction(Action a) {
0N/A boolean selected = false;
0N/A if (a != null) {
0N/A selected = AbstractAction.isSelected(a);
0N/A }
0N/A if (selected != isSelected()) {
0N/A // This won't notify ActionListeners, but that should be
0N/A // ok as the change is coming from the Action.
0N/A setSelected(selected);
0N/A // Make sure the change actually took effect
0N/A if (!selected && isSelected()) {
0N/A if (getModel() instanceof DefaultButtonModel) {
625N/A ButtonGroup group = ((DefaultButtonModel)getModel()).getGroup();
0N/A if (group != null) {
0N/A group.clearSelection();
0N/A }
0N/A }
0N/A }
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Creates and returns a <code>PropertyChangeListener</code> that is
0N/A * responsible for listening for changes from the specified
0N/A * <code>Action</code> and updating the appropriate properties.
0N/A * <p>
0N/A * <b>Warning:</b> If you subclass this do not create an anonymous
0N/A * inner class. If you do the lifetime of the button will be tied to
0N/A * that of the <code>Action</code>.
0N/A *
0N/A * @param a the button's action
0N/A * @since 1.3
0N/A * @see Action
0N/A * @see #setAction
0N/A */
0N/A protected PropertyChangeListener createActionPropertyChangeListener(Action a) {
0N/A return createActionPropertyChangeListener0(a);
0N/A }
0N/A
0N/A
0N/A PropertyChangeListener createActionPropertyChangeListener0(Action a) {
0N/A return new ButtonActionPropertyChangeListener(this, a);
0N/A }
0N/A
0N/A private static class ButtonActionPropertyChangeListener
0N/A extends ActionPropertyChangeListener<AbstractButton> {
0N/A ButtonActionPropertyChangeListener(AbstractButton b, Action a) {
0N/A super(b, a);
0N/A }
0N/A protected void actionPropertyChanged(AbstractButton button,
0N/A Action action,
0N/A PropertyChangeEvent e) {
0N/A if (AbstractAction.shouldReconfigure(e)) {
0N/A button.configurePropertiesFromAction(action);
0N/A } else {
0N/A button.actionPropertyChanged(action, e.getPropertyName());
0N/A }
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Gets the <code>borderPainted</code> property.
0N/A *
0N/A * @return the value of the <code>borderPainted</code> property
0N/A * @see #setBorderPainted
0N/A */
0N/A public boolean isBorderPainted() {
0N/A return paintBorder;
0N/A }
0N/A
0N/A /**
0N/A * Sets the <code>borderPainted</code> property.
0N/A * If <code>true</code> and the button has a border,
0N/A * the border is painted. The default value for the
0N/A * <code>borderPainted</code> property is <code>true</code>.
3095N/A * <p/>
3095N/A * Some look and feels might not support
3095N/A * the <code>borderPainted</code> property,
3095N/A * in which case they ignore this.
0N/A *
0N/A * @param b if true and border property is not <code>null</code>,
0N/A * the border is painted
0N/A * @see #isBorderPainted
0N/A * @beaninfo
0N/A * bound: true
0N/A * attribute: visualUpdate true
0N/A * description: Whether the border should be painted.
0N/A */
0N/A public void setBorderPainted(boolean b) {
0N/A boolean oldValue = paintBorder;
0N/A paintBorder = b;
0N/A borderPaintedSet = true;
0N/A firePropertyChange(BORDER_PAINTED_CHANGED_PROPERTY, oldValue, paintBorder);
0N/A if (b != oldValue) {
0N/A revalidate();
0N/A repaint();
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Paint the button's border if <code>BorderPainted</code>
0N/A * property is true and the button has a border.
0N/A * @param g the <code>Graphics</code> context in which to paint
0N/A *
0N/A * @see #paint
0N/A * @see #setBorder
0N/A */
0N/A protected void paintBorder(Graphics g) {
0N/A if (isBorderPainted()) {
0N/A super.paintBorder(g);
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Gets the <code>paintFocus</code> property.
0N/A *
0N/A * @return the <code>paintFocus</code> property
0N/A * @see #setFocusPainted
0N/A */
0N/A public boolean isFocusPainted() {
0N/A return paintFocus;
0N/A }
0N/A
0N/A /**
0N/A * Sets the <code>paintFocus</code> property, which must
0N/A * be <code>true</code> for the focus state to be painted.
0N/A * The default value for the <code>paintFocus</code> property
0N/A * is <code>true</code>.
0N/A * Some look and feels might not paint focus state;
0N/A * they will ignore this property.
0N/A *
0N/A * @param b if <code>true</code>, the focus state should be painted
0N/A * @see #isFocusPainted
0N/A * @beaninfo
0N/A * bound: true
0N/A * attribute: visualUpdate true
0N/A * description: Whether focus should be painted
0N/A */
0N/A public void setFocusPainted(boolean b) {
0N/A boolean oldValue = paintFocus;
0N/A paintFocus = b;
0N/A firePropertyChange(FOCUS_PAINTED_CHANGED_PROPERTY, oldValue, paintFocus);
0N/A if (b != oldValue && isFocusOwner()) {
0N/A revalidate();
0N/A repaint();
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Gets the <code>contentAreaFilled</code> property.
0N/A *
0N/A * @return the <code>contentAreaFilled</code> property
0N/A * @see #setContentAreaFilled
0N/A */
0N/A public boolean isContentAreaFilled() {
0N/A return contentAreaFilled;
0N/A }
0N/A
0N/A /**
0N/A * Sets the <code>contentAreaFilled</code> property.
0N/A * If <code>true</code> the button will paint the content
0N/A * area. If you wish to have a transparent button, such as
0N/A * an icon only button, for example, then you should set
0N/A * this to <code>false</code>. Do not call <code>setOpaque(false)</code>.
0N/A * The default value for the the <code>contentAreaFilled</code>
0N/A * property is <code>true</code>.
0N/A * <p>
0N/A * This function may cause the component's opaque property to change.
0N/A * <p>
0N/A * The exact behavior of calling this function varies on a
0N/A * component-by-component and L&F-by-L&F basis.
0N/A *
0N/A * @param b if true, the content should be filled; if false
0N/A * the content area is not filled
0N/A * @see #isContentAreaFilled
0N/A * @see #setOpaque
0N/A * @beaninfo
0N/A * bound: true
0N/A * attribute: visualUpdate true
0N/A * description: Whether the button should paint the content area
0N/A * or leave it transparent.
0N/A */
0N/A public void setContentAreaFilled(boolean b) {
0N/A boolean oldValue = contentAreaFilled;
0N/A contentAreaFilled = b;
0N/A contentAreaFilledSet = true;
0N/A firePropertyChange(CONTENT_AREA_FILLED_CHANGED_PROPERTY, oldValue, contentAreaFilled);
0N/A if (b != oldValue) {
0N/A repaint();
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Gets the <code>rolloverEnabled</code> property.
0N/A *
0N/A * @return the value of the <code>rolloverEnabled</code> property
0N/A * @see #setRolloverEnabled
0N/A */
0N/A public boolean isRolloverEnabled() {
0N/A return rolloverEnabled;
0N/A }
0N/A
0N/A /**
0N/A * Sets the <code>rolloverEnabled</code> property, which
0N/A * must be <code>true</code> for rollover effects to occur.
0N/A * The default value for the <code>rolloverEnabled</code>
0N/A * property is <code>false</code>.
0N/A * Some look and feels might not implement rollover effects;
0N/A * they will ignore this property.
0N/A *
0N/A * @param b if <code>true</code>, rollover effects should be painted
0N/A * @see #isRolloverEnabled
0N/A * @beaninfo
0N/A * bound: true
0N/A * attribute: visualUpdate true
0N/A * description: Whether rollover effects should be enabled.
0N/A */
0N/A public void setRolloverEnabled(boolean b) {
0N/A boolean oldValue = rolloverEnabled;
0N/A rolloverEnabled = b;
0N/A rolloverEnabledSet = true;
0N/A firePropertyChange(ROLLOVER_ENABLED_CHANGED_PROPERTY, oldValue, rolloverEnabled);
0N/A if (b != oldValue) {
0N/A repaint();
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Returns the keyboard mnemonic from the the current model.
0N/A * @return the keyboard mnemonic from the model
0N/A */
0N/A public int getMnemonic() {
0N/A return mnemonic;
0N/A }
0N/A
0N/A /**
0N/A * Sets the keyboard mnemonic on the current model.
0N/A * The mnemonic is the key which when combined with the look and feel's
0N/A * mouseless modifier (usually Alt) will activate this button
0N/A * if focus is contained somewhere within this button's ancestor
0N/A * window.
0N/A * <p>
0N/A * A mnemonic must correspond to a single key on the keyboard
0N/A * and should be specified using one of the <code>VK_XXX</code>
0N/A * keycodes defined in <code>java.awt.event.KeyEvent</code>.
1067N/A * These codes and the wider array of codes for international
1067N/A * keyboards may be obtained through
1067N/A * <code>java.awt.event.KeyEvent.getExtendedKeyCodeForChar</code>.
0N/A * Mnemonics are case-insensitive, therefore a key event
0N/A * with the corresponding keycode would cause the button to be
0N/A * activated whether or not the Shift modifier was pressed.
0N/A * <p>
0N/A * If the character defined by the mnemonic is found within
0N/A * the button's label string, the first occurrence of it
0N/A * will be underlined to indicate the mnemonic to the user.
0N/A *
0N/A * @param mnemonic the key code which represents the mnemonic
0N/A * @see java.awt.event.KeyEvent
0N/A * @see #setDisplayedMnemonicIndex
0N/A *
0N/A * @beaninfo
0N/A * bound: true
0N/A * attribute: visualUpdate true
0N/A * description: the keyboard character mnemonic
0N/A */
0N/A public void setMnemonic(int mnemonic) {
0N/A int oldValue = getMnemonic();
0N/A model.setMnemonic(mnemonic);
0N/A updateMnemonicProperties();
0N/A }
0N/A
0N/A /**
0N/A * This method is now obsolete, please use <code>setMnemonic(int)</code>
0N/A * to set the mnemonic for a button. This method is only designed
0N/A * to handle character values which fall between 'a' and 'z' or
0N/A * 'A' and 'Z'.
0N/A *
0N/A * @param mnemonic a char specifying the mnemonic value
0N/A * @see #setMnemonic(int)
0N/A * @beaninfo
0N/A * bound: true
0N/A * attribute: visualUpdate true
0N/A * description: the keyboard character mnemonic
0N/A */
0N/A public void setMnemonic(char mnemonic) {
0N/A int vk = (int) mnemonic;
0N/A if(vk >= 'a' && vk <='z')
0N/A vk -= ('a' - 'A');
0N/A setMnemonic(vk);
0N/A }
0N/A
0N/A /**
0N/A * Provides a hint to the look and feel as to which character in the
0N/A * text should be decorated to represent the mnemonic. Not all look and
0N/A * feels may support this. A value of -1 indicates either there is no
0N/A * mnemonic, the mnemonic character is not contained in the string, or
0N/A * the developer does not wish the mnemonic to be displayed.
0N/A * <p>
0N/A * The value of this is updated as the properties relating to the
0N/A * mnemonic change (such as the mnemonic itself, the text...).
0N/A * You should only ever have to call this if
0N/A * you do not wish the default character to be underlined. For example, if
0N/A * the text was 'Save As', with a mnemonic of 'a', and you wanted the 'A'
0N/A * to be decorated, as 'Save <u>A</u>s', you would have to invoke
0N/A * <code>setDisplayedMnemonicIndex(5)</code> after invoking
0N/A * <code>setMnemonic(KeyEvent.VK_A)</code>.
0N/A *
0N/A * @since 1.4
0N/A * @param index Index into the String to underline
0N/A * @exception IllegalArgumentException will be thrown if <code>index</code>
0N/A * is &gt;= length of the text, or &lt; -1
0N/A * @see #getDisplayedMnemonicIndex
0N/A *
0N/A * @beaninfo
0N/A * bound: true
0N/A * attribute: visualUpdate true
0N/A * description: the index into the String to draw the keyboard character
0N/A * mnemonic at
0N/A */
0N/A public void setDisplayedMnemonicIndex(int index)
0N/A throws IllegalArgumentException {
0N/A int oldValue = mnemonicIndex;
0N/A if (index == -1) {
0N/A mnemonicIndex = -1;
0N/A } else {
0N/A String text = getText();
0N/A int textLength = (text == null) ? 0 : text.length();
0N/A if (index < -1 || index >= textLength) { // index out of range
0N/A throw new IllegalArgumentException("index == " + index);
0N/A }
0N/A }
0N/A mnemonicIndex = index;
0N/A firePropertyChange("displayedMnemonicIndex", oldValue, index);
0N/A if (index != oldValue) {
0N/A revalidate();
0N/A repaint();
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Returns the character, as an index, that the look and feel should
0N/A * provide decoration for as representing the mnemonic character.
0N/A *
0N/A * @since 1.4
0N/A * @return index representing mnemonic character
0N/A * @see #setDisplayedMnemonicIndex
0N/A */
0N/A public int getDisplayedMnemonicIndex() {
0N/A return mnemonicIndex;
0N/A }
0N/A
0N/A /**
0N/A * Update the displayedMnemonicIndex property. This method
0N/A * is called when either text or mnemonic changes. The new
0N/A * value of the displayedMnemonicIndex property is the index
0N/A * of the first occurrence of mnemonic in text.
0N/A */
0N/A private void updateDisplayedMnemonicIndex(String text, int mnemonic) {
0N/A setDisplayedMnemonicIndex(
0N/A SwingUtilities.findDisplayedMnemonicIndex(text, mnemonic));
0N/A }
0N/A
0N/A /**
0N/A * Brings the mnemonic property in accordance with model's mnemonic.
0N/A * This is called when model's mnemonic changes. Also updates the
0N/A * displayedMnemonicIndex property.
0N/A */
0N/A private void updateMnemonicProperties() {
0N/A int newMnemonic = model.getMnemonic();
0N/A if (mnemonic != newMnemonic) {
0N/A int oldValue = mnemonic;
0N/A mnemonic = newMnemonic;
0N/A firePropertyChange(MNEMONIC_CHANGED_PROPERTY,
0N/A oldValue, mnemonic);
0N/A updateDisplayedMnemonicIndex(getText(), mnemonic);
0N/A revalidate();
0N/A repaint();
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Sets the amount of time (in milliseconds) required between
0N/A * mouse press events for the button to generate the corresponding
0N/A * action events. After the initial mouse press occurs (and action
0N/A * event generated) any subsequent mouse press events which occur
0N/A * on intervals less than the threshhold will be ignored and no
0N/A * corresponding action event generated. By default the threshhold is 0,
0N/A * which means that for each mouse press, an action event will be
0N/A * fired, no matter how quickly the mouse clicks occur. In buttons
0N/A * where this behavior is not desirable (for example, the "OK" button
0N/A * in a dialog), this threshhold should be set to an appropriate
0N/A * positive value.
0N/A *
0N/A * @see #getMultiClickThreshhold
0N/A * @param threshhold the amount of time required between mouse
0N/A * press events to generate corresponding action events
0N/A * @exception IllegalArgumentException if threshhold < 0
0N/A * @since 1.4
0N/A */
0N/A public void setMultiClickThreshhold(long threshhold) {
0N/A if (threshhold < 0) {
0N/A throw new IllegalArgumentException("threshhold must be >= 0");
0N/A }
0N/A this.multiClickThreshhold = threshhold;
0N/A }
0N/A
0N/A /**
0N/A * Gets the amount of time (in milliseconds) required between
0N/A * mouse press events for the button to generate the corresponding
0N/A * action events.
0N/A *
0N/A * @see #setMultiClickThreshhold
0N/A * @return the amount of time required between mouse press events
0N/A * to generate corresponding action events
0N/A * @since 1.4
0N/A */
0N/A public long getMultiClickThreshhold() {
0N/A return multiClickThreshhold;
0N/A }
0N/A
0N/A /**
0N/A * Returns the model that this button represents.
0N/A * @return the <code>model</code> property
0N/A * @see #setModel
0N/A */
0N/A public ButtonModel getModel() {
0N/A return model;
0N/A }
0N/A
0N/A /**
0N/A * Sets the model that this button represents.
0N/A * @param newModel the new <code>ButtonModel</code>
0N/A * @see #getModel
0N/A * @beaninfo
0N/A * bound: true
0N/A * description: Model that the Button uses.
0N/A */
0N/A public void setModel(ButtonModel newModel) {
0N/A
0N/A ButtonModel oldModel = getModel();
0N/A
0N/A if (oldModel != null) {
0N/A oldModel.removeChangeListener(changeListener);
0N/A oldModel.removeActionListener(actionListener);
0N/A oldModel.removeItemListener(itemListener);
0N/A changeListener = null;
0N/A actionListener = null;
0N/A itemListener = null;
0N/A }
0N/A
0N/A model = newModel;
0N/A
0N/A if (newModel != null) {
0N/A changeListener = createChangeListener();
0N/A actionListener = createActionListener();
0N/A itemListener = createItemListener();
0N/A newModel.addChangeListener(changeListener);
0N/A newModel.addActionListener(actionListener);
0N/A newModel.addItemListener(itemListener);
0N/A
0N/A updateMnemonicProperties();
0N/A //We invoke setEnabled() from JComponent
0N/A //because setModel() can be called from a constructor
0N/A //when the button is not fully initialized
0N/A super.setEnabled(newModel.isEnabled());
0N/A
0N/A } else {
0N/A mnemonic = '\0';
0N/A }
0N/A
0N/A updateDisplayedMnemonicIndex(getText(), mnemonic);
0N/A
0N/A firePropertyChange(MODEL_CHANGED_PROPERTY, oldModel, newModel);
0N/A if (newModel != oldModel) {
0N/A revalidate();
0N/A repaint();
0N/A }
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Returns the L&F object that renders this component.
0N/A * @return the ButtonUI object
0N/A * @see #setUI
0N/A */
0N/A public ButtonUI getUI() {
0N/A return (ButtonUI) ui;
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Sets the L&F object that renders this component.
0N/A * @param ui the <code>ButtonUI</code> L&F object
0N/A * @see #getUI
0N/A * @beaninfo
0N/A * bound: true
0N/A * hidden: true
0N/A * attribute: visualUpdate true
0N/A * description: The UI object that implements the LookAndFeel.
0N/A */
0N/A public void setUI(ButtonUI ui) {
0N/A super.setUI(ui);
0N/A // disabled icons are generated by the LF so they should be unset here
0N/A if (disabledIcon instanceof UIResource) {
0N/A setDisabledIcon(null);
0N/A }
0N/A if (disabledSelectedIcon instanceof UIResource) {
0N/A setDisabledSelectedIcon(null);
0N/A }
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Resets the UI property to a value from the current look
0N/A * and feel. Subtypes of <code>AbstractButton</code>
0N/A * should override this to update the UI. For
0N/A * example, <code>JButton</code> might do the following:
0N/A * <pre>
0N/A * setUI((ButtonUI)UIManager.getUI(
0N/A * "ButtonUI", "javax.swing.plaf.basic.BasicButtonUI", this));
0N/A * </pre>
0N/A */
0N/A public void updateUI() {
0N/A }
0N/A
0N/A /**
0N/A * Adds the specified component to this container at the specified
0N/A * index, refer to
0N/A * {@link java.awt.Container#addImpl(Component, Object, int)}
0N/A * for a complete description of this method.
0N/A *
0N/A * @param comp the component to be added
0N/A * @param constraints an object expressing layout constraints
0N/A * for this component
0N/A * @param index the position in the container's list at which to
0N/A * insert the component, where <code>-1</code>
0N/A * means append to the end
0N/A * @exception IllegalArgumentException if <code>index</code> is invalid
0N/A * @exception IllegalArgumentException if adding the container's parent
0N/A * to itself
0N/A * @exception IllegalArgumentException if adding a window to a container
0N/A * @since 1.5
0N/A */
0N/A protected void addImpl(Component comp, Object constraints, int index) {
0N/A if (!setLayout) {
0N/A setLayout(new OverlayLayout(this));
0N/A }
0N/A super.addImpl(comp, constraints, index);
0N/A }
0N/A
0N/A /**
0N/A * Sets the layout manager for this container, refer to
0N/A * {@link java.awt.Container#setLayout(LayoutManager)}
0N/A * for a complete description of this method.
0N/A *
0N/A * @param mgr the specified layout manager
0N/A * @since 1.5
0N/A */
0N/A public void setLayout(LayoutManager mgr) {
0N/A setLayout = true;
0N/A super.setLayout(mgr);
0N/A }
0N/A
0N/A /**
0N/A * Adds a <code>ChangeListener</code> to the button.
0N/A * @param l the listener to be added
0N/A */
0N/A public void addChangeListener(ChangeListener l) {
0N/A listenerList.add(ChangeListener.class, l);
0N/A }
0N/A
0N/A /**
0N/A * Removes a ChangeListener from the button.
0N/A * @param l the listener to be removed
0N/A */
0N/A public void removeChangeListener(ChangeListener l) {
0N/A listenerList.remove(ChangeListener.class, l);
0N/A }
0N/A
0N/A /**
0N/A * Returns an array of all the <code>ChangeListener</code>s added
0N/A * to this AbstractButton with addChangeListener().
0N/A *
0N/A * @return all of the <code>ChangeListener</code>s added or an empty
0N/A * array if no listeners have been added
0N/A * @since 1.4
0N/A */
0N/A public ChangeListener[] getChangeListeners() {
625N/A return listenerList.getListeners(ChangeListener.class);
0N/A }
0N/A
0N/A /**
0N/A * Notifies all listeners that have registered interest for
0N/A * notification on this event type. The event instance
0N/A * is lazily created.
0N/A * @see EventListenerList
0N/A */
0N/A protected void fireStateChanged() {
0N/A // Guaranteed to return a non-null array
0N/A Object[] listeners = listenerList.getListenerList();
0N/A // Process the listeners last to first, notifying
0N/A // those that are interested in this event
0N/A for (int i = listeners.length-2; i>=0; i-=2) {
0N/A if (listeners[i]==ChangeListener.class) {
0N/A // Lazily create the event:
0N/A if (changeEvent == null)
0N/A changeEvent = new ChangeEvent(this);
0N/A ((ChangeListener)listeners[i+1]).stateChanged(changeEvent);
0N/A }
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Adds an <code>ActionListener</code> to the button.
0N/A * @param l the <code>ActionListener</code> to be added
0N/A */
0N/A public void addActionListener(ActionListener l) {
0N/A listenerList.add(ActionListener.class, l);
0N/A }
0N/A
0N/A /**
0N/A * Removes an <code>ActionListener</code> from the button.
0N/A * If the listener is the currently set <code>Action</code>
0N/A * for the button, then the <code>Action</code>
0N/A * is set to <code>null</code>.
0N/A *
0N/A * @param l the listener to be removed
0N/A */
0N/A public void removeActionListener(ActionListener l) {
0N/A if ((l != null) && (getAction() == l)) {
0N/A setAction(null);
0N/A } else {
0N/A listenerList.remove(ActionListener.class, l);
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Returns an array of all the <code>ActionListener</code>s added
0N/A * to this AbstractButton with addActionListener().
0N/A *
0N/A * @return all of the <code>ActionListener</code>s added or an empty
0N/A * array if no listeners have been added
0N/A * @since 1.4
0N/A */
0N/A public ActionListener[] getActionListeners() {
625N/A return listenerList.getListeners(ActionListener.class);
0N/A }
0N/A
0N/A /**
0N/A * Subclasses that want to handle <code>ChangeEvents</code> differently
0N/A * can override this to return another <code>ChangeListener</code>
0N/A * implementation.
0N/A *
0N/A * @return the new <code>ChangeListener</code>
0N/A */
0N/A protected ChangeListener createChangeListener() {
0N/A return getHandler();
0N/A }
0N/A
0N/A /**
0N/A * Extends <code>ChangeListener</code> to be serializable.
0N/A * <p>
0N/A * <strong>Warning:</strong>
0N/A * Serialized objects of this class will not be compatible with
0N/A * future Swing releases. The current serialization support is
0N/A * appropriate for short term storage or RMI between applications running
0N/A * the same version of Swing. As of 1.4, support for long term storage
0N/A * of all JavaBeans<sup><font size="-2">TM</font></sup>
0N/A * has been added to the <code>java.beans</code> package.
0N/A * Please see {@link java.beans.XMLEncoder}.
0N/A */
0N/A protected class ButtonChangeListener implements ChangeListener, Serializable {
0N/A // NOTE: This class is NOT used, instead the functionality has
0N/A // been moved to Handler.
0N/A ButtonChangeListener() {
0N/A }
0N/A
0N/A public void stateChanged(ChangeEvent e) {
0N/A getHandler().stateChanged(e);
0N/A }
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Notifies all listeners that have registered interest for
0N/A * notification on this event type. The event instance
0N/A * is lazily created using the <code>event</code>
0N/A * parameter.
0N/A *
0N/A * @param event the <code>ActionEvent</code> object
0N/A * @see EventListenerList
0N/A */
0N/A protected void fireActionPerformed(ActionEvent event) {
0N/A // Guaranteed to return a non-null array
0N/A Object[] listeners = listenerList.getListenerList();
0N/A ActionEvent e = null;
0N/A // Process the listeners last to first, notifying
0N/A // those that are interested in this event
0N/A for (int i = listeners.length-2; i>=0; i-=2) {
0N/A if (listeners[i]==ActionListener.class) {
0N/A // Lazily create the event:
0N/A if (e == null) {
0N/A String actionCommand = event.getActionCommand();
0N/A if(actionCommand == null) {
0N/A actionCommand = getActionCommand();
0N/A }
0N/A e = new ActionEvent(AbstractButton.this,
0N/A ActionEvent.ACTION_PERFORMED,
0N/A actionCommand,
0N/A event.getWhen(),
0N/A event.getModifiers());
0N/A }
0N/A ((ActionListener)listeners[i+1]).actionPerformed(e);
0N/A }
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Notifies all listeners that have registered interest for
0N/A * notification on this event type. The event instance
0N/A * is lazily created using the <code>event</code> parameter.
0N/A *
0N/A * @param event the <code>ItemEvent</code> object
0N/A * @see EventListenerList
0N/A */
0N/A protected void fireItemStateChanged(ItemEvent event) {
0N/A // Guaranteed to return a non-null array
0N/A Object[] listeners = listenerList.getListenerList();
0N/A ItemEvent e = null;
0N/A // Process the listeners last to first, notifying
0N/A // those that are interested in this event
0N/A for (int i = listeners.length-2; i>=0; i-=2) {
0N/A if (listeners[i]==ItemListener.class) {
0N/A // Lazily create the event:
0N/A if (e == null) {
0N/A e = new ItemEvent(AbstractButton.this,
0N/A ItemEvent.ITEM_STATE_CHANGED,
0N/A AbstractButton.this,
0N/A event.getStateChange());
0N/A }
0N/A ((ItemListener)listeners[i+1]).itemStateChanged(e);
0N/A }
0N/A }
0N/A if (accessibleContext != null) {
0N/A if (event.getStateChange() == ItemEvent.SELECTED) {
0N/A accessibleContext.firePropertyChange(
0N/A AccessibleContext.ACCESSIBLE_STATE_PROPERTY,
0N/A null, AccessibleState.SELECTED);
0N/A accessibleContext.firePropertyChange(
0N/A AccessibleContext.ACCESSIBLE_VALUE_PROPERTY,
215N/A Integer.valueOf(0), Integer.valueOf(1));
0N/A } else {
0N/A accessibleContext.firePropertyChange(
0N/A AccessibleContext.ACCESSIBLE_STATE_PROPERTY,
0N/A AccessibleState.SELECTED, null);
0N/A accessibleContext.firePropertyChange(
0N/A AccessibleContext.ACCESSIBLE_VALUE_PROPERTY,
215N/A Integer.valueOf(1), Integer.valueOf(0));
0N/A }
0N/A }
0N/A }
0N/A
0N/A
0N/A protected ActionListener createActionListener() {
0N/A return getHandler();
0N/A }
0N/A
0N/A
0N/A protected ItemListener createItemListener() {
0N/A return getHandler();
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Enables (or disables) the button.
0N/A * @param b true to enable the button, otherwise false
0N/A */
0N/A public void setEnabled(boolean b) {
0N/A if (!b && model.isRollover()) {
0N/A model.setRollover(false);
0N/A }
0N/A super.setEnabled(b);
0N/A model.setEnabled(b);
0N/A }
0N/A
0N/A // *** Deprecated java.awt.Button APIs below *** //
0N/A
0N/A /**
0N/A * Returns the label text.
0N/A *
0N/A * @return a <code>String</code> containing the label
0N/A * @deprecated - Replaced by <code>getText</code>
0N/A */
0N/A @Deprecated
0N/A public String getLabel() {
0N/A return getText();
0N/A }
0N/A
0N/A /**
0N/A * Sets the label text.
0N/A *
0N/A * @param label a <code>String</code> containing the text
0N/A * @deprecated - Replaced by <code>setText(text)</code>
0N/A * @beaninfo
0N/A * bound: true
0N/A * description: Replace by setText(text)
0N/A */
0N/A @Deprecated
0N/A public void setLabel(String label) {
0N/A setText(label);
0N/A }
0N/A
0N/A /**
0N/A * Adds an <code>ItemListener</code> to the <code>checkbox</code>.
0N/A * @param l the <code>ItemListener</code> to be added
0N/A */
0N/A public void addItemListener(ItemListener l) {
0N/A listenerList.add(ItemListener.class, l);
0N/A }
0N/A
0N/A /**
0N/A * Removes an <code>ItemListener</code> from the button.
0N/A * @param l the <code>ItemListener</code> to be removed
0N/A */
0N/A public void removeItemListener(ItemListener l) {
0N/A listenerList.remove(ItemListener.class, l);
0N/A }
0N/A
0N/A /**
0N/A * Returns an array of all the <code>ItemListener</code>s added
0N/A * to this AbstractButton with addItemListener().
0N/A *
0N/A * @return all of the <code>ItemListener</code>s added or an empty
0N/A * array if no listeners have been added
0N/A * @since 1.4
0N/A */
0N/A public ItemListener[] getItemListeners() {
625N/A return listenerList.getListeners(ItemListener.class);
0N/A }
0N/A
0N/A /**
0N/A * Returns an array (length 1) containing the label or
0N/A * <code>null</code> if the button is not selected.
0N/A *
0N/A * @return an array containing 1 Object: the text of the button,
0N/A * if the item is selected; otherwise <code>null</code>
0N/A */
0N/A public Object[] getSelectedObjects() {
0N/A if (isSelected() == false) {
0N/A return null;
0N/A }
0N/A Object[] selectedObjects = new Object[1];
0N/A selectedObjects[0] = getText();
0N/A return selectedObjects;
0N/A }
0N/A
0N/A protected void init(String text, Icon icon) {
0N/A if(text != null) {
0N/A setText(text);
0N/A }
0N/A
0N/A if(icon != null) {
0N/A setIcon(icon);
0N/A }
0N/A
0N/A // Set the UI
0N/A updateUI();
0N/A
0N/A setAlignmentX(LEFT_ALIGNMENT);
0N/A setAlignmentY(CENTER_ALIGNMENT);
0N/A }
0N/A
0N/A
0N/A /**
0N/A * This is overridden to return false if the current <code>Icon</code>'s
0N/A * <code>Image</code> is not equal to the
0N/A * passed in <code>Image</code> <code>img</code>.
0N/A *
0N/A * @param img the <code>Image</code> to be compared
0N/A * @param infoflags flags used to repaint the button when the image
0N/A * is updated and which determine how much is to be painted
0N/A * @param x the x coordinate
0N/A * @param y the y coordinate
0N/A * @param w the width
0N/A * @param h the height
0N/A * @see java.awt.image.ImageObserver
0N/A * @see java.awt.Component#imageUpdate(java.awt.Image, int, int, int, int, int)
0N/A */
0N/A public boolean imageUpdate(Image img, int infoflags,
0N/A int x, int y, int w, int h) {
0N/A Icon iconDisplayed = getIcon();
0N/A if (iconDisplayed == null) {
0N/A return false;
0N/A }
0N/A
0N/A if (!model.isEnabled()) {
0N/A if (model.isSelected()) {
0N/A iconDisplayed = getDisabledSelectedIcon();
0N/A } else {
0N/A iconDisplayed = getDisabledIcon();
0N/A }
0N/A } else if (model.isPressed() && model.isArmed()) {
0N/A iconDisplayed = getPressedIcon();
0N/A } else if (isRolloverEnabled() && model.isRollover()) {
0N/A if (model.isSelected()) {
0N/A iconDisplayed = getRolloverSelectedIcon();
0N/A } else {
0N/A iconDisplayed = getRolloverIcon();
0N/A }
0N/A } else if (model.isSelected()) {
0N/A iconDisplayed = getSelectedIcon();
0N/A }
0N/A
0N/A if (!SwingUtilities.doesIconReferenceImage(iconDisplayed, img)) {
0N/A // We don't know about this image, disable the notification so
0N/A // we don't keep repainting.
0N/A return false;
0N/A }
0N/A return super.imageUpdate(img, infoflags, x, y, w, h);
0N/A }
0N/A
0N/A void setUIProperty(String propertyName, Object value) {
0N/A if (propertyName == "borderPainted") {
0N/A if (!borderPaintedSet) {
0N/A setBorderPainted(((Boolean)value).booleanValue());
0N/A borderPaintedSet = false;
0N/A }
0N/A } else if (propertyName == "rolloverEnabled") {
0N/A if (!rolloverEnabledSet) {
0N/A setRolloverEnabled(((Boolean)value).booleanValue());
0N/A rolloverEnabledSet = false;
0N/A }
0N/A } else if (propertyName == "iconTextGap") {
0N/A if (!iconTextGapSet) {
0N/A setIconTextGap(((Number)value).intValue());
0N/A iconTextGapSet = false;
0N/A }
0N/A } else if (propertyName == "contentAreaFilled") {
0N/A if (!contentAreaFilledSet) {
0N/A setContentAreaFilled(((Boolean)value).booleanValue());
0N/A contentAreaFilledSet = false;
0N/A }
0N/A } else {
0N/A super.setUIProperty(propertyName, value);
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Returns a string representation of this <code>AbstractButton</code>.
0N/A * This method
0N/A * is intended to be used only for debugging purposes, and the
0N/A * content and format of the returned string may vary between
0N/A * implementations. The returned string may be empty but may not
0N/A * be <code>null</code>.
0N/A * <P>
0N/A * Overriding <code>paramString</code> to provide information about the
0N/A * specific new aspects of the JFC components.
0N/A *
0N/A * @return a string representation of this <code>AbstractButton</code>
0N/A */
0N/A protected String paramString() {
0N/A String defaultIconString = ((defaultIcon != null)
0N/A && (defaultIcon != this) ?
0N/A defaultIcon.toString() : "");
0N/A String pressedIconString = ((pressedIcon != null)
0N/A && (pressedIcon != this) ?
0N/A pressedIcon.toString() : "");
0N/A String disabledIconString = ((disabledIcon != null)
0N/A && (disabledIcon != this) ?
0N/A disabledIcon.toString() : "");
0N/A String selectedIconString = ((selectedIcon != null)
0N/A && (selectedIcon != this) ?
0N/A selectedIcon.toString() : "");
0N/A String disabledSelectedIconString = ((disabledSelectedIcon != null) &&
0N/A (disabledSelectedIcon != this) ?
0N/A disabledSelectedIcon.toString()
0N/A : "");
0N/A String rolloverIconString = ((rolloverIcon != null)
0N/A && (rolloverIcon != this) ?
0N/A rolloverIcon.toString() : "");
0N/A String rolloverSelectedIconString = ((rolloverSelectedIcon != null) &&
0N/A (rolloverSelectedIcon != this) ?
0N/A rolloverSelectedIcon.toString()
0N/A : "");
0N/A String paintBorderString = (paintBorder ? "true" : "false");
0N/A String paintFocusString = (paintFocus ? "true" : "false");
0N/A String rolloverEnabledString = (rolloverEnabled ? "true" : "false");
0N/A
0N/A return super.paramString() +
0N/A ",defaultIcon=" + defaultIconString +
0N/A ",disabledIcon=" + disabledIconString +
0N/A ",disabledSelectedIcon=" + disabledSelectedIconString +
0N/A ",margin=" + margin +
0N/A ",paintBorder=" + paintBorderString +
0N/A ",paintFocus=" + paintFocusString +
0N/A ",pressedIcon=" + pressedIconString +
0N/A ",rolloverEnabled=" + rolloverEnabledString +
0N/A ",rolloverIcon=" + rolloverIconString +
0N/A ",rolloverSelectedIcon=" + rolloverSelectedIconString +
0N/A ",selectedIcon=" + selectedIconString +
0N/A ",text=" + text;
0N/A }
0N/A
0N/A
0N/A private Handler getHandler() {
0N/A if (handler == null) {
0N/A handler = new Handler();
0N/A }
0N/A return handler;
0N/A }
0N/A
0N/A
0N/A //
0N/A // Listeners that are added to model
0N/A //
0N/A class Handler implements ActionListener, ChangeListener, ItemListener,
0N/A Serializable {
0N/A //
0N/A // ChangeListener
0N/A //
0N/A public void stateChanged(ChangeEvent e) {
0N/A Object source = e.getSource();
0N/A
0N/A updateMnemonicProperties();
0N/A if (isEnabled() != model.isEnabled()) {
0N/A setEnabled(model.isEnabled());
0N/A }
0N/A fireStateChanged();
0N/A repaint();
0N/A }
0N/A
0N/A //
0N/A // ActionListener
0N/A //
0N/A public void actionPerformed(ActionEvent event) {
0N/A fireActionPerformed(event);
0N/A }
0N/A
0N/A //
0N/A // ItemListener
0N/A //
0N/A public void itemStateChanged(ItemEvent event) {
0N/A fireItemStateChanged(event);
0N/A if (shouldUpdateSelectedStateFromAction()) {
0N/A Action action = getAction();
0N/A if (action != null && AbstractAction.hasSelectedKey(action)) {
0N/A boolean selected = isSelected();
0N/A boolean isActionSelected = AbstractAction.isSelected(
0N/A action);
0N/A if (isActionSelected != selected) {
0N/A action.putValue(Action.SELECTED_KEY, selected);
0N/A }
0N/A }
0N/A }
0N/A }
0N/A }
0N/A
0N/A///////////////////
0N/A// Accessibility support
0N/A///////////////////
0N/A /**
0N/A * This class implements accessibility support for the
0N/A * <code>AbstractButton</code> class. It provides an implementation of the
0N/A * Java Accessibility API appropriate to button and menu item
0N/A * user-interface elements.
0N/A * <p>
0N/A * <strong>Warning:</strong>
0N/A * Serialized objects of this class will not be compatible with
0N/A * future Swing releases. The current serialization support is
0N/A * appropriate for short term storage or RMI between applications running
0N/A * the same version of Swing. As of 1.4, support for long term storage
0N/A * of all JavaBeans<sup><font size="-2">TM</font></sup>
0N/A * has been added to the <code>java.beans</code> package.
0N/A * Please see {@link java.beans.XMLEncoder}.
0N/A * @since 1.4
0N/A */
0N/A protected abstract class AccessibleAbstractButton
0N/A extends AccessibleJComponent implements AccessibleAction,
0N/A AccessibleValue, AccessibleText, AccessibleExtendedComponent {
0N/A
0N/A /**
0N/A * Returns the accessible name of this object.
0N/A *
0N/A * @return the localized name of the object -- can be
0N/A * <code>null</code> if this
0N/A * object does not have a name
0N/A */
0N/A public String getAccessibleName() {
0N/A String name = accessibleName;
0N/A
0N/A if (name == null) {
0N/A name = (String)getClientProperty(AccessibleContext.ACCESSIBLE_NAME_PROPERTY);
0N/A }
0N/A if (name == null) {
0N/A name = AbstractButton.this.getText();
0N/A }
0N/A if (name == null) {
0N/A name = super.getAccessibleName();
0N/A }
0N/A return name;
0N/A }
0N/A
0N/A /**
0N/A * Get the AccessibleIcons associated with this object if one
0N/A * or more exist. Otherwise return null.
0N/A * @since 1.3
0N/A */
0N/A public AccessibleIcon [] getAccessibleIcon() {
0N/A Icon defaultIcon = getIcon();
0N/A
0N/A if (defaultIcon instanceof Accessible) {
0N/A AccessibleContext ac =
0N/A ((Accessible)defaultIcon).getAccessibleContext();
0N/A if (ac != null && ac instanceof AccessibleIcon) {
0N/A return new AccessibleIcon[] { (AccessibleIcon)ac };
0N/A }
0N/A }
0N/A return null;
0N/A }
0N/A
0N/A /**
0N/A * Get the state set of this object.
0N/A *
0N/A * @return an instance of AccessibleState containing the current state
0N/A * of the object
0N/A * @see AccessibleState
0N/A */
0N/A public AccessibleStateSet getAccessibleStateSet() {
0N/A AccessibleStateSet states = super.getAccessibleStateSet();
0N/A if (getModel().isArmed()) {
0N/A states.add(AccessibleState.ARMED);
0N/A }
0N/A if (isFocusOwner()) {
0N/A states.add(AccessibleState.FOCUSED);
0N/A }
0N/A if (getModel().isPressed()) {
0N/A states.add(AccessibleState.PRESSED);
0N/A }
0N/A if (isSelected()) {
0N/A states.add(AccessibleState.CHECKED);
0N/A }
0N/A return states;
0N/A }
0N/A
0N/A /**
0N/A * Get the AccessibleRelationSet associated with this object if one
0N/A * exists. Otherwise return null.
0N/A * @see AccessibleRelation
0N/A * @since 1.3
0N/A */
0N/A public AccessibleRelationSet getAccessibleRelationSet() {
0N/A
0N/A // Check where the AccessibleContext's relation
0N/A // set already contains a MEMBER_OF relation.
0N/A AccessibleRelationSet relationSet
0N/A = super.getAccessibleRelationSet();
0N/A
0N/A if (!relationSet.contains(AccessibleRelation.MEMBER_OF)) {
0N/A // get the members of the button group if one exists
0N/A ButtonModel model = getModel();
0N/A if (model != null && model instanceof DefaultButtonModel) {
0N/A ButtonGroup group = ((DefaultButtonModel)model).getGroup();
0N/A if (group != null) {
0N/A // set the target of the MEMBER_OF relation to be
0N/A // the members of the button group.
0N/A int len = group.getButtonCount();
0N/A Object [] target = new Object[len];
0N/A Enumeration elem = group.getElements();
0N/A for (int i = 0; i < len; i++) {
0N/A if (elem.hasMoreElements()) {
0N/A target[i] = elem.nextElement();
0N/A }
0N/A }
0N/A AccessibleRelation relation =
0N/A new AccessibleRelation(AccessibleRelation.MEMBER_OF);
0N/A relation.setTarget(target);
0N/A relationSet.add(relation);
0N/A }
0N/A }
0N/A }
0N/A return relationSet;
0N/A }
0N/A
0N/A /**
0N/A * Get the AccessibleAction associated with this object. In the
0N/A * implementation of the Java Accessibility API for this class,
0N/A * return this object, which is responsible for implementing the
0N/A * AccessibleAction interface on behalf of itself.
0N/A *
0N/A * @return this object
0N/A */
0N/A public AccessibleAction getAccessibleAction() {
0N/A return this;
0N/A }
0N/A
0N/A /**
0N/A * Get the AccessibleValue associated with this object. In the
0N/A * implementation of the Java Accessibility API for this class,
0N/A * return this object, which is responsible for implementing the
0N/A * AccessibleValue interface on behalf of itself.
0N/A *
0N/A * @return this object
0N/A */
0N/A public AccessibleValue getAccessibleValue() {
0N/A return this;
0N/A }
0N/A
0N/A /**
0N/A * Returns the number of Actions available in this object. The
0N/A * default behavior of a button is to have one action - toggle
0N/A * the button.
0N/A *
0N/A * @return 1, the number of Actions in this object
0N/A */
0N/A public int getAccessibleActionCount() {
0N/A return 1;
0N/A }
0N/A
0N/A /**
0N/A * Return a description of the specified action of the object.
0N/A *
0N/A * @param i zero-based index of the actions
0N/A */
0N/A public String getAccessibleActionDescription(int i) {
0N/A if (i == 0) {
0N/A return UIManager.getString("AbstractButton.clickText");
0N/A } else {
0N/A return null;
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Perform the specified Action on the object
0N/A *
0N/A * @param i zero-based index of actions
0N/A * @return true if the the action was performed; else false.
0N/A */
0N/A public boolean doAccessibleAction(int i) {
0N/A if (i == 0) {
0N/A doClick();
0N/A return true;
0N/A } else {
0N/A return false;
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Get the value of this object as a Number.
0N/A *
0N/A * @return An Integer of 0 if this isn't selected or an Integer of 1 if
0N/A * this is selected.
0N/A * @see AbstractButton#isSelected
0N/A */
0N/A public Number getCurrentAccessibleValue() {
0N/A if (isSelected()) {
215N/A return Integer.valueOf(1);
0N/A } else {
215N/A return Integer.valueOf(0);
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Set the value of this object as a Number.
0N/A *
0N/A * @return True if the value was set.
0N/A */
0N/A public boolean setCurrentAccessibleValue(Number n) {
0N/A // TIGER - 4422535
0N/A if (n == null) {
0N/A return false;
0N/A }
0N/A int i = n.intValue();
0N/A if (i == 0) {
0N/A setSelected(false);
0N/A } else {
0N/A setSelected(true);
0N/A }
0N/A return true;
0N/A }
0N/A
0N/A /**
0N/A * Get the minimum value of this object as a Number.
0N/A *
0N/A * @return an Integer of 0.
0N/A */
0N/A public Number getMinimumAccessibleValue() {
215N/A return Integer.valueOf(0);
0N/A }
0N/A
0N/A /**
0N/A * Get the maximum value of this object as a Number.
0N/A *
0N/A * @return An Integer of 1.
0N/A */
0N/A public Number getMaximumAccessibleValue() {
215N/A return Integer.valueOf(1);
0N/A }
0N/A
0N/A
0N/A /* AccessibleText ---------- */
0N/A
0N/A public AccessibleText getAccessibleText() {
0N/A View view = (View)AbstractButton.this.getClientProperty("html");
0N/A if (view != null) {
0N/A return this;
0N/A } else {
0N/A return null;
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Given a point in local coordinates, return the zero-based index
0N/A * of the character under that Point. If the point is invalid,
0N/A * this method returns -1.
0N/A *
0N/A * Note: the AbstractButton must have a valid size (e.g. have
0N/A * been added to a parent container whose ancestor container
0N/A * is a valid top-level window) for this method to be able
0N/A * to return a meaningful value.
0N/A *
0N/A * @param p the Point in local coordinates
0N/A * @return the zero-based index of the character under Point p; if
0N/A * Point is invalid returns -1.
0N/A * @since 1.3
0N/A */
0N/A public int getIndexAtPoint(Point p) {
0N/A View view = (View) AbstractButton.this.getClientProperty("html");
0N/A if (view != null) {
0N/A Rectangle r = getTextRectangle();
0N/A if (r == null) {
0N/A return -1;
0N/A }
0N/A Rectangle2D.Float shape =
0N/A new Rectangle2D.Float(r.x, r.y, r.width, r.height);
0N/A Position.Bias bias[] = new Position.Bias[1];
0N/A return view.viewToModel(p.x, p.y, shape, bias);
0N/A } else {
0N/A return -1;
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Determine the bounding box of the character at the given
0N/A * index into the string. The bounds are returned in local
0N/A * coordinates. If the index is invalid an empty rectangle is
0N/A * returned.
0N/A *
0N/A * Note: the AbstractButton must have a valid size (e.g. have
0N/A * been added to a parent container whose ancestor container
0N/A * is a valid top-level window) for this method to be able
0N/A * to return a meaningful value.
0N/A *
0N/A * @param i the index into the String
0N/A * @return the screen coordinates of the character's the bounding box,
0N/A * if index is invalid returns an empty rectangle.
0N/A * @since 1.3
0N/A */
0N/A public Rectangle getCharacterBounds(int i) {
0N/A View view = (View) AbstractButton.this.getClientProperty("html");
0N/A if (view != null) {
0N/A Rectangle r = getTextRectangle();
0N/A if (r == null) {
0N/A return null;
0N/A }
0N/A Rectangle2D.Float shape =
0N/A new Rectangle2D.Float(r.x, r.y, r.width, r.height);
0N/A try {
0N/A Shape charShape =
0N/A view.modelToView(i, shape, Position.Bias.Forward);
0N/A return charShape.getBounds();
0N/A } catch (BadLocationException e) {
0N/A return null;
0N/A }
0N/A } else {
0N/A return null;
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Return the number of characters (valid indicies)
0N/A *
0N/A * @return the number of characters
0N/A * @since 1.3
0N/A */
0N/A public int getCharCount() {
0N/A View view = (View) AbstractButton.this.getClientProperty("html");
0N/A if (view != null) {
0N/A Document d = view.getDocument();
0N/A if (d instanceof StyledDocument) {
0N/A StyledDocument doc = (StyledDocument)d;
0N/A return doc.getLength();
0N/A }
0N/A }
0N/A return accessibleContext.getAccessibleName().length();
0N/A }
0N/A
0N/A /**
0N/A * Return the zero-based offset of the caret.
0N/A *
0N/A * Note: That to the right of the caret will have the same index
0N/A * value as the offset (the caret is between two characters).
0N/A * @return the zero-based offset of the caret.
0N/A * @since 1.3
0N/A */
0N/A public int getCaretPosition() {
0N/A // There is no caret.
0N/A return -1;
0N/A }
0N/A
0N/A /**
0N/A * Returns the String at a given index.
0N/A *
0N/A * @param part the AccessibleText.CHARACTER, AccessibleText.WORD,
0N/A * or AccessibleText.SENTENCE to retrieve
0N/A * @param index an index within the text >= 0
0N/A * @return the letter, word, or sentence,
0N/A * null for an invalid index or part
0N/A * @since 1.3
0N/A */
0N/A public String getAtIndex(int part, int index) {
0N/A if (index < 0 || index >= getCharCount()) {
0N/A return null;
0N/A }
0N/A switch (part) {
0N/A case AccessibleText.CHARACTER:
0N/A try {
0N/A return getText(index, 1);
0N/A } catch (BadLocationException e) {
0N/A return null;
0N/A }
0N/A case AccessibleText.WORD:
0N/A try {
0N/A String s = getText(0, getCharCount());
0N/A BreakIterator words = BreakIterator.getWordInstance(getLocale());
0N/A words.setText(s);
0N/A int end = words.following(index);
0N/A return s.substring(words.previous(), end);
0N/A } catch (BadLocationException e) {
0N/A return null;
0N/A }
0N/A case AccessibleText.SENTENCE:
0N/A try {
0N/A String s = getText(0, getCharCount());
0N/A BreakIterator sentence =
0N/A BreakIterator.getSentenceInstance(getLocale());
0N/A sentence.setText(s);
0N/A int end = sentence.following(index);
0N/A return s.substring(sentence.previous(), end);
0N/A } catch (BadLocationException e) {
0N/A return null;
0N/A }
0N/A default:
0N/A return null;
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Returns the String after a given index.
0N/A *
0N/A * @param part the AccessibleText.CHARACTER, AccessibleText.WORD,
0N/A * or AccessibleText.SENTENCE to retrieve
0N/A * @param index an index within the text >= 0
0N/A * @return the letter, word, or sentence, null for an invalid
0N/A * index or part
0N/A * @since 1.3
0N/A */
0N/A public String getAfterIndex(int part, int index) {
0N/A if (index < 0 || index >= getCharCount()) {
0N/A return null;
0N/A }
0N/A switch (part) {
0N/A case AccessibleText.CHARACTER:
0N/A if (index+1 >= getCharCount()) {
0N/A return null;
0N/A }
0N/A try {
0N/A return getText(index+1, 1);
0N/A } catch (BadLocationException e) {
0N/A return null;
0N/A }
0N/A case AccessibleText.WORD:
0N/A try {
0N/A String s = getText(0, getCharCount());
0N/A BreakIterator words = BreakIterator.getWordInstance(getLocale());
0N/A words.setText(s);
0N/A int start = words.following(index);
0N/A if (start == BreakIterator.DONE || start >= s.length()) {
0N/A return null;
0N/A }
0N/A int end = words.following(start);
0N/A if (end == BreakIterator.DONE || end >= s.length()) {
0N/A return null;
0N/A }
0N/A return s.substring(start, end);
0N/A } catch (BadLocationException e) {
0N/A return null;
0N/A }
0N/A case AccessibleText.SENTENCE:
0N/A try {
0N/A String s = getText(0, getCharCount());
0N/A BreakIterator sentence =
0N/A BreakIterator.getSentenceInstance(getLocale());
0N/A sentence.setText(s);
0N/A int start = sentence.following(index);
0N/A if (start == BreakIterator.DONE || start > s.length()) {
0N/A return null;
0N/A }
0N/A int end = sentence.following(start);
0N/A if (end == BreakIterator.DONE || end > s.length()) {
0N/A return null;
0N/A }
0N/A return s.substring(start, end);
0N/A } catch (BadLocationException e) {
0N/A return null;
0N/A }
0N/A default:
0N/A return null;
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Returns the String before a given index.
0N/A *
0N/A * @param part the AccessibleText.CHARACTER, AccessibleText.WORD,
0N/A * or AccessibleText.SENTENCE to retrieve
0N/A * @param index an index within the text >= 0
0N/A * @return the letter, word, or sentence, null for an invalid index
0N/A * or part
0N/A * @since 1.3
0N/A */
0N/A public String getBeforeIndex(int part, int index) {
0N/A if (index < 0 || index > getCharCount()-1) {
0N/A return null;
0N/A }
0N/A switch (part) {
0N/A case AccessibleText.CHARACTER:
0N/A if (index == 0) {
0N/A return null;
0N/A }
0N/A try {
0N/A return getText(index-1, 1);
0N/A } catch (BadLocationException e) {
0N/A return null;
0N/A }
0N/A case AccessibleText.WORD:
0N/A try {
0N/A String s = getText(0, getCharCount());
0N/A BreakIterator words = BreakIterator.getWordInstance(getLocale());
0N/A words.setText(s);
0N/A int end = words.following(index);
0N/A end = words.previous();
0N/A int start = words.previous();
0N/A if (start == BreakIterator.DONE) {
0N/A return null;
0N/A }
0N/A return s.substring(start, end);
0N/A } catch (BadLocationException e) {
0N/A return null;
0N/A }
0N/A case AccessibleText.SENTENCE:
0N/A try {
0N/A String s = getText(0, getCharCount());
0N/A BreakIterator sentence =
0N/A BreakIterator.getSentenceInstance(getLocale());
0N/A sentence.setText(s);
0N/A int end = sentence.following(index);
0N/A end = sentence.previous();
0N/A int start = sentence.previous();
0N/A if (start == BreakIterator.DONE) {
0N/A return null;
0N/A }
0N/A return s.substring(start, end);
0N/A } catch (BadLocationException e) {
0N/A return null;
0N/A }
0N/A default:
0N/A return null;
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Return the AttributeSet for a given character at a given index
0N/A *
0N/A * @param i the zero-based index into the text
0N/A * @return the AttributeSet of the character
0N/A * @since 1.3
0N/A */
0N/A public AttributeSet getCharacterAttribute(int i) {
0N/A View view = (View) AbstractButton.this.getClientProperty("html");
0N/A if (view != null) {
0N/A Document d = view.getDocument();
0N/A if (d instanceof StyledDocument) {
0N/A StyledDocument doc = (StyledDocument)d;
0N/A Element elem = doc.getCharacterElement(i);
0N/A if (elem != null) {
0N/A return elem.getAttributes();
0N/A }
0N/A }
0N/A }
0N/A return null;
0N/A }
0N/A
0N/A /**
0N/A * Returns the start offset within the selected text.
0N/A * If there is no selection, but there is
0N/A * a caret, the start and end offsets will be the same.
0N/A *
0N/A * @return the index into the text of the start of the selection
0N/A * @since 1.3
0N/A */
0N/A public int getSelectionStart() {
0N/A // Text cannot be selected.
0N/A return -1;
0N/A }
0N/A
0N/A /**
0N/A * Returns the end offset within the selected text.
0N/A * If there is no selection, but there is
0N/A * a caret, the start and end offsets will be the same.
0N/A *
0N/A * @return the index into teh text of the end of the selection
0N/A * @since 1.3
0N/A */
0N/A public int getSelectionEnd() {
0N/A // Text cannot be selected.
0N/A return -1;
0N/A }
0N/A
0N/A /**
0N/A * Returns the portion of the text that is selected.
0N/A *
0N/A * @return the String portion of the text that is selected
0N/A * @since 1.3
0N/A */
0N/A public String getSelectedText() {
0N/A // Text cannot be selected.
0N/A return null;
0N/A }
0N/A
0N/A /*
0N/A * Returns the text substring starting at the specified
0N/A * offset with the specified length.
0N/A */
0N/A private String getText(int offset, int length)
0N/A throws BadLocationException {
0N/A
0N/A View view = (View) AbstractButton.this.getClientProperty("html");
0N/A if (view != null) {
0N/A Document d = view.getDocument();
0N/A if (d instanceof StyledDocument) {
0N/A StyledDocument doc = (StyledDocument)d;
0N/A return doc.getText(offset, length);
0N/A }
0N/A }
0N/A return null;
0N/A }
0N/A
0N/A /*
0N/A * Returns the bounding rectangle for the component text.
0N/A */
0N/A private Rectangle getTextRectangle() {
0N/A
0N/A String text = AbstractButton.this.getText();
0N/A Icon icon = (AbstractButton.this.isEnabled()) ? AbstractButton.this.getIcon() : AbstractButton.this.getDisabledIcon();
0N/A
0N/A if ((icon == null) && (text == null)) {
0N/A return null;
0N/A }
0N/A
0N/A Rectangle paintIconR = new Rectangle();
0N/A Rectangle paintTextR = new Rectangle();
0N/A Rectangle paintViewR = new Rectangle();
0N/A Insets paintViewInsets = new Insets(0, 0, 0, 0);
0N/A
0N/A paintViewInsets = AbstractButton.this.getInsets(paintViewInsets);
0N/A paintViewR.x = paintViewInsets.left;
0N/A paintViewR.y = paintViewInsets.top;
0N/A paintViewR.width = AbstractButton.this.getWidth() - (paintViewInsets.left + paintViewInsets.right);
0N/A paintViewR.height = AbstractButton.this.getHeight() - (paintViewInsets.top + paintViewInsets.bottom);
0N/A
0N/A String clippedText = SwingUtilities.layoutCompoundLabel(
625N/A AbstractButton.this,
0N/A getFontMetrics(getFont()),
0N/A text,
0N/A icon,
0N/A AbstractButton.this.getVerticalAlignment(),
0N/A AbstractButton.this.getHorizontalAlignment(),
0N/A AbstractButton.this.getVerticalTextPosition(),
0N/A AbstractButton.this.getHorizontalTextPosition(),
0N/A paintViewR,
0N/A paintIconR,
0N/A paintTextR,
0N/A 0);
0N/A
0N/A return paintTextR;
0N/A }
0N/A
0N/A // ----- AccessibleExtendedComponent
0N/A
0N/A /**
0N/A * Returns the AccessibleExtendedComponent
0N/A *
0N/A * @return the AccessibleExtendedComponent
0N/A */
0N/A AccessibleExtendedComponent getAccessibleExtendedComponent() {
0N/A return this;
0N/A }
0N/A
0N/A /**
0N/A * Returns the tool tip text
0N/A *
0N/A * @return the tool tip text, if supported, of the object;
0N/A * otherwise, null
0N/A * @since 1.4
0N/A */
0N/A public String getToolTipText() {
0N/A return AbstractButton.this.getToolTipText();
0N/A }
0N/A
0N/A /**
0N/A * Returns the titled border text
0N/A *
0N/A * @return the titled border text, if supported, of the object;
0N/A * otherwise, null
0N/A * @since 1.4
0N/A */
0N/A public String getTitledBorderText() {
0N/A return super.getTitledBorderText();
0N/A }
0N/A
0N/A /**
0N/A * Returns key bindings associated with this object
0N/A *
0N/A * @return the key bindings, if supported, of the object;
0N/A * otherwise, null
0N/A * @see AccessibleKeyBinding
0N/A * @since 1.4
0N/A */
0N/A public AccessibleKeyBinding getAccessibleKeyBinding() {
0N/A int mnemonic = AbstractButton.this.getMnemonic();
0N/A if (mnemonic == 0) {
0N/A return null;
0N/A }
0N/A return new ButtonKeyBinding(mnemonic);
0N/A }
0N/A
0N/A class ButtonKeyBinding implements AccessibleKeyBinding {
0N/A int mnemonic;
0N/A
0N/A ButtonKeyBinding(int mnemonic) {
0N/A this.mnemonic = mnemonic;
0N/A }
0N/A
0N/A /**
0N/A * Returns the number of key bindings for this object
0N/A *
0N/A * @return the zero-based number of key bindings for this object
0N/A */
0N/A public int getAccessibleKeyBindingCount() {
0N/A return 1;
0N/A }
0N/A
0N/A /**
0N/A * Returns a key binding for this object. The value returned is an
0N/A * java.lang.Object which must be cast to appropriate type depending
0N/A * on the underlying implementation of the key. For example, if the
0N/A * Object returned is a javax.swing.KeyStroke, the user of this
0N/A * method should do the following:
0N/A * <nf><code>
0N/A * Component c = <get the component that has the key bindings>
0N/A * AccessibleContext ac = c.getAccessibleContext();
0N/A * AccessibleKeyBinding akb = ac.getAccessibleKeyBinding();
0N/A * for (int i = 0; i < akb.getAccessibleKeyBindingCount(); i++) {
0N/A * Object o = akb.getAccessibleKeyBinding(i);
0N/A * if (o instanceof javax.swing.KeyStroke) {
0N/A * javax.swing.KeyStroke keyStroke = (javax.swing.KeyStroke)o;
0N/A * <do something with the key binding>
0N/A * }
0N/A * }
0N/A * </code></nf>
0N/A *
0N/A * @param i zero-based index of the key bindings
0N/A * @return a javax.lang.Object which specifies the key binding
0N/A * @exception IllegalArgumentException if the index is
0N/A * out of bounds
0N/A * @see #getAccessibleKeyBindingCount
0N/A */
0N/A public java.lang.Object getAccessibleKeyBinding(int i) {
0N/A if (i != 0) {
0N/A throw new IllegalArgumentException();
0N/A }
0N/A return KeyStroke.getKeyStroke(mnemonic, 0);
0N/A }
0N/A }
0N/A }
0N/A}