Debian Codegraph @

src/dr/app/beauti/BeautiApp.java

raw symbols SCIP
1 /*
2 * BeautiApp.java
3 *
4 * Copyright (c) 2002-2015 Alexei Drummond, Andrew Rambaut and Marc Suchard
5 *
6 * This file is part of BEAST.
7 * See the NOTICE file distributed with this work for additional
8 * information regarding copyright ownership and licensing.
9 *
10 * BEAST is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU Lesser General Public License as
12 * published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
14 *
15 * BEAST is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License for more details.
19 *
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with BEAST; if not, write to the
22 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
23 * Boston, MA 02110-1301 USA
24 */
25
26 package dr.app.beauti;
27
28 import dr.app.beast.BeastVersion;
29 import dr.app.util.Arguments;
30 import dr.app.util.OSType;
31 import dr.util.Version;
32 import jam.framework.*;
33
34 import javax.swing.*;
35 import java.awt.*;
36 import java.lang.reflect.Method;
37 import java.security.AccessControlException;
38 import java.util.HashSet;
39 import java.util.Locale;
40 import java.util.Set;
41
42
43 /**
44 * @author Andrew Rambaut
45 * @author Alexei Drummond
46 * @version $Id: BeautiApp.java,v 1.18 2006/09/09 16:07:05 rambaut Exp $
47 */
48 public class BeautiApp extends MultiDocApplication {
49 public final static Version VERSION = new BeastVersion();
50
51 public BeautiApp(String nameString, String aboutString, Icon icon,
52 String websiteURLString, String helpURLString) {
53 super(new BeautiMenuBarFactory(), nameString, aboutString, icon, websiteURLString, helpURLString);
54 }
55
56 public static void centreLine(String line, int pageWidth) {
57 int n = pageWidth - line.length();
58 int n1 = n / 2;
59 for (int i = 0; i < n1; i++) {
60 System.out.print(" ");
61 }
62 System.out.println(line);
63 }
64
65 public static void printTitle() {
66 System.out.println();
67 centreLine("BEAUti " + VERSION.getVersionString() + ", " + VERSION.getDateString(), 60);
68 centreLine("Bayesian Evolutionary Analysis Utility", 60);
69 for (String creditLine : VERSION.getCredits()) {
70 centreLine(creditLine, 60);
71 }
72 System.out.println();
73 }
74
75 public static void printUsage(Arguments arguments) {
76
77 arguments.printUsage("beauti", "[<input-file-name> ...]");
78 System.out.println();
79 System.out.println(" Example: beauti test.nex");
80 System.out.println(" Example: beauti -help");
81 System.out.println();
82 }
83
84
85 // /**
86 // * In a departure from the standard UI, there is no "Open" command for this application
87 // * Instead, the user can create a New window, Import a NEXUS file and Apply a Template file.
88 // * None of these operations result in a file being associated with the DocumentFrame. All
89 // * these actions are located in the BeautiFrame class. This overriden method should never
90 // * be called and throw a RuntimeException if it is.
91 // *
92 // * @return the action
93 // */
94 // public Action getOpenAction() {
95 // throw new UnsupportedOperationException("getOpenAction is not supported");
96 // }
97
98 private static boolean lafLoaded = false;
99
100 // Main entry point
101 static public void main(String[] args) {
102
103 // There is a major issue with languages that use the comma as a decimal separator.
104 // To ensure compatibility between programs in the package, enforce the US locale.
105 Locale.setDefault(Locale.US);
106
107 Arguments arguments = new Arguments(
108 new Arguments.Option[]{
109 new Arguments.Option("advanced", "Enable advanced & developer features"),
110 new Arguments.Option("version", "Print the version and credits and stop"),
111 new Arguments.Option("help", "Print this information and stop"),
112 });
113
114 int argumentCount = 0;
115
116 try {
117 argumentCount = arguments.parseArguments(args);
118 } catch (Arguments.ArgumentException ae) {
119 printTitle();
120 System.out.println();
121 System.out.println(ae.getMessage());
122 System.out.println();
123 printUsage(arguments);
124 System.exit(1);
125 }
126
127 if (arguments.hasOption("help")) {
128 printTitle();
129 printUsage(arguments);
130 System.exit(0);
131 }
132
133 if (arguments.hasOption("version")) {
134 printTitle();
135 }
136
137 advanced = arguments.hasOption("advanced");
138
139 String[] args2 = arguments.getLeftoverArguments();
140
141 if (args2.length > 1) {
142 System.err.println("Unknown option: " + args2[1]);
143 System.err.println();
144 printUsage(arguments);
145 return;
146 }
147
148 // if (args2.length > 1) {
149 //
150 // if (args.length != 3) {
151 // printTitle();
152 // printUsage(arguments);
153 // System.exit(1);
154 // }
155 //
156 // String inputFileName = args[0];
157 // String templateFileName = args[1];
158 // String outputFileName = args[2];
159 //
160 // new CommandLineBeauti(inputFileName, templateFileName, outputFileName);
161 //
162 // } else {
163 String inputFileName = null;
164 if (args2.length == 1) {
165 inputFileName = args2[0];
166 }
167
168 if (OSType.isMac()) {
169 // Explicitly turn on font antialiasing.
170 System.setProperty("swing.aatext", "true");
171
172 System.setProperty("apple.awt.graphics.UseQuartz", "true");
173 System.setProperty("apple.awt.antialiasing", "true");
174 System.setProperty("apple.awt.rendering", "VALUE_RENDER_QUALITY");
175
176 System.setProperty("apple.laf.useScreenMenuBar", "true");
177 System.setProperty("apple.awt.draggableWindowBackground", "true");
178 System.setProperty("apple.awt.showGrowBox", "true");
179
180 // int javaVersion = Integer.parseInt(System.getProperty("java.version").split("\\.")[0]);
181 //
182 // System.out.println("Java version: " + javaVersion);
183 //
184 //
185 // if (javaVersion < 10) {
186 // try {
187 // // set the Quaqua Look and Feel in the UIManager
188 // javax.swing.SwingUtilities.invokeAndWait(new Runnable() {
189 // public void run() {
190 // try {
191 // System.setProperty(
192 // "Quaqua.design", "Sierra"
193 // );
194 //
195 // try {
196 // // We need to do this using dynamic class loading to avoid other platforms
197 // // having to link to this class. If the Quaqua library is not on the classpath
198 // // it simply won't be used.
199 // Class<?> qm = Class.forName("ch.randelshofer.quaqua.QuaquaManager");
200 //
201 //// Method method = qm.getMethod("setIncludedUIs", Set.class);
202 //// Set<String> includes = new HashSet<String>();
203 ////// includes.add("ColorChooser");
204 ////// includes.add("FileChooser");
205 //// includes.add("Button");
206 //// includes.add("SplitPane");
207 //// includes.add("Table");
208 //// includes.add("Panel");
209 //// method.invoke(null, includes);
210 //
211 // Method method = qm.getMethod("setExcludedUIs", Set.class);
212 // Set<String> excludes = new HashSet<String>();
213 // excludes.add("RootPane");
214 //// excludes.add("Table");
215 // excludes.add("TextField");
216 // method.invoke(null, excludes);
217 //
218 // } catch (Throwable e) {
219 // }
220 //
221 // //set the Quaqua Look and Feel in the UIManager
222 // UIManager.setLookAndFeel("ch.randelshofer.quaqua.QuaquaLookAndFeel");
223 // lafLoaded = true;
224 // } catch (Exception e) {
225 // }
226 // }
227 // });
228 // } catch (Exception e) {
229 // }
230 // }
231
232 UIManager.put("SystemFont", new Font("Lucida Grande", Font.PLAIN, 13));
233 UIManager.put("SmallSystemFont", new Font("Lucida Grande", Font.PLAIN, 11));
234 }
235
236 try {
237
238 if (!lafLoaded) {
239 try {
240 // set the System Look and Feel in the UIManager
241 javax.swing.SwingUtilities.invokeAndWait(new Runnable() {
242 public void run() {
243 try {
244 UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
245 } catch (Exception e) {
246 e.printStackTrace();
247 }
248 }
249 });
250 } catch (Exception e) {
251 e.printStackTrace();
252 }
253 }
254
255 java.net.URL url = BeautiApp.class.getResource("images/beauti.png");
256 Icon icon = null;
257
258 if (url != null) {
259 icon = new ImageIcon(url);
260 }
261
262 final String nameString = "BEAUti";
263 final String versionString = VERSION.getVersionString();
264
265 String aboutString = "<html>" +
266 "<div style=\"font-family:HelveticaNeue-Light, 'Helvetica Neue Light', Helvetica, Arial, 'Lucida Grande',sans-serif; font-weight: 100\">" +
267 "<center>" +
268 "<div style=\"font-size:13\"><p>Bayesian Evolutionary Analysis Utility<br>" +
269 "Version " + versionString + ", " + VERSION.getDateString() + "</p>" +
270 "<p>by Alexei J. Drummond, Andrew Rambaut, Marc A. Suchard and Walter Xie</p></div>" +
271 "<hr><div style=\"font-size:11;\">Part of the BEAST package:" +
272 VERSION.getHTMLCredits() +
273 "</div></center></div></html>";
274
275 String websiteURLString = "http://beast.community/BEAUti";
276 String helpURLString = "http://beast.community/BEAUti";
277
278 System.setProperty("BEAST & BEAUTi Version", VERSION.getVersion());
279
280 BeautiApp app = new BeautiApp(nameString, aboutString, icon,
281 websiteURLString, helpURLString);
282 app.setDocumentFrameFactory(new DocumentFrameFactory() {
283 public DocumentFrame createDocumentFrame(Application app, MenuBarFactory menuBarFactory) {
284 return new BeautiFrame(nameString);
285 }
286 });
287 app.initialize();
288
289 if (inputFileName != null) {
290 app.doOpen(inputFileName);
291 } else {
292 app.doNew();
293 }
294 } catch (Exception e) {
295 JOptionPane.showMessageDialog(new JFrame(), "Fatal exception: " + e,
296 "Please report this to the authors",
297 JOptionPane.ERROR_MESSAGE);
298 e.printStackTrace();
299 }
300 // }
301 }
302
303 public static boolean advanced = false;
304 }