Back to index

wims  3.65+svn20090927
MainWindow.java
Go to the documentation of this file.
00001 /*
00002     WIMSchem Elements: Chemistry molecular diagram drawing tool.
00003     
00004     (c) 2005 Dr. Alex M. Clark
00005     
00006     Released as GNUware, under the Gnu Public License (GPL)
00007     
00008     See www.gnu.org for details.
00009 */
00010 
00011 package WIMSchem;
00012 
00013 import WIMSchem.ds.*;
00014 
00015 import java.io.*;
00016 import java.awt.*;
00017 import java.util.*;
00018 import java.awt.image.*;
00019 import java.awt.event.*;
00020 import java.awt.datatransfer.*;
00021 import javax.swing.*;
00022 
00023 /* 
00024     Main application window, and entrypoint for application mode.
00025 */
00026 
00027 public class MainWindow extends JFrame
00028 {
00029     public MainPanel mainPanel=null;
00030 
00031     public MainWindow(String LoadFN,boolean StreamMode,Properties Translation) 
00032     {
00033        super("WIMSchem");
00034 
00035        // application
00036        
00037        JFrame.setDefaultLookAndFeelDecorated(false); 
00038        setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
00039 
00040        // main panel
00041 
00042        getContentPane().setLayout(new BorderLayout());
00043        mainPanel=new MainPanel(LoadFN,StreamMode,false,this,null,Translation,null,null,null,true,true);
00044        getContentPane().add(mainPanel,BorderLayout.CENTER);
00045        pack();
00046 
00047        setIconImage(mainPanel.mainIcon.getImage());
00048     }
00049 
00050     public MainPanel MainPanel() {return mainPanel;}
00051 
00052     // ------------------ init functions --------------------
00053     
00054     static String[] args;
00055     
00056     private static void createAndShowGUI() 
00057     {
00058        boolean dump=false,stream=false;
00059        ArrayList<String> openfiles=new ArrayList<String>();
00060        boolean dsmode=false;
00061        
00062        int i=0;
00063        while (i<args.length)
00064        {
00065            if (args[i].charAt(0)=='-')
00066            {
00067               if (args[i].compareTo("-h")==0 || args[i].compareTo("--help")==0) {dump=true; break;}
00068               else if (args[i].compareTo("-v")==0 || args[i].compareTo("--version")==0) {dump=true; break;}
00069               else if (args[i].compareTo("-s")==0 || args[i].compareTo("--stream")==0) {stream=true; i++;}
00070               else if (args[i].compareTo("-m")==0 || args[i].compareTo("--molecule")==0) {dsmode=false; i++;}
00071               else if (args[i].compareTo("-d")==0 || args[i].compareTo("--datasheet")==0) {dsmode=true; i++;}
00072               else
00073               {
00074                   System.out.println("Error: unexpected argument:");
00075                   System.out.println(args[i]);
00076                   return;
00077               }
00078            }
00079            else
00080            {
00081               File f=new File(args[i]);
00082               if (f.exists()) openfiles.add(args[i]);
00083               else System.out.println("Warning: Filename ["+args[i]+"] does not exist.");
00084               i++;
00085            }
00086        }
00087        
00088        if (stream && dsmode)
00089        {
00090            System.out.println("Invalid: stream mode cannot be combined with datasheet mode");
00091            return;
00092        }
00093        
00094        if (dump)
00095        {
00096            System.out.println("WIMSchem: Molecular drawing tool");
00097            System.out.println("          Version "+MainPanel.VERSION+"  2005-7 Dr. Alex M. Clark");
00098            System.out.println("          Open source, released under the Gnu Public License (GPL),");
00099            System.out.println("          see www.gnu.org. For home page and documentation, see");
00100            System.out.println("          http://sketchel.sf.net\n");
00101 
00102            System.out.println("Command line parameters:");
00103            System.out.println(" -h|--help|-v|--version    Show parameters and summary info");
00104            System.out.println(" -s|--stream               Read from <stdin> at startup, write to");
00105            System.out.println(" -m|--molecule             Open in new Molecule mode");
00106            System.out.println(" -d|--datasheet            Open in new DataSheet mode");
00107            System.out.println("                           <stdout> on quit.");
00108            System.out.println(" filenames                 Open files on startup.");
00109        }
00110        else
00111        {
00112            if (stream || openfiles.size()==0) 
00113            {
00114               if (!dsmode) new MainWindow(null,stream,null).setVisible(true);
00115               else new DataWindow(null).setVisible(true);
00116            }
00117            else 
00118            {
00119               for (int n=0;n<openfiles.size();n++) 
00120               {
00121                   if (!dsmode) new MainWindow(openfiles.get(n),false,null).setVisible(true);
00122                   else new DataWindow(openfiles.get(n)).setVisible(true);
00123               }
00124            }
00125        }
00126     }
00127 
00128     public static void main(String[] args)
00129     {
00130        MainWindow.args=args;
00131         javax.swing.SwingUtilities.invokeLater(new Runnable() {public void run() {createAndShowGUI();}});
00132     }
00133 }
00134 
00135