Path: blob/master/src/java.desktop/share/classes/sun/swing/UIAction.java
41153 views
/*1* Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/24package sun.swing;2526import java.beans.PropertyChangeListener;2728import javax.swing.Action;2930/**31* UIAction is the basis of all of basic's action classes that are used in32* an ActionMap. Subclasses need to override <code>actionPerformed</code>.33* <p>34* A typical subclass will look like:35* <pre>36* private static class Actions extends UIAction {37* Actions(String name) {38* super(name);39* }40*41* public void actionPerformed(ActionEvent ae) {42* if (getName() == "selectAll") {43* selectAll();44* }45* else if (getName() == "cancelEditing") {46* cancelEditing();47* }48* }49* }50* </pre>51* <p>52* Subclasses that wish to conditionalize the enabled state should override53* <code>isEnabled(Component)</code>, and be aware that the passed in54* <code>Component</code> may be null.55*56* @see javax.swing.Action57* @author Scott Violet58*/59public abstract class UIAction implements Action {60private String name;6162public UIAction(String name) {63this.name = name;64}6566public final String getName() {67return name;68}6970public Object getValue(String key) {71if (key == NAME) {72return name;73}74return null;75}7677// UIAction is not mutable, this does nothing.78public void putValue(String key, Object value) {79}8081// UIAction is not mutable, this does nothing.82public void setEnabled(boolean b) {83}8485/**86* Cover method for <code>isEnabled(null)</code>.87*/88public final boolean isEnabled() {89return accept(null);90}9192/**93* Subclasses that need to conditionalize the enabled state should94* override this. Be aware that <code>sender</code> may be null.95*96* @param sender Widget enabled state is being asked for, may be null.97*/98@Override99public boolean accept(Object sender) {100return true;101}102103// UIAction is not mutable, this does nothing.104public void addPropertyChangeListener(PropertyChangeListener listener) {105}106107// UIAction is not mutable, this does nothing.108public void removePropertyChangeListener(PropertyChangeListener listener) {109}110}111112113