|
62 | 62 | import java.util.concurrent.Callable; |
63 | 63 | import java.util.concurrent.ExecutionException; |
64 | 64 | import java.util.concurrent.FutureTask; |
| 65 | +import java.util.concurrent.TimeUnit; |
| 66 | +import java.util.concurrent.TimeoutException; |
65 | 67 |
|
66 | 68 | /** |
67 | 69 | * JavaFX {@link Pane} that is capable of plotting a {@link Graph} or {@link Digraph}. |
@@ -345,17 +347,22 @@ public Boolean call() throws Exception { |
345 | 347 | return true; |
346 | 348 | } |
347 | 349 | }); |
348 | | - |
349 | | - //this will be called from a non-javafx thread, so this must be guaranteed to run of the graphics thread |
350 | | - Platform.runLater(update); |
351 | 350 |
|
352 | | - try { |
353 | | - //wait for completion |
354 | | - update.get(); |
355 | | - } catch (InterruptedException | ExecutionException ex) { |
356 | | - Logger.getLogger(SmartGraphPanel.class.getName()).log(Level.SEVERE, null, ex); |
| 351 | + // |
| 352 | + if(!Platform.isFxApplicationThread()) { |
| 353 | + //this will be called from a non-javafx thread, so this must be guaranteed to run of the graphics thread |
| 354 | + Platform.runLater(update); |
| 355 | + |
| 356 | + //wait for completion, only outside javafx thread; otherwise -> deadlock |
| 357 | + try { |
| 358 | + update.get(1, TimeUnit.SECONDS); |
| 359 | + } catch (InterruptedException | ExecutionException | TimeoutException ex) { |
| 360 | + Logger.getLogger(SmartGraphPanel.class.getName()).log(Level.SEVERE, null, ex); |
| 361 | + } |
| 362 | + } else { |
| 363 | + updateNodes(); |
357 | 364 | } |
358 | | - |
| 365 | + |
359 | 366 | } |
360 | 367 |
|
361 | 368 | private synchronized void updateNodes() { |
@@ -899,6 +906,51 @@ private Collection<Edge<E, V>> unplottedEdges() { |
899 | 906 |
|
900 | 907 | return unplotted; |
901 | 908 | } |
| 909 | + |
| 910 | + /** |
| 911 | + * Sets a vertex position (its center) manually. |
| 912 | + * |
| 913 | + * The positioning should be inside the boundaries of the panel, but |
| 914 | + * no restrictions are enforced by this method, so be aware. |
| 915 | + * |
| 916 | + * @param v underlying vertex |
| 917 | + * @param x x-coordinate on panel |
| 918 | + * @param y y-coordinate on panel |
| 919 | + */ |
| 920 | + public void setVertexPosition(Vertex<V> v, double x, double y) { |
| 921 | + SmartGraphVertexNode<V> node = vertexNodes.get(v); |
| 922 | + if(node != null) { |
| 923 | + node.setPosition(x, y); |
| 924 | + } |
| 925 | + } |
| 926 | + |
| 927 | + /** |
| 928 | + * Return the current x-coordinate (relative to the panel) of a vertex. |
| 929 | + * |
| 930 | + * @param v underlying vertex |
| 931 | + * @return the x-coordinate or NaN if the vertex does not exist |
| 932 | + */ |
| 933 | + public double getVertexPositionX(Vertex<V> v) { |
| 934 | + SmartGraphVertexNode<V> node = vertexNodes.get(v); |
| 935 | + if(node != null) { |
| 936 | + return node.getPositionCenterX(); |
| 937 | + } |
| 938 | + return Double.NaN; |
| 939 | + } |
| 940 | + |
| 941 | + /** |
| 942 | + * Return the current y-coordinate (relative to the panel) of a vertex. |
| 943 | + * |
| 944 | + * @param v underlying vertex |
| 945 | + * @return the y-coordinate or NaN if the vertex does not exist |
| 946 | + */ |
| 947 | + public double getVertexPositionY(Vertex<V> v) { |
| 948 | + SmartGraphVertexNode<V> node = vertexNodes.get(v); |
| 949 | + if(node != null) { |
| 950 | + return node.getPositionCenterY(); |
| 951 | + } |
| 952 | + return Double.NaN; |
| 953 | + } |
902 | 954 |
|
903 | 955 | /** |
904 | 956 | * Returns the associated stylable element with a graph vertex. |
|
0 commit comments