Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
SelectionGeneralizableElement |
|
| 2.2857142857142856;2.286 |
1 | /* $Id: SelectionGeneralizableElement.java 17864 2010-01-12 20:11: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) 2007-2008 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.event.MouseEvent; | |
42 | ||
43 | import javax.swing.Icon; | |
44 | ||
45 | import org.argouml.application.helpers.ResourceLoaderWrapper; | |
46 | import org.argouml.model.Model; | |
47 | import org.argouml.uml.diagram.deployment.DeploymentDiagramGraphModel; | |
48 | import org.argouml.uml.diagram.ui.SelectionNodeClarifiers2; | |
49 | import org.tigris.gef.base.Editor; | |
50 | import org.tigris.gef.base.Globals; | |
51 | import org.tigris.gef.graph.GraphModel; | |
52 | import org.tigris.gef.presentation.Fig; | |
53 | ||
54 | /** | |
55 | * Buttons for a selected GeneralizableElement. | |
56 | * | |
57 | * @author Tom Morris | |
58 | */ | |
59 | public abstract class SelectionGeneralizableElement extends | |
60 | SelectionNodeClarifiers2 { | |
61 | ||
62 | 0 | private static Icon inherit = |
63 | ResourceLoaderWrapper.lookupIconResource("Generalization"); | |
64 | ||
65 | 0 | private static Icon[] icons = |
66 | {inherit, | |
67 | inherit, | |
68 | null, | |
69 | null, | |
70 | null, | |
71 | }; | |
72 | ||
73 | 0 | private static String[] instructions = |
74 | {"Add a supertype", | |
75 | "Add a subtype", | |
76 | null, | |
77 | null, | |
78 | null, | |
79 | "Move object(s)", | |
80 | }; | |
81 | ||
82 | ||
83 | private boolean useComposite; | |
84 | ||
85 | /** | |
86 | * Construct a SelectionGeneralizableElement | |
87 | * | |
88 | * @param f | |
89 | * Fig for which to construct the selection object | |
90 | */ | |
91 | public SelectionGeneralizableElement(Fig f) { | |
92 | 0 | super(f); |
93 | 0 | } |
94 | ||
95 | @Override | |
96 | protected Icon[] getIcons() { | |
97 | 0 | Editor ce = Globals.curEditor(); |
98 | 0 | GraphModel gm = ce.getGraphModel(); |
99 | ||
100 | // No generalizations in Deployment Diagrams | |
101 | 0 | if (gm instanceof DeploymentDiagramGraphModel) { |
102 | 0 | return null; |
103 | } | |
104 | 0 | if (Model.getModelManagementHelper().isReadOnly( |
105 | getContent().getOwner())) { | |
106 | 0 | return new Icon[] {null, inherit, null, null, null }; |
107 | } | |
108 | 0 | return icons; |
109 | } | |
110 | ||
111 | @Override | |
112 | protected String getInstructions(int i) { | |
113 | 0 | return instructions[ i - BASE]; |
114 | } | |
115 | ||
116 | @Override | |
117 | protected Object getNewEdgeType(int i) { | |
118 | 0 | if (i == TOP || i == BOTTOM) { |
119 | 0 | return Model.getMetaTypes().getGeneralization(); |
120 | } | |
121 | 0 | return null; |
122 | } | |
123 | ||
124 | @Override | |
125 | protected boolean isReverseEdge(int i) { | |
126 | 0 | if (i == BOTTOM) { |
127 | 0 | return true; |
128 | } | |
129 | 0 | return false; |
130 | } | |
131 | ||
132 | @Override | |
133 | protected boolean isEdgePostProcessRequested() { | |
134 | 0 | return useComposite; |
135 | } | |
136 | ||
137 | @Override | |
138 | public void mouseEntered(MouseEvent me) { | |
139 | 0 | super.mouseEntered(me); |
140 | 0 | useComposite = me.isShiftDown(); |
141 | 0 | } |
142 | ||
143 | } |