sun.swing.UIAction Java Examples
The following examples show how to use
sun.swing.UIAction.
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 File: SwingUtilities.java From jdk1.8-source-analysis with Apache License 2.0 | 4 votes |
/** * 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
Source File: SwingUtilities.java From dragonwell8_jdk with GNU General Public License v2.0 | 4 votes |
/** * 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 File: SwingUtilities.java From TencentKona-8 with GNU General Public License v2.0 | 4 votes |
/** * 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 File: SwingUtilities.java From jdk8u60 with GNU General Public License v2.0 | 4 votes |
/** * 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 File: SwingUtilities.java From JDKSourceCode1.8 with MIT License | 4 votes |
/** * 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 File: SwingUtilities.java From openjdk-jdk8u with GNU General Public License v2.0 | 4 votes |
/** * 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
Source File: SwingUtilities.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 4 votes |
/** * 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 File: SwingUtilities.java From jdk8u-jdk with GNU General Public License v2.0 | 4 votes |
/** * 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 File: SwingUtilities.java From Java8CN with Apache License 2.0 | 4 votes |
/** * 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 File: SwingUtilities.java From hottub with GNU General Public License v2.0 | 4 votes |
/** * 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
Source File: SwingUtilities.java From openjdk-8-source with GNU General Public License v2.0 | 4 votes |
/** * 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 File: SwingUtilities.java From openjdk-8 with GNU General Public License v2.0 | 4 votes |
/** * 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 File: SwingUtilities.java From jdk8u_jdk with GNU General Public License v2.0 | 4 votes |
/** * 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 File: SwingUtilities.java From jdk8u-jdk with GNU General Public License v2.0 | 4 votes |
/** * 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 File: SwingUtilities.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 4 votes |
/** * 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; }