Method from javax.swing.DefaultButtonModel Detail: |
public void addActionListener(ActionListener l) {
listenerList.add(ActionListener.class, l);
}
|
public void addChangeListener(ChangeListener l) {
listenerList.add(ChangeListener.class, l);
}
|
public void addItemListener(ItemListener l) {
listenerList.add(ItemListener.class, l);
}
|
protected void fireActionPerformed(ActionEvent e) {
// Guaranteed to return a non-null array
Object[] listeners = listenerList.getListenerList();
// Process the listeners last to first, notifying
// those that are interested in this event
for (int i = listeners.length-2; i >=0; i-=2) {
if (listeners[i]==ActionListener.class) {
// Lazily create the event:
// if (changeEvent == null)
// changeEvent = new ChangeEvent(this);
((ActionListener)listeners[i+1]).actionPerformed(e);
}
}
}
Notifies all listeners that have registered interest for
notification on this event type. |
protected void fireItemStateChanged(ItemEvent e) {
// Guaranteed to return a non-null array
Object[] listeners = listenerList.getListenerList();
// Process the listeners last to first, notifying
// those that are interested in this event
for (int i = listeners.length-2; i >=0; i-=2) {
if (listeners[i]==ItemListener.class) {
// Lazily create the event:
// if (changeEvent == null)
// changeEvent = new ChangeEvent(this);
((ItemListener)listeners[i+1]).itemStateChanged(e);
}
}
}
Notifies all listeners that have registered interest for
notification on this event type. |
protected void fireStateChanged() {
// Guaranteed to return a non-null array
Object[] listeners = listenerList.getListenerList();
// Process the listeners last to first, notifying
// those that are interested in this event
for (int i = listeners.length-2; i >=0; i-=2) {
if (listeners[i]==ChangeListener.class) {
// Lazily create the event:
if (changeEvent == null)
changeEvent = new ChangeEvent(this);
((ChangeListener)listeners[i+1]).stateChanged(changeEvent);
}
}
}
Notifies all listeners that have registered interest for
notification on this event type. The event instance
is created lazily. |
public String getActionCommand() {
return actionCommand;
}
|
public ActionListener[] getActionListeners() {
return listenerList.getListeners(ActionListener.class);
}
Returns an array of all the action listeners
registered on this DefaultButtonModel . |
public ChangeListener[] getChangeListeners() {
return listenerList.getListeners(ChangeListener.class);
}
Returns an array of all the change listeners
registered on this DefaultButtonModel . |
public ButtonGroup getGroup() {
return group;
}
Returns the group that the button belongs to.
Normally used with radio buttons, which are mutually
exclusive within their group. |
public ItemListener[] getItemListeners() {
return listenerList.getListeners(ItemListener.class);
}
Returns an array of all the item listeners
registered on this DefaultButtonModel . |
public T[] getListeners(Class<T> listenerType) {
return listenerList.getListeners(listenerType);
}
Returns an array of all the objects currently registered as
FooListener s
upon this model.
FooListener s
are registered using the addFooListener method.
You can specify the listenerType argument
with a class literal, such as FooListener.class .
For example, you can query a DefaultButtonModel
instance m
for its action listeners
with the following code:
ActionListener[] als = (ActionListener[])(m.getListeners(ActionListener.class));
If no such listeners exist,
this method returns an empty array. |
public int getMnemonic() {
return mnemonic;
}
|
public Object[] getSelectedObjects() {
return null;
}
Overridden to return null . |
public boolean isArmed() {
return (stateMask & ARMED) != 0;
}
|
public boolean isEnabled() {
return (stateMask & ENABLED) != 0;
}
|
boolean isMenuItem() {
return menuItem;
}
|
public boolean isPressed() {
return (stateMask & PRESSED) != 0;
}
|
public boolean isRollover() {
return (stateMask & ROLLOVER) != 0;
}
|
public boolean isSelected() {
return (stateMask & SELECTED) != 0;
}
|
public void removeActionListener(ActionListener l) {
listenerList.remove(ActionListener.class, l);
}
|
public void removeChangeListener(ChangeListener l) {
listenerList.remove(ChangeListener.class, l);
}
|
public void removeItemListener(ItemListener l) {
listenerList.remove(ItemListener.class, l);
}
|
public void setActionCommand(String actionCommand) {
this.actionCommand = actionCommand;
}
|
public void setArmed(boolean b) {
if(isMenuItem() &&
UIManager.getBoolean("MenuItem.disabledAreNavigable")) {
if ((isArmed() == b)) {
return;
}
} else {
if ((isArmed() == b) || !isEnabled()) {
return;
}
}
if (b) {
stateMask |= ARMED;
} else {
stateMask &= ~ARMED;
}
fireStateChanged();
}
|
public void setEnabled(boolean b) {
if(isEnabled() == b) {
return;
}
if (b) {
stateMask |= ENABLED;
} else {
stateMask &= ~ENABLED;
// unarm and unpress, just in case
stateMask &= ~ARMED;
stateMask &= ~PRESSED;
}
fireStateChanged();
}
|
public void setGroup(ButtonGroup group) {
this.group = group;
}
|
void setMenuItem(boolean menuItem) {
this.menuItem = menuItem;
}
|
public void setMnemonic(int key) {
mnemonic = key;
fireStateChanged();
}
|
public void setPressed(boolean b) {
if((isPressed() == b) || !isEnabled()) {
return;
}
if (b) {
stateMask |= PRESSED;
} else {
stateMask &= ~PRESSED;
}
if(!isPressed() && isArmed()) {
int modifiers = 0;
AWTEvent currentEvent = EventQueue.getCurrentEvent();
if (currentEvent instanceof InputEvent) {
modifiers = ((InputEvent)currentEvent).getModifiers();
} else if (currentEvent instanceof ActionEvent) {
modifiers = ((ActionEvent)currentEvent).getModifiers();
}
fireActionPerformed(
new ActionEvent(this, ActionEvent.ACTION_PERFORMED,
getActionCommand(),
EventQueue.getMostRecentEventTime(),
modifiers));
}
fireStateChanged();
}
|
public void setRollover(boolean b) {
if((isRollover() == b) || !isEnabled()) {
return;
}
if (b) {
stateMask |= ROLLOVER;
} else {
stateMask &= ~ROLLOVER;
}
fireStateChanged();
}
|
public void setSelected(boolean b) {
if (this.isSelected() == b) {
return;
}
if (b) {
stateMask |= SELECTED;
} else {
stateMask &= ~SELECTED;
}
fireItemStateChanged(
new ItemEvent(this,
ItemEvent.ITEM_STATE_CHANGED,
this,
b ? ItemEvent.SELECTED : ItemEvent.DESELECTED));
fireStateChanged();
}
|