|
1 |
| |
|
2 |
| |
|
3 |
| |
|
4 |
| |
|
5 |
| |
|
6 |
| |
|
7 |
| |
|
8 |
| |
|
9 |
| |
|
10 |
| |
|
11 |
| |
|
12 |
| |
|
13 |
| |
|
14 |
| |
|
15 |
| |
|
16 |
| |
|
17 |
| |
|
18 |
| package org.ericmignot.modeler.data; |
|
19 |
| |
|
20 |
| import java.awt.Point; |
|
21 |
| import java.util.ArrayList; |
|
22 |
| |
|
23 |
| import org.ericmignot.modeler.helpers.data.DefaultBusinessObject; |
|
24 |
| |
|
25 |
| |
|
26 |
| |
|
27 |
| |
|
28 |
| |
|
29 |
| |
|
30 |
| public class Link extends DefaultBusinessObject |
|
31 |
| { |
|
32 |
| public static final String FIELD_LABEL = "Label"; |
|
33 |
| public static final String REFERENCE_START = "Start"; |
|
34 |
| public static final String REFERENCE_END = "End"; |
|
35 |
| public static final String FIELD_POINTS = "Points"; |
|
36 |
| |
|
37 |
| private String label; |
|
38 |
| protected ArrayList points; |
|
39 |
| |
|
40 |
197
| public Link()
|
|
41 |
| { |
|
42 |
197
| this(-1, null, null);
|
|
43 |
| } |
|
44 |
| |
|
45 |
197
| public Link(long id, BusinessObject linkStart, BusinessObject linkEnd)
|
|
46 |
| { |
|
47 |
197
| super();
|
|
48 |
197
| this.setId(id);
|
|
49 |
197
| this.setLabel(null);
|
|
50 |
197
| this.setLinkStart(linkStart);
|
|
51 |
197
| this.setLinkEnd(linkEnd);
|
|
52 |
197
| this.points = new ArrayList();
|
|
53 |
| } |
|
54 |
| |
|
55 |
222
| public String getLabel()
|
|
56 |
| { |
|
57 |
222
| return this.label;
|
|
58 |
| } |
|
59 |
207
| public void setLabel(String label)
|
|
60 |
| { |
|
61 |
207
| this.label = label;
|
|
62 |
207
| fireUpdated();
|
|
63 |
| } |
|
64 |
| |
|
65 |
0
| public void resetPoints()
|
|
66 |
| { |
|
67 |
0
| this.points = new ArrayList();
|
|
68 |
| } |
|
69 |
83
| public Point[] getPoints()
|
|
70 |
| { |
|
71 |
83
| return (Point[]) this.points.toArray(new Point[0]);
|
|
72 |
| } |
|
73 |
9
| public String getPointsAsString()
|
|
74 |
| { |
|
75 |
2
| if (this.points.size()==0) return null;
|
|
76 |
| |
|
77 |
7
| String toReturn = "";
|
|
78 |
7
| for (int i = 0 ; i <this.points.size(); i++)
|
|
79 |
| { |
|
80 |
12
| Point p = (Point) this.points.get(i);
|
|
81 |
12
| toReturn += "(" + p.x + "," + p.y + ")";
|
|
82 |
| } |
|
83 |
7
| return toReturn;
|
|
84 |
| } |
|
85 |
| |
|
86 |
| |
|
87 |
| |
|
88 |
| |
|
89 |
4
| public void setPoints(String points)
|
|
90 |
| { |
|
91 |
4
| String tmp = points;
|
|
92 |
4
| while (!tmp.equalsIgnoreCase(""))
|
|
93 |
| { |
|
94 |
6
| Point p = Link.buildPoint(tmp.substring(0, 1+tmp.indexOf(")")));
|
|
95 |
6
| this.addPoint(p);
|
|
96 |
6
| tmp = tmp.substring(1+tmp.indexOf(")"));
|
|
97 |
| } |
|
98 |
| } |
|
99 |
| |
|
100 |
| |
|
101 |
| |
|
102 |
| |
|
103 |
| |
|
104 |
7
| public static Point buildPoint (String point)
|
|
105 |
| { |
|
106 |
7
| if (point.indexOf("(") == -1
|
|
107 |
| || point.indexOf(",") == -1 |
|
108 |
| || point.indexOf(")") == -1 |
|
109 |
| ) |
|
110 |
| { |
|
111 |
0
| throw new RuntimeException ("Bad format : " + point);
|
|
112 |
| } |
|
113 |
7
| int x = Integer.parseInt(point.substring(1, point.indexOf(",")));
|
|
114 |
7
| int y = Integer.parseInt(point.substring(1+point.indexOf(","), point.indexOf(")")));
|
|
115 |
7
| return new Point(x, y);
|
|
116 |
| } |
|
117 |
36
| public void addPoint(Point p)
|
|
118 |
| { |
|
119 |
36
| this.points.add(p);
|
|
120 |
| } |
|
121 |
8
| public void removePoint(Point p)
|
|
122 |
| { |
|
123 |
8
| this.points.remove(p);
|
|
124 |
| } |
|
125 |
| |
|
126 |
3
| public String[] getFieldNames()
|
|
127 |
| { |
|
128 |
3
| return new String[]
|
|
129 |
| { |
|
130 |
| FIELD_ID, |
|
131 |
| FIELD_LABEL |
|
132 |
| }; |
|
133 |
| } |
|
134 |
| |
|
135 |
13
| public boolean setFieldValue(String fieldName, String fieldValue)
|
|
136 |
| { |
|
137 |
13
| if (FIELD_LABEL.equalsIgnoreCase(fieldName))
|
|
138 |
| { |
|
139 |
4
| this.setLabel(fieldValue);
|
|
140 |
4
| return true;
|
|
141 |
| } |
|
142 |
9
| if (FIELD_POINTS.equalsIgnoreCase(fieldName))
|
|
143 |
| { |
|
144 |
2
| this.setPoints(fieldValue);
|
|
145 |
2
| return true;
|
|
146 |
| } |
|
147 |
7
| return super.setFieldValue(fieldName, fieldValue);
|
|
148 |
| } |
|
149 |
11
| public String getFieldValue(String fieldName)
|
|
150 |
| { |
|
151 |
11
| if (FIELD_LABEL.equalsIgnoreCase(fieldName))
|
|
152 |
| { |
|
153 |
6
| return this.getLabel();
|
|
154 |
| } |
|
155 |
5
| if (FIELD_POINTS.equalsIgnoreCase(fieldName))
|
|
156 |
| { |
|
157 |
3
| return this.getPointsAsString();
|
|
158 |
| } |
|
159 |
2
| return super.getFieldValue(fieldName);
|
|
160 |
| } |
|
161 |
| |
|
162 |
| |
|
163 |
805
| public BusinessObject getLinkStart()
|
|
164 |
| { |
|
165 |
805
| return this.getReference(Link.REFERENCE_START);
|
|
166 |
| } |
|
167 |
| |
|
168 |
496
| public BusinessObject getLinkEnd()
|
|
169 |
| { |
|
170 |
496
| return this.getReference(Link.REFERENCE_END);
|
|
171 |
| } |
|
172 |
| |
|
173 |
352
| public void setLinkEnd(BusinessObject linkEnd)
|
|
174 |
| { |
|
175 |
352
| this.setReference(Link.REFERENCE_END, linkEnd);
|
|
176 |
352
| this.fireUpdated();
|
|
177 |
| } |
|
178 |
| |
|
179 |
330
| public void setLinkStart(BusinessObject linkStart)
|
|
180 |
| { |
|
181 |
330
| this.setReference(Link.REFERENCE_START, linkStart);
|
|
182 |
330
| this.fireUpdated();
|
|
183 |
| } |
|
184 |
| |
|
185 |
5
| public String getParamsXML()
|
|
186 |
| { |
|
187 |
5
| String toReturn =
|
|
188 |
| "<Param Name='Id' Value='" + this.getId() + "' />"; |
|
189 |
5
| if (this.getLabel() != null)
|
|
190 |
| { |
|
191 |
0
| toReturn +=
|
|
192 |
| "<Param Name='Label' Value='" + this.getLabel() + "' />"; |
|
193 |
| } |
|
194 |
5
| if (this.points.size() > 0)
|
|
195 |
| { |
|
196 |
1
| toReturn +=
|
|
197 |
| "<Param Name='Points' Value='" + this.getFieldValue(Link.FIELD_POINTS) + "' />"; |
|
198 |
| } |
|
199 |
5
| return toReturn;
|
|
200 |
| } |
|
201 |
5
| public String getReferencesXML()
|
|
202 |
| { |
|
203 |
5
| String toReturn = "";
|
|
204 |
5
| if (this.getLinkStart() != null)
|
|
205 |
| { |
|
206 |
3
| toReturn +=
|
|
207 |
| "<Reference Name='Start' Type='"+ this.getLinkStart().getClass().getName() +"' Id='" + this.getLinkStart().getId() + "' />"; |
|
208 |
| } |
|
209 |
5
| if (this.getLinkEnd() != null)
|
|
210 |
| { |
|
211 |
3
| toReturn +=
|
|
212 |
| "<Reference Name='End' Type='"+ this.getLinkEnd().getClass().getName() +"' Id='" + this.getLinkEnd().getId() + "' />"; |
|
213 |
| } |
|
214 |
5
| return toReturn;
|
|
215 |
| } |
|
216 |
| |
|
217 |
3
| public String getReferenceEndXML()
|
|
218 |
| { |
|
219 |
3
| String toReturn = "";
|
|
220 |
3
| if (this.getLinkEnd() != null)
|
|
221 |
| { |
|
222 |
3
| toReturn +=
|
|
223 |
| "<Reference Name='End' Type='"+ this.getLinkEnd().getClass().getName() +"' Id='" + this.getLinkEnd().getId() + "' />"; |
|
224 |
| } |
|
225 |
3
| return toReturn;
|
|
226 |
| } |
|
227 |
| } |