| 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.bss; |
| 27 |
|
| 28 |
import jam.framework.SingleDocApplication; |
| 29 |
|
| 30 |
import java.awt.Font; |
| 31 |
import java.awt.Image; |
| 32 |
import java.awt.Toolkit; |
| 33 |
import java.net.URL; |
| 34 |
import java.util.Locale; |
| 35 |
|
| 36 |
import javax.swing.ImageIcon; |
| 37 |
import javax.swing.UIManager; |
| 38 |
import javax.swing.UnsupportedLookAndFeelException; |
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
public class BeagleSequenceSimulatorApp { |
| 45 |
|
| 46 |
public static final boolean DEBUG = false; |
| 47 |
public static final boolean VERBOSE = true; |
| 48 |
|
| 49 |
|
| 50 |
public static final String SHORT_NAME = "\u03C0BUSS"; |
| 51 |
public static final String LONG_NAME = "Parallel BEAST/BEAGLE Utility for Sequence Simulation"; |
| 52 |
public static final String VERSION = "1.4"; |
| 53 |
public static final String DATE = "2018"; |
| 54 |
|
| 55 |
|
| 56 |
private Image beagleSequenceSimulatorImage; |
| 57 |
|
| 58 |
public BeagleSequenceSimulatorApp() throws ClassNotFoundException, |
| 59 |
InstantiationException, IllegalAccessException, |
| 60 |
UnsupportedLookAndFeelException { |
| 61 |
|
| 62 |
boolean lafLoaded = false; |
| 63 |
|
| 64 |
|
| 65 |
if (System.getProperty("os.name").toLowerCase().startsWith("mac os x")) { |
| 66 |
|
| 67 |
|
| 68 |
System.setProperty("apple.awt.showGrowBox", "true"); |
| 69 |
System.setProperty("apple.awt.brushMetalLook", "true"); |
| 70 |
System.setProperty("apple.laf.useScreenMenuBar", "true"); |
| 71 |
|
| 72 |
System.setProperty("apple.awt.graphics.UseQuartz", "true"); |
| 73 |
System.setProperty("apple.awt.antialiasing", "true"); |
| 74 |
System.setProperty("apple.awt.rendering", "VALUE_RENDER_QUALITY"); |
| 75 |
|
| 76 |
System.setProperty("apple.laf.useScreenMenuBar", "true"); |
| 77 |
System.setProperty("apple.awt.draggableWindowBackground", "true"); |
| 78 |
System.setProperty("apple.awt.showGrowBox", "true"); |
| 79 |
|
| 80 |
UIManager.put("SystemFont", new Font("Lucida Grande", Font.PLAIN, |
| 81 |
13)); |
| 82 |
UIManager.put("SmallSystemFont", new Font("Lucida Grande", |
| 83 |
Font.PLAIN, 11)); |
| 84 |
|
| 85 |
try { |
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
UIManager |
| 91 |
.setLookAndFeel("ch.randelshofer.quaqua.QuaquaLookAndFeel"); |
| 92 |
lafLoaded = true; |
| 93 |
|
| 94 |
} catch (Exception e) { |
| 95 |
|
| 96 |
} |
| 97 |
|
| 98 |
} else { |
| 99 |
|
| 100 |
try { |
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
UIManager |
| 106 |
.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel"); |
| 107 |
lafLoaded = true; |
| 108 |
|
| 109 |
} catch (Exception e) { |
| 110 |
|
| 111 |
} |
| 112 |
|
| 113 |
} |
| 114 |
|
| 115 |
if (!lafLoaded) { |
| 116 |
|
| 117 |
try { |
| 118 |
|
| 119 |
UIManager.setLookAndFeel(UIManager |
| 120 |
.getSystemLookAndFeelClassName()); |
| 121 |
System.out |
| 122 |
.println("Specified l&f not found. Loading system default l&f"); |
| 123 |
|
| 124 |
} catch (Exception e) { |
| 125 |
|
| 126 |
e.printStackTrace(); |
| 127 |
|
| 128 |
} |
| 129 |
} |
| 130 |
|
| 131 |
ImageIcon bssIcon = Utils.createImageIcon(Utils.BSS_ICON); |
| 132 |
SingleDocApplication app = new SingleDocApplication(new MenuBarFactory(), |
| 133 |
LONG_NAME, |
| 134 |
VERSION.concat(" ").concat( |
| 135 |
DATE), |
| 136 |
bssIcon |
| 137 |
); |
| 138 |
|
| 139 |
beagleSequenceSimulatorImage = CreateImage(Utils.BSS_ICON); |
| 140 |
MainFrame frame = new MainFrame(SHORT_NAME + " " + VERSION); |
| 141 |
frame.setIconImage(beagleSequenceSimulatorImage); |
| 142 |
app.setDocumentFrame(frame); |
| 143 |
|
| 144 |
} |
| 145 |
|
| 146 |
public static void main(String args[]) { |
| 147 |
|
| 148 |
Locale.setDefault(Locale.US); |
| 149 |
|
| 150 |
if (args.length > 0) { |
| 151 |
|
| 152 |
try { |
| 153 |
|
| 154 |
BeagleSequenceSimulatorConsoleApp app = new BeagleSequenceSimulatorConsoleApp(); |
| 155 |
app.simulate(args); |
| 156 |
|
| 157 |
} catch (UnsupportedClassVersionError e) { |
| 158 |
|
| 159 |
Utils.handleException(e, "Your Java Runtime Environment is too old. Please update"); |
| 160 |
|
| 161 |
} |
| 162 |
|
| 163 |
} else { |
| 164 |
|
| 165 |
try { |
| 166 |
|
| 167 |
Thread.setDefaultUncaughtExceptionHandler(new ExceptionHandler()); |
| 168 |
new BeagleSequenceSimulatorApp(); |
| 169 |
|
| 170 |
|
| 171 |
System.out.println("Do the evolution baby!"); |
| 172 |
|
| 173 |
} catch (UnsupportedClassVersionError e) { |
| 174 |
|
| 175 |
Utils.handleException(e, "Your Java Runtime Environment is too old. Please update"); |
| 176 |
|
| 177 |
} catch (ClassNotFoundException e) { |
| 178 |
Utils.handleException(e, e.getMessage()); |
| 179 |
} catch (InstantiationException e) { |
| 180 |
Utils.handleException(e, e.getMessage()); |
| 181 |
} catch (IllegalAccessException e) { |
| 182 |
Utils.handleException(e, e.getMessage()); |
| 183 |
} catch (UnsupportedLookAndFeelException e) { |
| 184 |
Utils.handleException(e, e.getMessage()); |
| 185 |
} |
| 186 |
|
| 187 |
} |
| 188 |
|
| 189 |
} |
| 190 |
|
| 191 |
private Image CreateImage(String path) { |
| 192 |
URL imgURL = this.getClass().getResource(path); |
| 193 |
Toolkit kit = Toolkit.getDefaultToolkit(); |
| 194 |
Image img = kit.createImage(imgURL); |
| 195 |
|
| 196 |
if (img != null) { |
| 197 |
return img; |
| 198 |
} else { |
| 199 |
System.out.println("Couldn't find file: " + path + "\n"); |
| 200 |
return null; |
| 201 |
} |
| 202 |
|
| 203 |
} |
| 204 |
|
| 205 |
} |
| 206 |
|