ch.randelshofer.quaqua.QuaquaUIAction Maven / Gradle / Ivy
Show all versions of Quaqua Show documentation
/**
* @(#)QuaquaUIAction.java 1.0 Jan 25, 2008
*
* Copyright (c) 2008-2010 Werner Randelshofer, Immensee, Switzerland.
* All rights reserved.
*
* You may not use, copy or modify this file, except in compliance with the
* license agreement you entered into with Werner Randelshofer.
* For details see accompanying license terms.
*/
package ch.randelshofer.quaqua;
import java.beans.PropertyChangeListener;
import javax.swing.Action;
/**
* QuaquaUIAction 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.
*
* @author Werner Randelshofer
* @version 1.0 Jan 25, 2008 Created.
*/
public abstract class QuaquaUIAction implements Action {
private String name;
public QuaquaUIAction(String name) {
this.name = name;
}
public final String getName() {
return name;
}
public Object getValue(String key) {
if (key.equals(NAME)) {
return name;
}
return null;
}
// UIAction is not mutable, this does nothing.
public void putValue(String key, Object value) {
}
// UIAction is not mutable, this does nothing.
public void setEnabled(boolean b) {
}
/**
* Cover method for isEnabled(null)
.
*/
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.
public void addPropertyChangeListener(PropertyChangeListener listener) {
}
// UIAction is not mutable, this does nothing.
public void removePropertyChangeListener(PropertyChangeListener listener) {
}
}