org.jdesktop.swingx.plaf.UIAction Maven / Gradle / Ivy
Show all versions of swingx-all Show documentation
/*
* $Id: UIAction.java 4028 2011-06-03 19:32:19Z kschaefe $
*
* Copyright 2004 Sun Microsystems, Inc., 4150 Network Circle,
* Santa Clara, California 95054, U.S.A. All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
package org.jdesktop.swingx.plaf;
import javax.swing.Action;
import java.beans.PropertyChangeListener;
/**
* UIAction is the basis of all of basic's action classes that are used in
* an ActionMap. Subclasses need to override actionPerformed
.
*
* A typical subclass will look like:
*
* private static class Actions extends UIAction {
* Actions(String name) {
* super(name);
* }
*
* public void actionPerformed(ActionEvent ae) {
* if (getName() == "selectAll") {
* selectAll();
* }
* else if (getName() == "cancelEditing") {
* cancelEditing();
* }
* }
* }
*
*
* Subclasses that wish to conditionalize the enabled state should override
* isEnabled(Component)
, and be aware that the passed in
* Component
may be null.
*
* This is based on sun.swing.UIAction in J2SE 1.5
*
* @author Scott Violet
* @see Action
*/
public abstract class UIAction implements Action {
private final String name;
protected UIAction(String name) {
this.name = name;
}
public final String getName() {
return name;
}
@Override
public Object getValue(String key) {
return NAME.equals(key) ? name : null;
}
// UIAction is not mutable, this does nothing.
@Override
public void putValue(String key, Object value) {
}
// UIAction is not mutable, this does nothing.
@Override
public void setEnabled(boolean b) {
}
/**
* Cover method for isEnabled(null)
.
*/
@Override
public final boolean isEnabled() {
return isEnabled(null);
}
/**
* Subclasses that need to conditionalize the enabled state should
* override this. Be aware that sender
may be null.
*
* @param sender Widget enabled state is being asked for, may be null.
*/
public boolean isEnabled(Object sender) {
return true;
}
// UIAction is not mutable, this does nothing.
@Override
public void addPropertyChangeListener(PropertyChangeListener listener) {
}
// UIAction is not mutable, this does nothing.
@Override
public void removePropertyChangeListener(PropertyChangeListener listener) {
}
}