Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/classes/sun/swing/UIAction.java
38829 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 com.sun.java.swing.ExtendedAction57* @see javax.swing.Action58* @author Scott Violet59*/60public abstract class UIAction implements Action {61private String name;6263public UIAction(String name) {64this.name = name;65}6667public final String getName() {68return name;69}7071public Object getValue(String key) {72if (key == NAME) {73return name;74}75return null;76}7778// UIAction is not mutable, this does nothing.79public void putValue(String key, Object value) {80}8182// UIAction is not mutable, this does nothing.83public void setEnabled(boolean b) {84}8586/**87* Cover method for <code>isEnabled(null)</code>.88*/89public final boolean isEnabled() {90return isEnabled(null);91}9293/**94* Subclasses that need to conditionalize the enabled state should95* override this. Be aware that <code>sender</code> may be null.96*97* @param sender Widget enabled state is being asked for, may be null.98*/99public boolean isEnabled(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