|
7 | 7 | import org.w3c.dom.Node; |
8 | 8 | import org.w3c.dom.NodeList; |
9 | 9 |
|
| 10 | +import paintcomponents.annotations.PaintComponentAnnotation; |
10 | 11 | import painttools.tools.SelectTool; |
11 | 12 | import ui.PaintPanel; |
12 | 13 |
|
@@ -38,6 +39,7 @@ public abstract class PaintComponent { |
38 | 39 | static private long UNIQUE_ID = 0; |
39 | 40 | long uid = ++UNIQUE_ID; |
40 | 41 |
|
| 42 | + private PaintComponentAnnotation optionalAnnotation; |
41 | 43 | /** |
42 | 44 | * Get a Unique ID of this component. IDs resets to zero when JVM starts; |
43 | 45 | * |
@@ -95,6 +97,10 @@ public void paint(Graphics g) { |
95 | 97 | paintNotSelected(g); |
96 | 98 | } |
97 | 99 |
|
| 100 | + //paint annotation |
| 101 | + if(optionalAnnotation != null){ |
| 102 | + optionalAnnotation.paint(g); |
| 103 | + } |
98 | 104 | } |
99 | 105 |
|
100 | 106 | /** |
@@ -166,7 +172,11 @@ public boolean isSelected() { |
166 | 172 | public void translate(int i, int j) { |
167 | 173 | this.x += i; |
168 | 174 | this.y += j; |
169 | | - |
| 175 | + |
| 176 | + //if attached component is not null, translate it as well |
| 177 | + if(optionalAnnotation != null){ |
| 178 | + optionalAnnotation.translate(i, j); |
| 179 | + } |
170 | 180 | } |
171 | 181 |
|
172 | 182 | public abstract boolean contains(int x2, int y2); |
@@ -220,4 +230,18 @@ public PaintComponent(Element rootElement, PaintPanel panel) { |
220 | 230 | this.x = Integer.parseInt(pos.getElementsByTagName("xcoordinate").item(0).getTextContent()); |
221 | 231 | this.y = Integer.parseInt(pos.getElementsByTagName("ycoordinate").item(0).getTextContent()); |
222 | 232 | } |
| 233 | + |
| 234 | + /** |
| 235 | + * @return the optionalAnnotation |
| 236 | + */ |
| 237 | + public PaintComponentAnnotation getOptionalAnnotation() { |
| 238 | + return optionalAnnotation; |
| 239 | + } |
| 240 | + |
| 241 | + /** |
| 242 | + * @param optionalAnnotation the optionalAnnotation to set |
| 243 | + */ |
| 244 | + public void setOptionalAnnotation(PaintComponentAnnotation optionalAnnotation) { |
| 245 | + this.optionalAnnotation = optionalAnnotation; |
| 246 | + } |
223 | 247 | } |
0 commit comments