File: SplashScreen.java

package info (click to toggle)
cronometer 0.9.9%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd, stretch
  • size: 8,732 kB
  • sloc: java: 17,382; xml: 909; makefile: 19; sh: 18
file content (174 lines) | stat: -rw-r--r-- 5,509 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
package ca.spaz.cron.ui;


import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.image.BufferedImage;
import java.io.IOException;

import javax.swing.*;
import javax.swing.border.CompoundBorder;

import org.jdesktop.swingx.JXBusyLabel;
import org.jdesktop.swingx.graphics.GraphicsUtilities;
import org.jdesktop.swingx.graphics.ReflectionRenderer;

import se.datadosen.component.RiverLayout;
import ca.spaz.cron.CRONOMETER;
import ca.spaz.cron.user.UserManager;
import ca.spaz.gui.TranslucentPanel;
import ca.spaz.task.*;
import ca.spaz.util.ToolBox;

public class SplashScreen extends JFrame implements TaskListener {

   private TaskBar taskBar;
   private JLabel splash, version;
   private JPanel mainPanel;
   private JCheckBox checkForUpdates;
   private Task task;
   
   public static void showSplashScreen(Task startupTasks) {
      SplashScreen scr = new SplashScreen(startupTasks);
      scr.start();
   }
   
   public SplashScreen(Task startupTasks) {
      
      JPanel mp = new JPanel(new BorderLayout());
      mp.setBorder(new CompoundBorder(
            BorderFactory.createRaisedBevelBorder(),
            BorderFactory.createEmptyBorder(15,15,15,15) ));
      mp.add(getMainPanel(), BorderLayout.CENTER);
      
      setUndecorated(true);
      setTitle(CRONOMETER.getFullTitle());
      getContentPane().setLayout(new BorderLayout(4,4));
      getContentPane().add(mp, BorderLayout.CENTER);
      pack();
      ToolBox.centerFrame(this);
      this.task = startupTasks;
   }
   
   public ImageIcon getIcon() {
      try {
         BufferedImage img = GraphicsUtilities.loadCompatibleImage(this.getClass().getResource("/img/apple-100x100.png"));
         ReflectionRenderer r = new ReflectionRenderer(0.5f, 0.25f, true);
         return  new ImageIcon(r.appendReflection(img));
      } catch (IOException e) {
         e.printStackTrace();
      }
      return new ImageIcon(); // empty on failure
   }
   
   public void start() {
      setVisible(true);
      getTaskBar().executeTask(task);
   }
   
   private JPanel getMainPanel() {
      if (mainPanel == null) {
         mainPanel = new TranslucentPanel(0.3);
         mainPanel.setBackground(Color.BLACK);
         mainPanel.setLayout(new RiverLayout());
         mainPanel.setBorder(BorderFactory.createEmptyBorder(15,40,15,40));      
         mainPanel.add("p center", getSplash());
         
         JXBusyLabel busy = new JXBusyLabel();
         mainPanel.add("br center", busy);
         busy.setBusy(true);

         //mainPanel.add("p hfill", getTaskBar());
         
         mainPanel.add("p center", getVersionLabel());
         /* Don't check for updates in Debian
         if (System.getProperty("ca.spaz.mode", "application").equalsIgnoreCase("application")) {
            mainPanel.add("p center", getCheckForUpdatesBox());
         }
         */
      }
      return mainPanel;
   }
   
   private TaskBar getTaskBar() {
      if (taskBar == null) {
         taskBar = new TaskBar();
         taskBar.setOpaque(false);
         taskBar.getAbortButton().setVisible(false);
         taskBar.setBorder(BorderFactory.createEmptyBorder(6,6,6,6));
         taskBar.addTaskListener(this);
      }
      return taskBar;
   }
   
   private JLabel getSplash() {
      if (splash == null) {
         splash = new JLabel(CRONOMETER.TITLE, getIcon(), JLabel.CENTER);
         splash.setVerticalTextPosition(JLabel.BOTTOM);
         splash.setHorizontalTextPosition(JLabel.CENTER);
         splash.setBorder(BorderFactory.createEmptyBorder(10,10,10,10));
         splash.setFont(splash.getFont().deriveFont(Font.BOLD, 24));
      }
      return splash;
   }
   

   private JLabel getVersionLabel() {
      if (version == null) {
         version = new JLabel(CRONOMETER.getFullTitle(), JLabel.CENTER);         
         version.setFont(version.getFont().deriveFont(Font.PLAIN, 10));
         version.setForeground(Color.DARK_GRAY);
      }
      return version;
   }

   public void taskStarted(Task t) {}

   public void taskFinished(Task t) {
      setVisible(false);
      dispose();
   }

   public void taskAborted(Task t) {
      setVisible(false);
      dispose();
   }

   /**
    * Adds a task listener to this object to receive events on
    * a task's progress.
    * 
    * @param tl a task listener 
    */
   public synchronized void addTaskListener(TaskListener tl) {
      getTaskBar().addTaskListener(tl);
   }

   /**
    * Remove a task listener from the TaskBar
    * 
    * @param tl a task listener 
    */
   public synchronized void removeTaskListener(TaskListener tl) {
      getTaskBar().removeTaskListener(tl);
   }
  
   
   private JCheckBox getCheckForUpdatesBox() {
      if (checkForUpdates == null) {
         checkForUpdates = new JCheckBox(
               "check website for updates", 
               UserManager.getUserManager().getCheckForUpdates());              
         checkForUpdates.setFocusable(false);
         checkForUpdates.setOpaque(false);
         checkForUpdates.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
               UserManager.getUserManager().setCheckForUpdates(checkForUpdates.isSelected());
            }            
         });
      }
      return checkForUpdates;
   }
   
}