1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 package fr.ens.transcriptome.doelan;
23
24 import java.awt.Dimension;
25 import java.awt.Toolkit;
26 import java.io.InputStream;
27 import java.net.URL;
28 import java.util.Properties;
29
30 import javax.swing.ImageIcon;
31 import javax.swing.JFrame;
32
33 import org.apache.commons.cli.CommandLine;
34 import org.apache.commons.cli.CommandLineParser;
35 import org.apache.commons.cli.GnuParser;
36 import org.apache.commons.cli.HelpFormatter;
37 import org.apache.commons.cli.Option;
38 import org.apache.commons.cli.OptionBuilder;
39 import org.apache.commons.cli.Options;
40 import org.apache.commons.cli.ParseException;
41
42 import fr.ens.transcriptome.doelan.gui.CommonWindow;
43 import fr.ens.transcriptome.nividic.platform.Registery;
44
45 /***
46 * A Class to test the application with standalone application.
47 * @author Laurent Jourdren
48 */
49 public final class App extends JFrame {
50
51
52
53
54
55 /***
56 * Create the thread for the GUI
57 */
58 private static void mainInit() {
59
60 JFrame.setDefaultLookAndFeelDecorated(true);
61 Toolkit.getDefaultToolkit().setDynamicLayout(true);
62
63
64
65 javax.swing.SwingUtilities.invokeLater(new Runnable() {
66 public void run() {
67
68 App app = new App();
69 app.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
70 app.graphicalInit();
71 app.pack();
72 app.setResizable(true);
73 app.setVisible(true);
74 }
75 });
76 }
77
78 /***
79 * Create the GUI and show it. For thread safety, this method should be
80 * invoked from the event-dispatching thread.
81 */
82 private void graphicalInit() {
83
84 this.setName(Defaults.APP_NAME);
85 this.setTitle(Defaults.APP_NAME);
86 URL url = CommonWindow.class.getResource("/files/doelan-16.png");
87 ImageIcon ii = new ImageIcon(url);
88 setIconImage(ii.getImage());
89
90 CommonWindow window = new CommonWindow(this, null);
91 window.init();
92
93 }
94
95 /***
96 * Get the minimun size of the main window.
97 * @return a dimension object
98 */
99 public Dimension getMinimumSize() {
100 return new Dimension(Defaults.WINDOW_WIDTH, Defaults.WINDOW_HEIGHT);
101 }
102
103 /***
104 * Get the minimun size of the main window.
105 * @return a dimension object
106 */
107 public Dimension getPreferredSize() {
108 return new Dimension(Defaults.WINDOW_WIDTH, Defaults.WINDOW_HEIGHT);
109 }
110
111
112
113
114
115 /***
116 * Create the Options object for the command line.
117 * @return The Option object
118 */
119 private static Options makeOptions() {
120
121 Option help = new Option("help", "show this message");
122 Option licence = new Option("about", "show information this software");
123 Option suitelist = OptionBuilder.withArgName("suitelist").withDescription(
124 "testsuite list to open").create("suitelist");
125 Option suite = OptionBuilder.withArgName("suite").withDescription(
126 "testsuite open").create("suite");
127 Option conf = OptionBuilder.withArgName("conf").withDescription(
128 "configuration file").create("conf");
129
130 Options options = new Options();
131 options.addOption(help);
132 options.addOption(licence);
133 options.addOption(suitelist);
134 options.addOption(suite);
135 options.addOption(conf);
136
137 return options;
138 }
139
140 /***
141 * Show information about this application.
142 */
143 private static void about() {
144
145 System.out.println(DoelanRegistery.licence());
146 System.exit(0);
147 }
148
149 /***
150 * Show licence information about this application.
151 */
152 private static void licence() {
153
154 System.out.println(DoelanRegistery.about());
155 System.exit(0);
156 }
157
158 /***
159 * Main method.
160 * @param args Command line arguments
161 */
162 public static void main(final String[] args) {
163
164 System.out.println("hello from main(args[])");
165
166
167 DoelanRegistery.init();
168
169 commandLineMain(args);
170 }
171
172 private static void commandLineMain(final String[] args) {
173
174 Options options = makeOptions();
175 CommandLineParser parser = new GnuParser();
176
177 try {
178
179 CommandLine line = parser.parse(options, args);
180
181 if (line.hasOption("help")) {
182
183
184 HelpFormatter formatter = new HelpFormatter();
185 formatter.printHelp("aligneSondes", options);
186
187 System.exit(0);
188 }
189
190 if (line.hasOption("about"))
191 about();
192
193 if (line.hasOption("licence"))
194 about();
195
196 if (line.hasOption("conf"))
197 Registery.loadRegistery(line.getOptionValue("conf"));
198
199 } catch (ParseException exp) {
200 System.err.println("Error analysing command line");
201 System.exit(1);
202 }
203
204 mainInit();
205 }
206
207 /***
208 * Main method.
209 * @param is Input stream for configuration file
210 */
211 public static void main(final InputStream is) {
212
213
214 DoelanRegistery.init();
215
216 if (is != null)
217 Registery.loadRegistery(is);
218
219 mainInit();
220 }
221
222 /***
223 * Main method.
224 * @param properties for configuration
225 * @param args command line arguments
226 */
227 public static void main(final Properties properties, final String[] args) {
228
229
230 DoelanRegistery.init();
231
232 if (properties != null)
233 Registery.addPropertiesToRegistery(properties);
234
235 commandLineMain(args);
236 }
237
238 }