Package ca.cgjennings.apps.arkham
Class ContextBar.CommandButton
- java.lang.Object
-
- ca.cgjennings.apps.arkham.ContextBar.CommandButton
-
- All Implemented Interfaces:
ContextBar.Button,IconProvider,java.awt.event.ActionListener,java.util.EventListener
- Enclosing class:
- ContextBar
public static class ContextBar.CommandButton extends java.lang.Object implements ContextBar.Button
A context bar button that delegates to anAbstractCommand. The button will activate the command when clicked, and be enabled or disabled based on the current state of the command. The base class implementation will create a button that is always visible and performs no action when the context bar is attached or detached.
-
-
Constructor Summary
Constructors Constructor Description CommandButton(AbstractCommand command)Creates a newCommandButtonfor the specified command.CommandButton(java.lang.String id, AbstractCommand command)Creates a newCommandButtonfor the specified command.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidactionPerformed(java.awt.event.ActionEvent e)Activates the command associated with this button.AbstractCommandgetCommand()Returns the command that this button is a proxy for.javax.swing.IcongetIcon()Returns the button's icon.java.lang.StringgetID()Returns a unique ID for this button, such as "BOLD".java.lang.StringgetName()Returns the button's name, ornull.ContextBar.CommandButtonhideIfDisabled()Causes the default implementation ofisVisibleInCurrentContext(ca.cgjennings.apps.arkham.ContextBar.Context)to return the same value asisEnabledInCurrentContext(ca.cgjennings.apps.arkham.ContextBar.Context).booleanisEnabledInCurrentContext(ContextBar.Context context)Returnstrueif the button should be enabled in the current context.booleanisVisibleInCurrentContext(ContextBar.Context context)Returnstrueif the button should be visible in the current context.voidonAttach(ContextBar.Context context)This method is called to notify the button when the tool bar is about to be attached to a new target component (the component that it floats over and that its commands normally apply to).voidonDetach(ContextBar.Context context)This method is called to notify the button when the tool bar is about to be detached from the current target component (the component that it floats over and that its commands normally apply to).java.lang.StringtoString()Returns a string representation of the button suitable for debugging.protected voidupdate()Updates the state of the command that this button is a proxy for.
-
-
-
Constructor Detail
-
CommandButton
public CommandButton(AbstractCommand command)
Creates a newCommandButtonfor the specified command. The button's unique ID will be determined by reading the command'sAbstractCommand.BUTTON_ID_KEYkey.- Parameters:
command- the command to generate a button for- Throws:
java.lang.NullPointerException- if the command isnullor the command does not define a button ID value
-
CommandButton
public CommandButton(java.lang.String id, AbstractCommand command)Creates a newCommandButtonfor the specified command. The command will use the specified ID.- Parameters:
command- the command to generate a button forid- the unique ID to use for the button- Throws:
java.lang.NullPointerException- if the command isnull
-
-
Method Detail
-
getCommand
public final AbstractCommand getCommand()
Returns the command that this button is a proxy for.- Returns:
- the command used to create this button
-
getID
public java.lang.String getID()
Description copied from interface:ContextBar.ButtonReturns a unique ID for this button, such as "BOLD". Only letters, digits, underscores, and currency symbols may appear in an ID.- Specified by:
getIDin interfaceContextBar.Button- Returns:
- a short ID that will identify this button in the application preferences
-
getName
public java.lang.String getName()
Description copied from interface:ContextBar.ButtonReturns the button's name, ornull.- Specified by:
getNamein interfaceContextBar.Button- Returns:
- a localized description of the button's function
-
getIcon
public javax.swing.Icon getIcon()
Description copied from interface:ContextBar.ButtonReturns the button's icon.- Specified by:
getIconin interfaceContextBar.Button- Specified by:
getIconin interfaceIconProvider- Returns:
- a small transparent icon used to represent the button
-
onAttach
public void onAttach(ContextBar.Context context)
Description copied from interface:ContextBar.ButtonThis method is called to notify the button when the tool bar is about to be attached to a new target component (the component that it floats over and that its commands normally apply to).- Specified by:
onAttachin interfaceContextBar.Button- Parameters:
context- information about the current context
-
onDetach
public void onDetach(ContextBar.Context context)
Description copied from interface:ContextBar.ButtonThis method is called to notify the button when the tool bar is about to be detached from the current target component (the component that it floats over and that its commands normally apply to).- Specified by:
onDetachin interfaceContextBar.Button- Parameters:
context- information about the current context
-
isEnabledInCurrentContext
public boolean isEnabledInCurrentContext(ContextBar.Context context)
Description copied from interface:ContextBar.ButtonReturnstrueif the button should be enabled in the current context.- Specified by:
isEnabledInCurrentContextin interfaceContextBar.Button- Parameters:
context- information about the current context- Returns:
trueif the button should be enabled (ignored if not visible)
-
isVisibleInCurrentContext
public boolean isVisibleInCurrentContext(ContextBar.Context context)
Description copied from interface:ContextBar.ButtonReturnstrueif the button should be visible in the current context. A button should be invisible if it can never be enabled in the current context, and disabled if it is not currently usable due to a temporary restriction. For example, any text field can be copied from if there is an active selection, so a copy button should always be visible but should be enabled only if there is a selection. On the other hand, a command that only works for script code should be visible only when editing a script.- Specified by:
isVisibleInCurrentContextin interfaceContextBar.Button- Parameters:
context- information about the current context- Returns:
trueif the button should be visible
-
hideIfDisabled
public ContextBar.CommandButton hideIfDisabled()
Causes the default implementation ofisVisibleInCurrentContext(ca.cgjennings.apps.arkham.ContextBar.Context)to return the same value asisEnabledInCurrentContext(ca.cgjennings.apps.arkham.ContextBar.Context). (The default behaviour is to simply returntrue.)- Returns:
- this command button
-
update
protected void update()
Updates the state of the command that this button is a proxy for. If this is called more than once while the same event is being dispatched, it will only update the actual command once (the first time it is called for that event). This allows this method to be called multiple times while determining the button state without a significant performance penalty, even if the command's update process is complex.
-
actionPerformed
public void actionPerformed(java.awt.event.ActionEvent e)
Activates the command associated with this button.- Specified by:
actionPerformedin interfacejava.awt.event.ActionListener- Parameters:
e- the action event for the button activation
-
toString
public java.lang.String toString()
Returns a string representation of the button suitable for debugging. The returned string is Button<id>, where id is the button's ID as returned byContextBar.Button.getID().- Overrides:
toStringin classjava.lang.Object- Returns:
- a string representation of the button
-
-