Jedit 4.1

edu.bsu.cs.graph
Class JavaGraph

java.lang.Object
  |
  +--edu.bsu.cs.graph.JavaGraph
All Implemented Interfaces:
Serializable

public class JavaGraph
extends Object
implements Serializable

The base class for implementing a graph - consists of a set of vertices, a set of edges, and a graph type.

Since:
21 Jan 1997
Version:
22 May 2002
Author:
Aaron Nall
, Elizabeth VandenBerg
See Also:
Serializable, Serialized Form

Field Summary
static int DIGRAPH
          The flag for a directed Graph
static int GRAPH
          The flag for an undirected Graph
static int MULTIGRAPH
          Not currently in use
static int POLYGON
          Not currently in use
 
Constructor Summary
JavaGraph()
          Default constructor.
JavaGraph(int v, JavaGraph g1)
          Constructs a new graph from the component containing vertex v in graph g1.
JavaGraph(JavaGraph source)
          Cloning constructor.
JavaGraph(JavaGraph g1, JavaGraph g2)
          Constructs a new graph from two graphs (combines them into one graph with two components).
 
Method Summary
 void addComponent(JavaGraph g)
          Adds g as a component to the JavaGraph.
 void addEdge(double weight, int from, int to)
          Adds an edge from the Vertex with the first index to the Vertex with the second index and sets the new Edge's weight to the specified value.
 void addEdge(int from, int to)
          Adds an edge from the Vertex with the first index to the Vertex with the second index.
 void addVertex()
          Adds a single vertex with default properties
 void addVertex(Point location)
          Adds a new Vertex to the graph and moves it to the Point location.
 double[][] adjacencyMatrix()
          Returns the adjacency matrix of graph g.
 void arrangeComponent(int v)
          Arranges the component that the vertex numbered v is contained in.
 void arrangeVertices()
          Arranges all of the vertices in the graph in a circle.
 void arrangeVertices(double radiusFactor, int min, int max, int centerX, int centerY)
          Arranges the specified vertices in the graph in a circle.
 int componentOrder(int v)
          Returns the integer order of the component that the vertex v is contained in.
 Point componentVisualCenter(int v)
          Returns the graphical/visual center of the component that the vertex v is contained in.
 boolean existEdge(int from, int to)
          Returns true if an edge exists between the vertices numbered by from and to.
 Point findEdge(Point point)
          Finds an edge near a point.
 int findVertex(Point point)
          Finds a vertex near a point.
 Point getEdge(int from, int to)
          Returns a point containing the indices of the endpoints of the edge if it exists.
 Color getEdgeColor(int from, int to)
          Gets the Color of the specified Edge.
 String getEdgeLabel(int from, int to)
          Returns the label of the specified Edge
 double getEdgeWeight(int from, int to)
          Returns the weight of the specified Edge
 double getEdgeWeight2(int from, int to)
          Returns the second weight of the specified Edge
 int getGraphType()
          Returns a flag for the graph type as follows:
GRAPH = 0;
DIGRAPH = 1;
MULTIGRAPH = 2;
POLYGON = 3;
 Color getVertexColor(int vertexNumber)
          Gets the Color of the specified Vertex.
 Point getVertexCoord(int vertexNumber)
          Returns the coordinates of the specified Vertex.
 int getVertexDegree(int vertex)
          Return the degree of the specified vertex.
 String getVertexLabel(int vertexNumber)
          Returns the label of the specified Vertex.
 double getVertexWeight(int vertexNumber)
          Returns the weight of the specified Vertex.
 Rectangle getVisibleArea()
          Gets the visible area for the graph.
 boolean isEdgeMarked(int from, int to)
          Returns true if the specified Edge is marked.
 boolean isVertexMarked(int vertexNumber)
          Returns true if the specified Vertex is marked.
 void markAllEdges()
          Sets the marked flag to true for all of the Eges in the graph.
 void markAllVertices()
          Sets the marked flag to true for all of the Vertices in the graph.
 void markComponent(int v)
          Marks the component that the vertex numbered v is contained in.
 void markEdge(int from, int to)
          Sets the marked flag to true for the specified Edge.
 void markVertex(int vertexNumber)
          Sets the marked flag to true for the specified Vertex.
 void moveComponent(int v, Point offset, Point startingPoint)
          Moves the component that the vertex numbered v is contained in.
 void moveVertex(int vertexNumber, Point location)
          Sets the coordinates of the specified vertex to the Point location.
 void numberVertices()
          Sets the labels of the vertices to match their indices.
 int order()
          Returns the total number of vertices in the graph.
 void removeAllMarkedVertices()
          Removes all marked Vertices and their Edges from the graph.
 void removeAllVertices()
          Removes all Vertices and their Edges from the graph.
 void removeComponent(int v)
          Removes the component that the vertex numbered v is contained in.
 boolean removeEdge(int from, int to)
          Removes the specified Edge from the graph.
 boolean removeEdge(Point point)
          Removes the specified Edge from the graph.
 void removeVertex(int vertexNumber)
          Removes the speciefied vertex and all of its Edges from the graph.
 void resizeComponent(int v, double a)
          Resizes the component that the vertex numbered v is contained in.
 void resizeGraph(double a)
          Resizes a graph
 void rotateComponent(int v, double angle)
          Rotates the component that the vertex numbered v is contained in by the number of degrees in angle.
 void setEdgeColor(int from, int to, Color newColor)
          Sets the Color of the specified Edge.
 void setEdgeLabel(int from, int to, String label)
          Sets the label of the specified Edge
 void setEdgeWeight(int from, int to, double weight)
          Sets the weight of the specified Edge
 void setEdgeWeight2(int from, int to, double weight)
          Sets the second weight of the specified Edge
 void setGraphType(int newType)
          Sets the flag for graph type as follows:
GRAPH = 0;
DIGRAPH = 1;
MULTIGRAPH = 2;
POLYGON = 3;
 void setVertexColor(int vertexNumber, Color newColor)
          Sets the Color of the specified Vertex.
 void setVertexLabel(int vertexNumber, String newLabel)
          Sets the label of the specified Vertex.
 void setVertexWeight(int vertexNumber, double weight)
          Sets the weight of the specified Vertex
 void setVisibleArea(Rectangle input)
          Sets the visible area for the graph.
 String toString()
          Returns the String used in print and println method calls
 void unmarkAllEdges()
          Sets the marked flag to false for all of the Eges in the graph.
 void unmarkAllVertices()
          Sets the marked flag to false for all of the Vertices in the graph.
 void unmarkComponent(int v)
          Unmarks the component that the vertex numbered v is contained in.
 void unmarkEdge(int from, int to)
          Sets the marked flag to false for the specified Edge.
 void unmarkVertex(int vertexNumber)
          Sets the marked flag to false for the specified Vertex.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

GRAPH

public static final int GRAPH
The flag for an undirected Graph

See Also:
Constant Field Values

DIGRAPH

public static final int DIGRAPH
The flag for a directed Graph

See Also:
Constant Field Values

MULTIGRAPH

public static final int MULTIGRAPH
Not currently in use

See Also:
Constant Field Values

POLYGON

public static final int POLYGON
Not currently in use

See Also:
Constant Field Values
Constructor Detail

JavaGraph

public JavaGraph()
Default constructor. Sets internal private values with the following defaults:
matrix = an empty n x n matrix of edges
vertexList = an empty Vector of vertices
graphType = GRAPH
visibleArea = a Rectangle


JavaGraph

public JavaGraph(JavaGraph source)
Cloning constructor.

Parameters:
source - the graph to clone

JavaGraph

public JavaGraph(int v,
                 JavaGraph g1)
Constructs a new graph from the component containing vertex v in graph g1.

Parameters:
v - number of a vertex within the component
g1 - graph that the component is in

JavaGraph

public JavaGraph(JavaGraph g1,
                 JavaGraph g2)
Constructs a new graph from two graphs (combines them into one graph with two components). The starting vertex of the component created from g1 will be 0 and the starting vertex of the component created from g2 will be g1.order()+1.

Parameters:
g1 - first graph
g2 - second graph
Method Detail

addComponent

public void addComponent(JavaGraph g)
Adds g as a component to the JavaGraph.

Parameters:
g - a graph

order

public int order()
Returns the total number of vertices in the graph.

Returns:
int

getVertexDegree

public int getVertexDegree(int vertex)
Return the degree of the specified vertex.

Parameters:
vertex - the vertex number
Returns:
int

findVertex

public int findVertex(Point point)
Finds a vertex near a point. If a nearby vertex is found, its index is returned, otherwise, a -1 is returned.

Parameters:
point - the point to search near
Returns:
int

findEdge

public Point findEdge(Point point)
Finds an edge near a point. If a nearby edge is found, a point containing the indices of it's endpoint vertices is returned; otherwise, a null is returned.

Parameters:
point - the point to search near
Returns:
Point

getEdge

public Point getEdge(int from,
                     int to)
Returns a point containing the indices of the endpoints of the edge if it exists. Otherwise, returns null.

Parameters:
from -
to -
Returns:
Point

unmarkAllVertices

public void unmarkAllVertices()
Sets the marked flag to false for all of the Vertices in the graph.


markAllVertices

public void markAllVertices()
Sets the marked flag to true for all of the Vertices in the graph.


unmarkAllEdges

public void unmarkAllEdges()
Sets the marked flag to false for all of the Eges in the graph.


markAllEdges

public void markAllEdges()
Sets the marked flag to true for all of the Eges in the graph.


markVertex

public void markVertex(int vertexNumber)
Sets the marked flag to true for the specified Vertex.

Parameters:
vertexNumber -

unmarkVertex

public void unmarkVertex(int vertexNumber)
Sets the marked flag to false for the specified Vertex.

Parameters:
vertexNumber -

markEdge

public void markEdge(int from,
                     int to)
Sets the marked flag to true for the specified Edge.

Parameters:
from -
to -

unmarkEdge

public void unmarkEdge(int from,
                       int to)
Sets the marked flag to false for the specified Edge.

Parameters:
from -
to -

isVertexMarked

public boolean isVertexMarked(int vertexNumber)
Returns true if the specified Vertex is marked. Otherwise, it returns false.

Parameters:
vertexNumber -

isEdgeMarked

public boolean isEdgeMarked(int from,
                            int to)
Returns true if the specified Edge is marked. Otherwise, it returns false.

Parameters:
from -
to -

getVertexLabel

public String getVertexLabel(int vertexNumber)
Returns the label of the specified Vertex.

Parameters:
vertexNumber -

setVertexLabel

public void setVertexLabel(int vertexNumber,
                           String newLabel)
Sets the label of the specified Vertex.

Parameters:
vertexNumber -
newLabel -

setVertexColor

public void setVertexColor(int vertexNumber,
                           Color newColor)
Sets the Color of the specified Vertex.

Parameters:
vertexNumber -
newColor -

getVertexColor

public Color getVertexColor(int vertexNumber)
Gets the Color of the specified Vertex.

Parameters:
vertexNumber -

setEdgeColor

public void setEdgeColor(int from,
                         int to,
                         Color newColor)
Sets the Color of the specified Edge.

Parameters:
from -
to -
newColor -

getEdgeColor

public Color getEdgeColor(int from,
                          int to)
Gets the Color of the specified Edge.

Parameters:
from -
to -

getVertexCoord

public Point getVertexCoord(int vertexNumber)
Returns the coordinates of the specified Vertex.

Parameters:
vertexNumber -

getVertexWeight

public double getVertexWeight(int vertexNumber)
Returns the weight of the specified Vertex.

Parameters:
vertexNumber -

setVertexWeight

public void setVertexWeight(int vertexNumber,
                            double weight)
Sets the weight of the specified Vertex


getEdgeLabel

public String getEdgeLabel(int from,
                           int to)
Returns the label of the specified Edge


setEdgeLabel

public void setEdgeLabel(int from,
                         int to,
                         String label)
Sets the label of the specified Edge


getEdgeWeight2

public double getEdgeWeight2(int from,
                             int to)
Returns the second weight of the specified Edge


getEdgeWeight

public double getEdgeWeight(int from,
                            int to)
Returns the weight of the specified Edge


setEdgeWeight2

public void setEdgeWeight2(int from,
                           int to,
                           double weight)
Sets the second weight of the specified Edge


setEdgeWeight

public void setEdgeWeight(int from,
                          int to,
                          double weight)
Sets the weight of the specified Edge


toString

public String toString()
Returns the String used in print and println method calls

Overrides:
toString in class Object

addVertex

public void addVertex()
Adds a single vertex with default properties


moveVertex

public void moveVertex(int vertexNumber,
                       Point location)
Sets the coordinates of the specified vertex to the Point location.


addVertex

public void addVertex(Point location)
Adds a new Vertex to the graph and moves it to the Point location.


removeVertex

public void removeVertex(int vertexNumber)
Removes the speciefied vertex and all of its Edges from the graph.


numberVertices

public void numberVertices()
Sets the labels of the vertices to match their indices.


removeAllVertices

public void removeAllVertices()
Removes all Vertices and their Edges from the graph.


removeAllMarkedVertices

public void removeAllMarkedVertices()
Removes all marked Vertices and their Edges from the graph.


addEdge

public void addEdge(int from,
                    int to)
Adds an edge from the Vertex with the first index to the Vertex with the second index. The Edge will run from from to to.


addEdge

public void addEdge(double weight,
                    int from,
                    int to)
Adds an edge from the Vertex with the first index to the Vertex with the second index and sets the new Edge's weight to the specified value. The Edge will run from from to to.


removeEdge

public boolean removeEdge(int from,
                          int to)
Removes the specified Edge from the graph. If the Edge didn't exist, a false is returned, otherwise a true is returned.


removeEdge

public boolean removeEdge(Point point)
Removes the specified Edge from the graph. If the Edge didn't exist, a false is returned, otherwise a true is returned.


existEdge

public boolean existEdge(int from,
                         int to)
Returns true if an edge exists between the vertices numbered by from and to.


getGraphType

public int getGraphType()
Returns a flag for the graph type as follows:
GRAPH = 0;
DIGRAPH = 1;
MULTIGRAPH = 2;
POLYGON = 3;


setGraphType

public void setGraphType(int newType)
Sets the flag for graph type as follows:
GRAPH = 0;
DIGRAPH = 1;
MULTIGRAPH = 2;
POLYGON = 3;

Parameters:
newType -

setVisibleArea

public void setVisibleArea(Rectangle input)
Sets the visible area for the graph.


getVisibleArea

public Rectangle getVisibleArea()
Gets the visible area for the graph.


arrangeVertices

public void arrangeVertices()
Arranges all of the vertices in the graph in a circle. The circle is centerd in the visible area of the graph. There is a distance of 30 pixels between the center of center of each edge and it's nearest neighbor.


arrangeVertices

public void arrangeVertices(double radiusFactor,
                            int min,
                            int max,
                            int centerX,
                            int centerY)
Arranges the specified vertices in the graph in a circle. The vertices used are from min to max, inclusively. The circle is centerd at centerX, centerY. There is a distance of radiusFactor pixels between the center of each edge and it's nearest neighbor.

Parameters:
radiusFactor -
min -
max -
centerX -
centerY -

resizeGraph

public void resizeGraph(double a)
Resizes a graph


adjacencyMatrix

public double[][] adjacencyMatrix()
Returns the adjacency matrix of graph g.

Returns:
double[][]
Since:
22 May 2002

unmarkComponent

public void unmarkComponent(int v)
Unmarks the component that the vertex numbered v is contained in.


markComponent

public void markComponent(int v)
Marks the component that the vertex numbered v is contained in.


removeComponent

public void removeComponent(int v)
Removes the component that the vertex numbered v is contained in.


moveComponent

public void moveComponent(int v,
                          Point offset,
                          Point startingPoint)
Moves the component that the vertex numbered v is contained in. The component is moved from startingPoint plus offset.


arrangeComponent

public void arrangeComponent(int v)
Arranges the component that the vertex numbered v is contained in. The component is arranged in a circle around a the center point of the original location of v.


componentVisualCenter

public Point componentVisualCenter(int v)
Returns the graphical/visual center of the component that the vertex v is contained in. If the vertices in the component are rearranged or if the component is moved, this changes.


componentOrder

public int componentOrder(int v)
Returns the integer order of the component that the vertex v is contained in.


resizeComponent

public void resizeComponent(int v,
                            double a)
Resizes the component that the vertex numbered v is contained in.


rotateComponent

public void rotateComponent(int v,
                            double angle)
Rotates the component that the vertex numbered v is contained in by the number of degrees in angle.


Jedit 4.1