01: /*
02: * Project: AMODA - Abstract Modeled Application
03: * Class: de.gulden.framework.amoda.generic.behaviour.GenericCommandThread
04: * Version: snapshot-beautyj-1.1
05: *
06: * Date: 2004-09-29
07: *
08: * This is a snapshot version of the AMODA 0.2 development branch,
09: * it is not released as a seperate version.
10: * For AMODA, see http://amoda.berlios.de/.
11: *
12: * This is licensed under the GNU Lesser General Public License (LGPL)
13: * and comes with NO WARRANTY.
14: *
15: * Author: Jens Gulden
16: * Email: amoda@jensgulden.de
17: */
18:
19: package de.gulden.framework.amoda.generic.behaviour;
20:
21: import de.gulden.framework.amoda.model.behaviour.*;
22: import java.awt.event.*;
23: import java.lang.Runnable;
24: import java.util.*;
25:
26: /**
27: * Class GenericCommandThread.
28: *
29: * @author Jens Gulden
30: * @version snapshot-beautyj-1.1
31: */
32: public class GenericCommandThread extends GenericCommand implements
33: Runnable {
34:
35: // ------------------------------------------------------------------------
36: // --- fields ---
37: // ------------------------------------------------------------------------
38:
39: private Command wrapped;
40:
41: protected ActionEvent event;
42:
43: private boolean running;
44:
45: // ------------------------------------------------------------------------
46: // --- methods ---
47: // ------------------------------------------------------------------------
48:
49: public void perform() {
50: // your code here
51: }
52:
53: public void run() {
54: Object gui = event.getSource();
55: if (gui instanceof javax.swing.JComponent) {
56: ((javax.swing.JComponent) gui).setEnabled(false);
57: }
58:
59: try {
60: wrapped.perform();
61: } catch (Throwable t) {
62: getApplication().error(t);
63: }
64:
65: if (gui instanceof javax.swing.JComponent) {
66: ((javax.swing.JComponent) gui).setEnabled(true);
67: }
68: }
69:
70: public void actionPerformed(ActionEvent event) {
71: GenericCommandThread t = new GenericCommandThread(); // own instance for running in own thread
72: t.setParent(this .getParent());
73: t.wrapped = this ;
74: t.event = event;
75: Thread thread = new Thread(t);
76: thread.start();
77: }
78:
79: } // end GenericCommandThread
|