summaryrefslogtreecommitdiff
path: root/source/com/c2kernel/graph/model/Vertex.java
diff options
context:
space:
mode:
Diffstat (limited to 'source/com/c2kernel/graph/model/Vertex.java')
-rwxr-xr-xsource/com/c2kernel/graph/model/Vertex.java308
1 files changed, 308 insertions, 0 deletions
diff --git a/source/com/c2kernel/graph/model/Vertex.java b/source/com/c2kernel/graph/model/Vertex.java
new file mode 100755
index 0000000..1e8399b
--- /dev/null
+++ b/source/com/c2kernel/graph/model/Vertex.java
@@ -0,0 +1,308 @@
+package com.c2kernel.graph.model;
+
+import java.awt.Polygon;
+import java.io.Serializable;
+import java.util.Vector;
+
+
+public class Vertex implements Serializable
+{
+ private int mId = -1;
+ private String mName = "";
+ private GraphPoint mCentrePoint = new GraphPoint(0, 0);
+ private int mHeight = 0;
+ private int mWidth = 0;
+ private Vector mInEdgeIdVector = new Vector();
+ private Vector mOutEdgeIdVector = new Vector();
+ private Vector mTags = new Vector();
+
+ // The Java Polygon class is used to determine if a point
+ // lies within the outline of a vertex. Unfortunately
+ // both the polygon and the set of outline points need to
+ // kept in memory because a polygon never has 0 points
+ // which is required by Castor's unmarshall object mechanism
+ private Polygon mOutlinePolygon = new Polygon();
+ private GraphPoint[] mOutlinePoints = new GraphPoint[0];
+
+
+ private GraphModel graphModel;
+
+ public void setID(int id)
+ {
+ mId = id;
+ }
+
+
+ public int getID()
+ {
+ return mId;
+ }
+
+
+ public void setName(String n)
+ {
+ mName = n;
+ }
+
+
+ public String getName()
+ {
+ return mName;
+ }
+
+
+ public void setCentrePoint(GraphPoint p)
+ {
+ mCentrePoint = p;
+ }
+
+
+ public GraphPoint getCentrePoint()
+ {
+ return mCentrePoint;
+ }
+
+
+ public void setHeight(int h)
+ {
+ mHeight = h;
+ }
+
+
+ public int getHeight()
+ {
+ return mHeight;
+ }
+
+
+ public void setWidth(int w)
+ {
+ mWidth = w;
+ }
+
+
+ public int getWidth()
+ {
+ return mWidth;
+ }
+
+
+ // Sets the outline points and re-calculates the
+ // height and width
+ public void setOutlinePoints(GraphPoint[] outline)
+ {
+ int topLeftX = outline[0].x;
+ int topLeftY = outline[0].y;
+ int bottomRightX = 0;
+ int bottomRightY = 0;
+ int i = 0;
+
+ mOutlinePoints = outline;
+
+ // Construct a polygon in the outline of the vertex
+ // and calculate the top left and bottom right corners
+ mOutlinePolygon = new Polygon();
+
+ for(i=0; i<outline.length; i++)
+ {
+ mOutlinePolygon.addPoint(outline[i].x, outline[i].y);
+
+ if(outline[i].x < topLeftX)
+ {
+ topLeftX = outline[i].x;
+ }
+
+ if(outline[i].y < topLeftY)
+ {
+ topLeftY = outline[i].y;
+ }
+
+ if(outline[i].x > bottomRightX)
+ {
+ bottomRightX = outline[i].x;
+ }
+
+
+ if(outline[i].y > bottomRightY)
+ {
+ bottomRightY = outline[i].y;
+ }
+ }
+
+ // Set the height and width
+ mHeight = bottomRightY - topLeftY;
+ mWidth = bottomRightX - topLeftX;
+ }
+
+
+ public GraphPoint[] getOutlinePoints()
+ {
+ return mOutlinePoints;
+ }
+
+ public void moveAbsolute(GraphPoint p)
+ {
+ int deltaX = p.x - mCentrePoint.x;
+ int deltaY = p.y - mCentrePoint.y;
+ int i = 0;
+
+ // Update the outline points and the polygon
+ for(i=0; i<mOutlinePoints.length; i++)
+ {
+ mOutlinePoints[i].x += deltaX;
+ mOutlinePoints[i].y += deltaY;
+ }
+
+ mOutlinePolygon.translate(deltaX, deltaY);
+
+ mCentrePoint.x = p.x;
+ mCentrePoint.y = p.y;
+ }
+
+
+ public boolean containsPoint(GraphPoint p)
+ {
+ return mOutlinePolygon.contains(p.x, p.y);
+ }
+
+
+ public void setInEdgeIds(int[] ids)
+ {
+ int i = 0;
+
+ mInEdgeIdVector = new Vector(10, 10);
+ for(i=0; i<ids.length; i++)
+ mInEdgeIdVector.add(new Integer(ids[i]));
+ }
+
+
+ public int[] getInEdgeIds()
+ {
+ return integerVectorToIntArray(mInEdgeIdVector);
+ }
+
+
+ public void setOutEdgeIds(int[] ids)
+ {
+ int i = 0;
+
+ mOutEdgeIdVector = new Vector(10, 10);
+ for(i=0; i<ids.length; i++)
+ mOutEdgeIdVector.add(new Integer(ids[i]));
+ }
+
+
+ public int[] getOutEdgeIds()
+ {
+ return integerVectorToIntArray(mOutEdgeIdVector);
+ }
+
+
+ private int[] integerVectorToIntArray(Vector vector)
+ {
+ int[] array = new int[vector.size()];
+ Integer integer = null;
+ int i = 0;
+
+ for(i=0; i<array.length; i++)
+ {
+ integer = (Integer)vector.elementAt(i);
+ array[i] = integer.intValue();
+ }
+
+ return array;
+ }
+
+
+ public void addInEdgeId(int id)
+ {
+ mInEdgeIdVector.add(new Integer(id));
+ }
+
+
+ public void removeInEdgeId(int id)
+ {
+ Integer integer = null;
+ int i = 0;
+
+ for(i=0; i<mInEdgeIdVector.size(); i++)
+ {
+ integer = (Integer)mInEdgeIdVector.elementAt(i);
+
+ if(integer.intValue() == id)
+ {
+ mInEdgeIdVector.removeElementAt(i);
+ return;
+ }
+ }
+ }
+
+
+ public void addOutEdgeId(int id)
+ {
+ mOutEdgeIdVector.add(new Integer(id));
+ }
+
+
+ public void removeOutEdgeId(int id)
+ {
+ Integer integer = null;
+ int i = 0;
+
+ for(i=0; i<mOutEdgeIdVector.size(); i++)
+ {
+ integer = (Integer)mOutEdgeIdVector.elementAt(i);
+
+ if(integer.intValue() == id)
+ {
+ mOutEdgeIdVector.removeElementAt(i);
+ return;
+ }
+ }
+ }
+
+
+ public void setTag(Object o)
+ {
+ mTags.add(o);
+ }
+
+
+ public boolean hasTag(Object o)
+ {
+ return mTags.contains(o);
+ }
+
+ public void clearTag(Object o)
+ {
+ mTags.remove(o);
+ }
+
+
+ public GraphModel getChildGraphModel() {
+ return null;
+ }
+
+ public Object getCreationContext() {
+ return null;
+ }
+
+
+ public GraphModel getGraphModel()
+ {
+ return graphModel;
+ }
+
+ public void setGraphModel(GraphModel graphModel)
+ {
+ this.graphModel = graphModel;
+ }
+
+ public boolean isJoin() {
+ return false;
+ }
+ public boolean isLoop() {
+ return false;
+ }
+
+}