Client API. The Codename One framework your app is built on: this runs on the device, not in a backend.
public class Command
- Object
- Command
ImplementsActionListener<ActionEvent>
Known subtypesShareService, NavigationCommand
Fields
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 setDesktopMenuGroup(int group) | Places this command in a separator group within its desktop menu. |
public int getDesktopMenuGroup() | Returns the separator group set with #setDesktopMenuGroup(int), 0 when unset. |
public static Command createDesktopSeparator(String menu) | Creates a command that shows as a separator line in a desktop native menu, at the position it is added in. |
public boolean isDesktopSeparator() | True when this command was created by #createDesktopSeparator(String). |
public Command setDesktopChecked(boolean checked) | Makes this command a check item in the desktop native menu and sets its state. |
public boolean isDesktopCheckable() | True when this command is a check or radio item, see #setDesktopChecked(boolean). |
public boolean isDesktopChecked() | The checked state of a check or radio item, false when the command is not checkable. |
public Command setDesktopRadioGroup(String group) | Makes this command a radio item of the named group in the desktop native menu. |
public String getDesktopRadioGroup() | Returns the radio group set with #setDesktopRadioGroup(String), or null. |
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 Command setDesktopRole(String role) | Marks this command as one of the standard commands every desktop application has, so the native menu bar puts it where the platform’s own applications do: About, Settings and Quit in the application menu on macOS; About under Help, Options under Tools and Exit under File on Windows; Preferences under Edit on Linux. |
public String getDesktopRole() | Returns the standard desktop role, or null when unset. |
public static Command createDesktopRole(String role, ActionListener listener) | Creates a command for a standard desktop role, named the way the running platform names it: “Quit” on macOS and Linux and “Exit” on Windows, “Settings”, “Options” or “Preferences”, “About” followed by the application name. |
public Command setDesktopPlatforms(String... platforms) | Publishes this command on the native menu bar of the listed platforms only, for a command that only makes sense on some of them. |
public boolean isDesktopPlatform(String platform) | True when this command is published on the native menu bar of the named platform. |
public Command setDesktopEnabledWhenModified(boolean follow) | Makes this command’s enabled state follow the document-modified state of the form or window publishing it: enabled while the document has unsaved changes, disabled once it is saved. |
public boolean isDesktopEnabledWhenModified() | True when this command’s enabled state follows the document-modified state. |
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.
The value is a path: "File/Open Recent" puts the command in an “Open Recent”
submenu of the File menu, created on demand, and deeper paths nest further. The first
segment keeps the meaning above. Write // for a slash that is part of a title.
DESKTOP_MENU_APP
public static final String DESKTOP_MENU_APP = "App"DESKTOP_MENU_ABOUT
public static final String DESKTOP_MENU_ABOUT = "About"#DESKTOP_ROLE_ABOUT: placed where each platform
keeps it, see #setDesktopRole(String).DESKTOP_MENU_PREFERENCES
public static final String DESKTOP_MENU_PREFERENCES = "Preferences"#DESKTOP_ROLE_SETTINGS: placed where each
platform keeps it, see #setDesktopRole(String).DESKTOP_MENU_QUIT
public static final String DESKTOP_MENU_QUIT = "Quit"#DESKTOP_ROLE_QUIT: placed where each platform
keeps it, see #setDesktopRole(String).DESKTOP_MENU_FILE
public static final String DESKTOP_MENU_FILE = "File"DESKTOP_MENU_EDIT
public static final String DESKTOP_MENU_EDIT = "Edit"DESKTOP_MENU_VIEW
public static final String DESKTOP_MENU_VIEW = "View"DESKTOP_MENU_WINDOW
public static final String DESKTOP_MENU_WINDOW = "Window"DESKTOP_MENU_HELP
public static final String DESKTOP_MENU_HELP = "Help"DESKTOP_MENU_GROUP
public static final String DESKTOP_MENU_GROUP = "DesktopMenuGroup"Integer), see #setDesktopMenuGroup(int).DESKTOP_SEPARATOR
public static final String DESKTOP_SEPARATOR = "DesktopSeparator"#createDesktopSeparator(String).DESKTOP_CHECKED
public static final String DESKTOP_CHECKED = "DesktopChecked"Boolean). Its presence makes the item checkable, see
#setDesktopChecked(boolean).DESKTOP_RADIO_GROUP
public static final String DESKTOP_RADIO_GROUP = "DesktopRadioGroup"#setDesktopRadioGroup(String).DESKTOP_SHORTCUT_KEY
public static final String DESKTOP_SHORTCUT_KEY = "DesktopShortcutKey"Integer), see #setDesktopShortcut(char, int).DESKTOP_SHORTCUT_MODIFIERS
public static final String DESKTOP_SHORTCUT_MODIFIERS = "DesktopShortcutModifiers"Integer), see #setDesktopShortcut(char, int).DESKTOP_SHORTCUT_MODIFIER_PRIMARY
public static final int DESKTOP_SHORTCUT_MODIFIER_PRIMARY = 1DESKTOP_SHORTCUT_MODIFIER_SHIFT
public static final int DESKTOP_SHORTCUT_MODIFIER_SHIFT = 2DESKTOP_SHORTCUT_MODIFIER_ALT
public static final int DESKTOP_SHORTCUT_MODIFIER_ALT = 4DESKTOP_ROLE
public static final String DESKTOP_ROLE = "DesktopRole"DESKTOP_ROLE_* constants. See #setDesktopRole(String).DESKTOP_ROLE_ABOUT
public static final String DESKTOP_ROLE_ABOUT = "about"DESKTOP_ROLE_SETTINGS
public static final String DESKTOP_ROLE_SETTINGS = "settings"DESKTOP_ROLE_QUIT
public static final String DESKTOP_ROLE_QUIT = "quit"DESKTOP_ROLE_HIDE_APP
public static final String DESKTOP_ROLE_HIDE_APP = "hide"DESKTOP_ROLE_NEW
public static final String DESKTOP_ROLE_NEW = "new"DESKTOP_ROLE_OPEN
public static final String DESKTOP_ROLE_OPEN = "open"DESKTOP_ROLE_SAVE
public static final String DESKTOP_ROLE_SAVE = "save"Form#setDocumentModified(boolean).DESKTOP_ROLE_SAVE_AS
public static final String DESKTOP_ROLE_SAVE_AS = "saveAs"DESKTOP_ROLE_CLOSE
public static final String DESKTOP_ROLE_CLOSE = "close"DESKTOP_ROLE_PRINT
public static final String DESKTOP_ROLE_PRINT = "print"DESKTOP_ROLE_UNDO
public static final String DESKTOP_ROLE_UNDO = "undo"DESKTOP_ROLE_REDO
public static final String DESKTOP_ROLE_REDO = "redo"DESKTOP_ROLE_CUT
public static final String DESKTOP_ROLE_CUT = "cut"DESKTOP_ROLE_COPY
public static final String DESKTOP_ROLE_COPY = "copy"DESKTOP_ROLE_PASTE
public static final String DESKTOP_ROLE_PASTE = "paste"DESKTOP_ROLE_SELECT_ALL
public static final String DESKTOP_ROLE_SELECT_ALL = "selectAll"DESKTOP_ROLE_FIND
public static final String DESKTOP_ROLE_FIND = "find"DESKTOP_ROLE_FULL_SCREEN
public static final String DESKTOP_ROLE_FULL_SCREEN = "fullScreen"DESKTOP_ROLE_MINIMIZE
public static final String DESKTOP_ROLE_MINIMIZE = "minimize"DESKTOP_ROLE_ZOOM
public static final String DESKTOP_ROLE_ZOOM = "zoom"DESKTOP_ROLE_HELP
public static final String DESKTOP_ROLE_HELP = "help"DESKTOP_PLATFORMS
public static final String DESKTOP_PLATFORMS = "DesktopPlatforms"#setDesktopPlatforms(String...).DESKTOP_ENABLED_WHEN_MODIFIED
public static final String DESKTOP_ENABLED_WHEN_MODIFIED = "DesktopEnabledWhenModified"Boolean), see
#setDesktopEnabledWhenModified(boolean).Constructor details
Command
public Command(String command)Parameters
commandString- the string that will be placed on the Soft buttons\Menu
Command
public Command(String command, Image icon)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)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)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)Parameters
nameString- the name/title of the command
iconImage- the icon for the command
evActionListener- the even handler
Returns
createMaterial
public static Command createMaterial(String name, char icon, ActionListener ev)Parameters
nameString- the name/title of the command
iconchar- the icon for the command
evActionListener- the even handler
Returns
getId
public int getId()Returns
getCommandName
public String getCommandName()Returns
setCommandName
public void setCommandName(String command)getIcon
public Image getIcon()Returns
setIcon
public void setIcon(Image icon)Parameters
iconImage- the new icon
toString
public String toString()Returns
getPressedIcon
public Image getPressedIcon()Returns
setPressedIcon
public void setPressedIcon(Image pressedIcon)Parameters
pressedIconImage- icon used
getDisabledIcon
public Image getDisabledIcon()Returns
setDisabledIcon
public void setDisabledIcon(Image disabledIcon)Parameters
disabledIconImage- icon used
getRolloverIcon
public Image getRolloverIcon()Returns
setRolloverIcon
public void setRolloverIcon(Image rolloverIcon)Parameters
rolloverIconImage- icon to use
equals
public boolean equals(Object obj)Parameters
objObject- a Command Object to compare
Returns
hashCode
public int hashCode()Returns
actionPerformed
public void actionPerformed(ActionEvent evt)Parameters
evtActionEvent- the Event Object
isDisposesDialog
public boolean isDisposesDialog()setDisposesDialog
public void setDisposesDialog(boolean disposesDialog)isEnabled
public boolean isEnabled()Returns
setEnabled
public void setEnabled(boolean enabled)Parameters
enabledboolean- the enabled to set
getClientProperty
public Object getClientProperty(String key)Parameters
keyString- an arbitrary user key
Returns
putClientProperty
public void putClientProperty(String key, Object value)Parameters
keyString- an arbitrary user key
valueObject- an arbitrary user object, null to remove
setDesktopMenu
public Command setDesktopMenu(String menu)#DESKTOP_MENU.Parameters
menuString- one of the
DESKTOP_MENU_*constants or a custom top-level menu title
Returns
getDesktopMenu
public String getDesktopMenu()#DESKTOP_MENU.Returns
setDesktopMenuGroup
public Command setDesktopMenuGroup(int group)Parameters
groupint- the group number, lower groups come first
Returns
getDesktopMenuGroup
public int getDesktopMenuGroup()#setDesktopMenuGroup(int), 0 when unset.Returns
createDesktopSeparator
public static Command createDesktopSeparator(String menu)#setDesktopMenuGroup(int)) it is not needed.Parameters
menuString- the menu path the separator goes in, see
#setDesktopMenu(String)
Returns
isDesktopSeparator
public boolean isDesktopSeparator()#createDesktopSeparator(String).Returns
setDesktopChecked
public Command setDesktopChecked(boolean checked)#isDesktopChecked(). Changing the state while the command is in
the native menu updates the menu.Parameters
checkedboolean- the checked state
Returns
isDesktopCheckable
public boolean isDesktopCheckable()#setDesktopChecked(boolean).Returns
isDesktopChecked
public boolean isDesktopChecked()Returns
setDesktopRadioGroup
public Command setDesktopRadioGroup(String group)#setDesktopChecked(boolean), unchecks the others. Picking the checked item again
leaves it checked.Parameters
groupString- the radio group name, null to make this an ordinary item again
Returns
getDesktopRadioGroup
public String getDesktopRadioGroup()#setDesktopRadioGroup(String), or null.Returns
setDesktopShortcut
public Command setDesktopShortcut(char keyChar)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
setDesktopShortcut
public Command setDesktopShortcut(char keyChar, int modifiers)#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
getDesktopShortcutKeyChar
public int getDesktopShortcutKeyChar()#setDesktopShortcut(char, int),
or 0 when no accelerator is set.Returns
getDesktopShortcutModifiers
public int getDesktopShortcutModifiers()#setDesktopShortcut(char, int),
or 0 when no accelerator is set.Returns
setDesktopRole
public Command setDesktopRole(String role)Marks this command as one of the standard commands every desktop application has, so the native menu bar puts it where the platform’s own applications do: About, Settings and Quit in the application menu on macOS; About under Help, Options under Tools and Exit under File on Windows; Preferences under Edit on Linux. Each role also brings the platform’s standard shortcut and its position within the menu.
What the command sets itself wins: an explicit #setDesktopMenu(String),
#setDesktopMenuGroup(int) or #setDesktopShortcut(char, int) overrides the role’s.
The label is the command’s own name; #createDesktopRole(String, ActionListener) creates
a command named the way the running platform names the role (Quit or Exit, Settings or
Options or Preferences). A role the platform has no place for (Hide outside macOS, Quit
in a browser) leaves the command out of that platform’s menu bar.
Parameters
roleString- one of the
DESKTOP_ROLE_*constants, or null to clear it
Returns
getDesktopRole
public String getDesktopRole()#setDesktopRole(String).Returns
DESKTOP_ROLE_* constants or nullcreateDesktopRole
public static Command createDesktopRole(String role, ActionListener listener)cn1.menu.<role> resource key, for example cn1.menu.quit. See
#setDesktopRole(String).Parameters
roleString- one of the
DESKTOP_ROLE_*constants listenerActionListener- the action, may be null
Returns
setDesktopPlatforms
public Command setDesktopPlatforms(String... platforms)mac, win, linux
and web (the JavaScript port’s in-page menu). The command stays in the application’s
own menus everywhere; only the native menu bar is affected.Parameters
platformsString...- the platform names; none, or null, publishes it everywhere
Returns
isDesktopPlatform
public boolean isDesktopPlatform(String platform)#setDesktopPlatforms(String...).Parameters
platformStringmac,win,linuxorweb
Returns
setDesktopEnabledWhenModified
public Command setDesktopEnabledWhenModified(boolean follow)#DESKTOP_ROLE_SAVE. Nothing changes until the application
calls Form#setDocumentModified(boolean) or Window#setDocumentModified(boolean).Parameters
followboolean- true to follow the modified state
Returns
isDesktopEnabledWhenModified
public boolean isDesktopEnabledWhenModified()#setDesktopEnabledWhenModified(boolean).Returns
getMaterialIcon
public char getMaterialIcon()Returns
setMaterialIcon
public void setMaterialIcon(char materialIcon)Parameters
materialIconchar- the materialIcon to set
getIconGapMM
public float getIconGapMM()Returns
setIconGapMM
public void setIconGapMM(float iconGapMM)Parameters
iconGapMMfloat- the iconGapMM to set
getMaterialIconSize
public float getMaterialIconSize()Returns
setMaterialIconSize
public void setMaterialIconSize(float materialIconSize)Parameters
materialIconSizefloat- the materialIconSize to set
getIconFont
public Font getIconFont()Returns
setIconFont
public void setIconFont(Font iconFont)Parameters
iconFontFont- use iconFont for material icons instead of the system default MaterialDesign font