Prev Class | Next Class | Frames | No Frames |
Summary: Nested | Field | Method | Constr | Detail: Nested | Field | Method | Constr |
java.lang.Object
org.pietschy.command.Command
public abstract class Command
extends java.lang.Object
ActionCommand
and CommandGroup
.
ActionCommand
, CommandGroup
, Face
Field Summary | |
protected Logger | |
protected EventListenerList | |
protected SwingPropertyChangeSupport |
Constructor Summary | |
| |
|
Method Summary | |
void |
|
void |
|
Face |
|
void |
|
void |
|
void |
|
void |
|
protected Iterator |
|
protected void |
|
protected void |
|
protected void |
|
protected void |
|
AbstractButton |
|
AbstractButton |
|
AbstractButton |
|
AbstractButton |
|
JMenuItem |
|
JMenuItem |
|
JMenuItem |
|
JMenuItem |
|
void |
|
Command |
|
boolean |
|
protected void |
|
protected void |
|
KeyStroke |
|
String[] |
|
ButtonFactory |
|
AbstractButton |
|
CommandManager |
|
Face |
|
Face |
|
String |
|
Face |
|
Face |
|
Icon |
|
String |
|
String |
|
MenuFactory |
|
Integer |
|
Integer |
|
String |
|
String |
|
String[] | |
Icon |
|
String |
|
Integer |
|
ToolbarFactory |
|
protected void |
|
protected void |
|
boolean |
|
boolean |
|
boolean |
|
boolean |
|
void |
|
void |
|
void |
|
void |
|
void |
|
void |
|
void |
|
void |
|
void |
|
void |
|
void |
|
void |
|
void |
|
void |
|
void |
|
void |
|
void |
|
void |
|
void |
|
void |
|
String |
|
protected Command(CommandManager commandManager)
Creates a new anonymous command. Anonymous commands can't must be fully programatically generated and can't be exported to command containers.
protected Command(CommandManager commandManager, String id)
Constructs a new Command object with the specified Id.
- Parameters:
commandManager
-id
- the identifier of this command.
public void addFace(Face face)
Deprecated. use
getFace(String,boolean)
orgetDefaultFace(boolean)
instead.Adds a the specified face to the command. If a face with the same name already exists in the command, it is replaced with the specified face and all affected buttons are updated.
- Parameters:
face
- the new Face to installFace.
public void addHoverListener(HoverListener l)
Adds aHoverListener
to the command manager. The listener will be notified when ever the mouse hovers over a command.
- Parameters:
l
- the hover listener
public Face addNewFace(String faceName)
Deprecated.
Creates and adds a new empty face with the specified name.
- Parameters:
faceName
- the name of the face, "button" for example.
- Returns:
- the newly created face.
public void addNotify(CommandGroup parent)
Invoked whenever a command is added to a group. Please note that Commands may belong to more than one group at any given time. This method does nothing by default, subclasses may override to perform special configuration as required.
- Parameters:
parent
- the parent to which the command was added.
public void addPropertyChangeListener(PropertyChangeListener l)
Adds a property change listener to this command.
- Parameters:
l
- the listener
public void addPropertyChangeListener(String propertyName, PropertyChangeListener l)
Adds a property change listener to this command.
- Parameters:
propertyName
- the property to listen to.l
- the listener
public void attach(AbstractButton button, String faceName)
Attaches this command to the specified button. If the specified face doesn't exist, then the default face is used.
- Parameters:
button
- the button to which this command should be attached.
protected Iterator buttonIterator()
Creates and returns an iterator over the buttons.
- Returns:
- an Iterator over the attached buttons
protected void configureButtonAppearance(AbstractButton button)
Configures the appearance of the specified button. This method simply delegates toRenderManager.renderButton(javax.swing.AbstractButton)
.
- Parameters:
button
- the button to configure.
protected void configureButtonAppearances()
Reconfigures the appearances of all buttons bound to this command.
protected void configureButtonAppearances(Face face)
Reconfigures all the buttons attached to this command that have the specified face. This method will be automatically called whenever the property of a face is modified.
- Parameters:
face
- the face whose buttons are to be reconfigured.
protected void configureButtonStates(AbstractButton button)
This method is called to configureMenu newly created buttons. Subclasses may override this method to perform special configuration if required.
- Parameters:
button
- the button to configureMenu.
public AbstractButton createButton()
Creates a new button that is attached to the command.
- Returns:
- the newly created button
public AbstractButton createButton(String faceId)
Creates a new button that is attached to the command using the specified face. If the face doesn't exist, the default face is used.
- Returns:
- the newly created button
public AbstractButton createButton(ButtonFactory factory)
Create a new button for this command using the specifiedButtonFactory
. The defaultFace.BUTTON
is used, it it hasn't been defined, theFace.DEFAULT
is used.
- Returns:
- a new JButton that will execute this command.
- See Also:
ButtonFactory
public AbstractButton createButton(ButtonFactory factory, String faceId)
Create a new button for this command using the specifiedButtonFactory
andFace
. If theFace
is null the default faceFace.DEFAULT
for this command is used.
- Returns:
- a new JButton
public JMenuItem createMenuItem()
Creates a new menu item for this command. This command usesFace.MENU
and the currently configuredMenuFactory
. IfFace.MENU
hasn't been configured then the default face is used.
- Returns:
- a new
JMenuItem
.
- See Also:
createMenuItem(java.lang.String)
,createMenuItem(org.pietschy.command.MenuFactory, java.lang.String)
,createMenuItem(MenuFactory)
public JMenuItem createMenuItem(String faceId)
Creates a new menu item for this command using the specifedFace
name and the currently configuredMenuFactory
.
- Returns:
- a new
JMenuItem
.
- See Also:
createMenuItem(org.pietschy.command.MenuFactory, java.lang.String)
,createMenuItem(MenuFactory)
public JMenuItem createMenuItem(MenuFactory factory)
Creates a new menu item for this command usingFace.MENU
and the specifiedMenuFactory
. IfFace.MENU
hasn't been specified, then the default is used.
- Returns:
- a new JMenuItem
- See Also:
createMenuItem(org.pietschy.command.MenuFactory, java.lang.String)
public JMenuItem createMenuItem(MenuFactory factory, String faceId)
Creates a new menu item for this command using the specifiedFace
and the specifiedMenuFactory
.
- Returns:
- a new
JMenuItem
.
public void detach(AbstractButton button)
Detaches this command from the specified button.
- Parameters:
button
- the button from which this command is to be detached.
public Command export()
Registers this command with itsCommandManager
. Once exported the command will be available for use ingroups
.
public boolean faceExists(String faceName)
public KeyStroke getAccelerator()
Deprecated. use
getDefaultFace
instead.
public String[] getAlternativeFaceNames(String face)
Gets a list of face names that can be used in place of the specified name if it hasn't been registered with the command. This method doesn't need to return the default face in the list of options.
- Parameters:
face
- the face name
- Returns:
- a list of alternative faces with the best alternative at index 0.
public ButtonFactory getButtonFactory()
Gets the button factory to use for this command. If the button factory hasn't been configured by callingsetButtonFactory(ButtonFactory)
, then the default factory specified byCommandManager.setButtonFactory(ButtonFactory)
.
- Returns:
- this commands
ButtonFactory
.
public AbstractButton getButtonIn(Container container)
This method will find the first button from this command in the specified container.
- Parameters:
container
- the container that holds a button from this command.
public CommandManager getCommandManager()
Gets theCommandManager
this command belongs to.
- Returns:
- the commands
CommandManager
.
public Face getDefaultFace()
Gets this commands default face. This is either the face with the nameFace.DEFAULT
. If no face exists with this name, then the first registered face is returned.
- Returns:
- this commands default face.
public Face getDefaultFace(boolean createIfMissing)
Gets this commands default face. This is either the face with the nameFace.DEFAULT
. If no face exists with this name, then the first registered face is returned.
- Parameters:
createIfMissing
-true
to create the face if it doesn't exist,false
to return null if it doesn't exists.
- Returns:
- this commands default face.
public String getDescription()
Deprecated. use
getDefaultFace
instead.
public Face getFace(String faceName)
Gets the best matching face for the specified name. This method first attempts to get the exact face, if that fails it iterates over the face names returned bygetAlternativeFaceNames(String)
. If non of these faces exist, then the default face is returned.
- Parameters:
faceName
- the name of the face to retrieved.Face.BUTTON
for example.
- Returns:
- the specified face, or the next best face according to
getAlternativeFaceNames(String)
.
public Face getFace(String faceName, boolean createIfMissing)
Gets the face with the specified name.
- Parameters:
faceName
- the name of the face to retrieved.Face.BUTTON
for example.createIfMissing
-true
to create the face if it doesn't exist,false
to return the best matching face as determined bygetAlternativeFaceNames(String)
.
- Returns:
- the specified face, or the next best face according to
getAlternativeFaceNames(String)
.
public Icon getIcon()
Deprecated. use
getDefaultFace
instead.
public String getId()
Gets this commands identifier.
- Returns:
- the identifier of this command.
public String getLongDescription()
Deprecated. use
getDefaultFace
instead.
public MenuFactory getMenuFactory()
Gets theMenuFactory
to use for this command when creating menu items. If the factory hasn't been configured by callingsetMenuFactory(MenuFactory)
then the value provided byCommandManager.getMenuFactory()
is used.
- Returns:
- the
MenuFactory
to use.
public Integer getMnemonic()
Deprecated. use
getDefaultFace
instead.
public Integer getMnemonicIndex()
Deprecated. use
getDefaultFace
instead.
public String getProperty(String name)
public String getProperty(String name, String defaultValue)
public String[] getPropertyNames()
public Icon getSelectedIcon()
Deprecated. use
getDefaultFace
instead.
public String getText()
Deprecated. use
getDefaultFace
instead.
public Integer getTextPosition()
Deprecated. use
getDefaultFace
instead.
public ToolbarFactory getToolbarFactory()
Gets the toolbar factory to use for this command. If the factory hasn't been configured by callingsetToolbarFactory(ToolbarFactory)
, then the default factory specified byCommandManager.setToolbarFactory(ToolbarFactory)
is used.
- Returns:
- this commands
ButtonFactory
.
protected void installFace(Face face)
Adds a the specified face to the command. If a face with the same name already exists in the command, it is replaced with the specified face and all affected buttons are updated.
- Parameters:
face
- the new Face to installFace.
public boolean isAnonymous()
Checks if this is an anonymous command. Anonymous commands have no identifier, and can't be exported or configured by theCommandManager
. They are useful when you need to programatically create a command. All commands created without an identifier are anonymous.
- Returns:
- true if this command is anonymous, false otherwise.
public boolean isAttachedTo(JComponent b)
Tests if this command is attached to the specified button.
- Parameters:
b
- the button to check
- Returns:
- true if this command is attached to the button, false otherwise.
public boolean isEnabled()
Checks the enabled state of this action and it's attached buttons.
- Returns:
true
if the command is enabled.
public boolean isVisible()
Checks if the buttons of this command are visible.
- Returns:
- true if the command is visible, false otherwise.
public void putProperty(String name, String value)
public void removeHoverListener(HoverListener l)
Removes theHoverListener
from the command manager.
- Parameters:
l
- the hover listener
- See Also:
HoverListener
,addHoverListener(HoverListener)
public void removeNotify(CommandGroup parent)
Invoked whenever a command is remvoved from a group. Please note that Commands may belong to more than one group at any given time. This method does nothing by default, subclasses may override to perform special configuration as required.
- Parameters:
parent
- the parent from which the command was removed.
public void removePropertyChangeListener(PropertyChangeListener l)
Removes the listener from this command
- Parameters:
l
- the listener
public void removePropertyChangeListener(String propertyName, PropertyChangeListener l)
Removes the listener from this command
- Parameters:
propertyName
- the property to stop listening to.l
- the listener
public void requestFocusIn(Container container)
This method will find the first button from this command in the specified container and calljavax.swing.JComponent.requestFocus
followed byContainer.repaint
.
- Parameters:
container
- the container that holds a button from this command.
public void setAccelerator(KeyStroke accelerator)
Deprecated. use
getDefaultFace
instead.
public void setButtonFactory(ButtonFactory factory)
Sets theButtonFactory
for this command to use for default when creating buttons.
- Parameters:
factory
- theButtonFactory
to use.
public void setDescription(String shortDescription)
Deprecated. use
getDefaultFace
instead.
public void setEnabled(boolean enabled)
Updates the enabled state of this command and any attached buttons.
- Parameters:
enabled
-true
to enable the command.
public void setIcon(Icon icon)
Deprecated. use
getDefaultFace
instead.
public void setLongDescription(String longDescription)
Deprecated. use
getDefaultFace
instead.
public void setMenuFactory(MenuFactory factory)
Sets theMenuFactory
to use for menus created by this command.
- Parameters:
factory
- theMenuFactory
to use.
public void setMnemonic(Integer mnemonic)
Deprecated. use
getDefaultFace
instead.
public void setMnemonicIndex(Integer mnemonicIndex)
Deprecated. use
getDefaultFace
instead.
public void setSelectedIcon(Icon newSelectedIcon)
Deprecated. use
getDefaultFace
instead.
public void setText(String text)
Deprecated. use
getDefaultFace
instead.
public void setTextPosition(Integer textPosition)
Deprecated. use
getDefaultFace
instead.
public void setToolbarFactory(ToolbarFactory factory)
Sets theToolbarFactory
for this command to use for default when creating buttons on toolbars.
- Parameters:
factory
- theButtonFactory
to use.
public void setVisible(boolean value)
Sets the command and all it's buttons to be visible or not.
- Parameters:
value
-
public String toString()
Returns a string representation of the object. In general, thetoString
method returns a string that "textually represents" this object. The result should be a concise but informative representation that is easy for a person to read. It is recommended that all subclasses override this method. ThetoString
method for classObject
returns a string consisting of the name of the class of which the object is an instance, the at-sign character '@
', and the unsigned hexadecimal representation of the hash code of the object. In other words, this method returns a string equal to the value of:getClass().getName() + '@' + Integer.toHexString(hashCode())
- Returns:
- a string representation of the object.