KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > thinlet > drafts > ModalDemo


1 package thinlet.drafts;
2
3 import thinlet.*;
4 import java.awt.*;
5
6 public class ModalDemo {
7     
8     public void start(Thinlet thinlet, Object JavaDoc previousfield) {
9         Object JavaDoc modaldialog = null;
10         try {
11             modaldialog = thinlet.parse("/thinlet/drafts/modaldialog.xml", this);
12         } catch (Exception JavaDoc exc) { exc.printStackTrace(); return; }
13         Object JavaDoc field = thinlet.find(modaldialog, "field");
14         thinlet.setString(field, "text", String.valueOf(System.currentTimeMillis()));
15         thinlet.add(modaldialog);
16         
17         startModal(thinlet, modaldialog);
18         
19         String JavaDoc text = thinlet.getString(field, "text");
20         thinlet.setString(previousfield, "text", text);
21     }
22     
23     public void close(Thinlet thinlet, Object JavaDoc dialog) {
24         thinlet.remove(dialog);
25         stopModal();
26     }
27     
28     private void startModal(Thinlet thinlet, Object JavaDoc modaldialog) {
29         try {
30             EventQueue queue = thinlet.getToolkit().getSystemEventQueue();
31             while (thinlet.getParent(modaldialog) != null) {
32                     AWTEvent event = queue.getNextEvent();
33                     Object JavaDoc src = event.getSource();
34                     //if (event instanceof ActiveEvent) { // 1.2+
35
// ((ActiveEvent) event).dispatch();
36
//} else
37
if (src instanceof Component) {
38                         ((Component) src).dispatchEvent(event);
39                     } else if (src instanceof MenuComponent) {
40                         ((MenuComponent) src).dispatchEvent(event);
41                     }
42             }
43         } catch(InterruptedException JavaDoc ie) { ie.printStackTrace(); }
44     }
45     
46     private void stopModal() {
47         synchronized (this) {
48             notifyAll();
49         }
50     }
51 }
Popular Tags