]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.graphviz/src/org/simantics/graphviz/Graphs.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.graphviz / src / org / simantics / graphviz / Graphs.java
index 3f087a3030023714999068b1d631645331838dc1..b0b82f9e8dc30f25a4db96eebbd6b10274b80bce 100644 (file)
-/*******************************************************************************\r
- * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
- * in Industry THTH ry.\r
- * All rights reserved. This program and the accompanying materials\r
- * are made available under the terms of the Eclipse Public License v1.0\r
- * which accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- *     VTT Technical Research Centre of Finland - initial API and implementation\r
- *******************************************************************************/\r
-package org.simantics.graphviz;\r
-\r
-import java.io.File;\r
-import java.io.FileInputStream;\r
-import java.io.FileOutputStream;\r
-import java.io.IOException;\r
-import java.io.InputStream;\r
-import java.io.PrintStream;\r
-import java.util.Arrays;\r
-\r
-import javax.swing.SwingUtilities;\r
-\r
-import org.simantics.graphviz.continuation.Computation;\r
-import org.simantics.graphviz.drawable.GraphDrawable;\r
-import org.simantics.graphviz.drawable.JViewer;\r
-import org.simantics.graphviz.internal.parser.DotParser;\r
-import org.simantics.graphviz.internal.parser.ParseException;\r
-import org.simantics.graphviz.internal.process.CreateXDot;\r
-\r
-/**\r
- * A class containing only static methods for operating\r
- * on graphs.\r
- * \r
- * @author Hannu Niemist�\r
- */\r
-public class Graphs {\r
-\r
-    private Graphs() {}\r
-    \r
-    /**\r
-     * Parses a dot graph from an input stream.\r
-     */\r
-    public static Graph parse(InputStream stream) throws IOException {\r
-        try {\r
-            return new DotParser(stream).document();\r
-        } catch(ParseException e) {\r
-               System.out.println(\r
-                               e.currentToken.beginLine + ":" + e.currentToken.beginColumn + " - " +\r
-                               e.currentToken.endLine + ":" + e.currentToken.endColumn);\r
-            throw new IOException(e);\r
-        }\r
-    }\r
-    \r
-    /**\r
-     * Parses a dot graph from a file.\r
-     */\r
-    public static Graph parse(File file) throws IOException {\r
-        InputStream stream = new FileInputStream(file);\r
-        Graph graph = parse(stream);\r
-        stream.close();\r
-        \r
-        return graph;\r
-    }\r
-    \r
-    /**\r
-     * Layouts a graph with a given algorithm and writes it to the file using given output format.\r
-     */\r
-    public static void createImage(Graph graph, String algorithm, String type, File file) throws IOException {\r
-        System.out.println("Create image");\r
-        if(type.equals("dot")) {\r
-            PrintStream stream = new PrintStream(new FileOutputStream(file));\r
-            graph.write(stream);\r
-            stream.close();\r
-        }\r
-        else {  \r
-               File DOT_EXE = Activator.getDotExe();\r
-               Process process = new ProcessBuilder(\r
-                  DOT_EXE.toString(), "-T" + type, "-K" + algorithm, "-o"+ file.getAbsolutePath())\r
-                  .directory(DOT_EXE.getParentFile())\r
-                  .start();\r
-            \r
-            PrintStream stream = new PrintStream(process.getOutputStream());\r
-            \r
-            graph.write(stream);\r
-            stream.close();\r
-           \r
-            InputStream errorStream = process.getErrorStream();\r
-            while(true) {\r
-                int c = errorStream.read();\r
-                if(c <= 0)\r
-                    break;\r
-                System.err.print((char)c);\r
-            }\r
-            errorStream.close();\r
-            \r
-            try {\r
-                process.waitFor();\r
-            } catch (InterruptedException e) {\r
-                // TODO Auto-generated catch block\r
-                e.printStackTrace();\r
-            }\r
-        }\r
-    }\r
-    \r
-    /**\r
-     * Layouts the graph.\r
-     */\r
-    public static Computation<Graph> createXDot(Graph graph, String algorithm) {\r
-        CreateXDot process = new CreateXDot(graph, algorithm);\r
-        process.start();\r
-        return process;\r
-    }\r
-    \r
-    public static byte[] read(InputStream stream) throws IOException {\r
-       byte[] buffer = new byte[1024];\r
-       int pos = 0;\r
-       while(true) {                   \r
-               int len = stream.read(buffer, pos, buffer.length-pos);\r
-               if(len < 0)\r
-                       return Arrays.copyOf(buffer, pos);\r
-               pos += len;\r
-               if(pos == buffer.length) {\r
-                       buffer = Arrays.copyOf(buffer, (int)(buffer.length * 1.5));\r
-               }\r
-       }\r
-    }\r
-\r
-    /**\r
-     * Layouts the graph using given algorithm and visualizes it\r
-     * in a new viewer window.\r
-     */\r
-    public static void show(final Graph graph, final String algorithm) {\r
-        SwingUtilities.invokeLater(new Runnable() {\r
-            public void run() {\r
-                new JViewer(new GraphDrawable(graph, algorithm));\r
-            }\r
-        });        \r
-    }   \r
-    \r
-    /**\r
-     * Layouts the graph using dot algorithm and visualizes it\r
-     * in a new viewer window.\r
-     */\r
-    public static void show(final Graph graph) {\r
-        show(graph, "dot");      \r
-    }   \r
-    \r
-}\r
+/*******************************************************************************
+ * Copyright (c) 2007, 2010 Association for Decentralized Information Management
+ * in Industry THTH ry.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *     VTT Technical Research Centre of Finland - initial API and implementation
+ *******************************************************************************/
+package org.simantics.graphviz;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.PrintStream;
+import java.util.Arrays;
+
+import javax.swing.SwingUtilities;
+
+import org.simantics.graphviz.continuation.Computation;
+import org.simantics.graphviz.drawable.GraphDrawable;
+import org.simantics.graphviz.drawable.JViewer;
+import org.simantics.graphviz.internal.parser.DotParser;
+import org.simantics.graphviz.internal.parser.ParseException;
+import org.simantics.graphviz.internal.process.CreateXDot;
+
+/**
+ * A class containing only static methods for operating
+ * on graphs.
+ * 
+ * @author Hannu Niemist�
+ */
+public class Graphs {
+
+    private Graphs() {}
+    
+    /**
+     * Parses a dot graph from an input stream.
+     */
+    public static Graph parse(InputStream stream) throws IOException {
+        try {
+            return new DotParser(stream).document();
+        } catch(ParseException e) {
+               System.out.println(
+                               e.currentToken.beginLine + ":" + e.currentToken.beginColumn + " - " +
+                               e.currentToken.endLine + ":" + e.currentToken.endColumn);
+            throw new IOException(e);
+        }
+    }
+    
+    /**
+     * Parses a dot graph from a file.
+     */
+    public static Graph parse(File file) throws IOException {
+        InputStream stream = new FileInputStream(file);
+        Graph graph = parse(stream);
+        stream.close();
+        
+        return graph;
+    }
+    
+    /**
+     * Layouts a graph with a given algorithm and writes it to the file using given output format.
+     */
+    public static void createImage(Graph graph, String algorithm, String type, File file) throws IOException {
+        System.out.println("Create image");
+        if(type.equals("dot")) {
+            PrintStream stream = new PrintStream(new FileOutputStream(file));
+            graph.write(stream);
+            stream.close();
+        }
+        else {  
+               File DOT_EXE = Activator.getDotExe();
+               Process process = new ProcessBuilder(
+                  DOT_EXE.toString(), "-T" + type, "-K" + algorithm, "-o"+ file.getAbsolutePath())
+                  .directory(DOT_EXE.getParentFile())
+                  .start();
+            
+            PrintStream stream = new PrintStream(process.getOutputStream());
+            
+            graph.write(stream);
+            stream.close();
+           
+            InputStream errorStream = process.getErrorStream();
+            while(true) {
+                int c = errorStream.read();
+                if(c <= 0)
+                    break;
+                System.err.print((char)c);
+            }
+            errorStream.close();
+            
+            try {
+                process.waitFor();
+            } catch (InterruptedException e) {
+                // TODO Auto-generated catch block
+                e.printStackTrace();
+            }
+        }
+    }
+    
+    /**
+     * Layouts the graph.
+     */
+    public static Computation<Graph> createXDot(Graph graph, String algorithm) {
+        CreateXDot process = new CreateXDot(graph, algorithm);
+        process.start();
+        return process;
+    }
+    
+    public static byte[] read(InputStream stream) throws IOException {
+       byte[] buffer = new byte[1024];
+       int pos = 0;
+       while(true) {                   
+               int len = stream.read(buffer, pos, buffer.length-pos);
+               if(len < 0)
+                       return Arrays.copyOf(buffer, pos);
+               pos += len;
+               if(pos == buffer.length) {
+                       buffer = Arrays.copyOf(buffer, (int)(buffer.length * 1.5));
+               }
+       }
+    }
+
+    /**
+     * Layouts the graph using given algorithm and visualizes it
+     * in a new viewer window.
+     */
+    public static void show(final Graph graph, final String algorithm) {
+        SwingUtilities.invokeLater(new Runnable() {
+            public void run() {
+                new JViewer(new GraphDrawable(graph, algorithm));
+            }
+        });        
+    }   
+    
+    /**
+     * Layouts the graph using dot algorithm and visualizes it
+     * in a new viewer window.
+     */
+    public static void show(final Graph graph) {
+        show(graph, "dot");      
+    }   
+    
+}