Package: VdmElementImageDescriptor

VdmElementImageDescriptor

nameinstructionbranchcomplexitylinemethod
VdmElementImageDescriptor(ImageDescriptor, int, Point)
M: 18 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 7 C: 0
0%
M: 1 C: 0
0%
addBottomRightImage(ImageDescriptor, Point)
M: 29 C: 0
0%
M: 4 C: 0
0%
M: 3 C: 0
0%
M: 7 C: 0
0%
M: 1 C: 0
0%
addTopRightImage(ImageDescriptor, Point)
M: 22 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 6 C: 0
0%
M: 1 C: 0
0%
drawBottomLeft()
M: 1 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
drawBottomRight()
M: 21 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 5 C: 0
0%
M: 1 C: 0
0%
drawCompositeImage(int, int)
M: 17 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 6 C: 0
0%
M: 1 C: 0
0%
drawTopRight()
M: 63 C: 0
0%
M: 12 C: 0
0%
M: 7 C: 0
0%
M: 14 C: 0
0%
M: 1 C: 0
0%
equals(Object)
M: 29 C: 0
0%
M: 8 C: 0
0%
M: 5 C: 0
0%
M: 6 C: 0
0%
M: 1 C: 0
0%
getImageData(ImageDescriptor)
M: 18 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 5 C: 0
0%
M: 1 C: 0
0%
getImageSize()
M: 10 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getSize()
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
hashCode()
M: 11 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
setImageSize(Point)
M: 17 C: 0
0%
M: 4 C: 0
0%
M: 3 C: 0
0%
M: 4 C: 0
0%
M: 1 C: 0
0%
toString()
M: 10 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /*
2: * #%~
3: * org.overture.ide.ui
4: * %%
5: * Copyright (C) 2008 - 2014 Overture
6: * %%
7: * This program is free software: you can redistribute it and/or modify
8: * it under the terms of the GNU General Public License as
9: * published by the Free Software Foundation, either version 3 of the
10: * License, or (at your option) any later version.
11: *
12: * This program is distributed in the hope that it will be useful,
13: * but WITHOUT ANY WARRANTY; without even the implied warranty of
14: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15: * GNU General Public License for more details.
16: *
17: * You should have received a copy of the GNU General Public
18: * License along with this program. If not, see
19: * <http://www.gnu.org/licenses/gpl-3.0.html>.
20: * #~%
21: */
22: package org.overture.ide.ui.internal.viewsupport;
23:
24: import org.eclipse.core.runtime.Assert;
25: import org.eclipse.jface.resource.CompositeImageDescriptor;
26: import org.eclipse.jface.resource.ImageDescriptor;
27: import org.eclipse.swt.graphics.ImageData;
28: import org.eclipse.swt.graphics.Point;
29: import org.overture.ide.ui.VdmPluginImages;
30: import org.overture.ide.ui.VdmUIPlugin;
31:
32: /**
33: * A {@link JavaElementImageDescriptor} consists of a base image and several
34: * adornments. The adornments are computed according to the flags either passed
35: * during creation or set via the method {@link #setAdornments(int)}.
36: * <p>
37: * This class may be instantiated; it is not intended to be subclassed.
38: * </p>
39: *
40: * @since 2.0
41: * @noextend This class is not intended to be subclassed by clients.
42: */
43: public class VdmElementImageDescriptor extends CompositeImageDescriptor {
44:
45:         /** Flag to render the abstract adornment. */
46:         public final static int ABSTRACT = 0x001;
47:
48:         /** Flag to render the final adornment. */
49:         public final static int FINAL = 0x002;
50:
51:         /** Flag to render the synchronized adornment. */
52:         public final static int SYNCHRONIZED = 0x004;
53:
54:         /** Flag to render the static adornment. */
55:         public final static int STATIC = 0x008;
56:
57:         /** Flag to render the runnable adornment. */
58:         public final static int RUNNABLE = 0x010;
59:
60:         /** Flag to render the warning adornment. */
61:         public final static int WARNING = 0x020;
62:
63:         /** Flag to render the error adornment. */
64:         public final static int ERROR = 0x040;
65:
66:         /** Flag to render the 'override' adornment. */
67:         public final static int OVERRIDES = 0x080;
68:
69:         /** Flag to render the 'implements' adornment. */
70:         public final static int IMPLEMENTS = 0x100;
71:
72:         /** Flag to render the 'constructor' adornment. */
73:         public final static int CONSTRUCTOR = 0x200;
74:
75:         /**
76:          * Flag to render the 'deprecated' adornment.
77:          *
78:          * @since 3.0
79:          */
80:         public final static int DEPRECATED = 0x400;
81:
82:         /**
83:          * Flag to render the 'volatile' adornment.
84:          *
85:          * @since 3.3
86:          */
87:         public final static int VOLATILE = 0x800;
88:
89:         /**
90:          * Flag to render the 'transient' adornment.
91:          *
92:          * @since 3.3
93:          */
94:         public final static int TRANSIENT = 0x1000;
95:
96:         private ImageDescriptor fBaseImage;
97:         private int fFlags;
98:         private Point fSize;
99:
100:         /**
101:          * Creates a new JavaElementImageDescriptor.
102:          *
103:          * @param baseImage
104:          * an image descriptor used as the base image
105:          * @param flags
106:          * flags indicating which adornments are to be rendered. See
107:          * {@link #setAdornments(int)} for valid values.
108:          * @param size
109:          * the size of the resulting image
110:          */
111:         public VdmElementImageDescriptor(ImageDescriptor baseImage, int flags,
112:                         Point size) {
113:                 fBaseImage = baseImage;
114:                 Assert.isNotNull(fBaseImage);
115:                 fFlags = flags;
116:                 // Assert.isNotNull(element);
117:                 fSize = size;
118:                 Assert.isNotNull(fSize);
119:         }
120:
121:         /**
122:          * Sets the size of the image created by calling {@link #createImage()}.
123:          *
124:          * @param size
125:          * the size of the image returned from calling
126:          * {@link #createImage()}
127:          */
128:         public void setImageSize(Point size) {
129:                 Assert.isNotNull(size);
130:•                Assert.isTrue(size.x >= 0 && size.y >= 0);
131:                 fSize = size;
132:         }
133:
134:         /**
135:          * Returns the size of the image created by calling {@link #createImage()}.
136:          *
137:          * @return the size of the image created by calling {@link #createImage()}
138:          */
139:         public Point getImageSize() {
140:                 return new Point(fSize.x, fSize.y);
141:         }
142:
143:         /*
144:          * (non-Javadoc) Method declared in CompositeImageDescriptor
145:          */
146:         protected Point getSize() {
147:                 return fSize;
148:         }
149:
150:         // /* (non-Javadoc)
151:         // * Method declared on Object.
152:         // */
153:         // public boolean equals(Object object) {
154:         // if (object == null ||
155:         // !VdmElementImageDescriptor.class.equals(object.getClass()))
156:         // return false;
157:         //
158:         // VdmElementImageDescriptor other= (VdmElementImageDescriptor)object;
159:         // return (fBaseImage.equals(other.fBaseImage) && fFlags == other.fFlags &&
160:         // fSize.equals(other.fSize));
161:         // }
162:
163:         // /* (non-Javadoc)
164:         // * Method declared on Object.
165:         // */
166:         // public int hashCode() {
167:         // return fBaseImage.hashCode() | fFlags | fSize.hashCode();
168:         // }
169:
170:         /*
171:          * (non-Javadoc) Method declared in CompositeImageDescriptor
172:          */
173:         protected void drawCompositeImage(int width, int height) {
174:                 ImageData bg = getImageData(fBaseImage);
175:
176:                 drawImage(bg, 0, 0);
177:
178:                 drawTopRight();
179:                 drawBottomRight();
180:                 drawBottomLeft();
181:
182:         }
183:
184:         private ImageData getImageData(ImageDescriptor descriptor) {
185:                 ImageData data = descriptor.getImageData(); // see bug 51965:
186:                                                                                                         // getImageData can return
187:                                                                                                         // null
188:•                if (data == null) {
189:                         data = DEFAULT_IMAGE_DATA;
190:                         VdmUIPlugin
191:                                         .logErrorMessage("Image data not available: " + descriptor.toString()); //$NON-NLS-1$
192:                 }
193:                 return data;
194:         }
195:
196:         private void addTopRightImage(ImageDescriptor desc, Point pos) {
197:                 ImageData data = getImageData(desc);
198:                 int x = pos.x - data.width;
199:•                if (x >= 0) {
200:                         drawImage(data, x, pos.y);
201:                         pos.x = x;
202:                 }
203:         }
204:
205:         private void addBottomRightImage(ImageDescriptor desc, Point pos) {
206:                 ImageData data = getImageData(desc);
207:                 int x = pos.x - data.width;
208:                 int y = pos.y - data.height;
209:•                if (x >= 0 && y >= 0) {
210:                         drawImage(data, x, y);
211:                         pos.x = x;
212:                 }
213:         }
214:
215: //        private void addBottomLeftImage(ImageDescriptor desc, Point pos) {
216: //                ImageData data = getImageData(desc);
217: //                int x = pos.x;
218: //                int y = pos.y - data.height;
219: //                if (x + data.width < getSize().x && y >= 0) {
220: //                        drawImage(data, x, y);
221: //                        pos.x = x + data.width;
222: //                }
223: //        }
224:
225:         private void drawTopRight() {
226:                 Point pos = new Point(getSize().x, 0);
227:
228:•                if ((fFlags & ABSTRACT) != 0) {
229:                         addTopRightImage(VdmPluginImages.DESC_OVR_ABSTRACT, pos);
230:                 }
231:•                if ((fFlags & CONSTRUCTOR) != 0) {
232:                         addTopRightImage(VdmPluginImages.DESC_OVR_CONSTRUCTOR, pos);
233:                 }
234:•                if ((fFlags & FINAL) != 0) {
235:                         addTopRightImage(VdmPluginImages.DESC_OVR_FINAL, pos);
236:                 }
237:•                if ((fFlags & VOLATILE) != 0) {
238:                         addTopRightImage(VdmPluginImages.DESC_OVR_VOLATILE, pos);
239:                 }
240:•                if ((fFlags & STATIC) != 0) {
241:                         addTopRightImage(VdmPluginImages.DESC_OVR_STATIC, pos);
242:                 }
243:•                if ((fFlags & RUNNABLE) != 0) {
244:                         addTopRightImage(VdmPluginImages.DESC_OVR_RUN, pos);
245:                 }
246:
247:         }
248:
249:         private void drawBottomRight() {
250:                 Point size = getSize();
251:                 Point pos = new Point(size.x, size.y);
252:                 
253:•                if ((fFlags & OVERRIDES) != 0) {
254:                         addBottomRightImage(VdmPluginImages.DESC_OVR_OVERRIDES, pos);
255:                 }
256:
257:         }
258:
259:         private void drawBottomLeft() {
260:                 // FIXME: this was never used: why was it here? -jwc/22Feb2013
261:                 // Point pos = new Point(0, getSize().y);
262:
263:         }
264:
265:         @Override
266:         public String toString() {
267:•                if (fBaseImage != null) {
268:                         return fBaseImage.toString();
269:                 } else
270:                         return super.toString();
271:         }
272:
273:         @Override
274:         public boolean equals(Object obj) {
275:•                if (obj instanceof VdmElementImageDescriptor) {
276:                         VdmElementImageDescriptor other = (VdmElementImageDescriptor) obj;
277:•                        return this.fFlags == other.fFlags
278:•                                        && (this.fSize.equals(other.fSize))
279:•                                        && this.fBaseImage.equals(other.fBaseImage);
280:                 } else {
281:                         return false;
282:                 }
283:         }
284:
285:         @Override
286:         public int hashCode() {
287:                 return this.fFlags + fSize.hashCode() + fBaseImage.hashCode();
288:         }
289: }