/** * Get short description of action. Used for tooltip text. * * @return Short description. * * @see #SHORT_DESCRIPTION */ public String getShortDescription() { return (String)getValue( SHORT_DESCRIPTION ); }
/** * Set key stroke to use as keyboard accelerator. If {@code null} is * specified, any existing value is lost (removed). * * @param key Keystroke to use as keyboard accelerator. * * @see #ACCELERATOR_KEY * @see KeyStroke */ public void setAcceleratorKey( final KeyStroke key ) { putValue( ACCELERATOR_KEY, key ); }
setActionCommand( key ); setName( ResourceBundleTools.getString( bundle, key, key ) ); setDefaultIcon(); setShortDescription( ResourceBundleTools.getString( bundle, key + "Tip", null ) ); setAcceleratorKey( ResourceBundleTools.getString( bundle, key + "KeyStroke", null ) ); setMnemonicKey( ResourceBundleTools.getString( bundle, key + "Mnemonic", null ) );
setSmallIcon( new AsyncIcon( path, width, height ) ); System.err.println( "TODO: Set icon dimensions for '" + getActionCommand() + "' action" ); setSmallIcon( icon );
/** * Set key stroke to use as keyboard accelerator from a string in a format * compatible with {@code KeyStroke#getKeyStroke(String)}. If {@code null} * or an incorrectly formatted string is specified, any existing value is * lost (removed). * * @param key String representation of key stroke. * * @see #ACCELERATOR_KEY * @see KeyStroke * @see KeyStroke#getKeyStroke(String) */ public void setAcceleratorKey( final String key ) { if ( key != null ) { final KeyStroke keyStroke = KeyStroke.getKeyStroke( key ); if ( keyStroke == null ) { throw new IllegalArgumentException( "Invalid accelerator for " + getName() + ": " + key ); } setAcceleratorKey( keyStroke ); } }
/** * Forward execution requests for action to {@link #run} method. This * protects callers against exceptions thrown by this action. Any such * exceptions will be caught and presented in a 'crash dialog' to the user. * * @see #run */ public void actionPerformed( final ActionEvent event ) { try { run(); } catch ( Throwable problem ) { WindowTools.showErrorDialog( null, problem, getClass() ); } }
/** * Set mnemonic key from a string in a format compatible with {@code * KeyStroke#getKeyStroke(String)}. Any specified modifiers will be ignored. * If {@code null} or an incorrectly formatted string is specified, any * existing value is lost (removed). * * @param key String representation of mnemonic key. * * @see #MNEMONIC_KEY * @see KeyEvent * @see JMenuItem#setAction(Action) * @see KeyStroke#getKeyStroke(String) */ public void setMnemonicKey( final String key ) { final KeyStroke keyStroke = KeyStroke.getKeyStroke( key ); setMnemonicKey( ( keyStroke == null ) ? -1 : keyStroke.getKeyCode() ); }
/** * Set default icon for action. */ protected void setDefaultIcon() { final ResourceBundle bundle = _bundle; final String key = getActionCommand(); final String iconPath = ResourceBundleTools.getString( bundle, key + "Icon", null ); if ( iconPath != null ) { final int iconSize = ResourceBundleTools.getInt( bundle, key + "IconSize", -1 ); final int iconWidth = ResourceBundleTools.getInt( bundle, key + "IconWidth", iconSize ); final int iconHeight = ResourceBundleTools.getInt( bundle, key + "IconHeight", iconSize ); setSmallIcon( iconPath, iconWidth, iconHeight ); } }
/** * Set name of action. Used for a menu or button text. If {@code null} is * specified, any existing value is lost (removed). * * @param name Name of action. * * @see #NAME */ public void setName( final String name ) { putValue( NAME, name ); }
/** * Get small icon. Used for toolbar buttons. * * @return Small icon. * * @see #SMALL_ICON * @see Icon */ public Icon getSmallIcon() { return (Icon)getValue( SMALL_ICON ); }
/** * Set long description of action. Could be used for context-sensitive help. * If {@code null} is specified, any existing value is lost (removed). * * @param description Long description. * * @see #LONG_DESCRIPTION */ public void setLongDescription( final String description ) { putValue( LONG_DESCRIPTION, description ); }
/** * Get keystroke used as keyboard accelerator. * * @return Keystroke used as keyboard accelerator. * * @see #ACCELERATOR_KEY * @see KeyStroke */ public KeyStroke getAcceleratorKey() { return (KeyStroke)getValue( ACCELERATOR_KEY ); }
/** * Set command string to associate with action. If {@code null} is * specified, any existing value is lost (removed). * * @param command Command string to associate with action. * * @see #ACTION_COMMAND_KEY * @see ActionEvent */ private void setActionCommand( final String command ) { putValue( ACTION_COMMAND_KEY, command ); }
/** * Get name of action. Used for a menu or button text. * * @return Name of action. * * @see #NAME */ public String getName() { return (String)getValue( NAME ); }
/** * Set small icon. Used for toolbar buttons. If {@code null} is specified, * any existing value is lost (removed). * * @param icon Small icon. * * @see #SMALL_ICON * @see Icon */ public void setSmallIcon( final Icon icon ) { putValue( SMALL_ICON, icon ); }
/** * Get command string associated with action. * * @return Command string associated with action. * * @see #ACTION_COMMAND_KEY * @see ActionEvent */ public String getActionCommand() { return (String)getValue( ACTION_COMMAND_KEY ); }
/** * Set integer key code to use as mnemonic (e.g. key to select menu item). * If a negative code is specified, any existing value is lost (removed). * * @param key Integer key code to use as mnemonic. * * @see #MNEMONIC_KEY * @see java.awt.event.KeyEvent * @see javax.swing.JMenuItem#setAction(javax.swing.Action) */ public void setMnemonicKey( final int key ) { putValue( MNEMONIC_KEY, ( key < 0 ) ? null : new Integer( key ) ); }
/** * Get long description of action. Could be used for context-sensitive * help. * * @return Long description. * * @see #LONG_DESCRIPTION */ public String getLongDescription() { return (String)getValue( LONG_DESCRIPTION ); }
/** * Set short description of action. Used for tooltip text. If {@code null} * is specified, any existing value is lost (removed). * * @param description Short description. * * @see #SHORT_DESCRIPTION */ public void setShortDescription( final String description ) { putValue( SHORT_DESCRIPTION, TextTools.plainTextToHTML( description ) ); }
/** * Get integer key code used as mnemonic (e.g. key to select menu item). * * @return Integer key code used as mnemonic. * * @see #MNEMONIC_KEY * @see java.awt.event.KeyEvent * @see javax.swing.JMenuItem#setAction(javax.swing.Action) */ public int getMnemonicKey() { return ( (Number)getValue( MNEMONIC_KEY ) ).intValue(); }