]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
(refs #7272) Support updating named Graphviz windows 93/593/2
authorHannu Niemistö <hannu.niemisto@semantum.fi>
Fri, 2 Jun 2017 18:13:11 +0000 (21:13 +0300)
committerHannu Niemistö <hannu.niemisto@semantum.fi>
Fri, 2 Jun 2017 20:52:23 +0000 (23:52 +0300)
Change-Id: I72080ec1cba333cf9639a9801814e5fc100a8309

bundles/org.simantics.graphviz/scl/Visualization/GGraph.scl
bundles/org.simantics.graphviz/scl/Visualization/Graphviz.scl
bundles/org.simantics.graphviz/src/org/simantics/graphviz/Graphs.java
bundles/org.simantics.graphviz/src/org/simantics/graphviz/drawable/JViewer.java

index 58bdc41f240639b5117e8c8c2c18d63c5db96cb8..3179ab74db0d7ce8bf67e67a741653f8ef6f1277 100644 (file)
@@ -30,3 +30,6 @@ showGGraph (GGraph graph _ _) = showGraph graph
 
 showGGraphWithAlgorithm :: String -> GGraph a e -> <Proc> ()
 showGGraphWithAlgorithm algorithm (GGraph graph _ _) = showGraphWithAlgorithm graph algorithm
 
 showGGraphWithAlgorithm :: String -> GGraph a e -> <Proc> ()
 showGGraphWithAlgorithm algorithm (GGraph graph _ _) = showGraphWithAlgorithm graph algorithm
+
+showGGraphWithNamedWindow :: String -> String -> GGraph a e -> <Proc> ()
+showGGraphWithNamedWindow windowName algorithm (GGraph graph _ _) = showGraphWithNamedWindow windowName graph algorithm
index 47fa99b694aa59b3dbf71bfdd83bf71d90996f12..85db2d7cb38038d5933d4420256d061d12aa631a 100644 (file)
@@ -8,4 +8,7 @@ importJava "org.simantics.graphviz.Graphs" where
     showGraph :: Graph -> <Proc> ()
     
     @JavaName show
     showGraph :: Graph -> <Proc> ()
     
     @JavaName show
-    showGraphWithAlgorithm :: Graph -> String -> <Proc> ()
\ No newline at end of file
+    showGraphWithAlgorithm :: Graph -> String -> <Proc> ()
+    
+    @JavaName showWithNamedWindow
+    showGraphWithNamedWindow :: String -> Graph -> String -> <Proc> ()
\ No newline at end of file
index b0b82f9e8dc30f25a4db96eebbd6b10274b80bce..330aec5039133515ee226967dfdf9012c175c033 100644 (file)
@@ -18,6 +18,7 @@ import java.io.IOException;
 import java.io.InputStream;
 import java.io.PrintStream;
 import java.util.Arrays;
 import java.io.InputStream;
 import java.io.PrintStream;
 import java.util.Arrays;
+import java.util.HashMap;
 
 import javax.swing.SwingUtilities;
 
 
 import javax.swing.SwingUtilities;
 
@@ -146,4 +147,12 @@ public class Graphs {
         show(graph, "dot");      
     }   
     
         show(graph, "dot");      
     }   
     
+    public static void showWithNamedWindow(final String windowName, final Graph graph, final String algorithm) {
+        SwingUtilities.invokeLater(new Runnable() {
+            public void run() {
+                JViewer.getOrCreateViewer(windowName, new GraphDrawable(graph, algorithm));
+            }
+        });
+    }
+    
 }
 }
index 6f972d746d4e22620e8c7328acdb8bd54c8b14ab..2543a7a667429d10626e7a92fe8e507fad4ef493 100644 (file)
@@ -33,6 +33,7 @@ import java.awt.geom.AffineTransform;
 import java.awt.geom.Rectangle2D;
 import java.io.File;
 import java.io.IOException;
 import java.awt.geom.Rectangle2D;
 import java.io.File;
 import java.io.IOException;
+import java.util.HashMap;
 
 import javax.swing.AbstractAction;
 import javax.swing.JFileChooser;
 
 import javax.swing.AbstractAction;
 import javax.swing.JFileChooser;
@@ -41,6 +42,7 @@ import javax.swing.JMenu;
 import javax.swing.JMenuBar;
 import javax.swing.JMenuItem;
 import javax.swing.JOptionPane;
 import javax.swing.JMenuBar;
 import javax.swing.JMenuItem;
 import javax.swing.JOptionPane;
+import javax.swing.SwingUtilities;
 import javax.swing.filechooser.FileFilter;
 import javax.swing.filechooser.FileView;
 
 import javax.swing.filechooser.FileFilter;
 import javax.swing.filechooser.FileView;
 
@@ -51,12 +53,16 @@ import org.simantics.graphviz.Graphs;
  * A stand alone frame that shows and makes it
  * possible to navigate a given Drawable.
  * 
  * A stand alone frame that shows and makes it
  * possible to navigate a given Drawable.
  * 
- * @author Hannu Niemistö
+ * @author Hannu Niemist
  */
 public class JViewer extends JFrame {
  */
 public class JViewer extends JFrame {
+    private static final HashMap<String, JViewer> VIEWER_MAP = new HashMap<String, JViewer>(); 
+    
        private static final long serialVersionUID = 3022682167091092801L;
        Drawable drawable;
        ViewerCanvas canvas = new ViewerCanvas();
        private static final long serialVersionUID = 3022682167091092801L;
        Drawable drawable;
        ViewerCanvas canvas = new ViewerCanvas();
+
+    private String windowName;
        
        class ViewerCanvas extends Canvas {
                private static final long serialVersionUID = -5330090168115281754L;
        
        class ViewerCanvas extends Canvas {
                private static final long serialVersionUID = -5330090168115281754L;
@@ -205,6 +211,12 @@ public class JViewer extends JFrame {
            setVisible(true);
        }
        
            setVisible(true);
        }
        
+       public void updateDrawable(Drawable drawable) {
+           this.drawable = drawable;
+           canvas.fit();
+           canvas.repaint();
+       }
+       
        public class ExitAction extends AbstractAction {
 
                private static final long serialVersionUID = 5680421985865931443L;
        public class ExitAction extends AbstractAction {
 
                private static final long serialVersionUID = 5680421985865931443L;
@@ -324,5 +336,26 @@ public class JViewer extends JFrame {
                        return null;
                }
        }
                        return null;
                }
        }
-       
+
+    public static void getOrCreateViewer(String windowName, GraphDrawable graphDrawable) {
+        JViewer viewer = VIEWER_MAP.get(windowName);
+        if(viewer == null) {
+            viewer = new JViewer(graphDrawable);
+            viewer.setTitle(windowName);
+            viewer.windowName = windowName;
+            VIEWER_MAP.put(windowName, viewer);
+            viewer.toFront();
+        }
+        else {
+            viewer.updateDrawable(graphDrawable);
+            viewer.toFront();
+        }
+    }
+    
+    @Override
+    public void dispose() {
+        if(windowName != null)
+            VIEWER_MAP.remove(windowName);
+        super.dispose();
+    }
 }
 }