Changeset 35492 in osm
- Timestamp:
- 2020-06-14T11:43:27+02:00 (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/javafx/src/org/openstreetmap/josm/plugins/javafx/gui/JavaFxWrapper.java
r35375 r35492 1 1 // License: GPL. For details, see LICENSE file. 2 2 package org.openstreetmap.josm.plugins.javafx.gui; 3 4 3 import java.awt.Dimension; 4 import java.util.concurrent.ExecutionException; 5 import java.util.concurrent.FutureTask; 5 6 6 7 import org.openstreetmap.josm.tools.Logging; … … 24 25 25 26 /** 27 * Catch exceptions in the JavaFX thread (only instantiated with the JavaFxWrapper). 28 * Since most exceptions should be seen through the `future.get()` method in initialize, this is (mostly) safe. 29 */ 30 private static class UncaughtExceptionHandler implements Thread.UncaughtExceptionHandler { 31 private final Thread.UncaughtExceptionHandler currentHandler; 32 public UncaughtExceptionHandler() { 33 currentHandler = Thread.currentThread().getUncaughtExceptionHandler(); 34 Thread.currentThread().setUncaughtExceptionHandler(this); 35 } 36 @Override 37 public void uncaughtException(Thread t, Throwable e) { 38 if (currentHandler != null && !(e instanceof NoClassDefFoundError)) { 39 currentHandler.uncaughtException(t, e); 40 } else { 41 Logging.error(e); 42 } 43 } 44 } 45 46 private static UncaughtExceptionHandler handler; 47 48 /** 26 49 * <p> 27 50 * <b>Implementation note</b>: when the first {@code JFXPanel} object is … … 32 55 * @param node The JavaFX node that will be returned later with 33 56 * {@link JavaFxWrapper#getNode}. 57 * @throws ExecutionException If something happened during execution. If this happens, fall back to something else! 34 58 */ 35 public JavaFxWrapper(Class<T> node) {59 public JavaFxWrapper(Class<T> node) throws ExecutionException { 36 60 try { 37 61 initialize(node.getConstructor().newInstance()); … … 50 74 * @param node The JavaFX node that will be returned later with 51 75 * {@link JavaFxWrapper#getNode}. 76 * @throws ExecutionException If something happened during execution. If this happens, fall back to something else! 52 77 */ 53 public JavaFxWrapper(T node) {78 public JavaFxWrapper(T node) throws ExecutionException { 54 79 initialize(node); 55 80 } … … 59 84 * 60 85 * @param node The node that should be set to this.node 86 * @throws ExecutionException If something happened during execution. If this happens, fall back to something else! 61 87 */ 62 private void initialize(T node) {88 private void initialize(T node) throws ExecutionException { 63 89 this.node = node; 64 Platform.runLater(this::initFX); 90 FutureTask<Scene> task = new FutureTask<>(this::initFX); 91 Platform.runLater(task); 65 92 Platform.setImplicitExit(false); 66 93 this.setFocusTraversalKeysEnabled(node.isFocusTraversable()); 94 try { 95 task.get(); 96 } catch (InterruptedException e) { 97 Thread.currentThread().interrupt(); 98 Logging.error(e); 99 } 67 100 } 68 101 69 private void initFX() { 102 /** 103 * @return The scene to be used for initializing JavaFX 104 */ 105 protected Scene initFX() { 106 initializeExceptionHandler(); 70 107 Scene scene = createScene(); 71 108 setScene(scene); 109 return scene; 110 } 111 112 private static void initializeExceptionHandler() { 113 if (handler == null) 114 handler = new UncaughtExceptionHandler(); 72 115 } 73 116
Note:
See TracChangeset
for help on using the changeset viewer.