]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
(refs #7250) Merged feature/modularCHR to master. 00/600/1
authorHannu Niemistö <hannu.niemisto@semantum.fi>
Mon, 5 Jun 2017 12:47:37 +0000 (15:47 +0300)
committerHannu Niemistö <hannu.niemisto@semantum.fi>
Mon, 5 Jun 2017 12:48:30 +0000 (15:48 +0300)
Change-Id: Icad6e8c9594826f70d929792f7d258c5514d0550

bundles/org.simantics.document.server/src/org/simantics/document/server/ConsoleSCLReportingHandler.java
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 e227a89ca2472a8c0d597d7b859c5ab17aff3d23..fec8d600a421e0bf3c247b78924ad56579d51805 100644 (file)
@@ -5,6 +5,8 @@ import org.simantics.scl.runtime.reporting.SCLReportingHandler;
 
 public class ConsoleSCLReportingHandler implements SCLReportingHandler {
 
+       private static final boolean PRINT_TO_IDE = false;
+       
        private final IConsole console;
 
        public ConsoleSCLReportingHandler(IConsole console) {
@@ -13,16 +15,19 @@ public class ConsoleSCLReportingHandler implements SCLReportingHandler {
 
        @Override
        public void print(String text) {
+               if(PRINT_TO_IDE) System.err.println("simupedia console print: " + text);
                console.addMessage(text);
        }
 
        @Override
        public void printError(String error) {
+               if(PRINT_TO_IDE) System.err.println("simupedia console print error: " + error);
                console.addMessage(error);
        }
 
        @Override
        public void printCommand(String command) {
+               if(PRINT_TO_IDE) System.err.println("simupedia console print command: " + command);
                console.addMessage(command);
        }
 
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
+
+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
-    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.util.HashMap;
 
 import javax.swing.SwingUtilities;
 
@@ -146,4 +147,12 @@ public class Graphs {
         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.util.HashMap;
 
 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.SwingUtilities;
 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.
  * 
- * @author Hannu Niemistö
+ * @author Hannu Niemist
  */
 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 String windowName;
        
        class ViewerCanvas extends Canvas {
                private static final long serialVersionUID = -5330090168115281754L;
@@ -205,6 +211,12 @@ public class JViewer extends JFrame {
            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;
@@ -324,5 +336,26 @@ public class JViewer extends JFrame {
                        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();
+    }
 }