Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
FigEdgeNote |
|
| 2.0476190476190474;2.048 |
1 | /* $Id: FigEdgeNote.java 18729 2010-09-10 16:10:34Z bobtarling $ | |
2 | ***************************************************************************** | |
3 | * Copyright (c) 2009-2010 Contributors - see below | |
4 | * All rights reserved. This program and the accompanying materials | |
5 | * are made available under the terms of the Eclipse Public License v1.0 | |
6 | * which accompanies this distribution, and is available at | |
7 | * http://www.eclipse.org/legal/epl-v10.html | |
8 | * | |
9 | * Contributors: | |
10 | * Tom Morris | |
11 | * Bob Tarling | |
12 | ***************************************************************************** | |
13 | * | |
14 | * Some portions of this file was previously release using the BSD License: | |
15 | */ | |
16 | ||
17 | // Copyright (c) 1996-2007 The Regents of the University of California. All | |
18 | // Rights Reserved. Permission to use, copy, modify, and distribute this | |
19 | // software and its documentation without fee, and without a written | |
20 | // agreement is hereby granted, provided that the above copyright notice | |
21 | // and this paragraph appear in all copies. This software program and | |
22 | // documentation are copyrighted by The Regents of the University of | |
23 | // California. The software program and documentation are supplied "AS | |
24 | // IS", without any accompanying services from The Regents. The Regents | |
25 | // does not warrant that the operation of the program will be | |
26 | // uninterrupted or error-free. The end-user understands that the program | |
27 | // was developed for research purposes and is advised not to rely | |
28 | // exclusively on the program for any reason. IN NO EVENT SHALL THE | |
29 | // UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, | |
30 | // SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, | |
31 | // ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF | |
32 | // THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF | |
33 | // SUCH DAMAGE. THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY | |
34 | // WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF | |
35 | // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE | |
36 | // PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF | |
37 | // CALIFORNIA HAS NO OBLIGATIONS TO PROVIDE MAINTENANCE, SUPPORT, | |
38 | // UPDATES, ENHANCEMENTS, OR MODIFICATIONS. | |
39 | ||
40 | package org.argouml.uml.diagram.static_structure.ui; | |
41 | ||
42 | import java.awt.event.MouseEvent; | |
43 | import java.beans.PropertyChangeEvent; | |
44 | import java.beans.PropertyChangeListener; | |
45 | ||
46 | import org.apache.log4j.Logger; | |
47 | import org.argouml.i18n.Translator; | |
48 | import org.argouml.kernel.Owned; | |
49 | import org.argouml.kernel.Project; | |
50 | import org.argouml.model.Model; | |
51 | import org.argouml.model.RemoveAssociationEvent; | |
52 | import org.argouml.uml.CommentEdge; | |
53 | import org.argouml.uml.diagram.DiagramElement; | |
54 | import org.argouml.uml.diagram.DiagramSettings; | |
55 | import org.argouml.uml.diagram.ui.ArgoFig; | |
56 | import org.argouml.uml.diagram.ui.ArgoFigUtil; | |
57 | import org.argouml.util.IItemUID; | |
58 | import org.argouml.util.ItemUID; | |
59 | import org.tigris.gef.presentation.Fig; | |
60 | import org.tigris.gef.presentation.FigEdgePoly; | |
61 | import org.tigris.gef.presentation.FigNode; | |
62 | ||
63 | /** | |
64 | * Class to display a UML note connection to a annotated model element. | |
65 | * <p> | |
66 | * | |
67 | * The owner of this fig is always a CommentEdge. Because it is different from | |
68 | * most every other FigEdge in ArgoUML, it doesn't subclass FigEdgeModelElement. | |
69 | * | |
70 | * @author Andreas Rueckert a_rueckert@gmx.net | |
71 | * @author jaap.branderhorst@xs4all.nl | |
72 | */ | |
73 | public class FigEdgeNote extends FigEdgePoly | |
74 | implements ArgoFig, DiagramElement, Owned, IItemUID, PropertyChangeListener { | |
75 | ||
76 | 0 | private static final Logger LOG = Logger.getLogger(FigEdgeNote.class); |
77 | ||
78 | private Object comment; | |
79 | private Object annotatedElement; | |
80 | ||
81 | private DiagramSettings settings; | |
82 | ||
83 | private ItemUID itemUid; | |
84 | ||
85 | /** | |
86 | * @param element owning CommentEdge object. This is a special case since it | |
87 | * is not a UML element. | |
88 | * @param theSettings render settings | |
89 | */ | |
90 | public FigEdgeNote(Object element, DiagramSettings theSettings) { | |
91 | // element will normally be null when called from PGML parser | |
92 | // It will get it's source & destination set later in attachEdges | |
93 | 0 | super(); |
94 | 0 | settings = theSettings; |
95 | ||
96 | 0 | if (element != null) { |
97 | 0 | super.setOwner(element); |
98 | } else { | |
99 | 0 | super.setOwner(new CommentEdge()); |
100 | } | |
101 | ||
102 | 0 | setBetweenNearestPoints(true); |
103 | 0 | getFig().setLineWidth(LINE_WIDTH); |
104 | 0 | getFig().setDashed(true); |
105 | ||
106 | // Unfortunately the Fig and it's associated CommentEdge will not be | |
107 | // fully initialized yet here if we're being loaded from a PGML file. | |
108 | // The remainder of the initialization will happen when | |
109 | // set{Dest|Source}FigNode are called from PGMLStackParser.attachEdges() | |
110 | 0 | } |
111 | ||
112 | /* | |
113 | * @see org.tigris.gef.presentation.FigEdge#setFig(org.tigris.gef.presentation.Fig) | |
114 | */ | |
115 | @Override | |
116 | public void setFig(Fig f) { | |
117 | 0 | LOG.info("Setting the internal fig to " + f); |
118 | 0 | super.setFig(f); |
119 | 0 | getFig().setDashed(true); |
120 | 0 | } |
121 | ||
122 | ||
123 | /* | |
124 | * @see java.lang.Object#toString() | |
125 | */ | |
126 | @Override | |
127 | public String toString() { | |
128 | 0 | return Translator.localize("misc.comment-edge"); |
129 | } | |
130 | ||
131 | /* | |
132 | * Listen for a RemoveAssociationEvent between the comment | |
133 | * and the annotated element. When recieved delete the CommentEdge | |
134 | * and this FigEdgeNote. | |
135 | * @see org.argouml.uml.diagram.ui.FigEdgeModelElement#modelChanged(java.beans.PropertyChangeEvent) | |
136 | */ | |
137 | protected void modelChanged(PropertyChangeEvent e) { | |
138 | 0 | if (e instanceof RemoveAssociationEvent |
139 | && e.getOldValue() == annotatedElement) { | |
140 | 0 | removeFromDiagram(); |
141 | } | |
142 | 0 | } |
143 | ||
144 | /* | |
145 | * @see org.tigris.gef.presentation.Fig#getTipString(java.awt.event.MouseEvent) | |
146 | */ | |
147 | @Override | |
148 | public String getTipString(MouseEvent me) { | |
149 | 0 | return "Comment Edge"; // TODO: get tip string from comment |
150 | } | |
151 | ||
152 | ||
153 | /* | |
154 | * @see java.beans.PropertyChangeListener#propertyChange(java.beans.PropertyChangeEvent) | |
155 | */ | |
156 | @Override | |
157 | public void propertyChange(PropertyChangeEvent pve) { | |
158 | 0 | modelChanged(pve); |
159 | 0 | } |
160 | ||
161 | ||
162 | ||
163 | /* | |
164 | * @see org.tigris.gef.presentation.Fig#removeFromDiagram() | |
165 | */ | |
166 | @Override | |
167 | public final void removeFromDiagram() { | |
168 | 0 | Object o = getOwner(); |
169 | 0 | if (o != null) { |
170 | 0 | removeElementListener(o); |
171 | } | |
172 | ||
173 | 0 | super.removeFromDiagram(); |
174 | 0 | damage(); |
175 | 0 | } |
176 | ||
177 | ||
178 | /** | |
179 | * Returns the source of the edge. The source is the owner of the | |
180 | * node the edge travels from in a binary relationship. For | |
181 | * instance: for a classifierrole, this is the sender. | |
182 | * @return MModelElement | |
183 | */ | |
184 | protected Object getSource() { | |
185 | 0 | Object theOwner = getOwner(); |
186 | 0 | if (theOwner != null) { |
187 | 0 | return ((CommentEdge) theOwner).getSource(); |
188 | } | |
189 | 0 | return null; |
190 | } | |
191 | /** | |
192 | * Returns the destination of the edge. The destination is the | |
193 | * owner of the node the edge travels to in a binary | |
194 | * relationship. For instance: for a classifierrole, this is the | |
195 | * receiver. | |
196 | * @return Object | |
197 | */ | |
198 | protected Object getDestination() { | |
199 | 0 | Object theOwner = getOwner(); |
200 | 0 | if (theOwner != null) { |
201 | 0 | return ((CommentEdge) theOwner).getDestination(); |
202 | } | |
203 | 0 | return null; |
204 | } | |
205 | ||
206 | /* | |
207 | * @see org.tigris.gef.presentation.FigEdge#setDestFigNode(org.tigris.gef.presentation.FigNode) | |
208 | */ | |
209 | @Override | |
210 | public void setDestFigNode(FigNode fn) { | |
211 | // When this is called from PGMLStackParser.attachEdges, we finished | |
212 | // the initialization of owning pseudo element (CommentEdge) | |
213 | 0 | if (fn != null && Model.getFacade().isAComment(fn.getOwner())) { |
214 | 0 | Object oldComment = comment; |
215 | 0 | if (oldComment != null) { |
216 | 0 | removeElementListener(oldComment); |
217 | } | |
218 | 0 | comment = fn.getOwner(); |
219 | 0 | if (comment != null) { |
220 | 0 | addElementListener(comment); |
221 | } | |
222 | ||
223 | 0 | ((CommentEdge) getOwner()).setComment(comment); |
224 | 0 | } else if (fn != null |
225 | && !Model.getFacade().isAComment(fn.getOwner())) { | |
226 | 0 | annotatedElement = fn.getOwner(); |
227 | 0 | ((CommentEdge) getOwner()).setAnnotatedElement(annotatedElement); |
228 | } | |
229 | ||
230 | 0 | super.setDestFigNode(fn); |
231 | 0 | } |
232 | ||
233 | /* | |
234 | * @see org.tigris.gef.presentation.FigEdge#setSourceFigNode(org.tigris.gef.presentation.FigNode) | |
235 | */ | |
236 | @Override | |
237 | public void setSourceFigNode(FigNode fn) { | |
238 | // When this is called from PGMLStackParser.attachEdges, we finished | |
239 | // the initialization of owning pseudo element (CommentEdge) | |
240 | 0 | if (fn != null && Model.getFacade().isAComment(fn.getOwner())) { |
241 | 0 | Object oldComment = comment; |
242 | 0 | if (oldComment != null) { |
243 | 0 | removeElementListener(oldComment); |
244 | } | |
245 | 0 | comment = fn.getOwner(); |
246 | 0 | if (comment != null) { |
247 | 0 | addElementListener(comment); |
248 | } | |
249 | 0 | ((CommentEdge) getOwner()).setComment(comment); |
250 | 0 | } else if (fn != null |
251 | && !Model.getFacade().isAComment(fn.getOwner())) { | |
252 | 0 | annotatedElement = fn.getOwner(); |
253 | 0 | ((CommentEdge) getOwner()).setAnnotatedElement(annotatedElement); |
254 | } | |
255 | 0 | super.setSourceFigNode(fn); |
256 | 0 | } |
257 | ||
258 | private void addElementListener(Object element) { | |
259 | 0 | Model.getPump().addModelEventListener(this, element); |
260 | 0 | } |
261 | ||
262 | private void removeElementListener(Object element) { | |
263 | 0 | Model.getPump().removeModelEventListener(this, element); |
264 | 0 | } |
265 | ||
266 | @SuppressWarnings("deprecation") | |
267 | @Deprecated | |
268 | public Project getProject() { | |
269 | 0 | return ArgoFigUtil.getProject(this); |
270 | } | |
271 | ||
272 | public DiagramSettings getSettings() { | |
273 | 0 | return settings; |
274 | } | |
275 | ||
276 | public void renderingChanged() { | |
277 | ||
278 | 0 | } |
279 | ||
280 | @SuppressWarnings("deprecation") | |
281 | @Deprecated | |
282 | public void setProject(Project project) { | |
283 | // unimplemented | |
284 | 0 | } |
285 | ||
286 | public void setSettings(DiagramSettings theSettings) { | |
287 | 0 | settings = theSettings; |
288 | 0 | } |
289 | ||
290 | /** | |
291 | * Setter for the UID | |
292 | * @param newId the new UID | |
293 | */ | |
294 | public void setItemUID(ItemUID newId) { | |
295 | 0 | itemUid = newId; |
296 | 0 | } |
297 | ||
298 | /** | |
299 | * Getter for the UID | |
300 | * @return the UID | |
301 | */ | |
302 | public ItemUID getItemUID() { | |
303 | 0 | return itemUid; |
304 | } | |
305 | ||
306 | ||
307 | /** | |
308 | * Setting the owner of the Fig must be done in the constructor and not | |
309 | * changed afterwards for all ArgoUML figs. | |
310 | * | |
311 | * @param owner owning UML element | |
312 | * @deprecated for 0.27.3 by tfmorris. Set owner in constructor. This method | |
313 | * is implemented in GEF, so we'll leave this implementation | |
314 | * here to block any attempts to use it within ArgoUML. | |
315 | */ | |
316 | @SuppressWarnings("deprecation") | |
317 | @Deprecated | |
318 | public void setOwner(Object owner) { | |
319 | 0 | if (owner != getOwner()) { |
320 | 0 | throw new UnsupportedOperationException( |
321 | "Owner must be set in constructor and left unchanged"); | |
322 | } | |
323 | 0 | } |
324 | ||
325 | } |