Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
FigLink |
|
| 2.7142857142857144;2.714 |
1 | /* $Id: FigLink.java 18534 2010-07-19 14:53:25Z bobtarling $ | |
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.static_structure.ui; | |
40 | ||
41 | import org.argouml.model.Model; | |
42 | import org.argouml.uml.diagram.DiagramSettings; | |
43 | import org.argouml.uml.diagram.ui.FigEdgeModelElement; | |
44 | import org.argouml.uml.diagram.ui.FigTextGroup; | |
45 | import org.argouml.uml.diagram.ui.PathItemPlacement; | |
46 | import org.tigris.gef.presentation.Fig; | |
47 | ||
48 | /** | |
49 | * Class to display graphics for a UML Link in a diagram. <p> | |
50 | * | |
51 | * The underlined association name is shown next to the middle of the path. | |
52 | * | |
53 | * TODO: Show more notation as described in the standard: | |
54 | * "A rolename may be shown at each end of the link. An association | |
55 | * name may be shown near the path. If present, it is underlined | |
56 | * to indicate an instance. Links do not have instance names, | |
57 | * they take their identity from the instances that they relate. | |
58 | * Multiplicity is not shown for links because they are instances. | |
59 | * Other association adornments (aggregation, composition, | |
60 | * navigation) may be shown on the link ends." | |
61 | */ | |
62 | public class FigLink extends FigEdgeModelElement { | |
63 | ||
64 | /* | |
65 | * Text group to contain name & stereotype | |
66 | */ | |
67 | private FigTextGroup middleGroup; | |
68 | ||
69 | private void initialize() { | |
70 | 0 | middleGroup.addFig(getNameFig()); |
71 | 0 | middleGroup.addFig(getStereotypeFig()); |
72 | 0 | addPathItem(middleGroup, |
73 | new PathItemPlacement(this, middleGroup, 50, 25)); | |
74 | 0 | getNameFig().setUnderline(true); |
75 | 0 | getFig().setLineColor(LINE_COLOR); |
76 | 0 | setBetweenNearestPoints(true); |
77 | 0 | } |
78 | ||
79 | /** | |
80 | * Create a Fig representing a Link | |
81 | * | |
82 | * @param element owning UML element | |
83 | * @param settings render settings | |
84 | */ | |
85 | public FigLink(Object element, DiagramSettings settings) { | |
86 | 0 | super(element, settings); |
87 | 0 | middleGroup = new FigTextGroup(element, settings); |
88 | 0 | initialize(); |
89 | 0 | } |
90 | ||
91 | /* | |
92 | * Nothing is editable, since a Link takes its identity | |
93 | * from the Association. | |
94 | * | |
95 | * @see org.argouml.uml.diagram.ui.FigEdgeModelElement#canEdit( | |
96 | * org.tigris.gef.presentation.Fig) | |
97 | */ | |
98 | 0 | protected boolean canEdit(Fig f) { return false; } |
99 | ||
100 | /* | |
101 | * Listen also to the association, of which the link is an instantiation, | |
102 | * since we want to update the rendering when | |
103 | * the association name changes. | |
104 | * | |
105 | * @see org.argouml.uml.diagram.ui.FigEdgeModelElement#updateListeners( | |
106 | * java.lang.Object, java.lang.Object) | |
107 | */ | |
108 | protected void updateListeners(Object oldOwner, Object newOwner) { | |
109 | 0 | if (oldOwner != null) { |
110 | 0 | removeElementListener(oldOwner); |
111 | 0 | Object oldAssociation = Model.getFacade().getAssociation(oldOwner); |
112 | 0 | if (oldAssociation != null) { |
113 | 0 | removeElementListener(oldAssociation); |
114 | } | |
115 | } | |
116 | 0 | if (newOwner != null) { |
117 | 0 | addElementListener(newOwner, |
118 | new String[] {"remove", "name", "association"}); | |
119 | 0 | Object newAssociation = Model.getFacade().getAssociation(newOwner); |
120 | 0 | if (newAssociation != null) { |
121 | 0 | addElementListener(newAssociation, "name"); |
122 | } | |
123 | } | |
124 | 0 | } |
125 | ||
126 | /** | |
127 | * Generate the notation for the modelelement and stuff it into the text Fig | |
128 | */ | |
129 | protected void updateNameText() { | |
130 | 0 | if (getOwner() == null) { |
131 | 0 | return; |
132 | } | |
133 | 0 | String nameString = ""; |
134 | 0 | Object association = Model.getFacade().getAssociation(getOwner()); |
135 | 0 | if (association != null) { |
136 | 0 | nameString = Model.getFacade().getName(association); |
137 | 0 | if (nameString == null) { |
138 | 0 | nameString = ""; |
139 | } | |
140 | } | |
141 | 0 | getNameFig().setText(nameString); |
142 | 0 | calcBounds(); |
143 | 0 | setBounds(getBounds()); |
144 | 0 | } |
145 | ||
146 | /* | |
147 | * @see org.argouml.uml.diagram.ui.FigEdgeModelElement#getDestination() | |
148 | */ | |
149 | protected Object getDestination() { | |
150 | 0 | if (getOwner() != null) { |
151 | 0 | return Model.getCommonBehaviorHelper().getDestination(getOwner()); |
152 | } | |
153 | 0 | return null; |
154 | } | |
155 | ||
156 | /* | |
157 | * @see org.argouml.uml.diagram.ui.FigEdgeModelElement#getSource() | |
158 | */ | |
159 | protected Object getSource() { | |
160 | 0 | if (getOwner() != null) { |
161 | 0 | return Model.getCommonBehaviorHelper().getSource(getOwner()); |
162 | } | |
163 | 0 | return null; |
164 | } | |
165 | ||
166 | } /* end class FigLink */ |