Bringing things in line with my copy.

git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/sandbox/graph2/trunk@144613 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
ddp 2002-05-08 17:58:39 +00:00
parent e180946494
commit 2d7c74417c
2 changed files with 256 additions and 234 deletions

View File

@ -0,0 +1,8 @@
package org.apache.commons.graph.visualize;
import java.awt.Color;
public interface Colored {
public Color getBackgroundColor();
public Color getTextColor();
}

View File

@ -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;
}
}