001: package net.sourceforge.squirrel_sql.client.gui;
002:
003: /*
004: * Copyright (C) 2001-2006 Colin Bell
005: * colbell@users.sourceforge.net
006: *
007: * This library is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU Lesser General Public
009: * License as published by the Free Software Foundation; either
010: * version 2.1 of the License, or (at your option) any later version.
011: *
012: * This library is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this library; if not, write to the Free Software
019: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
020: */
021: import java.awt.Color;
022: import java.awt.GridBagConstraints;
023: import java.awt.GridBagLayout;
024: import java.awt.Insets;
025:
026: import javax.swing.BorderFactory;
027: import javax.swing.Icon;
028: import javax.swing.JLabel;
029: import javax.swing.JPanel;
030: import javax.swing.JProgressBar;
031: import javax.swing.JWindow;
032: import javax.swing.SwingUtilities;
033:
034: import net.sourceforge.squirrel_sql.client.preferences.SquirrelPreferences;
035: import net.sourceforge.squirrel_sql.client.resources.SquirrelResources;
036: import net.sourceforge.squirrel_sql.fw.gui.GUIUtils;
037: import net.sourceforge.squirrel_sql.fw.util.ClassLoaderListener;
038: import net.sourceforge.squirrel_sql.fw.util.StringManager;
039: import net.sourceforge.squirrel_sql.fw.util.StringManagerFactory;
040: import net.sourceforge.squirrel_sql.fw.util.log.ILogger;
041: import net.sourceforge.squirrel_sql.fw.util.log.LoggerController;
042:
043: public class SplashScreen extends JWindow {
044: /** Logger for this class. */
045: private final static ILogger s_log = LoggerController
046: .createLogger(SplashScreen.class);
047:
048: /** Internationalized strings for this class. */
049: private static final StringManager s_stringMgr = StringManagerFactory
050: .getStringManager(SplashScreen.class);
051:
052: private JProgressBar _progressBar;
053:
054: private JLabel _pluginLabel;
055:
056: SquirrelPreferences _prefs;
057:
058: public SplashScreen(SquirrelResources rsrc, int progressBarSize,
059: SquirrelPreferences prefs) throws IllegalArgumentException {
060: super ();
061: _prefs = prefs;
062: if (rsrc == null) {
063: throw new IllegalArgumentException("Null Resources passed");
064: }
065: createUserInterface(rsrc, progressBarSize);
066: }
067:
068: private void createUserInterface(SquirrelResources rsrc,
069: int progressBarSize) {
070: final JPanel mainPnl = new JPanel(new GridBagLayout());
071: final Color bgColor = new Color(
072: SquirrelResources.S_SPLASH_IMAGE_BACKGROUND);
073: mainPnl.setBackground(bgColor);
074: mainPnl.setBorder(BorderFactory.createRaisedBevelBorder());
075:
076: GridBagConstraints gbc;
077:
078: Icon icon = rsrc
079: .getIcon(SquirrelResources.IImageNames.SPLASH_SCREEN);
080:
081: gbc = new GridBagConstraints(0, 0, 1, 1, 1, 1,
082: GridBagConstraints.NORTHWEST, GridBagConstraints.BOTH,
083: new Insets(0, 5, 5, 5), 0, 0);
084: mainPnl.add(new JLabel(icon), gbc);
085:
086: _progressBar = new JProgressBar(0, progressBarSize);
087: _progressBar.setStringPainted(true);
088: _progressBar.setString("");
089: _progressBar.setBackground(bgColor);
090: _progressBar.setForeground(Color.blue);
091:
092: if (_prefs.getShowPluginFilesInSplashScreen()) {
093: _pluginLabel = new JLabel("Dummy");
094: _pluginLabel.setForeground(new Color(
095: SquirrelResources.S_SPLASH_IMAGE_BACKGROUND));
096:
097: gbc = new GridBagConstraints(0, 1, 1, 1, 0, 0,
098: GridBagConstraints.NORTHWEST,
099: GridBagConstraints.HORIZONTAL, new Insets(0, 5, 0,
100: 5), 0, 0);
101: mainPnl.add(new VersionPane(false), gbc);
102:
103: gbc = new GridBagConstraints(0, 2, 1, 1, 0, 0,
104: GridBagConstraints.NORTHWEST,
105: GridBagConstraints.HORIZONTAL, new Insets(0, 5, 3,
106: 5), 0, 0);
107: mainPnl.add(_pluginLabel, gbc);
108:
109: gbc = new GridBagConstraints(0, 3, 1, 1, 0, 0,
110: GridBagConstraints.NORTHWEST,
111: GridBagConstraints.HORIZONTAL, new Insets(0, 5, 3,
112: 5), 0, 0);
113: mainPnl.add(_progressBar, gbc);
114:
115: } else {
116: gbc = new GridBagConstraints(0, 1, 1, 1, 0, 0,
117: GridBagConstraints.NORTHWEST,
118: GridBagConstraints.HORIZONTAL, new Insets(0, 5, 7,
119: 5), 0, 0);
120: mainPnl.add(new VersionPane(false), gbc);
121:
122: gbc = new GridBagConstraints(0, 2, 1, 1, 0, 0,
123: GridBagConstraints.NORTHWEST,
124: GridBagConstraints.HORIZONTAL, new Insets(0, 5, 5,
125: 5), 0, 0);
126: mainPnl.add(_progressBar, gbc);
127: }
128:
129: getContentPane().add(mainPnl);
130:
131: pack();
132: setSize(400, 500);
133:
134: GUIUtils.centerWithinScreen(this );
135: setVisible(true);
136: }
137:
138: public void indicateLoadingFile(final String filename) {
139: try {
140: SwingUtilities.invokeAndWait(new Runnable() {
141: public void run() {
142: if (filename != null) {
143: _pluginLabel.setForeground(new Color(71, 73,
144: 139));
145: // i18n[SplashScreen.info.loadingfile=Loading file - ]
146: _pluginLabel
147: .setText(s_stringMgr
148: .getString("SplashScreen.info.loadingfile")
149: + filename);
150: } else {
151: _pluginLabel
152: .setForeground(new Color(
153: SquirrelResources.S_SPLASH_IMAGE_BACKGROUND));
154: _pluginLabel.setText("Dummy");
155: }
156: _pluginLabel.validate();
157: }
158: });
159: } catch (Exception ex) {
160: //i18n[SplashScreen.error.updatingprogressbar=Error occured updating progress bar]
161: s_log
162: .error(
163: s_stringMgr
164: .getString("SplashScreen.error.updatingprogressbar"),
165: ex);
166: }
167: }
168:
169: public void indicateNewTask(final String text) {
170: // Using a thread for this gets rid of most of the "white flash".
171: try {
172: SwingUtilities.invokeAndWait(new Runnable() {
173: public void run() {
174: _progressBar.setString(text);
175: _progressBar.setValue(_progressBar.getValue() + 1);
176: }
177: });
178: Thread.yield();
179: } catch (Exception ex) {
180: // i18n[SplashScreen.error.updatingprogressbar=Error occured updating progress bar]
181: s_log
182: .error(
183: s_stringMgr
184: .getString("SplashScreen.error.updatingprogressbar"),
185: ex);
186: }
187: }
188:
189: public ClassLoaderListener getClassLoaderListener() {
190: return new ClassLoaderListener() {
191: public void loadedZipFile(String filename) {
192: indicateLoadingFile(filename);
193: }
194:
195: public void finishedLoadingZipFiles() {
196: indicateLoadingFile(null);
197: }
198: };
199: }
200: }
|