javax.swing
abstract public class: AbstractAction [javadoc |
source]
java.lang.Object
javax.swing.AbstractAction
All Implemented Interfaces:
Action, Cloneable, Serializable
Direct Known Subclasses:
BeginLineAction, StringDownAction, CloseAction, SwitchRightAction, ClearAction, RedoAction, RestoreDatabase, SaveDatabaseAction, NextWordAction, PrevAction, SelectIdentityAction, ActionCombo, DeleteWordAction, PreviousWordAction, ActionScroller, ReflectionAction, NewEntryAction, CancelAction, DeletePrevCharAction, AlignmentAction, NextVisualPositionAction, RefreshAction, LastOpenHistoryAction, SimpleAction, FontFamilyAction, Synchronize, StyledTextAction, FontSizeAction, CancelAction, CloseAction, MsgDeleteAction, CopyAction, EndParagraphAction, CopyAction, SearchPaneAction, PlayAction, ViewAction, CopyKeyAction, ShowGroupsAction, ChangeDevice, ArrowButtonHandler, CancelSelectionAction, NewFolderAction, TreePageAction, SendAction, NewDirAction, TreeIncrementAction, CloseAction, ExtractAction, AboutAction, MergeDatabaseAction, NavigateLinkAction, SkinSelectAction, BackAction, OpenAction, ExitAction, BeginAction, CancelAction, DeleteTracksAction, RedoAction, SaveAction, QuitAction, NotifyAction, UpdatesAction, SaveSpecialAction, InsertTabAction, BoldAction, ItalicAction, CheckUniqueLabelAction, IncrementAction, NewAccountAction, MsgPrintAction, BeginAction, CloseArchiveAction, UndoAction, OptionsAction, NextWordAction, CancelAction, UndoAction, IndexAction, NewTransactionCategoryAction, DirectoryComboBoxAction, TextAction, TreeHomeAction, ListAction, AboutAction, InsertContentAction, ReloadAction, TutorialAction, PreviousWordAction, UndoAction, CancelAction, VerticalPageAction, CloseAction, CloseAction, OkAction, MinimizeAction, OpenTransactionCategoryAction, SizeAction, ForwardAction, FindAction, RedoAction, SelectParagraphAction, NewDatabaseAction, YesAction, EditPreambleAction, AddTracksToPlaylist, PageAction, SaveAndClearAction, ViewStatusBarAction, ExitAction, AboutAction, HistoryAction, CopyKeyAction, LastOutputAction, CompressionAction, InsertBreakAction, MaximizeAction, CloseAction, DeleteAction, TranslateAction, FilterAction, TreeTraverseAction, ActivateLinkAction, SharedActionScroller, TreeCancelEditingAction, SaveMsgAsAction, NewMsgAction, CancelAction, OKAction, OptionsAction, DeleteNextCharAction, UpdateAction, PlayTracks, RecentFilesAction, Next20WordAction, SelectAllAction, NoAction, SelectAllAction, ReplyAllAction, SortingAction, HistoryNextAction, FilteredFilesAction, ForwardAction, AddTrack, PasteAction, EndWordAction, ContentsAction, NewAccountTypeAction, BackupDatabase, RemoveStringAction, OpenDatabaseAction, EndAction, ExportPlaylistAction, SortDatabase, PasteAction, StoreFieldAction, Exit, OKAction, DeleteTrack, FindShortcutAction, UnselectAction, CancelAction, CloseAction, EndLineAction, UsersGuide, InvertSelectionAction, CancelAction, FocusAction, MoveUpAction, DatabaseInfo, TreeToggleAction, CancelAction, CloseAction, ExtractAction, IconifyAction, GoHomeAction, DumpModelAction, ExitAction, CloseDatabaseAction, UndoAction, DeleteAction, StoreFieldAction, FilteredFilesAction, DefaultAction, SimilarWordsAction, MoveDownAction, RemoveEntryAction, CreateAction, FontAction, SetupTableAction, MaximizeAction, YesToAllAction, SelectWordAction, AudioAction, RemoveFromGroupAction, CancelAction, WritableAction, ConfigurationGraphAction, OpenAccountTypeAction, SaveAsDatabaseAction, DictAction, NewStringAction, SelectLineAction, RedoAction, ExpandFolderAction, CancelAction, StringUpAction, CreateEmptyDatabase, OptionsAction, CloseAction, NewArchiveAction, ConfigurationWizardAction, MoveAction, AddToGroupAction, OpenAccountAction, BeepAction, InfoAction, EntireArchiveAction, OKAction, ReadOnlyAction, DefaultKeyTypedAction, NavigateAction, MsgPropertiesAction, DeletePlaylistAction, EditEntryAction, OpenArchiveAction, ReplyAction, RebuildDatabase, CutAction, PasteAction, StoreContentAction, ActionListenerProxy, InformationAction, ContentsAction, TextActionWrapper, DeleteAction, RefreshDatabase, About, UndoAction, CommitAction, RenamePlaylistAction, MinimizeAction, RestoreAction, GenerateKeyAction, IconifyAction, ToggleComponentOrientationAction, LicenseAction, MakeLabelAction, CutAction, BeginWordAction, AddAction, CloseAction, SelectAllAction, PreviewAction, SwitchLeftAction, MaximizeAction, ViewMsgAction, BaseAction, CloseAction, ApproveSelectionAction, NextAction, SelectSkinAction, UnderlineAction, HistoryPreviousAction, SelectedFilesAction, ChangeToParentDirectoryAction, HelpAction, ForegroundAction, BeginParagraphAction, CopyAction, EditStringsAction, License, StyledInsertBreakAction, RestoreAction, ShowSystemMenuAction, CancelAction, TestIntegrityAction
This class provides default implementations for the JFC
Action
interface. Standard behaviors like the get and set methods for
Action object properties (icon, text, and enabled) are defined
here. The developer need only subclass this abstract class and
define the
actionPerformed method.
Warning:
Serialized objects of this class will not be compatible with
future Swing releases. The current serialization support is
appropriate for short term storage or RMI between applications running
the same version of Swing. As of 1.4, support for long term storage
of all JavaBeansTM
has been added to the java.beans package.
Please see java.beans.XMLEncoder .
Also see:
- Action
- author:
Georges - Saab
| Field Summary |
|---|
| protected boolean | enabled | Specifies whether action is enabled; the default is true. |
| protected SwingPropertyChangeSupport | changeSupport | If any PropertyChangeListeners have been registered, the
changeSupport field describes them. |
| Constructor: |
public AbstractAction() {
}
Creates an {@code Action}. |
public AbstractAction(String name) {
putValue(Action.NAME, name);
}
Creates an {@code Action} with the specified name. Parameters:
name - the name ({@code Action.NAME}) for the action; a
value of {@code null} is ignored
|
public AbstractAction(String name,
Icon icon) {
this(name);
putValue(Action.SMALL_ICON, icon);
}
Creates an {@code Action} with the specified name and small icon. Parameters:
name - the name ({@code Action.NAME}) for the action; a
value of {@code null} is ignored
icon - the small icon ({@code Action.SMALL_ICON}) for the action; a
value of {@code null} is ignored
|
| Method from javax.swing.AbstractAction Summary: |
|---|
|
addPropertyChangeListener, clone, firePropertyChange, getKeys, getPropertyChangeListeners, getValue, hasSelectedKey, isEnabled, isSelected, putValue, removePropertyChangeListener, setEnabled, setEnabledFromAction, setToolTipTextFromAction, shouldReconfigure |
| Methods from java.lang.Object: |
|---|
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Method from javax.swing.AbstractAction Detail: |
public synchronized void addPropertyChangeListener(PropertyChangeListener listener) {
if (changeSupport == null) {
changeSupport = new SwingPropertyChangeSupport(this);
}
changeSupport.addPropertyChangeListener(listener);
}
Adds a PropertyChangeListener to the listener list.
The listener is registered for all properties.
A PropertyChangeEvent will get fired in response to setting
a bound property, e.g. setFont, setBackground,
or setForeground.
Note that if the current component is inheriting its foreground,
background, or font from its container, then no event will be
fired in response to a change in the inherited property. |
protected Object clone() throws CloneNotSupportedException {
AbstractAction newAction = (AbstractAction)super.clone();
synchronized(this) {
if (arrayTable != null) {
newAction.arrayTable = (ArrayTable)arrayTable.clone();
}
}
return newAction;
}
Clones the abstract action. This gives the clone
its own copy of the key/value list,
which is not handled for you by Object.clone(). |
protected void firePropertyChange(String propertyName,
Object oldValue,
Object newValue) {
if (changeSupport == null ||
(oldValue != null && newValue != null && oldValue.equals(newValue))) {
return;
}
changeSupport.firePropertyChange(propertyName, oldValue, newValue);
}
Supports reporting bound property changes. This method can be called
when a bound property has changed and it will send the appropriate
PropertyChangeEvent to any registered
PropertyChangeListeners. |
public Object[] getKeys() {
if (arrayTable == null) {
return null;
}
Object[] keys = new Object[arrayTable.size()];
arrayTable.getKeys(keys);
return keys;
}
Returns an array of Objects which are keys for
which values have been set for this AbstractAction,
or null if no keys have values set. |
public synchronized PropertyChangeListener[] getPropertyChangeListeners() {
if (changeSupport == null) {
return new PropertyChangeListener[0];
}
return changeSupport.getPropertyChangeListeners();
}
Returns an array of all the PropertyChangeListeners added
to this AbstractAction with addPropertyChangeListener(). |
public Object getValue(String key) {
if (key == "enabled") {
return enabled;
}
if (arrayTable == null) {
return null;
}
return arrayTable.get(key);
}
Gets the Object associated with the specified key. |
static boolean hasSelectedKey(Action a) {
return (a != null && a.getValue(Action.SELECTED_KEY) != null);
}
|
public boolean isEnabled() {
return enabled;
}
Returns true if the action is enabled. |
static boolean isSelected(Action a) {
return Boolean.TRUE.equals(a.getValue(Action.SELECTED_KEY));
}
|
public void putValue(String key,
Object newValue) {
Object oldValue = null;
if (key == "enabled") {
// Treat putValue("enabled") the same way as a call to setEnabled.
// If we don't do this it means the two may get out of sync, and a
// bogus property change notification would be sent.
//
// To avoid dependencies between putValue & setEnabled this
// directly changes enabled. If we instead called setEnabled
// to change enabled, it would be possible for stack
// overflow in the case where a developer implemented setEnabled
// in terms of putValue.
if (newValue == null || !(newValue instanceof Boolean)) {
newValue = false;
}
oldValue = enabled;
enabled = (Boolean)newValue;
} else {
if (arrayTable == null) {
arrayTable = new ArrayTable();
}
if (arrayTable.containsKey(key))
oldValue = arrayTable.get(key);
// Remove the entry for key if newValue is null
// else put in the newValue for key.
if (newValue == null) {
arrayTable.remove(key);
} else {
arrayTable.put(key,newValue);
}
}
firePropertyChange(key, oldValue, newValue);
}
Sets the Value associated with the specified key. |
public synchronized void removePropertyChangeListener(PropertyChangeListener listener) {
if (changeSupport == null) {
return;
}
changeSupport.removePropertyChangeListener(listener);
}
Removes a PropertyChangeListener from the listener list.
This removes a PropertyChangeListener that was registered
for all properties. |
public void setEnabled(boolean newValue) {
boolean oldValue = this.enabled;
if (oldValue != newValue) {
this.enabled = newValue;
firePropertyChange("enabled",
Boolean.valueOf(oldValue), Boolean.valueOf(newValue));
}
}
Sets whether the {@code Action} is enabled. The default is {@code true}. |
static void setEnabledFromAction(JComponent c,
Action a) {
c.setEnabled((a != null) ? a.isEnabled() : true);
}
Sets the enabled state of a component from an Action. |
static void setToolTipTextFromAction(JComponent c,
Action a) {
c.setToolTipText(a != null ?
(String)a.getValue(Action.SHORT_DESCRIPTION) : null);
}
Sets the tooltip text of a component from an Action. |
static boolean shouldReconfigure(PropertyChangeEvent e) {
if (e.getPropertyName() == null) {
synchronized(AbstractAction.class) {
if (RECONFIGURE_ON_NULL == null) {
RECONFIGURE_ON_NULL = Boolean.valueOf(
AccessController.doPrivileged(new GetPropertyAction(
"swing.actions.reconfigureOnNull", "false")));
}
return RECONFIGURE_ON_NULL;
}
}
return false;
}
Whether or not to reconfigure all action properties from the
specified event. |