1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
package ca.spaz.cron; |
5 |
|
|
6 |
|
import java.awt.*; |
7 |
|
|
8 |
|
import javax.swing.*; |
9 |
|
|
10 |
|
import ca.spaz.task.*; |
11 |
|
import ca.spaz.util.ToolBox; |
12 |
|
|
13 |
|
public class SplashScreen extends JFrame implements TaskListener { |
14 |
|
|
15 |
|
private TaskBar taskBar; |
16 |
|
private JLabel splash; |
17 |
|
private JPanel mainPanel; |
18 |
|
private Task task; |
19 |
|
|
20 |
|
public static void showSplashScreen(Task startupTasks) { |
21 |
0 |
SplashScreen scr = new SplashScreen(startupTasks); |
22 |
0 |
scr.start(); |
23 |
0 |
} |
24 |
|
|
25 |
0 |
public SplashScreen(Task startupTasks) { |
26 |
0 |
setUndecorated(true); |
27 |
0 |
setTitle("CRON-o-Meter v0.1-Crunchy"); |
28 |
0 |
getContentPane().setLayout(new BorderLayout(4,4)); |
29 |
0 |
getContentPane().add(getMainPanel(), BorderLayout.CENTER); |
30 |
0 |
pack(); |
31 |
0 |
ToolBox.centerFrame(this); |
32 |
0 |
this.task = startupTasks; |
33 |
0 |
} |
34 |
|
|
35 |
|
public void start() { |
36 |
0 |
setVisible(true); |
37 |
0 |
getTaskBar().executeTask(task); |
38 |
0 |
} |
39 |
|
|
40 |
|
private JPanel getMainPanel() { |
41 |
0 |
if (mainPanel == null) { |
42 |
0 |
mainPanel = new JPanel(class="keyword">new BorderLayout(4,4)); |
43 |
0 |
mainPanel.setBorder(BorderFactory.createRaisedBevelBorder()); |
44 |
0 |
mainPanel.add(getSplash(), BorderLayout.CENTER); |
45 |
0 |
mainPanel.add(getTaskBar(), BorderLayout.SOUTH); |
46 |
|
} |
47 |
0 |
return mainPanel; |
48 |
|
} |
49 |
|
|
50 |
|
private TaskBar getTaskBar() { |
51 |
0 |
if (taskBar == null) { |
52 |
0 |
taskBar = new TaskBar(); |
53 |
0 |
taskBar.getAbortButton().setVisible(false); |
54 |
0 |
taskBar.setBorder(BorderFactory.createEmptyBorder(6,6,6,6)); |
55 |
0 |
taskBar.addTaskListener(this); |
56 |
|
} |
57 |
0 |
return taskBar; |
58 |
|
} |
59 |
|
|
60 |
|
private JLabel getSplash() { |
61 |
0 |
if (splash == null) { |
62 |
0 |
splash = new JLabel("CRON-O-METER", JLabel.CENTER); |
63 |
0 |
splash.setBorder(BorderFactory.createEmptyBorder(10,10,10,10)); |
64 |
0 |
splash.setFont(splash.getFont().deriveFont(Font.BOLD, 24)); |
65 |
|
} |
66 |
0 |
return splash; |
67 |
|
} |
68 |
|
|
69 |
0 |
public void taskStarted(Task t) {} |
70 |
|
|
71 |
|
public void taskFinished(Task t) { |
72 |
0 |
setVisible(false); |
73 |
0 |
dispose(); |
74 |
0 |
} |
75 |
|
|
76 |
|
public void taskAborted(Task t) { |
77 |
0 |
setVisible(false); |
78 |
0 |
dispose(); |
79 |
0 |
} |
80 |
|
|
81 |
|
|
82 |
|
|
83 |
|
|
84 |
|
|
85 |
|
|
86 |
|
|
87 |
|
public synchronized void addTaskListener(TaskListener tl) { |
88 |
0 |
getTaskBar().addTaskListener(tl); |
89 |
0 |
} |
90 |
|
|
91 |
|
|
92 |
|
|
93 |
|
|
94 |
|
|
95 |
|
|
96 |
|
public synchronized void removeTaskListener(TaskListener tl) { |
97 |
0 |
getTaskBar().removeTaskListener(tl); |
98 |
0 |
} |
99 |
|
|
100 |
|
|
101 |
|
} |