Debian Codegraph @

src/com/jidesoft/plaf/basic/UIAction.java

raw
1 /*
2 * @(#)UIAction.java 8/20/2006
3 *
4 * Copyright 2002 - 2006 JIDE Software Inc. All rights reserved.
5 */
6
7 package com.jidesoft.plaf.basic;
8
9 import javax.swing.*;
10 import java.beans.PropertyChangeListener;
11
12 /**
13 * UIAction is the basis of all of basic's action classes that are used in an ActionMap. Subclasses
14 * need to override <code>actionPerformed</code>.
15 * <p/>
16 * A typical subclass will look like:
17 * <pre>
18 * private static class Actions extends UIAction {
19 * Actions(String name) {
20 * super(name);
21 * }
22 * <p/>
23 * public void actionPerformed(ActionEvent ae) {
24 * if (getName() == "selectAll") {
25 * selectAll();
26 * }
27 * else if (getName() == "cancelEditing") {
28 * cancelEditing();
29 * }
30 * }
31 * }
32 * </pre>
33 * <p/>
34 * Subclasses that wish to conditionalize the enabled state should override
35 * <code>isEnabled(Component)</code>, and be aware that the passed in <code>Component</code> may be
36 * null.
37 *
38 * @author Scott Violet
39 * @version 1.4 11/17/05
40 * @see javax.swing.Action
41 */
42 public abstract class UIAction implements Action {
43 private String name;
44
45 public UIAction(String name) {
46 this.name = name;
47 }
48
49 public final String getName() {
50 return name;
51 }
52
53 public Object getValue(String key) {
54 if (NAME.equals(key)) {
55 return name;
56 }
57 return null;
58 }
59
60 // UIAction is not mutable, this does nothing.
61 public void putValue(String key, Object value) {
62 }
63
64 // UIAction is not mutable, this does nothing.
65 public void setEnabled(boolean b) {
66 }
67
68 /**
69 * Cover method for <code>isEnabled(null)</code>.
70 */
71 public final boolean isEnabled() {
72 return isEnabled(null);
73 }
74
75 /**
76 * Subclasses that need to conditionalize the enabled state should override this. Be aware that
77 * <code>sender</code> may be null.
78 *
79 * @param sender Widget enabled state is being asked for, may be null.
80 *
81 * @return true.
82 */
83 public boolean isEnabled(Object sender) {
84 return true;
85 }
86
87 // UIAction is not mutable, this does nothing.
88 public void addPropertyChangeListener(PropertyChangeListener listener) {
89 }
90
91 // UIAction is not mutable, this does nothing.
92 public void removePropertyChangeListener(PropertyChangeListener listener) {
93 }
94 }