|
12 | 12 | import java.awt.event.WindowAdapter; |
13 | 13 | import java.awt.event.WindowEvent; |
14 | 14 | import java.io.File; |
| 15 | +import java.io.IOException; |
15 | 16 | import java.lang.reflect.Method; |
| 17 | +import java.net.MalformedURLException; |
16 | 18 | import java.net.URL; |
17 | 19 |
|
18 | 20 | import javax.swing.Action; |
|
30 | 32 |
|
31 | 33 | import beast.app.draw.MyAction; |
32 | 34 | import beast.app.util.Utils; |
| 35 | +import beast.util.AddOnManager; |
33 | 36 | import bsh.BshClassManager; |
34 | 37 | import bsh.ClassPathException; |
35 | 38 | import bsh.NameSource; |
@@ -366,10 +369,52 @@ private JMenuBar createMenuBar() { |
366 | 369 |
|
367 | 370 | return menuBar; |
368 | 371 | } |
369 | | - |
| 372 | + |
| 373 | + private static void loadJavaFX() { |
| 374 | + try { |
| 375 | + // JavaFX already loaded? |
| 376 | + Class x = Class.forName("javafx.embed.swing.JFXPanel"); |
| 377 | + // if we got here, all is fine. |
| 378 | + return; |
| 379 | + } catch (ClassNotFoundException e) { |
| 380 | + // JavaFX is not loaded yet |
| 381 | + try { |
| 382 | + String home = System.getenv("JAVA_HOME"); |
| 383 | + if (home != null) { |
| 384 | + AddOnManager.addURL(new URL("file:" + home + "/jre/lib/jfxrt.jar")); |
| 385 | + Class.forName("javafx.embed.swing.JFXPanel"); |
| 386 | + return; |
| 387 | + } |
| 388 | + String jarfile = System.getenv("JAVAFX_JAR"); |
| 389 | + if (jarfile != null) { |
| 390 | + AddOnManager.addURL(new URL("file:" + jarfile)); |
| 391 | + Class.forName("javafx.embed.swing.JFXPanel"); |
| 392 | + return; |
| 393 | + } |
| 394 | + File f = new File("/opt/java/jre/lib/jfxrt.jar"); |
| 395 | + if (f.exists()) { |
| 396 | + AddOnManager.addURL(new URL("file:" + f.getPath())); |
| 397 | + Class.forName("javafx.embed.swing.JFXPanel"); |
| 398 | + return; |
| 399 | + } |
| 400 | + } catch (MalformedURLException e1) { |
| 401 | + e1.printStackTrace(); |
| 402 | + } catch (IOException e1) { |
| 403 | + e1.printStackTrace(); |
| 404 | + } catch (ClassNotFoundException e1) { |
| 405 | + e1.printStackTrace(); |
| 406 | + } |
| 407 | + } |
| 408 | + JOptionPane.showMessageDialog(null, "Could not load JavaFX. Run with java 7 or higher, or set the JAVAFX_JAR environment variable to the location of jfxrt.jar or install jfxrt.jar at /opt/java/jre/lib/jfxrt.jar. -- exiting now"); |
| 409 | + System.exit(0); |
| 410 | + } |
| 411 | + |
370 | 412 | public static void main(String[] args) { |
371 | 413 | bsh.util.Util.startSplashScreen(); |
372 | | - |
| 414 | + |
| 415 | + // try to load JavaFX |
| 416 | + loadJavaFX(); |
| 417 | + |
373 | 418 | JFrame frame = new JFrame(); |
374 | 419 | final BEASTStudio studio = new BEASTStudio(args); |
375 | 420 | studio.setup(); |
|
0 commit comments