Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
FigDataType |
|
| 3.3333333333333335;3.333 |
1 | /* $Id: FigDataType.java 17735 2010-01-04 14:49:32Z bobtarling $ | |
2 | ******************************************************************************* | |
3 | * Copyright (c) 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 | * Bob Tarling | |
11 | ******************************************************************************* | |
12 | * | |
13 | * Some portions of this file was previously release using the BSD License: | |
14 | */ | |
15 | // $Id: FigDataType.java 17735 2010-01-04 14:49:32Z bobtarling $ | |
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 java.awt.Rectangle; | |
42 | ||
43 | import org.apache.log4j.Logger; | |
44 | import org.argouml.model.Model; | |
45 | import org.argouml.ui.targetmanager.TargetManager; | |
46 | import org.argouml.uml.diagram.ArgoDiagram; | |
47 | import org.argouml.uml.diagram.DiagramSettings; | |
48 | import org.tigris.gef.base.Selection; | |
49 | import org.tigris.gef.presentation.Fig; | |
50 | ||
51 | /** | |
52 | * Class to display graphics for a UML DataType in a diagram. | |
53 | * (much of this code is cloned from FigInterface - perhaps we need | |
54 | * a more generic class provide this common code). | |
55 | * <p> | |
56 | * A DataType shows a keyword, a name, stereotypes and | |
57 | * an operations compartment. Attributes are not supported | |
58 | * in ArgoUML. <p> | |
59 | * | |
60 | * Every DataType shows a keyword, but it is not | |
61 | * always <<datatype>>, e.g. for an Enumeration. <p> | |
62 | * | |
63 | * There is no need for a specific minimal width for this Fig, | |
64 | * since its width will most of the time be determined by the keyword.<p> | |
65 | * | |
66 | * This Fig supports a compartment for operations at the bottom. | |
67 | * Other compartments may be added above it by specializations | |
68 | * of the DataType Fig by overriding the addExtraCompartments() method. | |
69 | */ | |
70 | public class FigDataType extends FigClassifierBox { | |
71 | ||
72 | 0 | private static final Logger LOG = Logger.getLogger(FigDataType.class); |
73 | ||
74 | private void constructFigs(Rectangle bounds) { | |
75 | 0 | enableSizeChecking(false); |
76 | 0 | setSuppressCalcBounds(true); |
77 | ||
78 | 0 | getStereotypeFig().setKeyword(getKeyword()); |
79 | 0 | getStereotypeFig().setVisible(true); |
80 | /* The next line is needed so that we have the right dimension | |
81 | * when drawing this Fig on the diagram by pressing down | |
82 | * the mouse button, even before releasing the mouse button: */ | |
83 | 0 | getNameFig().setTopMargin( |
84 | getStereotypeFig().getMinimumSize().height); | |
85 | ||
86 | 0 | addFig(getBigPort()); |
87 | 0 | addFig(getNameFig()); |
88 | 0 | addFig(getStereotypeFig()); |
89 | 0 | addExtraCompartments(); |
90 | 0 | addFig(getOperationsFig()); |
91 | ||
92 | // Make all the parts match the main fig | |
93 | 0 | setFilled(true); |
94 | 0 | setFillColor(FILL_COLOR); |
95 | 0 | setLineColor(LINE_COLOR); |
96 | 0 | setLineWidth(LINE_WIDTH); |
97 | ||
98 | /* Set the drop location in the case of D&D: */ | |
99 | 0 | if (bounds != null) { |
100 | 0 | setLocation(bounds.x, bounds.y); |
101 | } | |
102 | ||
103 | 0 | setSuppressCalcBounds(false); |
104 | ||
105 | 0 | setBounds(getBounds()); |
106 | 0 | enableSizeChecking(true); |
107 | 0 | } |
108 | ||
109 | protected void addExtraCompartments() { | |
110 | /* Do nothing by default. */ | |
111 | 0 | } |
112 | ||
113 | /** | |
114 | * Primary constructor for a {@link FigDataType}. | |
115 | * | |
116 | * Parent {@link org.argouml.uml.diagram.ui.FigNodeModelElement} | |
117 | * will have created the main box {@link #getBigPort()} and | |
118 | * its name {@link #getNameFig()} and stereotype | |
119 | * (@link #getStereotypeFig()}. The FigClassifierBox | |
120 | * created a box for the operations.<p> | |
121 | * | |
122 | * The properties of all these graphic elements are adjusted | |
123 | * appropriately. | |
124 | * | |
125 | * @param owner owning UML element | |
126 | * @param bounds position and size | |
127 | * @param settings render settings | |
128 | */ | |
129 | public FigDataType(Object owner, Rectangle bounds, | |
130 | DiagramSettings settings) { | |
131 | 0 | super(owner, bounds, settings); |
132 | 0 | constructFigs(bounds); |
133 | 0 | } |
134 | ||
135 | /** | |
136 | * This function shall return the keyword to be used by the constructor. <p> | |
137 | * | |
138 | * Subclasses of DataType shall | |
139 | * override this method to set their own keyword. | |
140 | * | |
141 | * @return the string to be used as the keyword | |
142 | */ | |
143 | protected String getKeyword() { | |
144 | 0 | return "datatype"; |
145 | } | |
146 | ||
147 | @Override | |
148 | public Selection makeSelection() { | |
149 | 0 | return new SelectionDataType(this); |
150 | } | |
151 | ||
152 | @Override | |
153 | public void setEnclosingFig(Fig encloser) { | |
154 | 0 | Fig oldEncloser = getEnclosingFig(); |
155 | ||
156 | 0 | if (encloser == null |
157 | || (encloser != null | |
158 | && !Model.getFacade().isAInstance(encloser.getOwner()))) { | |
159 | 0 | super.setEnclosingFig(encloser); |
160 | } | |
161 | 0 | if (!(Model.getFacade().isAUMLElement(getOwner()))) { |
162 | 0 | return; |
163 | } | |
164 | /* If this fig is not visible, do not adapt the UML model! | |
165 | * This is used for deleting. See issue 3042. | |
166 | */ | |
167 | 0 | if (!isVisible()) { |
168 | 0 | return; |
169 | } | |
170 | 0 | Object me = getOwner(); |
171 | 0 | Object m = null; |
172 | ||
173 | try { | |
174 | // If moved into an Package | |
175 | 0 | if (encloser != null |
176 | && oldEncloser != encloser | |
177 | && Model.getFacade().isAPackage(encloser.getOwner())) { | |
178 | 0 | Model.getCoreHelper().setNamespace(me, encloser.getOwner()); |
179 | } | |
180 | ||
181 | // If default Namespace is not already set | |
182 | 0 | if (Model.getFacade().getNamespace(me) == null |
183 | && (TargetManager.getInstance().getTarget() | |
184 | instanceof ArgoDiagram)) { | |
185 | 0 | m = |
186 | ((ArgoDiagram) TargetManager.getInstance().getTarget()) | |
187 | .getNamespace(); | |
188 | 0 | Model.getCoreHelper().setNamespace(me, m); |
189 | } | |
190 | 0 | } catch (Exception e) { |
191 | 0 | LOG.error("could not set package due to:" + e |
192 | + "' at " + encloser, e); | |
193 | 0 | } |
194 | ||
195 | 0 | } |
196 | ||
197 | } |