1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package net.sf.jameleon.ui;
20
21 import java.awt.Point;
22 import java.io.File;
23
24 import javax.swing.JDialog;
25 import javax.swing.JFrame;
26 import javax.swing.JLabel;
27 import javax.swing.JPanel;
28 import javax.swing.JProgressBar;
29 import javax.swing.SpringLayout;
30
31 public class ProgressDialog extends JDialog {
32
33 protected int maxTimeInSeconds;
34 protected JProgressBar progressBar;
35 protected Thread task;
36 protected boolean keepGoing = true;
37 protected final int MULTIPLIER = 10;
38 protected TestCaseDocsExecutor tcde;
39
40 public ProgressDialog(JFrame rootFrame, int maxTimeInSeconds, TestCasePane testCasePane, File script){
41 super(rootFrame);
42 this.maxTimeInSeconds = maxTimeInSeconds;
43 Point rootLocation = rootFrame.getLocation();
44 int height = rootLocation.y + rootFrame.getHeight() / 2;
45 int width = rootLocation.x + rootFrame.getWidth() / 2;
46 setUndecorated(true);
47
48 tcde = new TestCaseDocsExecutor(script,testCasePane);
49 tcde.setContextClassLoader(Utils.createClassLoader());
50 init();
51 setLocation(width, height);
52 tcde.setProgressDialog(this);
53 beginWaitingOnTask();
54 setModal(true);
55 setVisible(true);
56 }
57
58 private void init(){
59 JPanel progressPanel = new JPanel(new SpringLayout());
60 progressBar = new JProgressBar(0, maxTimeInSeconds * MULTIPLIER);
61 JLabel generating = new JLabel("Generating Documentation");
62 progressPanel.add(generating);
63
64 progressPanel.add(progressBar);
65 SpringUtilities.makeCompactGrid(progressPanel,
66 2, 1,
67 6, 6,
68 6, 6);
69 getContentPane().add(progressPanel);
70 pack();
71 }
72
73 private void beginWaitingOnTask(){
74 task = new Thread(){
75 public void run() {
76 int interval = 100;
77 for (int i = 0; keepGoing && i <= (maxTimeInSeconds * MULTIPLIER); i++) {
78 try {
79 sleep(interval);
80 progressBar.setValue(i);
81 } catch (InterruptedException e) {
82 keepGoing = false;
83 break;
84 }
85 }
86 }
87 };
88 tcde.start();
89 task.start();
90 }
91
92 public void taskCompleted(){
93 keepGoing = false;
94 progressBar.setValue(maxTimeInSeconds);
95 dispose();
96 }
97 }