8024329: [macosx] JRadioButtonMenuItem behaves like a checkbox when using the ScreenMenuBar

Reviewed-by: anthony, serb
This commit is contained in:
Petr Pchelko 2013-10-11 18:04:45 +04:00
parent c002447a5e
commit 11caa358e7

View File

@ -93,9 +93,9 @@ final class ScreenMenuItemCheckbox extends CheckboxMenuItem implements ActionLis
}
if (fMenuItem instanceof JCheckBoxMenuItem) {
setState(((JCheckBoxMenuItem)fMenuItem).isSelected());
forceSetState(fMenuItem.isSelected());
} else {
setState(fMenuItem.getModel().isSelected());
forceSetState(fMenuItem.getModel().isSelected());
}
}
@ -196,10 +196,10 @@ final class ScreenMenuItemCheckbox extends CheckboxMenuItem implements ActionLis
switch (e.getStateChange()) {
case ItemEvent.SELECTED:
setState(true);
forceSetState(true);
break;
case ItemEvent.DESELECTED:
setState(false);
forceSetState(false);
break;
}
}
@ -210,4 +210,20 @@ final class ScreenMenuItemCheckbox extends CheckboxMenuItem implements ActionLis
((CCheckboxMenuItem)peer).setIsIndeterminate(indeterminate);
}
}
/*
* The CCheckboxMenuItem peer is calling setState unconditionally every time user clicks the menu
* However for Swing controls in the screen menu bar it is wrong - the state should be changed only
* in response to the ITEM_STATE_CHANGED event. So the setState is overridden to no-op and all the
* correct state changes are made with forceSetState
*/
@Override
public synchronized void setState(boolean b) {
// No Op
}
private void forceSetState(boolean b) {
super.setState(b);
}
}