1 /* 2 * Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 package sun.swing; 26 27 import java.beans.PropertyChangeListener; 28 29 import javax.swing.Action; 30 31 /** 32 * UIAction is the basis of all of basic's action classes that are used in 33 * an ActionMap. Subclasses need to override <code>actionPerformed</code>. 34 * <p> 35 * A typical subclass will look like: 36 * <pre> 37 * private static class Actions extends UIAction { 38 * Actions(String name) { 39 * super(name); 40 * } 41 * 42 * public void actionPerformed(ActionEvent ae) { 43 * if (getName() == "selectAll") { 44 * selectAll(); 45 * } 46 * else if (getName() == "cancelEditing") { 47 * cancelEditing(); 48 * } 49 * } 50 * } 51 * </pre> 52 * <p> 53 * Subclasses that wish to conditionalize the enabled state should override 54 * <code>isEnabled(Component)</code>, and be aware that the passed in 55 * <code>Component</code> may be null. 56 * 57 * @see javax.swing.Action 58 * @author Scott Violet 59 */ 60 public abstract class UIAction implements Action { 61 private String name; 62 63 public UIAction(String name) { 64 this.name = name; 65 } 66 67 public final String getName() { 68 return name; 69 } 70 71 public Object getValue(String key) { 72 if (key == NAME) { 73 return name; 74 } 75 return null; 76 } 77 78 // UIAction is not mutable, this does nothing. 79 public void putValue(String key, Object value) { 80 } 81 82 // UIAction is not mutable, this does nothing. 83 public void setEnabled(boolean b) { 84 } 85 86 /** 87 * Cover method for <code>isEnabled(null)</code>. 88 */ 89 public final boolean isEnabled() { 90 return isEnabled(null); 91 } 92 93 /** 94 * Subclasses that need to conditionalize the enabled state should 95 * 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 */ 99 public boolean isEnabled(Object sender) { 100 return true; 101 } 102 103 // UIAction is not mutable, this does nothing. 104 public void addPropertyChangeListener(PropertyChangeListener listener) { 105 } 106 107 // UIAction is not mutable, this does nothing. 108 public void removePropertyChangeListener(PropertyChangeListener listener) { 109 } 110 }