01: package org.jatha.display.action;
02:
03: import org.jatha.display.UnderConstruction;
04:
05: import javax.swing.*;
06: import java.awt.event.ActionEvent;
07:
08: import org.jatha.Jatha;
09:
10: /**
11: * Abstract base class used for Application actions.
12: * The actions are performed by menu items, buttons and key strokes.
13: * User: hewett
14: * Date: Mar 7, 2003
15: * Time: 11:50:02 AM
16: */
17: public abstract class ApplicationAction extends AbstractAction {
18: protected Jatha f_app = null;
19: protected String f_name = null;
20:
21: /**
22: * Creates a new Action.
23: * @param mainApp The application managing this action.
24: * @param name The name of the menu item corresponding to this action.
25: * @param tooltip A string to be displayed as brief user help.
26: * @param acceleratorKey The KeyStroke used to access this action as a menu item.
27: * @param mnemonic The (int) character used to access this action when it is a button.
28: */
29: public ApplicationAction(Jatha mainApp, String name, Icon icon,
30: String tooltip, KeyStroke acceleratorKey, Integer mnemonic) {
31: super (name, icon);
32: f_app = mainApp;
33: f_name = name;
34:
35: // Enabled by default.
36: this .setEnabled(true);
37:
38: // Set various fields
39: if (acceleratorKey != null)
40: this .putValue(ACCELERATOR_KEY, acceleratorKey);
41:
42: if (mnemonic != null)
43: this .putValue(MNEMONIC_KEY, mnemonic);
44:
45: if (name != null)
46: this .putValue(NAME, name);
47:
48: if (tooltip != null)
49: this .putValue(SHORT_DESCRIPTION, tooltip);
50: }
51:
52: public String getText() {
53: return (String) getValue(NAME);
54: }
55:
56: public void setText(String text) {
57: putValue(NAME, text);
58: }
59:
60: public ImageIcon getIcon() {
61: return (ImageIcon) getValue(SMALL_ICON);
62: }
63:
64: public void setIcon(ImageIcon icon) {
65: putValue(SMALL_ICON, icon);
66: }
67:
68: public Integer getMnemonicKey() {
69: return (Integer) getValue(MNEMONIC_KEY);
70: }
71:
72: public void setMnemonicKey(Integer mnemonicKey) {
73: putValue(MNEMONIC_KEY, mnemonicKey);
74: }
75:
76: public String getDescription() {
77: return (String) getValue(SHORT_DESCRIPTION);
78: }
79:
80: public void setDescription(String description) {
81: putValue(SHORT_DESCRIPTION, description);
82: }
83:
84: public void actionPerformed(ActionEvent e) {
85: new UnderConstruction(f_name, "The " + f_name
86: + " operation is under construction.");
87: }
88: }
|