DBVIEW
src/org/dbview/utils/dot/Edge.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 
00026 /**
00027  * This class represents an edge.
00028  * @author Denis Beurive
00029  */
00030 public class Edge
00031 {
00032     /**
00033      * Beginning of the edge.
00034      */
00035         private String __from       = null;
00036 
00037         /**
00038          * End of the edge.
00039          */
00040         private String __to         = null;
00041 
00042         /**
00043      * See GRAPHVIZ' documentation for "ltail".
00044      * @see http://www.graphviz.org/doc/info/attrs.html
00045          */
00046         private String __ltail          = null;
00047 
00048     /**
00049      * See GRAPHVIZ' documentation for "lhead".
00050      * @see http://www.graphviz.org/doc/info/attrs.html
00051      */
00052         private String __lhead          = null;
00053 
00054         /**
00055          * Color of the edge.
00056          */
00057         private String __color          = null;
00058 
00059         /**
00060          * width of the edge.
00061          */
00062         private String __penwidth       = null;
00063 
00064     /**
00065      * See GRAPHVIZ' documentation for "arrowtail".
00066      * @see http://www.graphviz.org/doc/info/attrs.html
00067      */
00068         private String __arrowtail  = null;
00069 
00070     /**
00071      * See GRAPHVIZ' documentation for "arrowhead".
00072      * @see http://www.graphviz.org/doc/info/attrs.html
00073      */
00074         private String __arrowhead  = null;
00075         
00076         /**
00077          * Is the edge visible?
00078          */
00079         private Boolean __edge_visible = Boolean.TRUE;
00080 
00081         /**
00082          * Set the edge invisible.
00083          */
00084         public void setInvisible()
00085         {
00086             this.__edge_visible = Boolean.FALSE;
00087         }
00088         
00089         /**
00090          * This method sets the position of the edge's tail.
00091          * @param in_value Name of the element that the edge's tail is attached to.
00092          */
00093         public void setLtail(String in_value) { this.__ltail = in_value; }
00094 
00095         /**
00096          * This method sets the position of the edge's head.
00097          * @param in_value Name of the element that the edge's head is attached to.
00098          */
00099         public void setLhead(String in_value) { this.__lhead = in_value; }
00100 
00101         /**
00102          * This method sets the edge's color.
00103          * @param in_value the color to set.
00104          */
00105         public void setColor(String in_value) { this.__color = in_value; }
00106 
00107         /**
00108          * This method sets the width of the line used to draw the edge.
00109          * @param in_value The width to set.
00110          */
00111         public void setPenwidth(String in_value) { this.__penwidth = in_value; }
00112 
00113         /**
00114          * Set the origin of the edge. Please note that the edge may not originate from the element, if you set the edge's tail.
00115          * @param in_value Name of the element that represents the origin of the edge.
00116          */
00117         public void setFrom(String in_value)
00118         {
00119             this.__from = Node.generateName(in_value);
00120         }
00121 
00122         /**
00123          * Name of the element that represents the edge's destination. Please note that the edge may not end to the element, if you set the edge's head.
00124          * @param in_value Name of the element that represents the edge's destination.
00125          */
00126         public void setTo(String in_value)
00127         {
00128             this.__to = Node.generateName(in_value);
00129         }
00130 
00131         /**
00132          * This method defines the appearance of the head of the edge.
00133          * @param in_value Head's appearance.
00134          */
00135         public void setArrowhead(String in_value) { this.__arrowhead    = in_value; }
00136 
00137         /**
00138      * This method defines the appearance of the tail of the edge.
00139      * @param in_value Tail's appearance.
00140      */
00141     public void setArrowtail(String in_value) { this.__arrowtail    = in_value; }
00142 
00143         /**
00144          * This method returns a DOT's representation of the edge.
00145          * @return The method returns a DOT's representation of the edge.
00146          */
00147         public String toString()
00148         {
00149                 if ((null == this.__from) || (null == this.__to)) { return "WARNING: You try to create a DOT edge without head or tail !!!"; }
00150 
00151                 String edge = this.__from + " -> " + this.__to;
00152                 ArrayList<String> words = new ArrayList<String>();
00153                 Boolean params = Boolean.FALSE;
00154 
00155                 if (null != this.__ltail)               { words.add("ltail="     + this.__ltail);               params = Boolean.TRUE; }
00156                 if (null != this.__lhead)               { words.add("lhead="     + this.__lhead);               params = Boolean.TRUE; }
00157                 if (null != this.__color)               { words.add("color="     + this.__color);               params = Boolean.TRUE; }
00158                 if (null != this.__penwidth)    { words.add("penwidth="  + this.__penwidth);    params = Boolean.TRUE; }
00159                 if (null != this.__arrowhead)   { words.add("arrowhead=" + this.__arrowhead);   params = Boolean.TRUE; }
00160                 if (null != this.__arrowtail)   { words.add("arrowtail=" + this.__arrowtail);   params = Boolean.TRUE; }
00161                 if (! this.__edge_visible)      { words.add("style=\"invis\"");                 params = Boolean.TRUE; }
00162 
00163                 if (params) { edge = edge + " [" + org.dbview.utils.Strings.join(words, " ") + "]"; }
00164                 return edge + ";";
00165         }
00166 }