|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectcom.pietschy.command.Command
public abstract class Command
The base class for all ActionCommands and CommandGroups. It provides
the core methods for creating, initialising and managing buttons and menu items.
ActionCommand,
CommandGroup,
Face| Field Summary | |
|---|---|
protected Logger |
internalLog
|
static java.lang.String |
PROPERTY_ENABLED
|
static java.lang.String |
PROPERTY_VISIBLE
|
| Constructor Summary | |
|---|---|
protected |
Command(java.lang.String id,
boolean loadConfiguration)
Constructs a new instance with the specified Id. |
| Method Summary | |
|---|---|
void |
addContainerPropertyListener(java.lang.String propertyName,
ContainerPropertyListener listener)
Adds a ContainerPropertyListener to the command. |
void |
addFace(Face face)
Adds the specified face to the command. |
void |
addHoverListener(HoverListener listener)
Adds the specified listner. |
void |
addNotify(CommandGroup parent)
Invoked whenever a command is added to a group. |
void |
addPropertyChangeListener(java.beans.PropertyChangeListener listener)
Adds the specified property change listener. |
void |
addPropertyChangeListener(java.lang.String propertyName,
java.beans.PropertyChangeListener listener)
Adds the specified listener for the specified property. |
protected void |
attach(javax.swing.JComponent component,
java.lang.String context)
Attaches this command to the specified component using the specified face context. |
void |
bind()
Binds to the global command container. |
void |
bind(CommandContainer container)
Binds to the specified CommandContainer. |
void |
bind(java.awt.Component component)
Binds to the specified component. |
protected abstract void |
bindToContainer(CommandContainer container)
Invoked to bind this instance to the specified command container. |
protected java.util.Iterator<javax.swing.AbstractButton> |
buttonIterator()
Returns an iterator over this commands buttons. |
void |
configureAppearance(java.awt.Component component)
Configures the appearance of the specified button. |
protected void |
configureAppearances(Face face)
Reconfigures all the buttons attached to this command that have the specified face. |
protected void |
configureButtonAppearances()
Configures the appearance of all buttons created by this command. |
protected void |
configureButtonStates()
Configures the enabled and visible state of all buttons and menu items. |
protected void |
configureButtonStates(javax.swing.AbstractButton button)
Called to configure the enabled and visibles states of the specified button. |
javax.swing.AbstractButton |
createButton()
Creates a new button. |
javax.swing.AbstractButton |
createButton(ButtonFactory factory)
Create a new button using the specified ButtonFactory. |
javax.swing.AbstractButton |
createButton(ButtonFactory factory,
java.lang.String context)
Create a new button for the specified context command using the specified ButtonFactory. |
javax.swing.AbstractButton |
createButton(java.lang.String context)
Creates a new button with for the specified context. |
javax.swing.JComponent |
createComponent(Factory factory,
java.lang.String context)
Convenience method that creates a new component for the specified face using the specified factory. |
javax.swing.JMenuItem |
createMenuItem()
Creates a new menu item. |
javax.swing.JMenuItem |
createMenuItem(MenuFactory factory)
Creates a new menu item using the specified MenuFactory. |
javax.swing.JMenuItem |
createMenuItem(MenuFactory factory,
java.lang.String context)
Creates a new menu item for the specified context sing the specified MenuFactory. |
javax.swing.JMenuItem |
createMenuItem(java.lang.String context)
Creates a new menu item for this command for the specified context. |
protected void |
detach(javax.swing.JComponent component)
Detaches this command from the specified button. |
protected void |
doButtonAttachments(javax.swing.AbstractButton button,
java.lang.String context)
Attaches this command to the specified button. |
protected void |
doButtonDetachments(javax.swing.AbstractButton button)
Detaches this command from the specified button. |
boolean |
faceExists(java.lang.String context)
Checks if a face exists for the specified context. |
Face |
findBestFace(java.lang.String context)
Finds the best face to use for buttons created for using in the specified context. |
protected void |
fireHoverEnded(Face face,
java.awt.Component source)
Fires the HoverListener.hoverEnded(HoverEvent) event. |
protected void |
fireHoverStarted(Face face,
java.awt.Component source)
Fires the HoverListener.hoverStarted(HoverEvent) event. |
protected void |
fireIndexedPropertyChange(java.lang.String context,
int i,
boolean b,
boolean b1)
|
protected void |
fireIndexedPropertyChange(java.lang.String context,
int i,
int i1,
int i2)
|
protected void |
fireIndexedPropertyChange(java.lang.String context,
int i,
java.lang.Object o,
java.lang.Object o1)
|
protected void |
firePropertyChange(java.lang.String context,
boolean b,
boolean b1)
|
protected void |
firePropertyChange(java.lang.String context,
int i,
int i1)
|
protected void |
firePropertyChange(java.lang.String context,
java.lang.Object o,
java.lang.Object o1)
|
java.lang.String[] |
getAlternativeFaceContexts(java.lang.String context)
Gets a list of alternate contexts to try if no face has been registered for the specified context. |
protected ButtonFactory |
getButtonFactory()
Gets the button factory to use for this command. |
javax.swing.AbstractButton |
getButtonIn(java.awt.Container container)
Finds the first button created by this command in the specified container. |
CommandContainer |
getCommandContainer()
Gets this commands CommandContainer or null if it doesn't have one. |
java.lang.Object |
getContainerProperty(java.lang.String property)
A convenience method for getting the specified property from this commands CommandContainer. |
(package private) ContainerPropertyListenerSupport |
getContainerPropertySupport()
Gets the ContainerPropertyListenerSupport instance. |
Face |
getDefaultFace()
Gets this default face of the command. |
Face |
getDefaultFace(boolean createIfMissing)
Gets the default face or creates it if it hasn't been defined. |
Face |
getFace(java.lang.String context)
Gets the face for the specified context. |
Face |
getFace(java.lang.String context,
boolean createIfMissing)
Gets the face with the specified name, optionally creating it if it doesn't exits. |
java.lang.String |
getId()
Gets the command id. |
protected MenuFactory |
getMenuFactory()
Gets the menu factory to use for this command. |
java.lang.String |
getProperty(java.lang.String name)
Gets the property value with the specified name. |
java.lang.String |
getProperty(java.lang.String name,
java.lang.String defaultValue)
Gets the property value with the specified name. |
java.lang.String[] |
getPropertyNames()
Gets all the property names defined for this command. |
protected ToolbarFactory |
getToolbarFactory()
Gets the toolbar factory to use for this command. |
boolean |
isAnonymous()
Checks if this is an anonymous instance. |
boolean |
isAttachedTo(java.awt.Component component)
Tests if this command is attached to the specified button. |
boolean |
isBound()
Checks if the command is currently bound to either a component or container. |
boolean |
isEnabled()
Checks the enabled state of this command. |
boolean |
isVisible()
Checks if the buttons of this command are visible. |
protected void |
loadConfiguration()
Invoked during the constructor to load this commands configuration from the currently installed ConfigurationLoader. |
protected void |
notifyCommandContainerHierarchyChanged()
Invoked to notify the command that a change in the container heirarchy has occured either via a binding operation or because a containers parent heirarchy has changed. |
void |
putProperties(java.util.Map<java.lang.String,java.lang.String> map)
Adds all the specified properties to this command. |
void |
putProperty(java.lang.String name,
java.lang.String value)
Adds a property to the command. |
void |
rebind()
Re-evaluates the current binding. |
void |
removeContainerPropertyListener(java.lang.String propertyName,
ContainerPropertyListener listener)
Removes the specified ContainerPropertyListener from the command. |
void |
removeHoverListener(HoverListener listener)
Removes the specified listener. |
void |
removeNotify(CommandGroup parent)
Invoked whenever a command is remvoved from a group. |
void |
removePropertyChangeListener(java.beans.PropertyChangeListener listener)
Removes the specified property change listener. |
void |
removePropertyChangeListener(java.lang.String propertyName,
java.beans.PropertyChangeListener listener)
Removes the specifed listener from the specified property. |
void |
requestFocusIn(java.awt.Container container)
Find the first button in the specified container and calls JComponent.requestFocus() followed by Component.repaint(). |
void |
setButtonFactory(ButtonFactory factory)
Sets the factory to use when creating buttons. |
void |
setEnabled(boolean enabled)
Updates the enabled state of this command and all its buttons. |
void |
setMenuFactory(MenuFactory factory)
Sets the factory to use when creating menus and menu items. |
void |
setToolbarFactory(ToolbarFactory factory)
Sets the factory to use when creating toolbars and toolbar buttons. |
void |
setVisible(boolean visible)
Sets the visible state of this command and all its buttons and menu item. |
java.lang.String |
toString()
Returns a string representation of the object. |
void |
unbind()
Unbinds from the current container or component. |
protected abstract void |
unbindFromContainer(CommandContainer container)
Invoked to unbind this instance from the specified command container. |
static void |
validateId(java.lang.String id)
Validates the specified command id. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
public static final java.lang.String PROPERTY_ENABLED
public static final java.lang.String PROPERTY_VISIBLE
protected Logger internalLog
| Constructor Detail |
|---|
protected Command(java.lang.String id,
boolean loadConfiguration)
id - the command id.loadConfiguration - true to invoke loadConfiguration() during
construction, false otherwise.
InvalidIdException - if the id contains whitespace.| Method Detail |
|---|
protected void loadConfiguration()
ConfigurationLoader.
public java.lang.String getId()
getId in interface Identifiablepublic boolean isAnonymous()
DefaultConfigurationLoader. They are useful when you need
to programatically create a command.
All commands created without an id are anonymous.
true if this command is anonymous, false otherwise.public void bind()
Bindable
bind in interface BindableCommandContainer.globalInstance()public void bind(java.awt.Component component)
BindableCommandContainer.
bind in interface Bindablecomponent - the component to bind to.CommandContainer.bind(Component)public void bind(CommandContainer container)
BindableCommandContainer.
bind in interface Bindablecontainer - the container to bind to.public void rebind()
Bindable
rebind in interface Bindablepublic void unbind()
Bindable
unbind in interface Bindablepublic boolean isBound()
true if the command is bound, false otherwise.protected abstract void bindToContainer(CommandContainer container)
container - the container to bind to.protected abstract void unbindFromContainer(CommandContainer container)
container - the container to unbind from.protected void notifyCommandContainerHierarchyChanged()
This operation does nothing but can be overridden by subclasses to perform any required updates.
This method will be invoked after both bindToContainer(CommandContainer)
and unbindFromContainer(CommandContainer).
public CommandContainer getCommandContainer()
CommandContainer or null if it doesn't have one.
CommandContainer or null if it doesn't have one.
public void putProperty(java.lang.String name,
java.lang.String value)
# specifiy the "color" property as "blue" command@properties.color=blue
name - the property namevalue - the property value.public void putProperties(java.util.Map<java.lang.String,java.lang.String> map)
map - the map containing the properties.putProperty(String, String)public java.lang.String getProperty(java.lang.String name)
name - the property name.
null if the property doesn't exists.
public java.lang.String getProperty(java.lang.String name,
java.lang.String defaultValue)
null
then the specified defaultValue is returned.
name - the property name.defaultValue - the defaultValue to return if the real value is null.
defaultValue if the real value is null.public java.lang.String[] getPropertyNames()
public java.lang.Object getContainerProperty(java.lang.String property)
CommandContainer.
This method will return null if the command isn't currently bound
to a container.
property - the property to retrieve.
null if the
command has no container.CommandContainer.getProperty(String),
addContainerPropertyListener(String, ContainerPropertyListener)public void addNotify(CommandGroup parent)
parent - the parent group to which the command was added.public void removeNotify(CommandGroup parent)
parent - the parent from which the command was removed.
protected void doButtonAttachments(javax.swing.AbstractButton button,
java.lang.String context)
button - the button to which this command should be attached.protected void doButtonDetachments(javax.swing.AbstractButton button)
button - the button from which this command is to be detached.
protected void attach(javax.swing.JComponent component,
java.lang.String context)
component - the component to which this command should be attached.context - the face context to use.protected void detach(javax.swing.JComponent component)
component - the button from which this command is to be detached.public boolean isAttachedTo(java.awt.Component component)
component - the button to check
protected void configureButtonStates()
configureButtonStates(AbstractButton)protected void configureButtonStates(javax.swing.AbstractButton button)
button - the button to configure.protected ButtonFactory getButtonFactory()
setButtonFactory(com.pietschy.command.factory.ButtonFactory), then the default factory specified
by Defaults.getButtonFactory() is used.
ButtonFactory.setButtonFactory(com.pietschy.command.factory.ButtonFactory),
Defaults.setButtonFactory(ButtonFactory)public void setButtonFactory(ButtonFactory factory)
factory - the factory to use or null to use the
global factory defined by Defaults.getButtonFactory().protected ToolbarFactory getToolbarFactory()
setToolbarFactory(ToolbarFactory) then the default
factory specified by Defaults.getToolbarFactory() is used.
setToolbarFactory(ToolbarFactory),
Defaults.setToolbarFactory(ToolbarFactory)public void setToolbarFactory(ToolbarFactory factory)
factory - the factory to use or null to use the
global factory defined by Defaults.getToolbarFactory().protected MenuFactory getMenuFactory()
setMenuFactory(MenuFactory) then the default
factory specified by Defaults.getMenuFactory() is used.
setMenuFactory(MenuFactory),
Defaults.setMenuFactory(MenuFactory)public void setMenuFactory(MenuFactory factory)
factory - the factory to use or null to use the
global factory defined by Defaults.getMenuFactory().public void setEnabled(boolean enabled)
enabled - true to enable the command, false to disable it.public boolean isEnabled()
true if the command is enabled, false if disabled.public void setVisible(boolean visible)
visible - true to show the commands buttons, false to hide them.public boolean isVisible()
protected java.util.Iterator<javax.swing.AbstractButton> buttonIterator()
public Face getDefaultFace()
null if this command has no faces.getDefaultFace(boolean),
findBestFace(String)public Face getDefaultFace(boolean createIfMissing)
createIfMissing - true to create the face if it doesn't exist,
false to return null if it doesn't exists.
false.findBestFace(String)public Face getFace(java.lang.String context)
context - the name of the face to retrieved. Face.BUTTON for example.
null if the face doesn't exists.getFace(String, boolean),
findBestFace(String)
public Face getFace(java.lang.String context,
boolean createIfMissing)
context - the context of the face to retrieved. Face.BUTTON for example.createIfMissing - true to create the face if it doesn't exist, false to
return null.
getAlternativeFaceContexts(java.lang.String).public void addFace(Face face)
face - the face to add.
java.lang.IllegalStateException - if a face with the same context already exists.public Face findBestFace(java.lang.String context)
getAlternativeFaceContexts(String). If no matching face is found a
FaceNotFoundException is thrown.
context - the desired face context.
FaceNotFoundException - if no suitable face can be found.public boolean faceExists(java.lang.String context)
context - the context of interest
true if a face exits, false otherwise.public java.lang.String[] getAlternativeFaceContexts(java.lang.String context)
This method delegates to Defaults.getAlternativeFaceContexts(String).
context - the desired context
public void addPropertyChangeListener(java.beans.PropertyChangeListener listener)
listener - the listener to add.
public void addPropertyChangeListener(java.lang.String propertyName,
java.beans.PropertyChangeListener listener)
propertyName - the property to listen to.listener - the listener to addpublic void removePropertyChangeListener(java.beans.PropertyChangeListener listener)
listener - the listener to remove
public void removePropertyChangeListener(java.lang.String propertyName,
java.beans.PropertyChangeListener listener)
propertyName - the property to stop listening to.listener - the listener to remove
public void addContainerPropertyListener(java.lang.String propertyName,
ContainerPropertyListener listener)
ContainerPropertyListener to the command. The listener will be notified
when ever there is a change to the value of the named container property. Container
property values may change as a result of:
CommandContainer.putProperty(String, Object) within the commands
container hierarchy
Unlike PropertyChangeListeners, ContainerPropertyListeners only provide
the new property value.
propertyName - the name of the property to monitorlistener - the listener
public void removeContainerPropertyListener(java.lang.String propertyName,
ContainerPropertyListener listener)
ContainerPropertyListener from the command.
propertyName - the property that was being monitored.listener - the listener to remove.ContainerPropertyListenerSupport getContainerPropertySupport()
ContainerPropertyListenerSupport instance. This method lazily creates the
support object.
public void addHoverListener(HoverListener listener)
See HoverManager to listen to hover events from all commands.
listener - the listener to add.HoverManagerpublic void removeHoverListener(HoverListener listener)
listener - the listener to removeHoverManager
protected void fireHoverStarted(Face face,
java.awt.Component source)
HoverListener.hoverStarted(HoverEvent) event.
face - the face used to create the hovered component.source - the component that was hovered.
protected void fireHoverEnded(Face face,
java.awt.Component source)
HoverListener.hoverEnded(HoverEvent) event.
face - the face used to create the hovered component.source - the component that was hovered.public void requestFocusIn(java.awt.Container container)
JComponent.requestFocus() followed by Component.repaint().
container - the container that contains a button from this command.public javax.swing.AbstractButton getButtonIn(java.awt.Container container)
container - the container that holds a button from this command.public javax.swing.AbstractButton createButton()
public javax.swing.AbstractButton createButton(java.lang.String context)
public javax.swing.AbstractButton createButton(ButtonFactory factory)
ButtonFactory.
ButtonFactory
public javax.swing.AbstractButton createButton(ButtonFactory factory,
java.lang.String context)
ButtonFactory.
public javax.swing.JMenuItem createMenuItem()
createMenuItem(String),
createMenuItem(MenuFactory, String),
createMenuItem(MenuFactory)public javax.swing.JMenuItem createMenuItem(java.lang.String context)
createMenuItem(MenuFactory, String),
createMenuItem(MenuFactory)public javax.swing.JMenuItem createMenuItem(MenuFactory factory)
MenuFactory.
createMenuItem(MenuFactory, String)
public javax.swing.JMenuItem createMenuItem(MenuFactory factory,
java.lang.String context)
MenuFactory.
public javax.swing.JComponent createComponent(Factory factory,
java.lang.String context)
This method will invoke either createButton(ButtonFactory, String) or
createMenuItem(MenuFactory, String) based on the factory type.
This method is also the main entry point for the library when creating buttons
and menus for using in groups. This allows subclasses to create custom components
that are not an instance of AbstractButton.
factory - the factory to use to create the component.context - the face context to use.
protected void configureButtonAppearances()
protected void configureAppearances(Face face)
face - the face whose buttons are to be reconfigured.public void configureAppearance(java.awt.Component component)
Defaults.getFaceRenderer().
component - the button to configure.
protected void firePropertyChange(java.lang.String context,
java.lang.Object o,
java.lang.Object o1)
protected void firePropertyChange(java.lang.String context,
int i,
int i1)
protected void firePropertyChange(java.lang.String context,
boolean b,
boolean b1)
protected void fireIndexedPropertyChange(java.lang.String context,
int i,
java.lang.Object o,
java.lang.Object o1)
protected void fireIndexedPropertyChange(java.lang.String context,
int i,
int i1,
int i2)
protected void fireIndexedPropertyChange(java.lang.String context,
int i,
boolean b,
boolean b1)
public java.lang.String toString()
toString 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.
The toString method for class Object
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())
toString in class java.lang.Objectpublic static void validateId(java.lang.String id)
id - the id to check.
InvalidIdException - if the id isn't valid.
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||