Package ca.cgjennings.apps.arkham
Class ContextBar.AbstractButton
- java.lang.Object
-
- ca.cgjennings.apps.arkham.ContextBar.AbstractButton
-
- All Implemented Interfaces:
ContextBar.Button,IconProvider,java.awt.event.ActionListener,java.util.EventListener
- Enclosing class:
- ContextBar
public abstract static class ContextBar.AbstractButton extends java.lang.Object implements ContextBar.Button
An abstract base class for implementing a context bar button. The base class implements the following behaviour:-
getID(),getName(), andgetIcon()will provide an ID, name, and icon (respectively) based on the values passed to the constructor - the button is always enabled and visible
(
isEnabledInCurrentContext(ca.cgjennings.apps.arkham.ContextBar.Context)andisVisibleInCurrentContext(ca.cgjennings.apps.arkham.ContextBar.Context)always returntrue)
At a minimum, subclasses must implement
ActionListener.actionPerformed(java.awt.event.ActionEvent)in order to execute an action when the button is pressed.
-
-
Constructor Summary
Constructors Constructor Description AbstractButton(java.lang.String id, java.lang.String name, java.lang.String iconResource)Creates a new button the specified id, name, and with an icon loaded from the specified resource.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description 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.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.
-
-
-
Constructor Detail
-
AbstractButton
public AbstractButton(java.lang.String id, java.lang.String name, java.lang.String iconResource)Creates a new button the specified id, name, and with an icon loaded from the specified resource. The icon image is loaded usingResourceKit.getIcon(java.lang.String), except that if the icon resource does not contain a slash, the resource will be loaded fromresources/icons/toolbar.- Parameters:
id- a unique button identifiername- the user-friendly name of the buttoniconResource- the resource to load the button's icon from- Throws:
java.lang.NullPointerException- if the name or icon resource isnull
-
-
Method Detail
-
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
-
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
-
-