1
15
16 package gate.swing;
17
18 import java.awt.*;
19
20 import javax.swing.*;
21
22
29 public class WaitDialog extends JWindow implements Runnable {
30
31
33 private static final boolean DEBUG = false;
34
35
37 Box centerBox;
38
39
40 public WaitDialog(Frame frame, String title) {
41 super(frame);
42 this.icon = new ImageIcon(ClassLoader.getSystemResource(
43 "gate/resources/img/working.gif"));
44 this.frame = frame;
45 try {
46 jbInit();
47 pack();
48 }
49 catch(Exception ex) {
50 ex.printStackTrace();
51 }
52 }
53
54
59 public synchronized void showDialog(String[] texts) {
60 centerBox.removeAll();
61
62 for(int i =0; i < texts.length; i++){
63 centerBox.add(new JLabel(texts[i]));
64 }
65
66 centerBox.validate();
67 pack();
68
74 stop = false;
75 Thread thread = new Thread(Thread.currentThread().getThreadGroup(),
76 this,
77 "WaitDialog1");
78 thread.setPriority(Thread.MAX_PRIORITY);
79 thread.start();
80 setVisible(true);
81 }
82
83
88 public synchronized void showDialog(Component[] components) {
89 centerBox.removeAll();
90 for(int i =0; i < components.length; i++){
91 centerBox.add(components[i]);
92 }
93 centerBox.validate();
94 pack();
95
100 stop = false;
101 Thread thread = new Thread(Thread.currentThread().getThreadGroup(),
102 this,
103 "WaitDialog2");
104 thread.setPriority(Thread.MAX_PRIORITY);
105 thread.start();
106 setVisible(true);
107 }
108
109
110 void jbInit() throws Exception {
111 JPanel centerPanel = new JPanel();
112 Container content = getContentPane();
113 centerBox = Box.createVerticalBox();
114 centerPanel.setLayout(borderLayout1);
115 picture = new JLabel(icon);
119 picture.setOpaque(false);
120 centerPanel.add(centerBox, BorderLayout.CENTER);
121 centerPanel.add(picture, BorderLayout.WEST);
122 centerPanel.add(Box.createVerticalStrut(5), BorderLayout.NORTH);
123 centerPanel.add(Box.createVerticalStrut(5), BorderLayout.SOUTH);
124 centerPanel.add(Box.createHorizontalStrut(8), BorderLayout.EAST);
125 getContentPane().add(centerPanel, BorderLayout.CENTER);
126 centerPanel.setOpaque(false);
127 }
128
129
133 public void goAway() {
134 stop = true;
135 }
136
137
139 public void run() {
140 while(!stop){
141 try{
142 Thread.sleep(300);
143 centerBox.validate();
144 pack();
145
150 picture.paintImmediately(picture.getVisibleRect());
151 }catch(InterruptedException ie){}
152 }
153 this.setVisible(false);
154 }
155
156
157 boolean stop = false;
158
159 BorderLayout borderLayout1 = new BorderLayout();
160
161 Frame frame;
162
163 JLabel picture;
164
165 Icon icon;
166
167 }