]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.graphviz/src/org/simantics/graphviz/Record.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.graphviz / src / org / simantics / graphviz / Record.java
index fad2200cfbbb245c691dd7a11e36ea89be399ac7..a60420c9ae4ab5e4fe4862d30be0fca6c5c9703d 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.util.ArrayList;\r
-\r
-/**\r
- * A helper class for creating record shaped nodes.\r
- * \r
- * @author Hannu Niemistö\r
- */\r
-public class Record {\r
\r
-    static class IdentifiableField {\r
-        String id;\r
-        String label;\r
-        \r
-        public IdentifiableField(String id, String label) {\r
-            super();\r
-            this.id = id;\r
-            this.label = label;\r
-        }            \r
-    }\r
-    \r
-    static class Field {\r
-        String label;\r
-\r
-        public Field(String label) {\r
-            super();\r
-            this.label = label;\r
-        }        \r
-    }\r
-    \r
-    ArrayList<Object> fields = new ArrayList<Object>();\r
-    boolean rotated = false;\r
-    \r
-    public Record() {        \r
-    }\r
-    \r
-    /**\r
-     * Adds a simple nonreferable field to a record.\r
-     */\r
-    public void add(String label) {\r
-        fields.add(new Field(label));\r
-    }\r
-\r
-    /**\r
-     * Adds a field to a record that can be referred in \r
-     * connections. Example\r
-     * <blockquote><pre>\r
-     *   Record r = new Record();\r
-     *   r.add("A field");\r
-     *   r.add("id1", "An another field");\r
-     *   Node n1 = r.toField(g);\r
-     *   Node n2 = new Node(g2);\r
-     *   new Edge(n1.getPort("id1"), n2);\r
-     * </pre></blockquote>\r
-     */\r
-    public void add(String id, String label) {\r
-        fields.add(new IdentifiableField(id, label));\r
-    }\r
-    \r
-    /**\r
-     * Puts a record inside this record. This is most useful\r
-     * if the record added is rotated. In this way, one can\r
-     * build records that both horizontally and vertically\r
-     * divided areas.\r
-     */\r
-    public void add(Record record) {\r
-        fields.add(record);\r
-    }\r
-    \r
-    /**\r
-     * Creates a node whose shape is build according to the\r
-     * record definition.\r
-     */\r
-    public Node toNode(Graph g) {\r
-        Node node = new Node(g);\r
-        node.setShape("record");\r
-        StringBuilder b = new StringBuilder();\r
-        toString(b);\r
-        node.setLabel(b.toString());\r
-        return node;\r
-    }\r
-    \r
-    private void toString(StringBuilder b) {\r
-        if(rotated)\r
-            b.append('{');\r
-        for(int i=0;i<fields.size();++i) {\r
-            Object f = fields.get(i);\r
-            if(i > 0)\r
-                b.append('|');\r
-            if(f instanceof Field) {\r
-                Field ff = (Field)f;\r
-                b.append(ff.label);\r
-            }\r
-            else if(f instanceof IdentifiableField) {\r
-                IdentifiableField ff = (IdentifiableField)f;\r
-                b.append('<');\r
-                b.append(ff.id);\r
-                b.append('>');\r
-                b.append(ff.label);\r
-            }\r
-            else if(f instanceof Record) {\r
-                ((Record)f).toString(b);\r
-            }\r
-        }\r
-        if(rotated)\r
-            b.append('}');\r
-    }\r
-    \r
-    /**\r
-     * Tells if the record has opposite orientation from\r
-     * its surroundings. If the record is converted into\r
-     * node, this means the rankdir of the graph. If\r
-     * the record is put inside other record, then rotation\r
-     * is relative to the orientation of the parent record.\r
-     */\r
-    public void setRotated(boolean rotated) {\r
-        this.rotated = rotated;\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.util.ArrayList;
+
+/**
+ * A helper class for creating record shaped nodes.
+ * 
+ * @author Hannu Niemistö
+ */
+public class Record {
+    static class IdentifiableField {
+        String id;
+        String label;
+        
+        public IdentifiableField(String id, String label) {
+            super();
+            this.id = id;
+            this.label = label;
+        }            
+    }
+    
+    static class Field {
+        String label;
+
+        public Field(String label) {
+            super();
+            this.label = label;
+        }        
+    }
+    
+    ArrayList<Object> fields = new ArrayList<Object>();
+    boolean rotated = false;
+    
+    public Record() {        
+    }
+    
+    /**
+     * Adds a simple nonreferable field to a record.
+     */
+    public void add(String label) {
+        fields.add(new Field(label));
+    }
+
+    /**
+     * Adds a field to a record that can be referred in 
+     * connections. Example
+     * <blockquote><pre>
+     *   Record r = new Record();
+     *   r.add("A field");
+     *   r.add("id1", "An another field");
+     *   Node n1 = r.toField(g);
+     *   Node n2 = new Node(g2);
+     *   new Edge(n1.getPort("id1"), n2);
+     * </pre></blockquote>
+     */
+    public void add(String id, String label) {
+        fields.add(new IdentifiableField(id, label));
+    }
+    
+    /**
+     * Puts a record inside this record. This is most useful
+     * if the record added is rotated. In this way, one can
+     * build records that both horizontally and vertically
+     * divided areas.
+     */
+    public void add(Record record) {
+        fields.add(record);
+    }
+    
+    /**
+     * Creates a node whose shape is build according to the
+     * record definition.
+     */
+    public Node toNode(Graph g) {
+        Node node = new Node(g);
+        node.setShape("record");
+        StringBuilder b = new StringBuilder();
+        toString(b);
+        node.setLabel(b.toString());
+        return node;
+    }
+    
+    private void toString(StringBuilder b) {
+        if(rotated)
+            b.append('{');
+        for(int i=0;i<fields.size();++i) {
+            Object f = fields.get(i);
+            if(i > 0)
+                b.append('|');
+            if(f instanceof Field) {
+                Field ff = (Field)f;
+                b.append(ff.label);
+            }
+            else if(f instanceof IdentifiableField) {
+                IdentifiableField ff = (IdentifiableField)f;
+                b.append('<');
+                b.append(ff.id);
+                b.append('>');
+                b.append(ff.label);
+            }
+            else if(f instanceof Record) {
+                ((Record)f).toString(b);
+            }
+        }
+        if(rotated)
+            b.append('}');
+    }
+    
+    /**
+     * Tells if the record has opposite orientation from
+     * its surroundings. If the record is converted into
+     * node, this means the rankdir of the graph. If
+     * the record is put inside other record, then rotation
+     * is relative to the orientation of the parent record.
+     */
+    public void setRotated(boolean rotated) {
+        this.rotated = rotated;
+    }
+}