commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d..@apache.org
Subject cvs commit: jakarta-commons-sandbox/graph2/src/java/org/apache/commons/graph/visualize Colored.java TouchGraph.java
Date Wed, 08 May 2002 17:58:39 GMT
ddp         02/05/08 10:58:39

  Modified:    graph2/src/java/org/apache/commons/graph/visualize
                        TouchGraph.java
  Added:       graph2/src/java/org/apache/commons/graph/visualize
                        Colored.java
  Log:
  Bringing things in line with my copy.
  
  Revision  Changes    Path
  1.2       +248 -234  jakarta-commons-sandbox/graph2/src/java/org/apache/commons/graph/visualize/TouchGraph.java
  
  Index: TouchGraph.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/graph2/src/java/org/apache/commons/graph/visualize/TouchGraph.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- TouchGraph.java	17 Mar 2002 16:28:17 -0000	1.1
  +++ TouchGraph.java	8 May 2002 17:58:39 -0000	1.2
  @@ -1,234 +1,248 @@
  -package org.apache.commons.graph.visualize;
  -
  -import java.util.Random;
  -import java.util.Iterator;
  -
  -import java.io.OutputStream;
  -import java.io.PrintWriter;
  -
  -import java.awt.Color;
  -
  -import org.apache.commons.graph.*;
  -
  -/**
  - * Description of the Class
  - */
  -public class TouchGraph
  -{
  -    private Color vertexColor = Color.yellow;
  -    private Color textColor = Color.black;
  -    private Color edgeColor = Color.red;
  -
  -    private double lengthFactor = 500.0;
  -    private double defaultLength = 1.0;
  -    private int fontSize = 18;
  -
  -    private Random random = new Random();
  -
  -    /**
  -     * Constructor for the TouchGraph object
  -     */
  -    public TouchGraph() { }
  -
  -    /**
  -     * Gets the colorText attribute of the TouchGraph object
  -     */
  -    private String getColorText(Color color)
  -    {
  -        return Integer.toHexString(color.getRGB()).toUpperCase();
  -    }
  -
  -    /**
  -     * Sets the vertexColor attribute of the TouchGraph object
  -     */
  -    public void setVertexColor(Color vertexColor)
  -    {
  -        this.vertexColor = vertexColor;
  -    }
  -
  -    /**
  -     * Gets the vertexColor attribute of the TouchGraph object
  -     */
  -    public Color getVertexColor()
  -    {
  -        return this.vertexColor;
  -    }
  -
  -    /**
  -     * Gets the vertexColorText attribute of the TouchGraph object
  -     */
  -    private String getVertexColorText()
  -    {
  -        return getColorText(getVertexColor());
  -    }
  -
  -    /**
  -     * Sets the textColor attribute of the TouchGraph object
  -     */
  -    public void setTextColor(Color vertexColor)
  -    {
  -        this.vertexColor = vertexColor;
  -    }
  -
  -    /**
  -     * Gets the textColor attribute of the TouchGraph object
  -     */
  -    public Color getTextColor()
  -    {
  -        return this.vertexColor;
  -    }
  -
  -    /**
  -     * Gets the textColorText attribute of the TouchGraph object
  -     */
  -    private String getTextColorText()
  -    {
  -        return getColorText(getTextColor());
  -    }
  -
  -    /**
  -     * Sets the edgeColor attribute of the TouchGraph object
  -     */
  -    public void setEdgeColor(Color edgeColor)
  -    {
  -        this.edgeColor = edgeColor;
  -    }
  -
  -    /**
  -     * Gets the edgeColor attribute of the TouchGraph object
  -     */
  -    public Color getEdgeColor()
  -    {
  -        return this.edgeColor;
  -    }
  -
  -    /**
  -     * Gets the edgeColorText attribute of the TouchGraph object
  -     */
  -    private String getEdgeColorText()
  -    {
  -        return getColorText(getEdgeColor());
  -    }
  -
  -    /**
  -     * Sets the fontSize attribute of the TouchGraph object
  -     */
  -    public void setFontSize(int size)
  -    {
  -        this.fontSize = size;
  -    }
  -
  -    /**
  -     * Gets the fontSize attribute of the TouchGraph object
  -     */
  -    public int getFontSize()
  -    {
  -        return fontSize;
  -    }
  -
  -    /**
  -     * Sets the defaultEdgeLength attribute of the TouchGraph object
  -     */
  -    public void setDefaultEdgeLength(int length)
  -    {
  -        this.defaultLength = length;
  -    }
  -
  -    /**
  -     * Gets the defaultEdgeLength attribute of the TouchGraph object
  -     */
  -    public double getDefaultEdgeLength()
  -    {
  -        return defaultLength;
  -    }
  -
  -    /**
  -     * Description of the Method
  -     */
  -    protected void writeNodeset(PrintWriter pw,
  -                                DirectedGraph graph)
  -    {
  -        pw.println("<NODESET>");
  -        Iterator vertices =
  -            graph.getVertices().iterator();
  -        while (vertices.hasNext())
  -        {
  -            Vertex v = (Vertex) vertices.next();
  -
  -            pw.println("<NODE nodeID=\"" + v.toString() + "\">");
  -            pw.println("<NODE_LOCATION x=\"" + random.nextInt(25) +
  -                "\" y = \"" + random.nextInt(25) +
  -                "\" visible=\"true\" />");
  -
  -            String label;
  -            if (v instanceof Named)
  -            {
  -                label = ((Named) v).getName();
  -            }
  -            else
  -            {
  -                label = v.toString();
  -            }
  -
  -            pw.println("<NODE_LABEL label=\"" + label + "\" " +
  -                "shape=\"2\" " +
  -                "backColor=\"" + getVertexColorText() + "\" " +
  -                "textColor=\"" + getTextColorText() + "\" " +
  -                "fontSize=\"" + fontSize + "\" />");
  -
  -            pw.println("</NODE>");
  -        }
  -
  -        pw.println("</NODESET>");
  -    }
  -
  -    /**
  -     * Description of the Method
  -     */
  -    protected void writeEdgeset(PrintWriter pw, DirectedGraph graph)
  -    {
  -        pw.println("<EDGESET>");
  -
  -        Iterator edges = graph.getEdges().iterator();
  -        while (edges.hasNext())
  -        {
  -            Edge next = (Edge) edges.next();
  -
  -            int length = new Double(lengthFactor *
  -                defaultLength).intValue();
  -
  -            if (graph instanceof WeightedGraph)
  -            {
  -                length =
  -                    new Double(lengthFactor *
  -                    ((WeightedGraph) graph)
  -                    .getWeight(next)).intValue();
  -            }
  -
  -            pw.println("<EDGE fromID=\"" + graph.getSource(next) + "\" " +
  -                "toID=\"" + graph.getTarget(next) + "\" " +
  -                "type=\"2\" " +
  -                "visible=\"true\" " +
  -                "length=\"" + length + "\" />");
  -
  -        }
  -        pw.println("</EDGESET>");
  -    }
  -
  -    /**
  -     * Description of the Method
  -     */
  -    public void toXML(DirectedGraph graph,
  -                      OutputStream os)
  -    {
  -        PrintWriter pw = new PrintWriter(os);
  -        pw.println("<?xml version=\"1.0\"?>");
  -        pw.println("<TOUCHGRAPH_LB version=\"1.20\">");
  -        writeNodeset(pw, graph);
  -        writeEdgeset(pw, graph);
  -        pw.println("</TOUCHGRAPH_LB>");
  -        pw.flush();
  -
  -        return;
  -    }
  -}
  +package org.apache.commons.graph.visualize;
  +
  +import java.util.Random;
  +import java.util.Iterator;
  +
  +import java.io.OutputStream;
  +import java.io.PrintWriter;
  +
  +import java.awt.Color;
  +
  +import org.apache.commons.graph.*;
  +
  +/**
  + * Description of the Class
  + */
  +public class TouchGraph
  +{
  +    private Color vertexColor = Color.yellow;
  +    private Color textColor = Color.black;
  +    private Color edgeColor = Color.red;
  +
  +    private double lengthFactor = 500.0;
  +    private double defaultLength = 1.0;
  +    private int fontSize = 18;
  +
  +    private Random random = new Random();
  +
  +    /**
  +     * Constructor for the TouchGraph object
  +     */
  +    public TouchGraph() { }
  +
  +    /**
  +     * Gets the colorText attribute of the TouchGraph object
  +     */
  +    private String getColorText(Color color)
  +    {
  +      String RC = Integer.toHexString( color.getRGB()).toUpperCase();
  +      return RC.substring( 2, 8 );
  +    }
  +
  +    /**
  +     * Sets the vertexColor attribute of the TouchGraph object
  +     */
  +    public void setVertexColor(Color vertexColor)
  +    {
  +        this.vertexColor = vertexColor;
  +    }
  +
  +    /**
  +     * Gets the vertexColor attribute of the TouchGraph object
  +     */
  +    public Color getVertexColor()
  +    {
  +        return this.vertexColor;
  +    }
  +
  +    /**
  +     * Gets the vertexColorText attribute of the TouchGraph object
  +     */
  +    private String getVertexColorText()
  +    {
  +        return getColorText(getVertexColor());
  +    }
  +
  +    /**
  +     * Sets the textColor attribute of the TouchGraph object
  +     */
  +    public void setTextColor(Color vertexColor)
  +    {
  +        this.vertexColor = vertexColor;
  +    }
  +
  +    /**
  +     * Gets the textColor attribute of the TouchGraph object
  +     */
  +    public Color getTextColor()
  +    {
  +        return this.vertexColor;
  +    }
  +
  +    /**
  +     * Gets the textColorText attribute of the TouchGraph object
  +     */
  +    private String getTextColorText()
  +    {
  +        return getColorText(getTextColor());
  +    }
  +
  +    /**
  +     * Sets the edgeColor attribute of the TouchGraph object
  +     */
  +    public void setEdgeColor(Color edgeColor)
  +    {
  +        this.edgeColor = edgeColor;
  +    }
  +
  +    /**
  +     * Gets the edgeColor attribute of the TouchGraph object
  +     */
  +    public Color getEdgeColor()
  +    {
  +        return this.edgeColor;
  +    }
  +
  +    /**
  +     * Gets the edgeColorText attribute of the TouchGraph object
  +     */
  +    private String getEdgeColorText()
  +    {
  +        return getColorText(getEdgeColor());
  +    }
  +
  +    /**
  +     * Sets the fontSize attribute of the TouchGraph object
  +     */
  +    public void setFontSize(int size)
  +    {
  +        this.fontSize = size;
  +    }
  +
  +    /**
  +     * Gets the fontSize attribute of the TouchGraph object
  +     */
  +    public int getFontSize()
  +    {
  +        return fontSize;
  +    }
  +
  +    /**
  +     * Sets the defaultEdgeLength attribute of the TouchGraph object
  +     */
  +    public void setDefaultEdgeLength(int length)
  +    {
  +        this.defaultLength = length;
  +    }
  +
  +    /**
  +     * Gets the defaultEdgeLength attribute of the TouchGraph object
  +     */
  +    public double getDefaultEdgeLength()
  +    {
  +        return defaultLength;
  +    }
  +
  +    /**
  +     * Description of the Method
  +     */
  +    protected void writeNodeset(PrintWriter pw,
  +                                DirectedGraph graph)
  +    {
  +        pw.println("<NODESET>");
  +        Iterator vertices =
  +            graph.getVertices().iterator();
  +        while (vertices.hasNext())
  +        {
  +            Vertex v = (Vertex) vertices.next();
  +
  +            pw.println("<NODE nodeID=\"" + v.toString() + "\">");
  +            pw.println("<NODE_LOCATION x=\"" + random.nextInt(200) +
  +                "\" y = \"" + random.nextInt(200) +
  +                "\" visible=\"true\" />");
  +
  +            String label;
  +            if (v instanceof Named)
  +            {
  +                label = ((Named) v).getName();
  +            }
  +            else
  +            {
  +                label = v.toString();
  +            }
  +
  +	    String backColor = null;
  +	    String textColor = null;
  +
  +	    if (v instanceof Colored) {
  +	      backColor = getColorText(((Colored) v).getBackgroundColor());
  +	      textColor = getColorText(((Colored) v).getTextColor() );
  +	    } else {
  +	      backColor = getVertexColorText();
  +	      textColor = getTextColorText();
  +	    }
  +
  +            pw.println("<NODE_LABEL label=\"" + label + "\" " +
  +                "shape=\"2\" " +
  +                "backColor=\"" + backColor + "\" " +
  +                "textColor=\"" + textColor + "\" " +
  +                "fontSize=\"" + fontSize + "\" />");
  +
  +            pw.println("</NODE>");
  +        }
  +
  +        pw.println("</NODESET>");
  +    }
  +
  +    /**
  +     * Description of the Method
  +     */
  +    protected void writeEdgeset(PrintWriter pw, DirectedGraph graph)
  +    {
  +        pw.println("<EDGESET>");
  +
  +        Iterator edges = graph.getEdges().iterator();
  +        while (edges.hasNext())
  +        {
  +            Edge next = (Edge) edges.next();
  +
  +            int length = new Double(lengthFactor *
  +                defaultLength).intValue();
  +
  +            if (graph instanceof WeightedGraph)
  +            {
  +                length =
  +                    new Double(lengthFactor *
  +                    ((WeightedGraph) graph)
  +                    .getWeight(next)).intValue();
  +            }
  +
  +            pw.println("<EDGE fromID=\"" + graph.getSource(next) + "\" " +
  +                "toID=\"" + graph.getTarget(next) + "\" " +
  +                "type=\"2\" " +
  +                "visible=\"true\" " +
  +                "length=\"" + length + "\" />");
  +
  +        }
  +        pw.println("</EDGESET>");
  +    }
  +
  +    /**
  +     * Description of the Method
  +     */
  +    public void toXML(DirectedGraph graph,
  +                      OutputStream os)
  +    {
  +        PrintWriter pw = new PrintWriter(os);
  +        pw.println("<?xml version=\"1.0\"?>");
  +        pw.println("<TOUCHGRAPH_LB version=\"1.20\">");
  +        writeNodeset(pw, graph);
  +        writeEdgeset(pw, graph);
  +        pw.println("</TOUCHGRAPH_LB>");
  +        pw.flush();
  +
  +        return;
  +    }
  +}
  +
  +
  
  
  
  1.1                  jakarta-commons-sandbox/graph2/src/java/org/apache/commons/graph/visualize/Colored.java
  
  Index: Colored.java
  ===================================================================
  package org.apache.commons.graph.visualize;
  
  import java.awt.Color;
  
  public interface Colored {
    public Color getBackgroundColor();
    public Color getTextColor();
  }
  
  
  

--
To unsubscribe, e-mail:   <mailto:commons-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:commons-dev-help@jakarta.apache.org>


Mime
View raw message