<Swing Dev> Review request for 8133039 Provide public API to sun.swing.UIAction#isEnabled(Object)
Alexander Scherbatiy
alexandr.scherbatiy at oracle.com
Tue Nov 10 11:26:04 UTC 2015
Hello,
Could you review the fix:
bug: https://bugs.openjdk.java.net/browse/JDK-8133039
webrev: http://cr.openjdk.java.net/~alexsch/8133039/webrev.00
There are two use cases for the requested API:
- javax.swing.Action can be only enabled or disabled for all
components at once.
Sometimes it is necessary that an action was enabled only for some
components with required properties.
This is now implemented by internal
sun.swing.UIAction.isEnabled(Object sender) method.
- Wrap an existed action to add new behaviour.
For example:
------------------------------------------
/**
* Mute an action by doing nothing if the original action is enabled
*/
private static class MutedAction extends AbstractAction {
private final Object sender;
private final Action action;
public MutedAction(Object sender, Action action) {
this.sender = sender;
this.action = action;
}
@Override
public void actionPerformed(ActionEvent e) {
// muted
}
@Override
public boolean isEnabled() {
if(action instanceof sun.swing.UIAction) {
// internal API is used
return ((sun.swing.UIAction) action).isEnabled(sender);
}
else {
return action.isEnabled();
}
}
}
------------------------------------------
For more details see the email:
http://mail.openjdk.java.net/pipermail/swing-dev/2015-August/004729.html
The proposed fix adds public 'accept' method to the
javax.swing.Action class:
------------------------------------------
/**
* Determines whether the action should be invoked for the specified
* component.
*
* @param component the component to check
* @return {@code true} if the action should be invoked for the passed
* component
*/
default boolean accept(JComponent component) {
return true;
}
------------------------------------------
Thanks,
Alexandr.
More information about the swing-dev
mailing list