Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
ClAttributeCompartment |
|
| 2.5714285714285716;2.571 |
1 | /* $Id: ClAttributeCompartment.java 17849 2010-01-12 19:50:34Z 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 | * bobtarling | |
11 | ***************************************************************************** | |
12 | * | |
13 | * Some portions of this file was previously release using the BSD License: | |
14 | */ | |
15 | ||
16 | // Copyright (c) 1996-2006 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.cognitive.critics; | |
40 | ||
41 | import java.awt.Color; | |
42 | import java.awt.Component; | |
43 | import java.awt.Graphics; | |
44 | import java.awt.Rectangle; | |
45 | ||
46 | import org.argouml.cognitive.ToDoItem; | |
47 | import org.argouml.model.Model; | |
48 | import org.argouml.ui.Clarifier; | |
49 | import org.argouml.uml.diagram.ui.FigCompartment; | |
50 | import org.argouml.uml.diagram.ui.FigCompartmentBox; | |
51 | import org.tigris.gef.presentation.Fig; | |
52 | ||
53 | /** | |
54 | * Class that represents the clarifier (red wavy line) | |
55 | * for a attribute compartment. | |
56 | * | |
57 | */ | |
58 | 0 | public class ClAttributeCompartment implements Clarifier { |
59 | ||
60 | 0 | private static ClAttributeCompartment theInstance = |
61 | new ClAttributeCompartment(); | |
62 | ||
63 | private static final int WAVE_LENGTH = 4; | |
64 | private static final int WAVE_HEIGHT = 2; | |
65 | ||
66 | //////////////////////////////////////////////////////////////// | |
67 | // instance variables | |
68 | private Fig fig; | |
69 | ||
70 | /* | |
71 | * @see org.argouml.ui.Clarifier#setFig(org.tigris.gef.presentation.Fig) | |
72 | */ | |
73 | 0 | public void setFig(Fig f) { fig = f; } |
74 | ||
75 | /* | |
76 | * @see org.argouml.ui.Clarifier#setToDoItem(org.argouml.cognitive.ToDoItem) | |
77 | */ | |
78 | 0 | public void setToDoItem(ToDoItem i) { } |
79 | ||
80 | /* | |
81 | * @see javax.swing.Icon#paintIcon(java.awt.Component, java.awt.Graphics, | |
82 | * int, int) | |
83 | */ | |
84 | public void paintIcon(Component c, Graphics g, int x, int y) { | |
85 | 0 | final Object modelElement = fig.getOwner(); |
86 | 0 | if (Model.getUmlFactory().isContainmentValid( |
87 | Model.getMetaTypes().getAttribute(), modelElement)) { | |
88 | 0 | FigCompartmentBox fcb = (FigCompartmentBox) fig; |
89 | 0 | FigCompartment fc = |
90 | fcb.getCompartment(Model.getMetaTypes().getAttribute()); | |
91 | ||
92 | // added by Eric Lefevre 13 Mar 1999: we must check if the | |
93 | // FigText for attributes is drawn before drawing things | |
94 | // over it | |
95 | 0 | if (fc == null || !fc.isVisible()) { |
96 | 0 | fig = null; |
97 | 0 | return; |
98 | } | |
99 | ||
100 | 0 | Rectangle fr = fc.getBounds(); |
101 | 0 | int left = fr.x + 6; |
102 | 0 | int height = fr.y + fr.height - 5; |
103 | 0 | int right = fr.x + fr.width - 6; |
104 | 0 | g.setColor(Color.red); |
105 | 0 | int i = left; |
106 | while (true) { | |
107 | 0 | g.drawLine(i, height, i + WAVE_LENGTH, height + WAVE_HEIGHT); |
108 | 0 | i += WAVE_LENGTH; |
109 | 0 | if (i >= right) { |
110 | 0 | break; |
111 | } | |
112 | 0 | g.drawLine(i, height + WAVE_HEIGHT, i + WAVE_LENGTH, height); |
113 | 0 | i += WAVE_LENGTH; |
114 | 0 | if (i >= right) { |
115 | 0 | break; |
116 | } | |
117 | 0 | g.drawLine(i, height, i + WAVE_LENGTH, |
118 | height + WAVE_HEIGHT / 2); | |
119 | 0 | i += WAVE_LENGTH; |
120 | 0 | if (i >= right) { |
121 | 0 | break; |
122 | } | |
123 | 0 | g.drawLine(i, height + WAVE_HEIGHT / 2, i + WAVE_LENGTH, |
124 | height); | |
125 | 0 | i += WAVE_LENGTH; |
126 | 0 | if (i >= right) { |
127 | 0 | break; |
128 | } | |
129 | } | |
130 | 0 | fig = null; |
131 | } | |
132 | 0 | } |
133 | ||
134 | /* | |
135 | * @see javax.swing.Icon#getIconWidth() | |
136 | */ | |
137 | 0 | public int getIconWidth() { return 0; } |
138 | ||
139 | /* | |
140 | * @see javax.swing.Icon#getIconHeight() | |
141 | */ | |
142 | 0 | public int getIconHeight() { return 0; } |
143 | ||
144 | /* | |
145 | * @see org.argouml.ui.Clarifier#hit(int, int) | |
146 | */ | |
147 | public boolean hit(int x, int y) { | |
148 | 0 | final Object modelElement = fig.getOwner(); |
149 | 0 | if (Model.getUmlFactory().isContainmentValid( |
150 | Model.getMetaTypes().getAttribute(), modelElement)) { | |
151 | 0 | FigCompartmentBox fcb = (FigCompartmentBox) fig; |
152 | 0 | FigCompartment fc = |
153 | fcb.getCompartment(Model.getMetaTypes().getAttribute()); | |
154 | 0 | Rectangle fr = fc.getBounds(); |
155 | 0 | fig = null; |
156 | 0 | return fr.contains(x, y); |
157 | } | |
158 | 0 | return false; |
159 | } | |
160 | /** | |
161 | * @return Returns the theInstance. | |
162 | */ | |
163 | public static ClAttributeCompartment getTheInstance() { | |
164 | 0 | return theInstance; |
165 | } | |
166 | ||
167 | } /* end class ClAttributeCompartment */ |