public class ToolbarButton
extends java.lang.Object
ActionHandler
can be
attached to a button which will be called when the button is clicked.Modifier and Type | Field and Description |
---|---|
static int |
PICTURE_MODE_DISABLED
Key for the disabled button picture.
|
static int |
PICTURE_MODE_NORMAL
Key for the normal button picture.
|
static int |
PICTURE_MODE_PRESSED
Key for the pressed button picture.
|
static int |
PICTURE_MODE_SELECTED
Key for the selected button picture.
|
Constructor and Description |
---|
ToolbarButton(Pixmap pixmap)
Creates a new button with the associated picture.
|
Modifier and Type | Method and Description |
---|---|
java.lang.String |
getActionCommand()
Gets the button action command.
|
ActionHandler |
getActionHandler()
Returns the current action handler.
|
int |
getCommand()
Returns the button command.
|
ActionHandler |
getDefaultActionHandler()
Return the default action handler implemented in the application itself.
|
java.lang.Object |
getParent()
Returns the parent object of this button.
|
Pixmap |
getPixmap()
Returns the button default's picture.
|
Pixmap |
getPixmap(int mode)
Returns the button picture for the specified mode.
|
java.lang.String |
getText()
Returns the text of the button, if the button is a text field button.
|
java.lang.String |
getTooltip()
Returns the tooltip string associated with this button.
|
boolean |
isEnabled()
Returns the state of this button.
|
boolean |
isSeparator()
Returns whether the button is a separator.
|
boolean |
isText()
Returns whether the button is a text field button.
|
void |
setActionCommand(java.lang.String actionCommand)
Sets the button action command.
|
ActionHandler |
setActionHandler(ActionHandler handler)
Sets the action handler for this button.
|
void |
setEnabled(boolean bEnabled)
Sets the state of this button
|
void |
setPixmap(int mode,
Pixmap pixmap)
Set the button's picture for the specified mode.
|
void |
setPixmap(Pixmap pixmap)
Sets the default button's picture.
|
void |
setTooltip(java.lang.String sTooltip)
Sets the tooltip string for this button.
|
public static final int PICTURE_MODE_NORMAL
public static final int PICTURE_MODE_DISABLED
public static final int PICTURE_MODE_SELECTED
public static final int PICTURE_MODE_PRESSED
public ToolbarButton(Pixmap pixmap)
pixmap
- the button default's picture.public java.lang.Object getParent()
Toolbar
to which this button belongs.public int getCommand()
public boolean isSeparator()
true
if the button is a separator; false otherwise.
public boolean isText()
true
if the button is a text field button; false otherwise.
public Pixmap getPixmap()
public Pixmap getPixmap(int mode)
mode
- the picture mode. Possible values are: public void setPixmap(Pixmap pixmap)
pixmap
- the picture.public void setPixmap(int mode, Pixmap pixmap)
class MyClass { private Pixmap loadPNGPixmap (String name) { return Pixmap.createPixmapFromPNG(getClass().getResourceAsStream (name)); } ... Pixmap normalPixmap = loadPNGPixmap("MyImage.png"); Pixmap selectedPixmap = loadPNGPixmap("MySelectedImage.png"); ToolbarButton myButton = new ToolbarButton(normalPixmap); myButton.setPixmap(ToolbarButton.PICTURE_MODE_SELECTED, selectedPixmap); ... }
mode
- the picture mode. Possible values are: pixmap
- the picture.public void setActionCommand(java.lang.String actionCommand)
actionCommand
- a string that may specify a command associated with the item.public java.lang.String getActionCommand()
public void setEnabled(boolean bEnabled)
bEnabled
- true
if the button should be enabled; false
otherwise.public boolean isEnabled()
true
if the button is enabled; false
otherwise.public java.lang.String getTooltip()
public void setTooltip(java.lang.String sTooltip)
sTooltip
- the tooltip string for this button.public java.lang.String getText()
null
otherwise.public ActionHandler setActionHandler(ActionHandler handler)
class MyClass implements ActionHandler { ... ToolbarButton button = new ToolbarButton(pixmap); button.setActionCommand("MyCommand"); button.setActionHandler(this); Application.getInstance().getToolbar().addButton(button); public void handleAction (ActionEvent e) { ToolbarButton button = (ToolbarButton) e.getSource(); String cmd = button.getActionCommand(); if (cmd.equals("MyCommand")) { JOptionPane.showMessageDialog(null, "Button " + button + " was clicked\n"); } } ... }
handler
- the new action handler.public ActionHandler getActionHandler()
public ActionHandler getDefaultActionHandler()
www.canto.com
Canto, the Canto logo, the Cumulus logo, and Cumulus are registered trademarks of Canto GmbH, registered in the U.S. and other countries.