Package jsynoptic.installer

Source Code of jsynoptic.installer.Installer

/*
* Created on 6 mai 2004
*
* To change the template for this generated file go to
* Window - Preferences - Java - Code Generation - Code and Comments
*/
package jsynoptic.installer;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.File;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.util.Locale;
import java.util.ResourceBundle;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;

import javax.swing.Box;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;

import simtools.ui.CustomizedLocale;
import simtools.ui.ResourceFinder;
import simtools.ui.UserProperties;

/**
* @author nicolas
*
* To change the template for this generated type comment go to
* Window - Preferences - Java - Code Generation - Code and Comments
*/
public class Installer extends JFrame {

  public JButton next, cancel, previous;
  public static ResourceBundle resources;
  protected static UserProperties userProperties;
  protected int currentPanel;
  protected Class[] panelClasses = new Class[] {LangPanel.class, LicensePanel.class, PackagesPanel.class};
  protected InstallerPanel[] panels;
  public File jre,zip;
 
  public Installer(String[] args) {

    if ((args.length!=0) && (!args[0].equals(""))) {
      jre = new File(new File(System.getProperty("user.dir")),"jre");
    }
    else jre = null;
   
    if ((args.length>1) && (!args[1].equals(""))) {
      zip = new File(args[1]);
      if (!zip.exists()) zip = null;
     
      try{
        ZipFile zipFile = new ZipFile(zip);
        ZipEntry entry = zipFile.getEntry("jre");
        if (entry==null) zip=null;
        zipFile.close();
      } catch(IOException ioe) {}
    }
    else zip = null;
   
    // Code common with Run class

    // Read properties => this contain the user preference, including language setup
    userProperties=new UserProperties("jsynoptic");
    userProperties.read();

    // language may be "fr", or "en_US", or whatever. If unsupported, it will default to best match
    String language = userProperties.getString("jsynoptic.language","");
    // Let command-line -D JVM define take precedence
    if ((System.getProperty("language")==null) || System.getProperty("language").equals(""))
    if (!language.equals("")) {
      int sep = language.indexOf('_');
      if (sep==-1) {
        CustomizedLocale.set(new Locale(language));
      } else {
        String lang = language.substring(0,sep);
        String country = language.substring(sep+1);
        sep = country.indexOf('_');
        if (sep==-1) {
          CustomizedLocale.set(new Locale(lang, country));
        } else {
          CustomizedLocale.set(new Locale(lang, country.substring(0,sep), country.substring(sep+1)));
        }
      }
    }

    // Now initialize default resources => those use the Locale defined above.
    resources = ResourceFinder.get(Installer.class);
   
    next = new JButton(resources.getString("next"));
    cancel = new JButton(resources.getString("cancel"));
    previous = new JButton(resources.getString("previous"));
    setTitle(resources.getString("title"));

    panels = new InstallerPanel[panelClasses.length];
    currentPanel = 0;
   
    Box buttonZone = Box.createHorizontalBox();
    buttonZone.add(Box.createHorizontalGlue());
    buttonZone.add(previous);
    buttonZone.add(cancel);
    buttonZone.add(next);
       
    getContentPane().setLayout(new BorderLayout());
    getContentPane().add(getPanel(),BorderLayout.CENTER);
    getContentPane().add(buttonZone,BorderLayout.SOUTH);

    next.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
        if (!getPanel().process()) return; // wait for current panel process completion
        if (currentPanel == panels.length-1) return;
        getContentPane().remove(getPanel());
        currentPanel++;
        getContentPane().add(getPanel(),BorderLayout.CENTER);
        getPanel().update();
        getPanel().invalidate();
        Installer.this.repaint();
        previous.setVisible(true);
      }
    });
   
    getRootPane().setDefaultButton(next);
 
    previous.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
        if (currentPanel>0) {
          getContentPane().remove(getPanel());
          currentPanel--;
          getContentPane().add(getPanel(),BorderLayout.CENTER);
          getPanel().update();
          getPanel().invalidate();
          Installer.this.repaint();
        }
        if (currentPanel==0) previous.setVisible(false);
      }
    });

    cancel.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
        System.exit(0); // Cancels installation
      }
    });

    addWindowListener(new WindowAdapter() {
      public void windowClosing(WindowEvent e) {
        System.exit(0); // Cancels installation
      }
    });
   
    previous.setVisible(false);
    pack();

    Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
    setLocation((d.width-getWidth())/2, (d.height - getHeight())/2);
  }

  protected InstallerPanel getPanel() {
    if (panels[currentPanel]==null) {
      try {
        panels[currentPanel] = (InstallerPanel)panelClasses[currentPanel].getDeclaredConstructor(new Class[] {Installer.class}).newInstance(new Object[] {this});
      } catch (InstantiationException e) {
        e.printStackTrace();
      } catch (IllegalAccessException e) {
        e.printStackTrace();
      } catch (IllegalArgumentException e) {
        e.printStackTrace();
      } catch (SecurityException e) {
        e.printStackTrace();
      } catch (InvocationTargetException e) {
        e.printStackTrace();
      } catch (NoSuchMethodException e) {
        e.printStackTrace();
      }
    }
    return panels[currentPanel];
  }

  public void writeProperties() {
   
    // Final code to store and pass on properties to JSynoptic
    Locale l = CustomizedLocale.get();
    String lang = l.getLanguage();
    if (!l.getCountry().equals("")) lang += "_" + l.getCountry();
    if (!l.getVariant().equals("")) lang += "_" + l.getVariant();
    userProperties.setString("jsynoptic.language",lang);
    userProperties.write();
  }
 
  public static void main(String[] args) {
    try {
      UIManager.setLookAndFeel(new com.incors.plaf.kunststoff.KunststoffLookAndFeel());
    } catch (UnsupportedLookAndFeelException e) {
      // Never mind!
    }
    new Installer(args).show();
  }
}


TOP

Related Classes of jsynoptic.installer.Installer

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.