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.Icon
getIcon()
Returns the button's icon.java.lang.String
getID()
Returns a unique ID for this button, such as "BOLD".java.lang.String
getName()
Returns the button's name, ornull
.boolean
isEnabledInCurrentContext(ContextBar.Context context)
Returnstrue
if the button should be enabled in the current context.boolean
isVisibleInCurrentContext(ContextBar.Context context)
Returnstrue
if the button should be visible in the current context.void
onAttach(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).void
onDetach(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.String
toString()
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.Button
Returns a unique ID for this button, such as "BOLD". Only letters, digits, underscores, and currency symbols may appear in an ID.- Specified by:
getID
in 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.Button
Returns the button's name, ornull
.- Specified by:
getName
in interfaceContextBar.Button
- Returns:
- a localized description of the button's function
-
getIcon
public javax.swing.Icon getIcon()
Description copied from interface:ContextBar.Button
Returns the button's icon.- Specified by:
getIcon
in interfaceContextBar.Button
- Specified by:
getIcon
in interfaceIconProvider
- Returns:
- a small transparent icon used to represent the button
-
onAttach
public void onAttach(ContextBar.Context context)
Description copied from interface:ContextBar.Button
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).- Specified by:
onAttach
in interfaceContextBar.Button
- Parameters:
context
- information about the current context
-
onDetach
public void onDetach(ContextBar.Context context)
Description copied from interface:ContextBar.Button
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).- Specified by:
onDetach
in interfaceContextBar.Button
- Parameters:
context
- information about the current context
-
isEnabledInCurrentContext
public boolean isEnabledInCurrentContext(ContextBar.Context context)
Description copied from interface:ContextBar.Button
Returnstrue
if the button should be enabled in the current context.- Specified by:
isEnabledInCurrentContext
in interfaceContextBar.Button
- Parameters:
context
- information about the current context- Returns:
true
if the button should be enabled (ignored if not visible)
-
isVisibleInCurrentContext
public boolean isVisibleInCurrentContext(ContextBar.Context context)
Description copied from interface:ContextBar.Button
Returnstrue
if 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:
isVisibleInCurrentContext
in interfaceContextBar.Button
- Parameters:
context
- information about the current context- Returns:
true
if 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:
toString
in classjava.lang.Object
- Returns:
- a string representation of the button
-
-