]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.graphviz/src/org/simantics/graphviz/Node.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.graphviz / src / org / simantics / graphviz / Node.java
1 /*******************************************************************************
2  * Copyright (c) 2007, 2010 Association for Decentralized Information Management
3  * in Industry THTH ry.
4  * All rights reserved. This program and the accompanying materials
5  * are made available under the terms of the Eclipse Public License v1.0
6  * which accompanies this distribution, and is available at
7  * http://www.eclipse.org/legal/epl-v10.html
8  *
9  * Contributors:
10  *     VTT Technical Research Centre of Finland - initial API and implementation
11  *******************************************************************************/
12 package org.simantics.graphviz;
13
14 import java.io.PrintStream;
15
16 /**
17  * A node of a graph.
18  * 
19  * @author Hannu Niemistö
20  */
21 public class Node extends AbstractIdentifiableGraphPart {
22
23     public Node(IGraph graph) {
24         this(graph, "");
25     }
26
27     public Node(IGraph graph, String label) {
28         super(graph);
29         setLabel(label);
30     }
31
32     @Override
33     public void write(PrintStream s) {
34         s.print(id);
35         writeAttributes(s);
36     }
37
38     /**
39      * Text label attached to objects. If a node's shape is record, then the label can have a special format which describes the record layout.
40      */
41     public void setLabel(String label) {
42         set("label", label);
43     }
44
45     /**
46      * <p>
47      * Basic drawing color for graphics, not text. For the latter, use the
48      * fontcolor attribute. For edges, the value can either be a single color or
49      * a colorList. In the latter case, the edge is drawn using parallel splines
50      * or lines, one for each color in the list, in the order given. The head
51      * arrow, if any, is drawn using the first color in the list, and the tail
52      * arrow, if any, the second color. This supports the common case of drawing
53      * opposing edges, but using parallel splines instead of separately routed
54      * multiedges.
55      * </p>
56      * <p>Supports arbitrary RGB(A) colors in format #xxxxxx, where
57      * each x is a hex digit. Supports also color names in x11 color chart.</p>
58      */
59     public void setColor(String color) {
60         set("color", color);
61     }
62     
63     /**
64      * Color used to fill the background of a node or cluster assuming style=filled. If fillcolor is not defined, color is used. (For clusters, if color is not defined, bgcolor is used.) If this is not defined, the default is used, except for shape=point or when the output format is MIF, which use black by default. Note that a cluster inherits the root graph's attributes if defined. Thus, if the root graph has defined a fillcolor, this will override a color or bgcolor attribute set for the cluster.
65      */
66     public void setFillColor(String color) {
67         set("fillcolor", color);
68     }
69     
70     
71     /**
72      * Color used for text.
73      */
74     public void setFontColor(String color) {
75         set("fontcolor", color);
76     }
77     
78     /**
79      * Set style for node or edge. For cluster subgraph, if "filled", the cluster box's background is filled.
80      */
81     public void setStyle(String style) {
82         set("style", style);
83     }
84
85     /**
86      * <p>
87      * Set the shape of a node.
88      * </p>
89      * <p>
90      * Alternatives:
91      * 
92      * 
93      * <tt>box polygon ellipse circle point egg triangle plaintext diamond trapezium parallelogram house pentagon hexagon septagon octagon doublecircle doubleoctagon tripleoctagon invtriangle invtrapezium invhouse Mdiamond Msquare Mcircle rect rectangle none note tab box3d component</tt>
94      * </p>
95      */
96     public void setShape(String shape) {
97         set("shape", shape);
98     }
99     
100     /**
101      * Width of node, in inches. This is taken as the initial, minimum width of the node. If fixedsize is true, this will be the final width of the node. Otherwise, if the node label requires more width to fit, the node's width will be increased to contain the label. Note also that, if the output format is dot, the value given to width will be the final value.
102      */
103     public void setWidth(double width) {
104         set("width", Double.toString(width));
105     }
106     
107     /**
108      * Height of node, in inches. This is taken as the initial, minimum height of the node. If fixedsize is true, this will be the final height of the node. Otherwise, if the node label requires more height to fit, the node's height will be increased to contain the label. Note also that, if the output format is dot, the value given to height will be the final value.
109      */
110     public void setHeight(double width) {
111         set("height", Double.toString(width));
112     }
113     
114     /**
115      * If true, the node size is specified by the values of the width and height attributes only and is not expanded to contain the text label.
116      */
117     public void setFixedSize(boolean fixedSize) {
118         set("fixedsize", Boolean.toString(fixedSize));
119     }
120     
121     public Identifiable getPort(final String portName) {
122         return new Identifiable() {
123
124             @Override
125             public String getId() {
126                 return id + ":" + portName;
127             }
128
129             @Override
130             public IGraph getParent() {
131                 return parent;
132             }
133             
134         };
135     }
136
137 }