/**
* 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
*/
public void doClick(int pressTime) {
Dimension size = getSize();
model.setArmed(true);
model.setPressed(true);
paintImmediately(new Rectangle(0,0, size.width, size.height));
try {
Thread.currentThread().sleep(pressTime);
} catch(InterruptedException ie) {
}
model.setPressed(false);
model.setArmed(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.
*/
public void setMargin(Insets m) {
// Cache the old margin if it comes from the UI
if(m instanceof UIResource) {
defaultMargin = m;
} else if(margin instanceof UIResource) {
defaultMargin = margin;
}
// If the client passes in a null insets, restore the margin
// from the UI if possible
if(m == null && defaultMargin != null) {
m = defaultMargin;
}
Insets old = margin;
margin = m;
firePropertyChange(MARGIN_CHANGED_PROPERTY, old, m);
if (old == null || !old.equals(m)) {
revalidate();
repaint();
}
}
=4= |