001: /*
002: * SplashScreen.java Copyright (c) 2006,07 Swaroop Belur
003: *
004: * This program is free software; you can redistribute it and/or
005: * modify it under the terms of the GNU General Public License
006: * as published by the Free Software Foundation; either version 2
007: * of the License, or (at your option) any later version.
008:
009: * This program is distributed in the hope that it will be useful,
010: * but WITHOUT ANY WARRANTY; without even the implied warranty of
011: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
012: * GNU General Public License for more details.
013:
014: * You should have received a copy of the GNU General Public License
015: * along with this program; if not, write to the Free Software
016: * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
017: *
018: */
019:
020: package net.sf.jdec.ui.util;
021:
022: import javax.swing.*;
023: import javax.swing.border.MatteBorder;
024: import java.awt.*;
025: import java.awt.image.ImageObserver;
026: import java.io.*;
027:
028: public class SplashScreen extends JFrame implements ImageObserver {
029:
030: public static JProgressBar progress;
031: static {
032: progress = new JProgressBar(0, 100);
033: }
034:
035: public boolean showSplash(Image img) {
036:
037: java.lang.String classname = getLNFClassName();
038: if (classname != null) {
039: try {
040:
041: UIManager.setLookAndFeel(classname);
042: SwingUtilities.updateComponentTreeUI(this );
043:
044: } catch (Exception exp) {
045: try {
046: UIManager.setLookAndFeel(UIManager
047: .getCrossPlatformLookAndFeelClassName());
048: SwingUtilities.updateComponentTreeUI(this );
049: } catch (Exception ex) {
050: }
051:
052: }
053: } else {
054: try {
055: UIManager.setLookAndFeel(UIManager
056: .getCrossPlatformLookAndFeelClassName());
057: SwingUtilities.updateComponentTreeUI(this );
058: } catch (Exception ex) {
059: }
060: }
061:
062: JWindow splash = new JWindow(this , getGraphicsConfiguration());
063: JPanel panel = new JPanel();
064: //panel.setSize(450,470);
065: panel.setSize(500, 500);
066: JLabel lbl = new JLabel();
067: ImageIcon icon = new ImageIcon(img);
068: lbl.setIcon(icon);
069: panel.add(lbl);
070: splash.getContentPane().add(panel, BorderLayout.CENTER);
071: st = new JLabel("Please Wait Jdec is loading");
072: st.setForeground(Color.RED);
073: JPanel footer = new JPanel();
074: footer.setLayout(new BoxLayout(footer, BoxLayout.Y_AXIS));
075: footer.add(st);
076: footer.add(progress);
077: splash.getContentPane().add(footer, BorderLayout.SOUTH);
078: splash.setSize(panel.getWidth(), panel.getHeight());
079: panel.setBorder(new MatteBorder(3, 3, 3, 3, Color.DARK_GRAY));
080: Dimension d = getToolkit().getScreenSize();
081: splash.setLocation(d.getSize().width / 2
082: - splash.getSize().width / 2, d.getSize().height / 2
083: - splash.getSize().height / 2);
084: splash.setVisible(true);
085: pack();
086: splash.show();
087: return true;
088: }
089:
090: public void advance(final int i) {
091:
092: progress.setValue(i);
093:
094: /* try{
095: SwingUtilities.invokeLater(new Runnable(){
096: public void run()
097: {
098: double d=progress.getPercentComplete();
099: progress.setValue(i);
100: }
101: });
102: }
103: catch(Exception exp){}*/
104: }
105:
106: public SplashScreen() {
107: super ("");
108:
109: }
110:
111: public void splash() {
112: java.lang.String fsep = File.separator;
113: java.lang.String prefix = "imgs" + fsep; //jdecSplashCopy_2.gif
114: File img = new File(prefix + "jdecSplash.gif");
115: showSplash(Toolkit.getDefaultToolkit().getImage(
116: img.getAbsolutePath()));
117: }
118:
119: public JLabel st;
120:
121: private java.lang.String getLNFClassName() {
122:
123: String def = System.getProperty("user.lookNfeel.choice");
124: if (def != null) {
125: return def;
126: }
127: File configf = new File(System.getProperty("user.home")
128: + "JDecUserPreferences.txt");
129: if (!configf.exists()) {
130: return null;
131: }
132: try {
133: FileInputStream fis = new FileInputStream(configf);
134: BufferedInputStream bis = new BufferedInputStream(fis);
135: BufferedReader br = new BufferedReader(
136: new InputStreamReader(bis));
137: String temp = br.readLine();
138: while (temp != null) {
139:
140: if (temp.indexOf("DefaultLNKFeel") != -1) {
141: int eq = temp.indexOf("=");
142: if (eq != -1) {
143: String clazz = temp.substring(eq + 1);
144: if (clazz != null) {
145: clazz = clazz.trim();
146: return clazz;
147: }
148: } else
149: return null;
150: } else {
151: temp = br.readLine();
152: continue;
153: }
154:
155: }
156: return null;
157:
158: } catch (IOException e) {
159:
160: return null;
161: }
162:
163: }
164:
165: }
|