| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 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 |
|
| 45 |
|
| 46 |
|
| 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 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
private static boolean lafLoaded = false; |
| 99 |
|
| 100 |
|
| 101 |
static public void main(String[] args) { |
| 102 |
|
| 103 |
|
| 104 |
|
| 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 |
|
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
|
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
String inputFileName = null; |
| 164 |
if (args2.length == 1) { |
| 165 |
inputFileName = args2[0]; |
| 166 |
} |
| 167 |
|
| 168 |
if (OSType.isMac()) { |
| 169 |
|
| 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 |
|
| 181 |
|
| 182 |
|
| 183 |
|
| 184 |
|
| 185 |
|
| 186 |
|
| 187 |
|
| 188 |
|
| 189 |
|
| 190 |
|
| 191 |
|
| 192 |
|
| 193 |
|
| 194 |
|
| 195 |
|
| 196 |
|
| 197 |
|
| 198 |
|
| 199 |
|
| 200 |
|
| 201 |
|
| 202 |
|
| 203 |
|
| 204 |
|
| 205 |
|
| 206 |
|
| 207 |
|
| 208 |
|
| 209 |
|
| 210 |
|
| 211 |
|
| 212 |
|
| 213 |
|
| 214 |
|
| 215 |
|
| 216 |
|
| 217 |
|
| 218 |
|
| 219 |
|
| 220 |
|
| 221 |
|
| 222 |
|
| 223 |
|
| 224 |
|
| 225 |
|
| 226 |
|
| 227 |
|
| 228 |
|
| 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 |
|
| 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 |
} |