public class Command
- Object
- Command
ImplementsActionListener<ActionEvent>
Known subtypesShareService, NavigationCommand
The Command class provides a useful extension to the ActionListener
interface in cases where the same functionality may be accessed by several controls.
Fields
public static final String DESKTOP_MENU = "DesktopMenu" | Client property key carrying the desktop native-menu placement hint for this command. |
public static final String DESKTOP_MENU_APP = "App" | Standard desktop menu placement: the application menu (macOS app menu / a leading menu). |
public static final String DESKTOP_MENU_ABOUT = "About" | Standard desktop menu placement: an “About” item, conventionally in the application menu. |
public static final String DESKTOP_MENU_PREFERENCES = "Preferences" | Standard desktop menu placement: a “Preferences”/“Settings” item in the application menu. |
public static final String DESKTOP_MENU_QUIT = "Quit" | Standard desktop menu placement: a “Quit”/“Exit” item in the application menu. |
public static final String DESKTOP_MENU_FILE = "File" | Standard desktop menu placement: the File menu. |
public static final String DESKTOP_MENU_EDIT = "Edit" | Standard desktop menu placement: the Edit menu. |
public static final String DESKTOP_MENU_VIEW = "View" | Standard desktop menu placement: the View menu. |
public static final String DESKTOP_MENU_WINDOW = "Window" | Standard desktop menu placement: the Window menu. |
public static final String DESKTOP_MENU_HELP = "Help" | Standard desktop menu placement: the Help menu. |
public static final String DESKTOP_SHORTCUT_KEY = "DesktopShortcutKey" | Client property key carrying the upper-cased character of the desktop keyboard accelerator (as an Integer), see #setDesktopShortcut(char, int). |
public static final String DESKTOP_SHORTCUT_MODIFIERS = "DesktopShortcutModifiers" | Client property key carrying the modifier bit-mask of the desktop keyboard accelerator (as an Integer), see #setDesktopShortcut(char, int). |
public static final int DESKTOP_SHORTCUT_MODIFIER_PRIMARY = 1 | Accelerator modifier flag for the platform’s primary command key: Command on macOS, Control on Windows/Linux. |
public static final int DESKTOP_SHORTCUT_MODIFIER_SHIFT = 2 | Accelerator modifier flag for the Shift key. |
public static final int DESKTOP_SHORTCUT_MODIFIER_ALT = 4 | Accelerator modifier flag for the Alt/Option key. |
Constructors
public Command(String command) | Creates a new instance of Command |
public Command(String command, Image icon) | Creates a new instance of Command |
public Command(String command, int id) | Creates a new instance of Command |
public Command(String command, Image icon, int id) | Creates a new instance of Command |
Methods
public static Command create(String name, Image icon, ActionListener ev) | Creates a new command instance that encapsulates the action listener and details, the main value of this approach is in our ability to write commands using the shorthand lambda syntax of Java 8. |
public static Command createMaterial(String name, char icon, ActionListener ev) | Creates a new command instance that encapsulates the action listener and details, the main value of this approach is in our ability to write commands using the shorthand lambda syntax of Java 8. |
public int getId() | Return the command ID |
public String getCommandName() | gets the Command Name |
public void setCommandName(String command) | sets the Command name |
public Image getIcon() | Returns the icon representing the command |
public void setIcon(Image icon) | Sets the icon for the command |
public String toString() | Returns a string representation of the object |
public Image getPressedIcon() | Indicates the icon that is displayed on the button when the button is in pressed state |
public void setPressedIcon(Image pressedIcon) | Indicates the icon that is displayed on the button when the button is in pressed state |
public Image getDisabledIcon() | Indicates the icon that is displayed on the button when the button is in the disabled state |
public void setDisabledIcon(Image disabledIcon) | Indicates the icon that is displayed on the button when the button is in the disabled state |
public Image getRolloverIcon() | Indicates the icon that is displayed on the button when the button is in rolled over state |
public void setRolloverIcon(Image rolloverIcon) | Indicates the icon that is displayed on the button when the button is in rolled over state |
public boolean equals(Object obj) | compare two commands |
public int hashCode() | Allows storing commands in a vector/hashtable |
public void actionPerformed(ActionEvent evt) | This method is called when the soft button/Menu item is clicked |
public boolean isDisposesDialog() | Indicates whether this command causes the dialog to dispose implicitly, defaults to true |
public void setDisposesDialog(boolean disposesDialog) | Indicates whether this command causes the dialog to dispose implicitly, defaults to true |
public boolean isEnabled() | Allows disabling/enabling the command |
public void setEnabled(boolean enabled) | Allows disabling/enabling the command |
public Object getClientProperty(String key) | The client properties are a useful way to associate meta-data with a command without subclassing |
public void putClientProperty(String key, Object value) | The client properties are a useful way to associate meta-data with a command without sub classing |
public Command setDesktopMenu(String menu) | Sets the desktop native-menu placement hint for this command. |
public String getDesktopMenu() | Returns the desktop native-menu placement hint, or null when unset. |
public Command setDesktopShortcut(char keyChar) | Assigns a keyboard accelerator to this command for the desktop native menu bar using the platform’s primary modifier (Command on macOS, Control elsewhere). |
public Command setDesktopShortcut(char keyChar, int modifiers) | Assigns a keyboard accelerator to this command for the desktop native menu bar. |
public int getDesktopShortcutKeyChar() | Returns the upper-cased accelerator character assigned via #setDesktopShortcut(char, int), or 0 when no accelerator is set. |
public int getDesktopShortcutModifiers() | Returns the accelerator modifier bit-mask assigned via #setDesktopShortcut(char, int), or 0 when no accelerator is set. |
public char getMaterialIcon() | |
public void setMaterialIcon(char materialIcon) | |
public float getIconGapMM() | The gap between the text and the icon in millimeters or -1 for default |
public void setIconGapMM(float iconGapMM) | The gap between the text and the icon in millimeters or -1 for default |
public float getMaterialIconSize() | |
public void setMaterialIconSize(float materialIconSize) | |
public Font getIconFont() | |
public void setIconFont(Font iconFont) |
Inherited methods
Field details
DESKTOP_MENU
public static final String DESKTOP_MENU = "DesktopMenu"Client property key carrying the desktop native-menu placement hint for this command.
When a desktop app bridges its commands to the native menu bar (title-bar mode
native/custom), the value selects which menu the command appears under.
Recognized values (case-insensitive): #DESKTOP_MENU_APP, #DESKTOP_MENU_ABOUT,
#DESKTOP_MENU_PREFERENCES, #DESKTOP_MENU_QUIT, #DESKTOP_MENU_FILE,
#DESKTOP_MENU_EDIT, #DESKTOP_MENU_VIEW, #DESKTOP_MENU_WINDOW, #DESKTOP_MENU_HELP.
Any other value becomes a top-level menu with that literal title. Commands without the
hint are grouped under a default application-commands menu.DESKTOP_MENU_APP
public static final String DESKTOP_MENU_APP = "App"Standard desktop menu placement: the application menu (macOS app menu / a leading menu).
DESKTOP_MENU_ABOUT
public static final String DESKTOP_MENU_ABOUT = "About"Standard desktop menu placement: an “About” item, conventionally in the application menu.
DESKTOP_MENU_PREFERENCES
public static final String DESKTOP_MENU_PREFERENCES = "Preferences"Standard desktop menu placement: a “Preferences”/“Settings” item in the application menu.
DESKTOP_MENU_QUIT
public static final String DESKTOP_MENU_QUIT = "Quit"Standard desktop menu placement: a “Quit”/“Exit” item in the application menu.
DESKTOP_MENU_FILE
public static final String DESKTOP_MENU_FILE = "File"Standard desktop menu placement: the File menu.
DESKTOP_MENU_EDIT
public static final String DESKTOP_MENU_EDIT = "Edit"Standard desktop menu placement: the Edit menu.
DESKTOP_MENU_VIEW
public static final String DESKTOP_MENU_VIEW = "View"Standard desktop menu placement: the View menu.
DESKTOP_MENU_WINDOW
public static final String DESKTOP_MENU_WINDOW = "Window"Standard desktop menu placement: the Window menu.
DESKTOP_MENU_HELP
public static final String DESKTOP_MENU_HELP = "Help"Standard desktop menu placement: the Help menu.
DESKTOP_SHORTCUT_KEY
public static final String DESKTOP_SHORTCUT_KEY = "DesktopShortcutKey"Client property key carrying the upper-cased character of the desktop keyboard
accelerator (as an
Integer), see #setDesktopShortcut(char, int).DESKTOP_SHORTCUT_MODIFIERS
public static final String DESKTOP_SHORTCUT_MODIFIERS = "DesktopShortcutModifiers"Client property key carrying the modifier bit-mask of the desktop keyboard accelerator
(as an
Integer), see #setDesktopShortcut(char, int).DESKTOP_SHORTCUT_MODIFIER_PRIMARY
public static final int DESKTOP_SHORTCUT_MODIFIER_PRIMARY = 1Accelerator modifier flag for the platform’s primary command key: Command on macOS,
Control on Windows/Linux. This is the modifier used by the vast majority of menu
shortcuts so it’s the default.
DESKTOP_SHORTCUT_MODIFIER_SHIFT
public static final int DESKTOP_SHORTCUT_MODIFIER_SHIFT = 2Accelerator modifier flag for the Shift key.
DESKTOP_SHORTCUT_MODIFIER_ALT
public static final int DESKTOP_SHORTCUT_MODIFIER_ALT = 4Accelerator modifier flag for the Alt/Option key.
Constructor details
Command
public Command(String command)Creates a new instance of Command
Parameters
commandString- the string that will be placed on the Soft buttons\Menu
Command
public Command(String command, Image icon)Creates a new instance of Command
Parameters
commandString- the string that will be placed on the Soft buttons\Menu
iconImage- the icon representing the command
Command
public Command(String command, int id)Creates a new instance of Command
Parameters
commandString- the string that will be placed on the Soft buttons\Menu
idint- user defined ID for a command simplifying switch statement code working with a command
Command
public Command(String command, Image icon, int id)Creates a new instance of Command
Parameters
commandString- the string that will be placed on the Soft buttons\Menu
iconImage- the icon representing the command
idint- user defined ID for a command simplifying switch statement code working with a command
Method details
create
public static Command create(String name, Image icon, ActionListener ev)Creates a new command instance that encapsulates the action listener and details, the main
value of this approach is in our ability to write commands using the shorthand lambda syntax
of Java 8.
Parameters
nameString- the name/title of the command
iconImage- the icon for the command
evActionListener- the even handler
Returns
a newly created Command instance
createMaterial
public static Command createMaterial(String name, char icon, ActionListener ev)Creates a new command instance that encapsulates the action listener and details, the main
value of this approach is in our ability to write commands using the shorthand lambda syntax
of Java 8.
Parameters
nameString- the name/title of the command
iconchar- the icon for the command
evActionListener- the even handler
Returns
a newly created Command instance
getId
public int getId()Return the command ID
Returns
the command ID
getCommandName
public String getCommandName()gets the Command Name
Returns
the Command name
setCommandName
public void setCommandName(String command)sets the Command name
getIcon
public Image getIcon()Returns the icon representing the command
Returns
an icon representing the command
setIcon
public void setIcon(Image icon)Sets the icon for the command
Parameters
iconImage- the new icon
toString
public String toString()Returns a string representation of the object
Returns
Returns a string representation of the object
getPressedIcon
public Image getPressedIcon()Indicates the icon that is displayed on the button when the button is in
pressed state
Returns
icon used
setPressedIcon
public void setPressedIcon(Image pressedIcon)Indicates the icon that is displayed on the button when the button is in
pressed state
Parameters
pressedIconImage- icon used
getDisabledIcon
public Image getDisabledIcon()Indicates the icon that is displayed on the button when the button is in
the disabled state
Returns
icon used
setDisabledIcon
public void setDisabledIcon(Image disabledIcon)Indicates the icon that is displayed on the button when the button is in
the disabled state
Parameters
disabledIconImage- icon used
getRolloverIcon
public Image getRolloverIcon()Indicates the icon that is displayed on the button when the button is in
rolled over state
Returns
icon used
setRolloverIcon
public void setRolloverIcon(Image rolloverIcon)Indicates the icon that is displayed on the button when the button is in
rolled over state
Parameters
rolloverIconImage- icon to use
equals
public boolean equals(Object obj)compare two commands
Parameters
objObject- a Command Object to compare
Returns
true if the obj has the same command name
hashCode
public int hashCode()Allows storing commands in a vector/hashtable
Returns
unique hashcode for the command class
actionPerformed
public void actionPerformed(ActionEvent evt)This method is called when the soft button/Menu item is clicked
Parameters
evtActionEvent- the Event Object
isDisposesDialog
public boolean isDisposesDialog()Indicates whether this command causes the dialog to dispose implicitly, defaults to true
setDisposesDialog
public void setDisposesDialog(boolean disposesDialog)Indicates whether this command causes the dialog to dispose implicitly, defaults to true
isEnabled
public boolean isEnabled()Allows disabling/enabling the command
Returns
the enabled
setEnabled
public void setEnabled(boolean enabled)Allows disabling/enabling the command
Parameters
enabledboolean- the enabled to set
getClientProperty
public Object getClientProperty(String key)The client properties are a useful way to associate meta-data with a command
without subclassing
Parameters
keyString- an arbitrary user key
Returns
an arbitrary user object
putClientProperty
public void putClientProperty(String key, Object value)The client properties are a useful way to associate meta-data with a command
without sub classing
Parameters
keyString- an arbitrary user key
valueObject- an arbitrary user object, null to remove
setDesktopMenu
public Command setDesktopMenu(String menu)Sets the desktop native-menu placement hint for this command. See
#DESKTOP_MENU.Parameters
menuString- one of the
DESKTOP_MENU_*constants or a custom top-level menu title
Returns
this command, for chaining
getDesktopMenu
public String getDesktopMenu()Returns the desktop native-menu placement hint, or null when unset. See
#DESKTOP_MENU.Returns
the placement hint or null
setDesktopShortcut
public Command setDesktopShortcut(char keyChar)Assigns a keyboard accelerator to this command for the desktop native menu bar using the
platform’s primary modifier (Command on macOS, Control elsewhere). For example
setDesktopShortcut('S') produces Cmd+S / Ctrl+S next to the menu item. The hint is
inert on platforms without a native menu bar, so it’s safe to set unconditionally.Parameters
keyCharchar- the accelerator character (case-insensitive)
Returns
this command, for chaining
setDesktopShortcut
public Command setDesktopShortcut(char keyChar, int modifiers)Assigns a keyboard accelerator to this command for the desktop native menu bar. See
#setDesktopShortcut(char) for the common case.Parameters
keyCharchar- the accelerator character (case-insensitive)
modifiersint- a bit-mask of
#DESKTOP_SHORTCUT_MODIFIER_PRIMARY,#DESKTOP_SHORTCUT_MODIFIER_SHIFTand#DESKTOP_SHORTCUT_MODIFIER_ALT
Returns
this command, for chaining
getDesktopShortcutKeyChar
public int getDesktopShortcutKeyChar()Returns the upper-cased accelerator character assigned via
#setDesktopShortcut(char, int),
or 0 when no accelerator is set.Returns
the accelerator character or 0
getDesktopShortcutModifiers
public int getDesktopShortcutModifiers()Returns the accelerator modifier bit-mask assigned via
#setDesktopShortcut(char, int),
or 0 when no accelerator is set.Returns
the modifier bit-mask
getMaterialIcon
public char getMaterialIcon()Returns
the materialIcon
setMaterialIcon
public void setMaterialIcon(char materialIcon)Parameters
materialIconchar- the materialIcon to set
getIconGapMM
public float getIconGapMM()The gap between the text and the icon in millimeters or -1 for default
Returns
the iconGapMM
setIconGapMM
public void setIconGapMM(float iconGapMM)The gap between the text and the icon in millimeters or -1 for default
Parameters
iconGapMMfloat- the iconGapMM to set
getMaterialIconSize
public float getMaterialIconSize()Returns
the materialIconSize
setMaterialIconSize
public void setMaterialIconSize(float materialIconSize)Parameters
materialIconSizefloat- the materialIconSize to set
getIconFont
public Font getIconFont()Returns
the set iconFont or null if none defined (meaning for material icons instead of the system default MaterialDesign font
setIconFont
public void setIconFont(Font iconFont)Parameters
iconFontFont- use iconFont for material icons instead of the system default MaterialDesign font