package de.nplusc.izc.tools.UiToolz;
import de.nplusc.izc.tools.baseTools.Lock;
import de.nplusc.izc.tools.baseTools.Tools;
import javax.swing.JFrame;
import javax.swing.UIManager;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * BootStrap.java
 *
 * Created on 13.12.2011, 19:27:16
 */
/**
 *
 * @author LH
 */
public class BootStrap extends javax.swing.JFrame {

    /** Creates new form BootStrap */
    @SuppressWarnings("UseSpecificCatch")
    public static Lock bootLock;
    static{
        bootLock = new Lock();//dient um zu chnellesetups zu fangen
        try
        {
            bootLock.lock();
        }
        catch (InterruptedException ex)
        {
            ex.printStackTrace();
        }
    }
    public BootStrap() {
        try {
	    UIManager.setLookAndFeel( UIManager.getSystemLookAndFeelClassName() );
	} catch( Exception e ) { 
	    //e.printStackTrace();
	}
        initComponents();
      }
    

    /** 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() {

        pbar = new javax.swing.JProgressBar();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("LOADING.......");
        setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
        setResizable(false);
        setType(java.awt.Window.Type.UTILITY);
        addComponentListener(new java.awt.event.ComponentAdapter() {
            public void componentShown(java.awt.event.ComponentEvent evt) {
                formComponentShown(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(pbar, javax.swing.GroupLayout.DEFAULT_SIZE, 400, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(pbar, javax.swing.GroupLayout.DEFAULT_SIZE, 66, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents
    public static  BootStrap b;
    private void formComponentShown(java.awt.event.ComponentEvent evt) {//GEN-FIRST:event_formComponentShown
      
    }//GEN-LAST:event_formComponentShown

    /**
     * @param args the command line arguments
     *//*
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                b = new BootStrap();

            }
        });*/
        
        //java.awt.EventQueue.invokeLater();
        
    //}

    
    private JFrame shw;
    
    /**
     * lädt bootstrapper mit folgendem jframe
     * @param trg jframe zum danach anzeigen
     */
    
    public BootStrap(JFrame trg)
    {
        this(trg,false);
    }
    
    public BootStrap(JFrame trg,boolean indet)
    {
                        try {
	    UIManager.setLookAndFeel( UIManager.getSystemLookAndFeelClassName() );
	} catch( Exception e ) { 
	    //e.printStackTrace();
	}
        initComponents();
                shw = trg;
                //b=this;
                int[] scrsiz = UiTools.getScreenRes();
                
                setVisible(true);
                
                patchedShow(indet);
                setLocation((scrsiz[0]/2)-(getWidth()/2), (scrsiz[1]/2)-(getHeight()/2));
    }
    
    /**
     * ladegebälk-manager
     */
    
    public void patchedShow(final boolean indet)
    {
         if(indet)
         {
             pbar.setIndeterminate(true);
         }
         Thread t = new Thread(new Runnable() {

            @SuppressWarnings("SleepWhileInLoop")//Hx
            public void run() {
                if(!indet)
                {
                    pbar.setMinimum(0);
                    pbar.setMaximum(100);//
                    for(int i=0;i<=100;i++)
                    {
                        try
                        {
                        pbar.setValue(i);
                        pbar.updateUI();
                        }
                        catch(Exception e)
                        {

                        }

                        try {
                            Thread.sleep(20L);
                            Tools.DebugHelperPrint(i+"", true, "Toolkit.enableFinerDebug");
                        } catch (InterruptedException ex) {
                            //ex.printStackTrace();
                        }
                    }   
                }
                else
                {

                    try
                    {
                        Thread.sleep(2000L);
                    }
                    catch (InterruptedException ex)
                    {
                        ex.printStackTrace();
                    }
                }
                shw.setVisible(true);
                bootLock.unlock();
                setVisible(false);
                
            }
        });
         t.start();
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JProgressBar pbar;
    // End of variables declaration//GEN-END:variables
}
