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 SplashScreen scr = new SplashScreen(startupTasks);
22 scr.start();
23 }
24
25 public SplashScreen(Task startupTasks) {
26 setUndecorated(true);
27 setTitle("CRON-o-Meter v0.1-Crunchy");
28 getContentPane().setLayout(new BorderLayout(4,4));
29 getContentPane().add(getMainPanel(), BorderLayout.CENTER);
30 pack();
31 ToolBox.centerFrame(this);
32 this.task = startupTasks;
33 }
34
35 public void start() {
36 setVisible(true);
37 getTaskBar().executeTask(task);
38 }
39
40 private JPanel getMainPanel() {
41 if (mainPanel == null) {
42 mainPanel = new JPanel(new BorderLayout(4,4));
43 mainPanel.setBorder(BorderFactory.createRaisedBevelBorder());
44 mainPanel.add(getSplash(), BorderLayout.CENTER);
45 mainPanel.add(getTaskBar(), BorderLayout.SOUTH);
46 }
47 return mainPanel;
48 }
49
50 private TaskBar getTaskBar() {
51 if (taskBar == null) {
52 taskBar = new TaskBar();
53 taskBar.getAbortButton().setVisible(false);
54 taskBar.setBorder(BorderFactory.createEmptyBorder(6,6,6,6));
55 taskBar.addTaskListener(this);
56 }
57 return taskBar;
58 }
59
60 private JLabel getSplash() {
61 if (splash == null) {
62 splash = new JLabel("CRON-O-METER", JLabel.CENTER);
63 splash.setBorder(BorderFactory.createEmptyBorder(10,10,10,10));
64 splash.setFont(splash.getFont().deriveFont(Font.BOLD, 24));
65 }
66 return splash;
67 }
68
69 public void taskStarted(Task t) {}
70
71 public void taskFinished(Task t) {
72 setVisible(false);
73 dispose();
74 }
75
76 public void taskAborted(Task t) {
77 setVisible(false);
78 dispose();
79 }
80
81 /***
82 * Adds a task listener to this object to receive events on
83 * a task's progress.
84 *
85 * @param tl a task listener
86 */
87 public synchronized void addTaskListener(TaskListener tl) {
88 getTaskBar().addTaskListener(tl);
89 }
90
91 /***
92 * Remove a task listener from the TaskBar
93 *
94 * @param tl a task listener
95 */
96 public synchronized void removeTaskListener(TaskListener tl) {
97 getTaskBar().removeTaskListener(tl);
98 }
99
100
101 }