DBVIEW
src/org/dbview/utils/dot/Node.java
00001 /*
00002         DbView - Graph Visualization
00003     Copyright (C) 2012  Denis BEURIVE
00004 
00005     This program is free software: you can redistribute it and/or modify
00006     it under the terms of the GNU General Public License as published by
00007     the Free Software Foundation, either version 3 of the License, or
00008     (at your option) any later version.
00009 
00010     This program is distributed in the hope that it will be useful,
00011     but WITHOUT ANY WARRANTY; without even the implied warranty of
00012     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013     GNU General Public License for more details.
00014 
00015     You should have received a copy of the GNU General Public License
00016     along with this program.  If not, see <http://www.gnu.org/licenses/>.
00017 */
00018 
00019 /**
00020  * @author Denis Beurive
00021  */
00022 package org.dbview.utils.dot;
00023 
00024 import java.util.*;
00025 import org.dbview.utils.*;
00026 
00027 /**
00028  * This class represents a node.
00029  * @author Denis Beurive
00030  */
00031 public class Node
00032 {
00033     /**
00034      * Name of the node.
00035      */
00036     private String __name     = null;
00037 
00038     /**
00039      * Shape of the node.
00040      * @see http://www.graphviz.org/doc/info/attrs.html
00041      */
00042     private String __shape    = null;
00043 
00044     /**
00045      * Style of the node.
00046      * @see http://www.graphviz.org/doc/info/attrs.html
00047      */
00048     private String __style    = null;
00049 
00050     /**
00051      * Node's label.
00052      * @see http://www.graphviz.org/doc/info/attrs.html
00053      */
00054     private String __label    = null;
00055 
00056     /**
00057      * Node's foreground color.
00058      * @see http://www.graphviz.org/doc/info/attrs.html
00059      */
00060     private String __color    = null;
00061 
00062     /**
00063      * Node's background color.
00064      * @see http://www.graphviz.org/doc/info/attrs.html
00065      */
00066     private String __bg_color = null;
00067 
00068     /**
00069      * Create a unique, <b>and valid</b> (no spaces...), name for the node.
00070      * @param in_name Original name.
00071      * @return The method returns a unique name.
00072      * @throws Exception
00073      */
00074     public static String generateName(String in_name)
00075     {
00076         return "node_" + Strings.SHAsum(in_name);
00077     }
00078     
00079     /**
00080      * Create a node.
00081      * @param in_name Name of the node to create.
00082      */
00083     public Node(String in_name)
00084     { this.__name = Node.generateName(in_name); }
00085 
00086     /**
00087      * Set the node's shape.
00088      * @param in_shape The node's shape.
00089      */
00090     public void setShape(String in_shape) { this.__shape = in_shape; }
00091 
00092     /**
00093      * Set the node's style.
00094      * @param in_style The style to set.
00095      */
00096     public void setStyle(String in_style) { this.__style = in_style; }
00097 
00098     /**
00099      * Set the node's label.
00100      * @param in_label The label to set.
00101      */
00102     public void setLabel(String in_label) { this.__label = in_label; }
00103 
00104     /**
00105      * Set the node's color.
00106      * @param in_color The color to set.
00107      */
00108     public void setColor(String in_color) { this.__color = in_color; }
00109 
00110     /**
00111      * Set the background color of the node.
00112      * @param in_color Background color of the node.
00113      * @note This setting may not have any effect, depending on the node's style. See the GraphViz documentation.
00114      */
00115     public void setFillColor(String in_color)   { this.__bg_color = in_color; }
00116 
00117     /**
00118      * The method returns the DOT's representation of the node.
00119          * @return The method returns the DOT's representation of the node.
00120      */
00121     public String toString()
00122     {
00123                 ArrayList<String> words = new ArrayList<String>();
00124                 if (null != this.__shape)      { words.add("shape=" + this.__shape); }
00125                 if (null != this.__style)      { words.add("style=\"" + this.__style + "\""); }
00126                 if (null != this.__label)      { words.add("label=\"" + this.__label + "\""); }
00127                 if (null != this.__color)      { words.add("color=\"" + this.__color + "\""); }
00128                 if (null != this.__bg_color)   { words.add("fillcolor=\"" + this.__bg_color + "\""); }
00129                 return this.__name + " [" + org.dbview.utils.Strings.join(words, " ") + "];";
00130     }
00131 }