blob: f8db540c3f6c2572cd085e5825ced4274f17ea00 (
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
|
/**
* This file is part of the CRISTAL-iSE kernel.
* Copyright (c) 2001-2014 The CRISTAL Consortium. All rights reserved.
*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published
* by the Free Software Foundation; either version 3 of the License, or (at
* your option) any later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; with out even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this library; if not, write to the Free Software Foundation,
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
*
* http://www.fsf.org/licensing/licenses/lgpl.html
*/
package com.c2kernel.graph.model;
/**
* @version $Revision: 1.24 $ $Date: 2005/10/05 07:39:37 $
* @author $Author: abranson $
*/
import com.c2kernel.common.InvalidData;
import com.c2kernel.utils.CastorHashMap;
import com.c2kernel.utils.KeyValuePair;
public abstract class GraphableVertex extends Vertex
{
private CastorHashMap mProperties = null;
private boolean mIsLayoutable;
protected boolean mIsComposite;
private GraphModel mChildrenGraphModel;
public GraphableVertex()
{
mProperties = new CastorHashMap();
}
public void setProperties(CastorHashMap props)
{
mProperties = props;
}
public CastorHashMap getProperties()
{
return mProperties;
}
protected Integer getVersionNumberProperty(String propName) throws InvalidData {
Object val = getProperties().get(propName);
if (val == null || val.equals("") || val.toString().equals("-1")) return null;
try {
return new Integer(val.toString());
} catch (NumberFormatException ex) {
throw new InvalidData("Invalid version number for property '"+propName+"': "+val.toString());
}
}
public KeyValuePair[] getKeyValuePairs()
{
return mProperties.getKeyValuePairs();
}
public void setKeyValuePairs(KeyValuePair[] pairs)
{
mProperties.setKeyValuePairs(pairs);
}
/** @associates Graphable that is directly containing it*/
private GraphableVertex parent;
/**
* Returns the parent.
* @return Graphable
*/
public GraphableVertex getParent()
{
return parent;
}
/**
* Sets the parent.
* @param parent The parent to set
*/
public void setParent(GraphableVertex parent)
{
if (this.equals(parent))
throw new ExceptionInInitializerError();
this.parent = parent;
}
@Override
public GraphModel getChildGraphModel()
{
return mChildrenGraphModel;
}
@Override
public Object getCreationContext()
{
return this;
}
public Vertex[] getOutGraphables()
{
if (parent == null)
return new Vertex[0]; // none if no parent
return parent.mChildrenGraphModel.getOutVertices(this);
}
public DirectedEdge[] getOutEdges()
{
if (parent == null)
return new DirectedEdge[0]; // none if no parent
return parent.mChildrenGraphModel.getOutEdges(this);
}
public DirectedEdge[] getInEdges()
{
if (parent == null)
return new DirectedEdge[0]; // none if no parent
DirectedEdge[] edges = getParent().mChildrenGraphModel.getInEdges(this);
if (edges != null)
return edges;
else
return new DirectedEdge[0];
}
public GraphableVertex[] getChildren()
{
return getLayoutableChildren();
}
public DirectedEdge[] getChildrenEdges()
{
if (getIsComposite())
{
return getChildGraphModel().getEdges();
}
return null;
}
public GraphableVertex[] getLayoutableChildren()
{
if (getIsComposite())
{
Vertex[] vs = mChildrenGraphModel.getVertices();
GraphableVertex[] gvs = new GraphableVertex[vs.length];
for (int i = 0; i < vs.length; i++)
{
gvs[i] = (GraphableVertex) vs[i];
}
return gvs;
}
return null;
}
/**@returns the Graphable searched or null if not this or children*/
public GraphableVertex search(String ids)
{
if (getName().equals(ids))
return this;
if (String.valueOf(getID()).equals(ids))
return this;
if (getIsComposite())
{
GraphableVertex[] graphables = getChildren();
if (ids.startsWith(String.valueOf(getID())))
ids = ids.substring(ids.indexOf("/") + 1);
else if (ids.startsWith(getName()))
ids = ids.substring(getName().length() + 1);
else if (ids.startsWith(getPath()))
ids = ids.substring(getPath().length() + 1);
else
return null;
for (GraphableVertex graphable : graphables) {
GraphableVertex grap = graphable.search(ids);
if (grap != null) return grap;
}
}
return null;
}
/**
* Returns the isLayoutable.
* @return boolean
*/
public boolean getIsLayoutable()
{
return mIsLayoutable;
}
/**
* Sets the isLayoutable.
* @param isLayoutable The isLayoutable to set
*/
public void setIsLayoutable(boolean isLayoutable)
{
mIsLayoutable = isLayoutable;
}
/**
* Returns the isComposite.
* @return boolean
*/
public boolean getIsComposite()
{
return mIsComposite;
}
/**
* Sets the isComposite.
* @param isComposite The isComposite to set
*/
public void setIsComposite(boolean isComposite)
{
mIsComposite = isComposite;
}
public void addChild(GraphableVertex graphableVertex, GraphPoint g)
{
getChildGraphModel().addVertexAndCreateId(graphableVertex, g);
graphableVertex.setParent(this);
}
/**
* Returns the childrenGraph.
* @return GraphModel
*/
public GraphModel getChildrenGraphModel()
{
return mChildrenGraphModel;
}
/**
* Sets the childrenGraph.
* @param childrenGraph The childrenGraph to set
*/
public void setChildrenGraphModel(GraphModel childrenGraph)
{
mChildrenGraphModel = childrenGraph;
DirectedEdge[] edges = mChildrenGraphModel.getEdges();
GraphableVertex[] graphables = this.getLayoutableChildren();
if (graphables != null)
for (GraphableVertex graphable : graphables)
graphable.setParent(this);
if (edges != null)
for (DirectedEdge edge : edges)
((GraphableEdge) edge).setParent(this);
childrenGraph.setContainingVertex(this);
}
/**
* @see com.c2kernel.graph.model.Vertex#getCentrePoint()
*/
@Override
public GraphPoint getCentrePoint()
{
if (!getIsLayoutable())
return null;
return super.getCentrePoint();
}
/**
* @see com.c2kernel.graph.model.Vertex#getInEdgeIds()
*/
@Override
public int[] getInEdgeIds()
{
if (!getIsLayoutable())
return null;
return super.getInEdgeIds();
}
/**
* @see com.c2kernel.graph.model.Vertex#getOutEdgeIds()
*/
@Override
public int[] getOutEdgeIds()
{
if (!getIsLayoutable())
return null;
return super.getOutEdgeIds();
}
/**
* @see com.c2kernel.graph.model.Vertex#getOutlinePoints()
*/
@Override
public GraphPoint[] getOutlinePoints()
{
if (!getIsLayoutable())
return null;
return super.getOutlinePoints();
}
public String getPath()
{
if (getName() != null && !getName().equals(""))
return getParent().getPath() + "/" + getName();
return getParent().getPath() + "/" + getID();
}
}
|