KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > de > gulden > framework > amoda > generic > behaviour > GenericCommandThread


1 /*
2  * Project: AMODA - Abstract Modeled Application
3  * Class: de.gulden.framework.amoda.generic.behaviour.GenericCommandThread
4  * Version: snapshot-beautyj-1.1
5  *
6  * Date: 2004-09-29
7  *
8  * This is a snapshot version of the AMODA 0.2 development branch,
9  * 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 JavaDoc;
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 Runnable JavaDoc {
33
34     // ------------------------------------------------------------------------
35
// --- fields ---
36
// ------------------------------------------------------------------------
37

38     private Command wrapped;
39
40     protected ActionEvent event;
41
42     private boolean running;
43
44
45     // ------------------------------------------------------------------------
46
// --- methods ---
47
// ------------------------------------------------------------------------
48

49     public void perform() {
50         // your code here
51
}
52
53     public void run() {
54         Object JavaDoc gui = event.getSource();
55         if (gui instanceof javax.swing.JComponent JavaDoc) {
56             ((javax.swing.JComponent JavaDoc)gui).setEnabled(false);
57         }
58
59         try {
60             wrapped.perform();
61         } catch (Throwable JavaDoc t) {
62             getApplication().error(t);
63         }
64
65         if (gui instanceof javax.swing.JComponent JavaDoc) {
66             ((javax.swing.JComponent JavaDoc)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 JavaDoc thread = new Thread JavaDoc(t);
76         thread.start();
77     }
78
79 } // end GenericCommandThread
80
Popular Tags