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