本文整理汇总了Java中sun.swing.UIAction类的典型用法代码示例。如果您正苦于以下问题:Java UIAction类的具体用法?Java UIAction怎么用?Java UIAction使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
UIAction类属于sun.swing包,在下文中一共展示了UIAction类的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: notifyAction
import sun.swing.UIAction; //导入依赖的package包/类
/**
* Invokes <code>actionPerformed</code> on <code>action</code> if
* <code>action</code> is enabled (and non-{@code null}). The command for the
* ActionEvent is determined by:
* <ol>
* <li>If the action was registered via
* <code>registerKeyboardAction</code>, then the command string
* passed in ({@code null} will be used if {@code null} was passed in).
* <li>Action value with name Action.ACTION_COMMAND_KEY, unless {@code null}.
* <li>String value of the KeyEvent, unless <code>getKeyChar</code>
* returns KeyEvent.CHAR_UNDEFINED..
* </ol>
* This will return true if <code>action</code> is non-{@code null} and
* actionPerformed is invoked on it.
*
* @since 1.3
*/
public static boolean notifyAction(Action action, KeyStroke ks,
KeyEvent event, Object sender,
int modifiers) {
if (action == null) {
return false;
}
if (action instanceof UIAction) {
if (!((UIAction)action).isEnabled(sender)) {
return false;
}
}
else if (!action.isEnabled()) {
return false;
}
Object commandO;
boolean stayNull;
// Get the command object.
commandO = action.getValue(Action.ACTION_COMMAND_KEY);
if (commandO == null && (action instanceof JComponent.ActionStandin)) {
// ActionStandin is used for historical reasons to support
// registerKeyboardAction with a null value.
stayNull = true;
}
else {
stayNull = false;
}
// Convert it to a string.
String command;
if (commandO != null) {
command = commandO.toString();
}
else if (!stayNull && event.getKeyChar() != KeyEvent.CHAR_UNDEFINED) {
command = String.valueOf(event.getKeyChar());
}
else {
// Do null for undefined chars, or if registerKeyboardAction
// was called with a null.
command = null;
}
action.actionPerformed(new ActionEvent(sender,
ActionEvent.ACTION_PERFORMED, command, event.getWhen(),
modifiers));
return true;
}