/* * WindowSplashScreen.java * * Created on 2009-04-01, 14:36:25 */ package app.navigps.SplashScreen; import app.config.GUIConfiguration; import app.config.MainConfiguration; import app.navigps.NaviGPSCore; import app.navigps.Version; import app.navigps.WindowInitialEvent; import app.navigps.WindowInitialListener; import app.navigps.gui.NaviRootWindow; import app.navigps.utils.NaviLogger; import java.awt.BorderLayout; import java.awt.Color; import java.awt.GradientPaint; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.GridBagConstraints; import java.awt.GridBagLayout; import java.awt.Insets; import java.awt.Rectangle; import java.awt.Shape; import java.awt.Window; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.geom.RoundRectangle2D; import java.lang.reflect.Method; import java.util.ArrayList; import java.util.concurrent.ExecutionException; import java.util.logging.Level; import javax.swing.JComponent; import javax.swing.JPanel; import javax.swing.SwingWorker; import javax.swing.Timer; /** * * @author Grzegorz (wara) Warywoda */ public class WindowSplashScreen extends javax.swing.JFrame implements ActionListener{ private ArrayList<String> args; private ReflectionPanel reflectionPanel; private Task task = new Task(); private SplashPanel splashPanel; /** Creates new form TestRelection */ public WindowSplashScreen(ArrayList<String> a) { super("NaviGPS splash"); args = a; setAlwaysOnTop(true); System.out.println("Initial Splash screen ..."); setUndecorated(true); initComponents(); setContentPane(new GradientPanel()); getContentPane().setLayout(new GridBagLayout()); add(buildReflectionPanel(), new GridBagConstraints(0, 0, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(5, 0, 5, 0), 0, 0)); splashPanel.getTextManager().getContentText().setForeground(Color.WHITE); pack(); setLocationRelativeTo(null); setResizable(false); setShapedWindow(); //setDefaultCloseOperation(EXIT_ON_CLOSE); } private JComponent buildReflectionPanel() { reflectionPanel = new ReflectionPanel(); splashPanel = buildReflectedComponent(); reflectionPanel.add(splashPanel); return reflectionPanel; } private SplashPanel buildReflectedComponent() { return new SplashPanel(); } /** This method is called from within the constructor to * initialize the form. * WARNING: Do NOT modify this code. The content of this method is * always regenerated by the Form Editor. */ @SuppressWarnings("unchecked") // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents private void initComponents() { setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGap(0, 363, Short.MAX_VALUE) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGap(0, 430, Short.MAX_VALUE) ); pack(); }// </editor-fold>//GEN-END:initComponents /** * @param args the command line arguments */ public static void main(String args[]) { final ArrayList<String> arguments = new ArrayList<String>(); for (int i=0; i<args.length; i++){ arguments.add(args[i]); } java.awt.EventQueue.invokeLater(new Runnable() { @Override public void run() { final WindowSplashScreen ws = new WindowSplashScreen(arguments); ws.pack(); ws.setVisible(true); ws.startTest(); ws.setShapedWindow(); } }); } @Override protected void finalize() throws Throwable { System.out.println(getClass().getCanonicalName()+ " Method Finalize !"); } protected void setShapedWindow(){ try { //AWTAccessor.getComponentAccessor().setOpaqueForMixing(this, true); //Shape wShape = AWTUtilities.getWindowShape(this); Class<?> awtUtilitiesClass = Class.forName("com.sun.awt.AWTUtilities"); Method mSetWindowShape = awtUtilitiesClass.getMethod("setWindowShape", Window.class, Shape.class); Rectangle rec = getBounds(); System.out.println(""+rec); RoundRectangle2D roundRec = new RoundRectangle2D.Double(0,0, rec.getWidth(), rec.getHeight(), 20, 20); mSetWindowShape.invoke(null,this,roundRec); } catch (Exception ex) { NaviLogger.logger.log(Level.WARNING, "Shaped window Splash <require at least jre 1.6u10>", ex); return; } } public synchronized void setProgressText(final String txt){ //System.out.println(""+txt); splashPanel.setProgressText(txt); } @Override public void actionPerformed(ActionEvent e) { } private static class GradientPanel extends JPanel { public GradientPanel() { super(new BorderLayout(2,2)); } @Override protected void paintComponent(Graphics g) { Graphics2D g2 = (Graphics2D) g.create(); g2.setPaint(new GradientPaint(0.0f, getHeight() * 0.22f, new Color(46,57,79), 0.0f, getHeight() * 0.9f, new Color(35,28,33), true)); Rectangle clip = g.getClipBounds(); g2.fillRect(clip.x, clip.y, clip.width, clip.height); g2.dispose(); } } public void startTest(){ task = new Task(); task.addPropertyChangeListener(splashPanel); task.execute(); } class Task extends SwingWorker<NaviRootWindow, Void> { @Override public NaviRootWindow doInBackground() { setProgress(0); incrementProgress(10); setProgressText("Create core object"); try {Thread.sleep(500);} catch (InterruptedException ex1) {} NaviGPSCore core = new NaviGPSCore(args); incrementProgress(10); setProgressText("Parse arguments"); try {Thread.sleep(500);} catch (InterruptedException ex1) {} try { incrementProgress(5); core.executeParameters(); incrementProgress(10); } catch (Exception ex) { setProgressText("Error !"); try {Thread.sleep(500);} catch (InterruptedException ex1) {} System.exit(-1); } setProgressText("Parse arguments done !"); incrementProgress(15); setProgressText("Create gui ..."); NaviRootWindow.addWindowinitialListener(new WindowInitialListener() { @Override public void initialPrepare(WindowInitialEvent e) { setProgressText("initial Prepare !!!"); } @Override public void initialCompleted(WindowInitialEvent e) { setProgressText("initial Completed !!!"); } }); incrementProgress(10); NaviRootWindow nw = new NaviRootWindow(core); incrementProgress(10); nw.setSize(GUIConfiguration.getWindowSize()); nw.initComponents(); if (MainConfiguration.getPathToChartFile() != null) { nw.openSVGDocument(MainConfiguration.getPathToChartFile()); } nw.setTitle(Version.getVersion()); setProgressText("Gui created !"); incrementProgress(40); setProgressText("Display gui"); return nw; } /* * Executed in event dispatching thread */ @Override public void done() { //Toolkit.getDefaultToolkit().beep(); try { incrementProgress(30); splashPanel.getTextManager().setAnimatorEnabled(false); setProgressText("Done !"); get().setDisplayMode(); } catch (InterruptedException ex) { System.err.println(""+ex); } catch (ExecutionException ex) { System.err.println(""+ex); } new CloseDelay(2500); this.removePropertyChangeListener(splashPanel); } private void incrementProgress(int count){ int curr = getProgress(); //System.out.println(""+curr); for (int i = curr; i <= curr+count && i<=100; i++) { setProgress(i); //System.out.println("setprogrss "+i); try {Thread.sleep(20);} catch (InterruptedException ex1) {} } } } private class CloseDelay implements ActionListener{ private Timer timer; public CloseDelay(int time){ timer = new Timer(time, this); timer.start(); } @Override public void actionPerformed(ActionEvent e) { getContentPane().removeAll(); reflectionPanel = null; splashPanel = null; args = null; task = null; setVisible(false); dispose(); } } /* public class Test implements Runnable,ActionListener{ private final String [] sample = new String[]{"Loading application...","Loading main gui...","Initial gui"}; private int time = 10; private int sleep = 1; private boolean loop = true; private Timer timer; public Test(){ timer = new Timer(time*1000,this); new Thread(this).start(); } @Override public void run() { int counter = 0; timer.start(); while(loop){ try { String msg = sample[counter++ % sample.length]; setProgressText(msg); Thread.sleep((sleep * 1000)); } catch (InterruptedException ex) {} } timer.stop(); } @Override public void actionPerformed(ActionEvent e) { splashPanel.getTextManager().addActionText("Loading completed", new ActionListener() { @Override public void actionPerformed(ActionEvent e) { WindowSplashScreen.this.setVisible(false); WindowSplashScreen.this.dispose(); } }); loop = false; setProgressText("Loading completed"); } } // Variables declaration - do not modify//GEN-BEGIN:variables // End of variables declaration//GEN-END:variables */ }