001: /*
002: * Copyright 2001-2007 Geert Bevin <gbevin[remove] at uwyn dot com>
003: * Distributed under the terms of either:
004: * - the common development and distribution license (CDDL), v1.0; or
005: * - the GNU Lesser General Public License, v2.1 or later
006: * $Id: JAction.java 3634 2007-01-08 21:42:24Z gbevin $
007: */
008: package com.uwyn.rife.swing;
009:
010: import com.uwyn.rife.swing.Command;
011: import java.awt.event.ActionEvent;
012: import javax.swing.AbstractAction;
013: import javax.swing.Action;
014: import javax.swing.Icon;
015: import javax.swing.KeyStroke;
016:
017: public class JAction extends AbstractAction {
018: private static final long serialVersionUID = 8035921004854064778L;
019:
020: private Command mCommand = null;
021:
022: private JAction() {
023: }
024:
025: public JAction(Command command, String name) {
026: this (command, name, null, null, null, null);
027: }
028:
029: public JAction(Command command, String name, char mnemonic) {
030: this (command, name, new Integer(mnemonic), null, null, null);
031: }
032:
033: public JAction(Command command, String name, Integer mnemonic) {
034: this (command, name, mnemonic, null, null, null);
035: }
036:
037: public JAction(Command command, String name, char mnemonic,
038: KeyStroke accelerator) {
039: this (command, name, new Integer(mnemonic), accelerator, null,
040: null);
041: }
042:
043: public JAction(Command command, String name, Integer mnemonic,
044: KeyStroke accelerator) {
045: this (command, name, mnemonic, accelerator, null, null);
046: }
047:
048: public JAction(Command command, String name, char mnemonic,
049: KeyStroke accelerator, Icon icon) {
050: this (command, name, new Integer(mnemonic), accelerator, icon,
051: null);
052: }
053:
054: public JAction(Command command, String name, Integer mnemonic,
055: KeyStroke accelerator, Icon icon) {
056: this (command, name, mnemonic, accelerator, icon, null);
057: }
058:
059: public JAction(Command command, Icon icon) {
060: this (command, null, null, null, icon, null);
061: }
062:
063: public JAction(Command command, Icon icon, String shortDescription) {
064: this (command, null, null, null, icon, shortDescription);
065: }
066:
067: public JAction(Command command, String name, char mnemonic,
068: KeyStroke accelerator, Icon icon, String shortDescription) {
069: this (command, name, new Integer(mnemonic), accelerator, icon,
070: shortDescription);
071: }
072:
073: public JAction(Command command, String name, Integer mnemonic,
074: KeyStroke accelerator, Icon icon, String shortDescription) {
075: super ();
076:
077: setCommand(command);
078:
079: if (null != name) {
080: setName(name);
081: }
082: if (null != mnemonic) {
083: setMnemonic(mnemonic);
084: }
085: if (null != accelerator) {
086: setAccelerator(accelerator);
087: }
088: if (null != icon) {
089: setIcon(icon);
090: }
091: if (null != shortDescription) {
092: setShortDescription(shortDescription);
093: }
094: }
095:
096: public void setCommand(Command command) {
097: mCommand = command;
098: }
099:
100: public void setName(String name) {
101: putValue(Action.NAME, name);
102: }
103:
104: public void setMnemonic(char mnemonic) {
105: setMnemonic(new Integer(mnemonic));
106: }
107:
108: public void setMnemonic(Integer mnemonic) {
109: putValue(Action.MNEMONIC_KEY, mnemonic);
110: }
111:
112: public void setAccelerator(KeyStroke accelerator) {
113: putValue(Action.ACCELERATOR_KEY, accelerator);
114: }
115:
116: public void setIcon(Icon icon) {
117: putValue(Action.SMALL_ICON, icon);
118: }
119:
120: public void setShortDescription(String shortDescription) {
121: putValue(Action.SHORT_DESCRIPTION, shortDescription);
122: }
123:
124: public void actionPerformed(ActionEvent e) {
125: if (null != mCommand) {
126: new Thread() {
127: public void run() {
128: mCommand.execute();
129: }
130: }.start();
131: }
132: }
133: }
|