318 |
{ |
{ |
319 |
int oldstate = stateMask; |
int oldstate = stateMask; |
320 |
int newstate; |
int newstate; |
321 |
|
boolean toggle = (this instanceof JToggleButton.ToggleButtonModel); |
322 |
|
|
323 |
if (b) |
if (b) |
324 |
newstate = oldstate | stateflag; |
newstate = oldstate | stateflag; |
340 |
{ |
{ |
341 |
fireItemStateChanged(new ItemEvent(this, ItemEvent.ITEM_STATE_CHANGED, |
fireItemStateChanged(new ItemEvent(this, ItemEvent.ITEM_STATE_CHANGED, |
342 |
null, ItemEvent.SELECTED)); |
null, ItemEvent.SELECTED)); |
343 |
|
// If the button is a toggle button then we fire action performed when |
344 |
|
// the button changes state (selected/deselected), not when it changes |
345 |
|
// from pressed to unpressed |
346 |
|
if (toggle) |
347 |
|
fireActionPerformed(new ActionEvent(this, ActionEvent.ACTION_PERFORMED, |
348 |
|
actionCommand)); |
349 |
if (group != null) |
if (group != null) |
350 |
group.setSelected(this, true); |
group.setSelected(this, true); |
351 |
} |
} |
354 |
{ |
{ |
355 |
fireItemStateChanged(new ItemEvent(this, ItemEvent.ITEM_STATE_CHANGED, |
fireItemStateChanged(new ItemEvent(this, ItemEvent.ITEM_STATE_CHANGED, |
356 |
null, ItemEvent.DESELECTED)); |
null, ItemEvent.DESELECTED)); |
357 |
|
// If the button is a toggle button then we fire action performed when |
358 |
|
// the button changes state (selected/deselected), not when it changes |
359 |
|
// from pressed to unpressed |
360 |
|
if (toggle) |
361 |
|
fireActionPerformed(new ActionEvent(this, ActionEvent.ACTION_PERFORMED, |
362 |
|
actionCommand)); |
363 |
if (group != null) |
if (group != null) |
364 |
group.setSelected(this, false); |
group.setSelected(this, false); |
365 |
} |
} |
366 |
|
|
367 |
else if (((oldstate & ARMED) == ARMED && (oldstate & PRESSED) == PRESSED) |
else if (((oldstate & ARMED) == ARMED && (oldstate & PRESSED) == PRESSED) |
368 |
&& ((newstate & ARMED) == ARMED && (newstate & PRESSED) == 0)) |
&& ((newstate & ARMED) == ARMED && (newstate & PRESSED) == 0) && (!toggle)) |
369 |
fireActionPerformed(new ActionEvent(this, ActionEvent.ACTION_PERFORMED, |
fireActionPerformed(new ActionEvent(this, ActionEvent.ACTION_PERFORMED, |
370 |
actionCommand)); |
actionCommand)); |
371 |
} |
} |