001: /*
002: * Jacareto Copyright (c) 2002-2005
003: * Applied Computer Science Research Group, Darmstadt University of
004: * Technology, Institute of Mathematics & Computer Science,
005: * Ludwigsburg University of Education, and Computer Based
006: * Learning Research Group, Aachen University. All rights reserved.
007: *
008: * Jacareto is free software; you can redistribute it and/or
009: * modify it under the terms of the GNU General Public
010: * License as published by the Free Software Foundation; either
011: * version 2 of the License, or (at your option) any later version.
012: *
013: * Jacareto is distributed in the hope that it will be useful,
014: * but WITHOUT ANY WARRANTY; without even the implied warranty of
015: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
016: * General Public License for more details.
017: *
018: * You should have received a copy of the GNU General Public
019: * License along with Jacareto; if not, write to the Free
020: * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
021: *
022: */
023:
024: package jacareto.cleverphl.gui;
025:
026: import jacareto.cleverphl.CleverPHL;
027: import jacareto.toolkit.ResourceLoader;
028:
029: import java.awt.BorderLayout;
030: import java.awt.Color;
031: import java.awt.Component;
032: import java.awt.Dimension;
033: import java.awt.Graphics;
034: import java.awt.Toolkit;
035:
036: import javax.swing.ImageIcon;
037: import javax.swing.JLabel;
038: import javax.swing.JPanel;
039: import javax.swing.JWindow;
040: import javax.swing.border.CompoundBorder;
041: import javax.swing.border.EmptyBorder;
042: import javax.swing.border.LineBorder;
043:
044: /**
045: * CleverPHL's splash screen.
046: *
047: * @author <a href="mailto:cspannagel@web.de">Christian Spannagel</a>
048: * @version 1.01
049: */
050: public class SplashScreen extends JWindow {
051: /** The width of the splash screen. */
052: private int width;
053:
054: /** The height of the splash screen. */
055: private int height;
056:
057: /** Whether or not the image has been loaded. */
058: private boolean imageLoaded;
059:
060: /** Version of CleverPHL. */
061: private String version;
062:
063: /** Build number of CleverPHL. */
064: private int build;
065:
066: /** The cleverphl instance. */
067: private CleverPHL cleverPHL;
068:
069: /** The progress label. */
070: private JLabel progressLabel;
071:
072: /** The info panel. */
073: private JPanel infoPanel;
074:
075: /** The image label. */
076: private JLabel imageLabel;
077:
078: /**
079: * Creates a new splash screen.
080: *
081: * @param cleverPHL the CleverPHL instance
082: */
083: public SplashScreen(CleverPHL cleverPHL) {
084: this .cleverPHL = cleverPHL;
085:
086: version = CleverPHL.VERSION;
087: build = CleverPHL.BUILD;
088:
089: imageLabel = null;
090:
091: ImageIcon icon = null;
092:
093: // Load the image
094: try {
095: icon = ResourceLoader.getImageIcon("CleverPHLLogo.gif");
096:
097: if (icon == null) {
098: throw new Exception();
099: }
100:
101: imageLabel = new JLabel(icon);
102:
103: infoPanel = new JPanel() {
104: public void paint(Graphics g) {
105: g.setColor(Color.white);
106: g.fillRect(0, 0, getWidth(), getHeight());
107: g.setColor(Color.black);
108: g.setFont(g.getFont().deriveFont(10f));
109: g.drawString("Open Source Project", 10, 20);
110: g.drawString("Version " + version + " build "
111: + build, 10, 35);
112: g.drawString("(c) 2002-2007", 10, 65);
113: g
114: .drawString(
115: "Applied Computer Science Research Group, Darmstadt University of Technology",
116: 10, 80);
117: g
118: .drawString(
119: "Mathematics & Computer Science Department, Ludwigsburg University of Education",
120: 10, 95);
121: g
122: .drawString(
123: "Computer Based Learning, Computer Science Department, Aachen University",
124: 10, 110);
125: }
126:
127: public Dimension getPreferredSize() {
128: return new Dimension(200, 125);
129: }
130: };
131:
132: progressLabel = new JLabel();
133: progressLabel.setText(" ");
134: progressLabel.setBorder(new EmptyBorder(0, 10, 0, 0));
135:
136: JPanel wrapperPanel = new JPanel(new BorderLayout());
137: wrapperPanel.setBackground(Color.white);
138: wrapperPanel.add(imageLabel, BorderLayout.NORTH);
139: wrapperPanel.add(infoPanel, BorderLayout.CENTER);
140: wrapperPanel.add(progressLabel, BorderLayout.SOUTH);
141: wrapperPanel.setBorder(new CompoundBorder(new LineBorder(
142: Color.black), new EmptyBorder(30, 30, 30, 30)));
143: getContentPane().add(wrapperPanel);
144: pack();
145:
146: width = getWidth();
147: height = getHeight();
148:
149: // Set the size of the splash screen
150: Dimension screenDim = Toolkit.getDefaultToolkit()
151: .getScreenSize();
152: int x = (screenDim.width - width) / 2;
153: int y = (screenDim.height - height) / 2;
154:
155: setSize(width, height);
156: setLocation(x, y);
157:
158: imageLoaded = true;
159: } catch (Exception e) {
160: e.printStackTrace();
161: imageLoaded = false;
162: }
163: }
164:
165: /**
166: * Shows the splash screen. If the image could not be loaded, just a message will be printed on
167: * System.out.
168: */
169: public void showSplashScreen() {
170: if (imageLoaded) {
171: setVisible(true);
172: } else {
173: System.out.println("\nCleverPHL Version " + version);
174: System.out.println();
175: }
176: }
177:
178: /**
179: * Returns the image label.
180: *
181: * @return the label showing the cleverphl image
182: */
183: public Component getImageLabel() {
184: return imageLabel;
185: }
186:
187: /**
188: * Returns the info panel.
189: *
190: * @return the panel showing information like version number.
191: */
192: public Component getInfoPanel() {
193: return infoPanel;
194: }
195:
196: /**
197: * Sets the progress text.
198: *
199: * @param progressText the new progressText
200: */
201: public void setProgressText(String progressText) {
202: if (imageLoaded) {
203: progressLabel.setText(progressText);
204: } else {
205: System.out.println(progressText);
206: }
207: }
208:
209: /**
210: * Closes the frame.
211: */
212: public void close() {
213: if (imageLoaded) {
214: setVisible(false);
215: dispose();
216: }
217: }
218: }
|