Rev 3662 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
3662 | schaersvoo | 1 | /* |
7246 | schaersvoo | 2 | Sketch Elements: Chemistry molecular diagram drawing tool. |
3662 | schaersvoo | 3 | |
4 | (c) 2005 Dr. Alex M. Clark |
||
5 | |||
6 | Released as GNUware, under the Gnu Public License (GPL) |
||
7 | |||
8 | See www.gnu.org for details. |
||
9 | */ |
||
10 | |||
11 | package WIMSchem; |
||
12 | |||
13 | import WIMSchem.ds.*; |
||
14 | |||
15 | import java.io.*; |
||
16 | import java.awt.*; |
||
17 | import java.util.*; |
||
18 | import java.awt.image.*; |
||
19 | import java.awt.event.*; |
||
20 | import java.awt.datatransfer.*; |
||
21 | import javax.swing.*; |
||
22 | |||
23 | /* |
||
24 | Main application window, and entrypoint for application mode. |
||
25 | */ |
||
26 | |||
27 | public class MainWindow extends JFrame |
||
28 | { |
||
29 | public MainPanel mainPanel=null; |
||
30 | |||
7246 | schaersvoo | 31 | public MainWindow(String LoadFN,boolean StreamMode) |
3662 | schaersvoo | 32 | { |
33 | super("WIMSchem"); |
||
34 | |||
35 | // application |
||
36 | |||
37 | JFrame.setDefaultLookAndFeelDecorated(false); |
||
38 | setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); |
||
39 | |||
40 | // main panel |
||
41 | |||
42 | getContentPane().setLayout(new BorderLayout()); |
||
7246 | schaersvoo | 43 | mainPanel=new MainPanel(LoadFN,MainPanel.MODE_NORMAL,this); |
3662 | schaersvoo | 44 | getContentPane().add(mainPanel,BorderLayout.CENTER); |
45 | pack(); |
||
46 | |||
47 | setIconImage(mainPanel.mainIcon.getImage()); |
||
48 | } |
||
49 | |||
7246 | schaersvoo | 50 | public MainPanel mainPanel() {return mainPanel;} |
3662 | schaersvoo | 51 | |
52 | // ------------------ init functions -------------------- |
||
53 | |||
54 | static String[] args; |
||
55 | |||
56 | private static void createAndShowGUI() |
||
57 | { |
||
58 | boolean dump=false,stream=false; |
||
59 | ArrayList<String> openfiles=new ArrayList<String>(); |
||
60 | boolean dsmode=false; |
||
61 | |||
62 | int i=0; |
||
63 | while (i<args.length) |
||
64 | { |
||
65 | if (args[i].charAt(0)=='-') |
||
66 | { |
||
67 | if (args[i].compareTo("-h")==0 || args[i].compareTo("--help")==0) {dump=true; break;} |
||
68 | else if (args[i].compareTo("-v")==0 || args[i].compareTo("--version")==0) {dump=true; break;} |
||
69 | else if (args[i].compareTo("-s")==0 || args[i].compareTo("--stream")==0) {stream=true; i++;} |
||
70 | else if (args[i].compareTo("-m")==0 || args[i].compareTo("--molecule")==0) {dsmode=false; i++;} |
||
71 | else if (args[i].compareTo("-d")==0 || args[i].compareTo("--datasheet")==0) {dsmode=true; i++;} |
||
72 | else |
||
73 | { |
||
74 | System.out.println("Error: unexpected argument:"); |
||
75 | System.out.println(args[i]); |
||
76 | return; |
||
77 | } |
||
78 | } |
||
79 | else |
||
80 | { |
||
81 | File f=new File(args[i]); |
||
82 | if (f.exists()) openfiles.add(args[i]); |
||
83 | else System.out.println("Warning: Filename ["+args[i]+"] does not exist."); |
||
84 | i++; |
||
85 | } |
||
86 | } |
||
87 | |||
88 | if (stream && dsmode) |
||
89 | { |
||
90 | System.out.println("Invalid: stream mode cannot be combined with datasheet mode"); |
||
91 | return; |
||
92 | } |
||
93 | |||
94 | if (dump) |
||
95 | { |
||
96 | System.out.println("WIMSchem: Molecular drawing tool"); |
||
7246 | schaersvoo | 97 | System.out.println(" Version "+MainPanel.VERSION+" © 2005-2013 Dr. Alex M. Clark"); |
3662 | schaersvoo | 98 | System.out.println(" Open source, released under the Gnu Public License (GPL),"); |
99 | System.out.println(" see www.gnu.org. For home page and documentation, see"); |
||
100 | System.out.println(" http://sketchel.sf.net\n"); |
||
101 | |||
102 | System.out.println("Command line parameters:"); |
||
103 | System.out.println(" -h|--help|-v|--version Show parameters and summary info"); |
||
104 | System.out.println(" -s|--stream Read from <stdin> at startup, write to"); |
||
105 | System.out.println(" -m|--molecule Open in new Molecule mode"); |
||
106 | System.out.println(" -d|--datasheet Open in new DataSheet mode"); |
||
107 | System.out.println(" <stdout> on quit."); |
||
108 | System.out.println(" filenames Open files on startup."); |
||
109 | } |
||
110 | else |
||
111 | { |
||
112 | if (stream || openfiles.size()==0) |
||
113 | { |
||
7246 | schaersvoo | 114 | if (!dsmode) new MainWindow(null,stream).setVisible(true); |
3662 | schaersvoo | 115 | else new DataWindow(null).setVisible(true); |
116 | } |
||
117 | else |
||
118 | { |
||
119 | for (int n=0;n<openfiles.size();n++) |
||
120 | { |
||
7246 | schaersvoo | 121 | if (!dsmode) new MainWindow(openfiles.get(n),false).setVisible(true); |
3662 | schaersvoo | 122 | else new DataWindow(openfiles.get(n)).setVisible(true); |
123 | } |
||
124 | } |
||
125 | } |
||
126 | } |
||
127 | |||
128 | public static void main(String[] args) |
||
129 | { |
||
130 | MainWindow.args=args; |
||
131 | javax.swing.SwingUtilities.invokeLater(new Runnable() {public void run() {createAndShowGUI();}}); |
||
132 | } |
||
133 | } |
||
134 | |||
135 |