Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
FigAssociationEnd |
|
| 1.9166666666666667;1.917 |
1 | /* $Id: FigAssociationEnd.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) 2005-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.Color; | |
42 | import java.awt.Graphics; | |
43 | import java.util.HashSet; | |
44 | import java.util.Set; | |
45 | ||
46 | import org.argouml.notation.NotationProviderFactory2; | |
47 | import org.argouml.uml.diagram.DiagramSettings; | |
48 | import org.tigris.gef.presentation.FigText; | |
49 | ||
50 | /** | |
51 | * Class to display graphics for N-ary association edges (association ends).<p> | |
52 | * | |
53 | * This class represents an association End Fig on a diagram, | |
54 | * i.e. the line between the diamond and a node (like a class). <p> | |
55 | * | |
56 | * The direction of the lines is from the diamond outwards, | |
57 | * hence the destination is the side of the classifier, | |
58 | * where the labels are shown. <p> | |
59 | * | |
60 | * There is no support for arrows indicating navigability. <p> | |
61 | * | |
62 | * Showing qualifiers or aggregation is not permitted | |
63 | * according the UML 1.4.2 standard. | |
64 | * | |
65 | * @author pepargouml@yahoo.es | |
66 | */ | |
67 | public class FigAssociationEnd extends FigEdgeModelElement { | |
68 | ||
69 | /** | |
70 | * Group for the FigTexts concerning the association end. | |
71 | */ | |
72 | private FigAssociationEndAnnotation destGroup; | |
73 | private FigMultiplicity destMult; | |
74 | ||
75 | /** | |
76 | * Construct Fig. | |
77 | * | |
78 | * @param owner owning UML element (i.e. an AssociationEnd) | |
79 | * @param settings rendering settings | |
80 | */ | |
81 | public FigAssociationEnd(Object owner, DiagramSettings settings) { | |
82 | 0 | super(owner, settings); |
83 | ||
84 | 0 | destMult = new FigMultiplicity(owner, settings); |
85 | 0 | addPathItem(destMult, |
86 | new PathItemPlacement(this, destMult, 100, -5, 45, 5)); | |
87 | 0 | ArgoFigUtil.markPosition(this, 100, -5, 45, 5, Color.green); |
88 | ||
89 | 0 | destGroup = new FigAssociationEndAnnotation(this, owner, settings); |
90 | 0 | addPathItem(destGroup, |
91 | new PathItemPlacement(this, destGroup, 100, -5, -45, 5)); | |
92 | 0 | ArgoFigUtil.markPosition(this, 100, -5, -45, 5, Color.blue); |
93 | ||
94 | 0 | setBetweenNearestPoints(true); |
95 | ||
96 | 0 | initializeNotationProvidersInternal(owner); |
97 | 0 | } |
98 | ||
99 | /* | |
100 | * @see org.argouml.uml.diagram.ui.FigEdgeModelElement#getNotationProviderType() | |
101 | */ | |
102 | @Override | |
103 | protected int getNotationProviderType() { | |
104 | 0 | return NotationProviderFactory2.TYPE_ASSOCIATION_END_NAME; |
105 | } | |
106 | ||
107 | @SuppressWarnings("deprecation") | |
108 | @Override | |
109 | protected void initNotationProviders(Object own) { | |
110 | 0 | initializeNotationProvidersInternal(own); |
111 | 0 | } |
112 | ||
113 | @SuppressWarnings("deprecation") | |
114 | private void initializeNotationProvidersInternal(Object own) { | |
115 | 0 | super.initNotationProviders(own); |
116 | 0 | destMult.initNotationProviders(); |
117 | 0 | initNotationArguments(); |
118 | 0 | } |
119 | ||
120 | protected void initNotationArguments() { | |
121 | /* Nothing yet. Later maybe something like: */ | |
122 | // putNotationArgument("showAssociationName", | |
123 | // getSettings().isShowAssociationNames()); | |
124 | 0 | } |
125 | ||
126 | /* | |
127 | * @see org.argouml.uml.diagram.ui.FigEdgeModelElement#updateListeners(java.lang.Object) | |
128 | */ | |
129 | @Override | |
130 | public void updateListeners(Object oldOwner, Object newOwner) { | |
131 | 0 | Set<Object[]> listeners = new HashSet<Object[]>(); |
132 | 0 | if (newOwner != null) { |
133 | 0 | listeners.add(new Object[] {newOwner, |
134 | new String[] {"isAbstract", "remove"} | |
135 | }); | |
136 | } | |
137 | 0 | updateElementListeners(listeners); |
138 | 0 | } |
139 | ||
140 | /* | |
141 | * @see org.argouml.uml.diagram.ui.FigEdgeModelElement#textEdited(org.tigris.gef.presentation.FigText) | |
142 | */ | |
143 | @Override | |
144 | protected void textEdited(FigText ft) { | |
145 | 0 | if (getOwner() == null) { |
146 | 0 | return; |
147 | } | |
148 | 0 | super.textEdited(ft); |
149 | 0 | if (getOwner() == null) { |
150 | 0 | return; |
151 | } | |
152 | 0 | if (ft == destGroup.getRole()) { |
153 | 0 | destGroup.getRole().textEdited(); |
154 | 0 | } else if (ft == destMult) { |
155 | /* The text the user has filled in the textfield is first checked | |
156 | * to see if it's a valid multiplicity. If so then that is the | |
157 | * multiplicity to be set. If not the input is rejected. */ | |
158 | 0 | destMult.textEdited(); |
159 | } | |
160 | 0 | } |
161 | ||
162 | /* | |
163 | * @see org.argouml.uml.diagram.ui.FigEdgeModelElement#textEditStarted(org.tigris.gef.presentation.FigText) | |
164 | */ | |
165 | @Override | |
166 | protected void textEditStarted(FigText ft) { | |
167 | 0 | if (ft == destGroup.getRole()) { |
168 | 0 | destGroup.getRole().textEditStarted(); |
169 | 0 | } else if (ft == destMult) { |
170 | 0 | destMult.textEditStarted(); |
171 | } else { | |
172 | 0 | super.textEditStarted(ft); |
173 | } | |
174 | 0 | } |
175 | ||
176 | @Override | |
177 | public void renderingChanged() { | |
178 | 0 | super.renderingChanged(); |
179 | // Fonts and colors should get updated automatically for contained figs | |
180 | 0 | destMult.renderingChanged(); |
181 | 0 | destGroup.renderingChanged(); |
182 | 0 | initNotationArguments(); |
183 | 0 | } |
184 | ||
185 | @Override | |
186 | protected void updateStereotypeText() { | |
187 | /* There is none... */ | |
188 | 0 | } |
189 | ||
190 | @Override | |
191 | public void paintClarifiers(Graphics g) { | |
192 | 0 | indicateBounds(getNameFig(), g); |
193 | 0 | indicateBounds(destMult, g); |
194 | 0 | indicateBounds(destGroup.getRole(), g); |
195 | 0 | super.paintClarifiers(g); |
196 | 0 | } |
197 | ||
198 | /** | |
199 | * Updates the multiplicity field. | |
200 | */ | |
201 | protected void updateMultiplicity() { | |
202 | 0 | if (getOwner() != null |
203 | && destMult.getOwner() != null) { | |
204 | 0 | destMult.setText(); |
205 | } | |
206 | 0 | } |
207 | ||
208 | /* TODO: Support navigability. | |
209 | * The code below causes and exception in FigAssociationEndAnnotation. */ | |
210 | // @Override | |
211 | // public void paint(Graphics g) { | |
212 | // if (getOwner() == null ) { | |
213 | // LOG.error( | |
214 | // "Trying to paint a FigAssociationEnd without an owner. "); | |
215 | // } else { | |
216 | // applyArrowHeads(); | |
217 | // } | |
218 | // if (getSourceArrowHead() != null) { | |
219 | // getSourceArrowHead().setLineColor(getLineColor()); | |
220 | // } | |
221 | // super.paint(g); | |
222 | // } | |
223 | ||
224 | // /** | |
225 | // * Choose the arrowhead style for each end. <p> | |
226 | // * | |
227 | // * TODO: This is called from paint(). Would it not better | |
228 | // * be called from renderingChanged()? | |
229 | // */ | |
230 | // protected void applyArrowHeads() { | |
231 | // int sourceArrowType = destGroup.getArrowType(); | |
232 | // | |
233 | // if (!getSettings().isShowBidirectionalArrows() | |
234 | // && sourceArrowType > 2) { | |
235 | // sourceArrowType -= 3; | |
236 | // } | |
237 | // | |
238 | // setSourceArrowHead(FigAssociationEndAnnotation | |
239 | // .ARROW_HEADS[sourceArrowType]); | |
240 | // } | |
241 | ||
242 | } |