X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.graphviz%2Fsrc%2Forg%2Fsimantics%2Fgraphviz%2FRecord.java;h=a60420c9ae4ab5e4fe4862d30be0fca6c5c9703d;hb=refs%2Fchanges%2F38%2F238%2F2;hp=fad2200cfbbb245c691dd7a11e36ea89be399ac7;hpb=24e2b34260f219f0d1644ca7a138894980e25b14;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.graphviz/src/org/simantics/graphviz/Record.java b/bundles/org.simantics.graphviz/src/org/simantics/graphviz/Record.java index fad2200cf..a60420c9a 100644 --- a/bundles/org.simantics.graphviz/src/org/simantics/graphviz/Record.java +++ b/bundles/org.simantics.graphviz/src/org/simantics/graphviz/Record.java @@ -1,131 +1,131 @@ -/******************************************************************************* - * 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 fields = new ArrayList(); - 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 - *
-     *   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);
-     * 
- */ - 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 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; - } -} +/******************************************************************************* + * 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 fields = new ArrayList(); + 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 + *
+     *   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);
+     * 
+ */ + 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 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; + } +}