Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
FigEdgeAssociationClass |
|
| 2.7;2.7 |
1 | /* $Id: FigEdgeAssociationClass.java 17865 2010-01-12 20:45:26Z linus $ | |
2 | ***************************************************************************** | |
3 | * Copyright (c) 2009 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 | * mvw | |
11 | ***************************************************************************** | |
12 | * | |
13 | * Some portions of this file was previously release using the BSD License: | |
14 | */ | |
15 | ||
16 | // Copyright (c) 1996-2009 The Regents of the University of California. All | |
17 | // Rights Reserved. Permission to use, copy, modify, and distribute this | |
18 | // software and its documentation without fee, and without a written | |
19 | // agreement is hereby granted, provided that the above copyright notice | |
20 | // and this paragraph appear in all copies. This software program and | |
21 | // documentation are copyrighted by The Regents of the University of | |
22 | // California. The software program and documentation are supplied "AS | |
23 | // IS", without any accompanying services from The Regents. The Regents | |
24 | // does not warrant that the operation of the program will be | |
25 | // uninterrupted or error-free. The end-user understands that the program | |
26 | // was developed for research purposes and is advised not to rely | |
27 | // exclusively on the program for any reason. IN NO EVENT SHALL THE | |
28 | // UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, | |
29 | // SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, | |
30 | // ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF | |
31 | // THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF | |
32 | // SUCH DAMAGE. THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY | |
33 | // WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF | |
34 | // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE | |
35 | // PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF | |
36 | // CALIFORNIA HAS NO OBLIGATIONS TO PROVIDE MAINTENANCE, SUPPORT, | |
37 | // UPDATES, ENHANCEMENTS, OR MODIFICATIONS. | |
38 | ||
39 | package org.argouml.uml.diagram.ui; | |
40 | ||
41 | import java.awt.event.KeyListener; | |
42 | import java.awt.event.MouseListener; | |
43 | import java.beans.PropertyChangeEvent; | |
44 | import java.beans.PropertyChangeListener; | |
45 | import java.beans.VetoableChangeListener; | |
46 | ||
47 | import org.apache.log4j.Logger; | |
48 | import org.argouml.kernel.DelayedVChangeListener; | |
49 | import org.argouml.uml.diagram.DiagramSettings; | |
50 | import org.tigris.gef.presentation.Fig; | |
51 | import org.tigris.gef.presentation.FigNode; | |
52 | ||
53 | ||
54 | /** | |
55 | * Class to display the dashed line connecting the class box figure and the | |
56 | * association line pieces of a composite Association Class group. This should | |
57 | * not be confused with the primary edge that forms the Association. That is | |
58 | * {@link FigAssociationClass}. | |
59 | * <em>NOTE:</em> It must be used only from a FigAssociationClass. | |
60 | * | |
61 | * @author pepargouml | |
62 | */ | |
63 | public class FigEdgeAssociationClass | |
64 | extends FigEdgeModelElement | |
65 | implements VetoableChangeListener, | |
66 | DelayedVChangeListener, | |
67 | MouseListener, | |
68 | KeyListener, | |
69 | PropertyChangeListener { | |
70 | ||
71 | /** | |
72 | * Serial version generated by Eclipse for rev 1.9 | |
73 | */ | |
74 | private static final long serialVersionUID = 4627163341288968877L; | |
75 | ||
76 | 0 | private static final Logger LOG = |
77 | Logger.getLogger(FigEdgeAssociationClass.class); | |
78 | ||
79 | private void constructFigs(FigClassAssociationClass classBoxFig, | |
80 | Fig ownerFig) { | |
81 | 0 | LOG.info("FigEdgeAssociationClass constructor"); |
82 | 0 | if (classBoxFig == null) { |
83 | 0 | throw new IllegalArgumentException("No class box found while " |
84 | + "creating FigEdgeAssociationClass"); | |
85 | } | |
86 | 0 | if (ownerFig == null) { |
87 | 0 | throw new IllegalArgumentException("No association edge found " |
88 | + "while creating FigEdgeAssociationClass"); | |
89 | } | |
90 | 0 | setDestFigNode(classBoxFig); |
91 | 0 | setDestPortFig(classBoxFig); |
92 | final FigNode port; | |
93 | 0 | if (ownerFig instanceof FigEdgeModelElement) { |
94 | 0 | ((FigEdgeModelElement) ownerFig).makeEdgePort(); |
95 | 0 | port = ((FigEdgeModelElement) ownerFig).getEdgePort(); |
96 | } else { | |
97 | 0 | port = (FigNode) ownerFig; |
98 | } | |
99 | 0 | setSourcePortFig(port); |
100 | 0 | setSourceFigNode(port); |
101 | 0 | computeRoute(); |
102 | 0 | } |
103 | ||
104 | /** | |
105 | * The constructor for the AssociationClass fig. | |
106 | * | |
107 | * @param classBoxFig the figure representing the Class | |
108 | * @param ownerFig the owner fig | |
109 | * @param settings render settings | |
110 | */ | |
111 | FigEdgeAssociationClass(FigClassAssociationClass classBoxFig, | |
112 | FigAssociationClass ownerFig, DiagramSettings settings) { | |
113 | 0 | super(ownerFig.getOwner(), settings); |
114 | 0 | constructFigs(classBoxFig, ownerFig); |
115 | 0 | } |
116 | ||
117 | /** | |
118 | * The constructor for the AssociationClass fig. | |
119 | * | |
120 | * @param classBoxFig the figure representing the Class | |
121 | * @param ownerFig the owner fig | |
122 | * @param settings render settings | |
123 | */ | |
124 | public FigEdgeAssociationClass(FigClassAssociationClass classBoxFig, | |
125 | FigNodeAssociation ownerFig, DiagramSettings settings) { | |
126 | 0 | super(ownerFig.getOwner(), settings); |
127 | 0 | constructFigs(classBoxFig, ownerFig); |
128 | 0 | } |
129 | ||
130 | /** | |
131 | * @param owner the owner | |
132 | * @param settings the render settings | |
133 | */ | |
134 | public FigEdgeAssociationClass(Object owner, | |
135 | DiagramSettings settings) { | |
136 | 0 | super(owner, settings); |
137 | 0 | setBetweenNearestPoints(true); |
138 | 0 | } |
139 | ||
140 | /* | |
141 | * @see org.tigris.gef.presentation.FigEdge#setFig(org.tigris.gef.presentation.Fig) | |
142 | */ | |
143 | @Override | |
144 | public void setFig(Fig f) { | |
145 | 0 | super.setFig(f); |
146 | 0 | getFig().setDashed(true); |
147 | 0 | } |
148 | ||
149 | /* | |
150 | * @see org.argouml.uml.diagram.ui.FigEdgeModelElement#canEdit(org.tigris.gef.presentation.Fig) | |
151 | */ | |
152 | @Override | |
153 | protected boolean canEdit(Fig f) { | |
154 | 0 | return false; |
155 | } | |
156 | ||
157 | /* | |
158 | * @see org.argouml.uml.diagram.ui.FigEdgeModelElement#modelChanged(java.beans.PropertyChangeEvent) | |
159 | */ | |
160 | @Override | |
161 | protected void modelChanged(PropertyChangeEvent e) { | |
162 | // TODO: are we intentionally eating all events? - tfm 20060203 | |
163 | // document! | |
164 | 0 | } |
165 | ||
166 | /** | |
167 | * If the user requests deletion of this Fig then delegate to the attached | |
168 | * FigAssociationClass. | |
169 | * @return the attached FigAssociationClass | |
170 | */ | |
171 | @Override | |
172 | protected Fig getRemoveDelegate() { | |
173 | 0 | FigNode node = getDestFigNode(); |
174 | 0 | if (!(node instanceof FigEdgePort || node instanceof FigNodeAssociation)) { |
175 | 0 | node = getSourceFigNode(); |
176 | } | |
177 | 0 | if (!(node instanceof FigEdgePort || node instanceof FigNodeAssociation)) { |
178 | 0 | LOG.warn("The is no FigEdgePort attached" |
179 | + " to the association class link"); | |
180 | 0 | return null; |
181 | } | |
182 | ||
183 | final Fig delegate; | |
184 | // Actually return the FigEdge that the FigEdgePort is part of. | |
185 | 0 | if (node instanceof FigEdgePort) { |
186 | 0 | delegate = node.getGroup(); |
187 | } else { | |
188 | 0 | delegate = node; |
189 | } | |
190 | 0 | if (LOG.isInfoEnabled()) { |
191 | 0 | LOG.info("Delegating remove to " + delegate.getClass().getName()); |
192 | // throw new IllegalArgumentException(); | |
193 | } | |
194 | 0 | return delegate; |
195 | } | |
196 | ||
197 | ||
198 | @Override | |
199 | public void setDestFigNode(FigNode fn) { | |
200 | 0 | if (!(fn instanceof FigClassAssociationClass)) { |
201 | 0 | throw new IllegalArgumentException( |
202 | "The dest of an association class dashed link can " | |
203 | + "only be a FigClassAssociationClass"); | |
204 | } | |
205 | 0 | super.setDestFigNode(fn); |
206 | 0 | } |
207 | ||
208 | @Override | |
209 | public void setSourceFigNode(FigNode fn) { | |
210 | 0 | if (!(fn instanceof FigEdgePort || fn instanceof FigNodeAssociation)) { |
211 | 0 | throw new IllegalArgumentException( |
212 | "The source of an association class dashed link can " | |
213 | + "only be a FigEdgePort"); | |
214 | } | |
215 | 0 | super.setSourceFigNode(fn); |
216 | 0 | } |
217 | ||
218 | } |