Java Code Examples for sun.swing.UIAction

The following examples show how to use sun.swing.UIAction. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: jdk1.8-source-analysis   Source File: SwingUtilities.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * 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;
}
 
Example 2
/**
 * 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;
}
 
Example 3
Source Project: TencentKona-8   Source File: SwingUtilities.java    License: GNU General Public License v2.0 4 votes vote down vote up
/**
 * 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;
}
 
Example 4
Source Project: jdk8u60   Source File: SwingUtilities.java    License: GNU General Public License v2.0 4 votes vote down vote up
/**
 * 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;
}
 
Example 5
Source Project: JDKSourceCode1.8   Source File: SwingUtilities.java    License: MIT License 4 votes vote down vote up
/**
 * 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;
}
 
Example 6
Source Project: openjdk-jdk8u   Source File: SwingUtilities.java    License: GNU General Public License v2.0 4 votes vote down vote up
/**
 * 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;
}
 
Example 7
/**
 * 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;
}
 
Example 8
Source Project: jdk8u-jdk   Source File: SwingUtilities.java    License: GNU General Public License v2.0 4 votes vote down vote up
/**
 * 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;
}
 
Example 9
Source Project: Java8CN   Source File: SwingUtilities.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * 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;
}
 
Example 10
Source Project: hottub   Source File: SwingUtilities.java    License: GNU General Public License v2.0 4 votes vote down vote up
/**
 * 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;
}
 
Example 11
/**
 * 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;
}
 
Example 12
Source Project: openjdk-8   Source File: SwingUtilities.java    License: GNU General Public License v2.0 4 votes vote down vote up
/**
 * 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;
}
 
Example 13
Source Project: jdk8u_jdk   Source File: SwingUtilities.java    License: GNU General Public License v2.0 4 votes vote down vote up
/**
 * 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;
}
 
Example 14
Source Project: jdk8u-jdk   Source File: SwingUtilities.java    License: GNU General Public License v2.0 4 votes vote down vote up
/**
 * 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;
}
 
Example 15
Source Project: jdk8u-dev-jdk   Source File: SwingUtilities.java    License: GNU General Public License v2.0 4 votes vote down vote up
/**
 * 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;
}