Source code: jgift/ui/SplashScreen.java
1 /*
2 * This file is part of jgiFT.
3 * Copyright (C) 2003, Jason Shobe
4 *
5 * jgiFT is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * jgiFT is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with jgiFT; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */
19 package jgift.ui;
20
21 import java.awt.BorderLayout;
22 import java.awt.Color;
23 import java.awt.Dimension;
24 import java.awt.Font;
25 import java.awt.Frame;
26 import java.awt.GridBagConstraints;
27 import java.awt.GridBagLayout;
28 import java.awt.Insets;
29 import java.awt.Toolkit;
30 import java.awt.Window;
31 import javax.swing.BorderFactory;
32 import javax.swing.ImageIcon;
33 import javax.swing.JLabel;
34 import javax.swing.JPanel;
35 import javax.swing.JProgressBar;
36 import javax.swing.SwingUtilities;
37
38 /**
39 * Displays the application splash screen during startup.
40 *
41 * @author Jason Shobe
42 * @version $Revision: 1.2 $
43 */
44 public class SplashScreen extends Window {
45 /**
46 * Creates a new instance of SplashScreen.
47 */
48 public SplashScreen() {
49 super(new Frame());
50
51 setLayout(new BorderLayout());
52 setBackground(Color.WHITE);
53
54 JPanel panel = new JPanel(new BorderLayout());
55 panel.setBackground(Color.WHITE);
56 panel.setBorder(BorderFactory.createLineBorder(Color.BLACK, 1));
57
58 panel.add(new JLabel(new ImageIcon(getClass().
59 getResource("/jgift/ui/images/splash.png"))), BorderLayout.CENTER);
60
61 JPanel panel2 = new JPanel(new GridBagLayout());
62 panel2.setBackground(Color.WHITE);
63
64 GridBagConstraints gbc = new GridBagConstraints();
65 gbc.gridwidth = 1;
66 gbc.gridheight = 1;
67 gbc.weightx = 0.0;
68 gbc.weighty = 0.0;
69
70 JLabel label = new JLabel("jgiFT P2P Client");
71 Font font = new Font("Dialog", 0, 10);
72 label.setFont(font);
73 gbc.anchor = GridBagConstraints.WEST;
74 gbc.gridx = 0;
75 gbc.gridy = 0;
76 gbc.insets = new Insets(10, 5, 0, 5);
77 panel2.add(label, gbc);
78
79 label = new JLabel("Copyright \u00a9 2003, Jason Shobe");
80 label.setFont(font);
81 gbc.gridy = 1;
82 gbc.insets = new Insets(5, 5, 0, 5);
83 panel2.add(label, gbc);
84
85 progress.setMinimum(0);
86 progress.setMaximum(100);
87 progress.setOrientation(JProgressBar.HORIZONTAL);
88 progress.setFont(font);
89 progress.setStringPainted(true);
90 progress.setString("");
91 gbc.anchor = GridBagConstraints.CENTER;
92 gbc.weightx = 1.0;
93 gbc.fill = GridBagConstraints.HORIZONTAL;
94 gbc.gridy = 2;
95 gbc.insets = new Insets(15, 5, 15, 5);
96 panel2.add(progress, gbc);
97
98 panel.add(panel2, BorderLayout.SOUTH);
99 add(panel, BorderLayout.CENTER);
100
101 pack();
102 Dimension screenDim = Toolkit.getDefaultToolkit().getScreenSize();
103 Dimension splashDim = getSize();
104 setLocation((screenDim.width - splashDim.width) / 2,
105 (screenDim.height - splashDim.height) / 2);
106 }
107
108 /**
109 * Set the position of the progress bar.
110 *
111 * @param progress a value between 0.0 and 1.0 representing the percentage
112 * of the loading that has been completed.
113 */
114 public void setProgress(double progress) {
115 if(progress < 0) {
116 progress = 0.0;
117 }
118 else if(progress > 1) {
119 progress = 1.0;
120 }
121
122 this.progress.setValue((int) (100 * progress));
123 }
124
125 /**
126 * Set the text of the progress bar.
127 *
128 * @param text the text to display in the progress bar.
129 */
130 public void setProgressText(String text) {
131 progress.setString(text);
132 }
133
134 private JProgressBar progress = new JProgressBar();
135 }
136