summaryrefslogtreecommitdiff
path: root/src/main/java/com/c2kernel/graph/model/Vertex.java
blob: ccef437552214360aca4376f65d8ebf32a0bc656 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
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<Integer>       mInEdgeIdVector  = new Vector<Integer>();
    private Vector<Integer>       mOutEdgeIdVector = new Vector<Integer>();
    private Vector<Object>       mTags             = new Vector<Object>();

    // 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<Integer>(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<Integer>(10, 10);
       	for(i=0; i<ids.length; i++)
       		mOutEdgeIdVector.add(new Integer(ids[i]));
    }


    public int[] getOutEdgeIds()
    {
        return integerVectorToIntArray(mOutEdgeIdVector);
    }


    private static int[] integerVectorToIntArray(Vector<Integer> vector)
    {
        int[]   array   = new int[vector.size()];
        Integer integer = null;
        int     i       = 0;

        for(i=0; i<array.length; i++)
        {
            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 = 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 = 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;
    }

}