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 = gate.gui.MainFrame.getIcon("working.gif");
46 this.frame = frame;
47 try {
48 jbInit();
49 pack();
50 }
51 catch(Exception ex) {
52 ex.printStackTrace();
53 }
54 }
55
56
61 public synchronized void showDialog(String[] texts) {
62 centerBox.removeAll();
63
64 for(int i =0; i < texts.length; i++){
65 centerBox.add(new JLabel(texts[i]));
66 }
67
68 centerBox.validate();
69 pack();
70
76 stop = false;
77 Thread thread = new Thread(Thread.currentThread().getThreadGroup(),
78 this,
79 "WaitDialog1");
80 thread.setPriority(Thread.MAX_PRIORITY);
81 thread.start();
82 setVisible(true);
83 }
84
85
90 public synchronized void showDialog(Component[] components) {
91 centerBox.removeAll();
92 for(int i =0; i < components.length; i++){
93 centerBox.add(components[i]);
94 }
95 centerBox.validate();
96 pack();
97
102 stop = false;
103 Thread thread = new Thread(Thread.currentThread().getThreadGroup(),
104 this,
105 "WaitDialog2");
106 thread.setPriority(Thread.MAX_PRIORITY);
107 thread.start();
108 setVisible(true);
109 }
110
111
112 void jbInit() throws Exception {
113 JPanel centerPanel = new JPanel();
114 Container content = getContentPane();
115 centerBox = Box.createVerticalBox();
116 centerPanel.setLayout(borderLayout1);
117 picture = new JLabel(icon);
121 picture.setOpaque(false);
122 centerPanel.add(centerBox, BorderLayout.CENTER);
123 centerPanel.add(picture, BorderLayout.WEST);
124 centerPanel.add(Box.createVerticalStrut(5), BorderLayout.NORTH);
125 centerPanel.add(Box.createVerticalStrut(5), BorderLayout.SOUTH);
126 centerPanel.add(Box.createHorizontalStrut(8), BorderLayout.EAST);
127 getContentPane().add(centerPanel, BorderLayout.CENTER);
128 centerPanel.setOpaque(false);
129 }
130
131
135 public void goAway() {
136 stop = true;
137 }
138
139
141 public void run() {
142 while(!stop){
143 try{
144 Thread.sleep(300);
145 centerBox.validate();
146 pack();
147
152 picture.paintImmediately(picture.getVisibleRect());
153 }catch(InterruptedException ie){}
154 }
155 this.setVisible(false);
156 }
157
158
159 boolean stop = false;
160
161 BorderLayout borderLayout1 = new BorderLayout();
162
163 Frame frame;
164
165 JLabel picture;
166
167 Icon icon;
168
169 }