Skip to content

Package: OverlayImageDescriptor

OverlayImageDescriptor

nameinstructionbranchcomplexitylinemethod
OverlayImageDescriptor(Image, ImageDescriptor, int)
M: 12 C: 18
60%
M: 4 C: 0
0%
M: 2 C: 1
33%
M: 0 C: 8
100%
M: 0 C: 1
100%
OverlayImageDescriptor(ImageData, ImageDescriptor, int)
M: 12 C: 17
59%
M: 4 C: 0
0%
M: 2 C: 1
33%
M: 0 C: 8
100%
M: 0 C: 1
100%
drawCompositeImage(int, int)
M: 42 C: 52
55%
M: 5 C: 3
38%
M: 5 C: 1
17%
M: 5 C: 11
69%
M: 0 C: 1
100%
getSize()
M: 0 C: 6
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
static {...}
M: 0 C: 1
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%

Coverage

1: /*******************************************************************************
2: * Copyright (c) 2011-2013 EclipseSource Muenchen GmbH and others.
3: *
4: * All rights reserved. This program and the accompanying materials
5: * are made available under the terms of the Eclipse Public License 2.0
6: * which accompanies this distribution, and is available at
7: * https://www.eclipse.org/legal/epl-2.0/
8: *
9: * SPDX-License-Identifier: EPL-2.0
10: *
11: * Contributors:
12: * Shterev - initial API and implementation
13: *
14: *******************************************************************************/
15:
16: package org.eclipse.emf.ecp.edit.internal.swt.util;
17:
18: import org.eclipse.jface.resource.CompositeImageDescriptor;
19: import org.eclipse.jface.resource.ImageDescriptor;
20: import org.eclipse.swt.graphics.Image;
21: import org.eclipse.swt.graphics.ImageData;
22: import org.eclipse.swt.graphics.Point;
23:
24: /**
25: * Allows one image descriptor to be overlayed on another image descriptor to generate a new image. Commonly used to
26: * decorate an image with a second image decoration.
27: *
28: * @author Shterev
29: */
30: public class OverlayImageDescriptor extends CompositeImageDescriptor {
31:
32:         /** display the overlay image in the upper left corner. */
33:         public static final int UPPER_LEFT = 0;
34:
35:         /** display the overlay image in the upper right corner. */
36:         public static final int UPPER_RIGHT = 1;
37:
38:         /** display the overlay image in the lower right corner. */
39:         public static final int LOWER_RIGHT = 2;
40:
41:         /** display the overlay image in the lower left corner. */
42:         public static final int LOWER_LEFT = 3;
43:
44:         /** default image width. */
45:         private static final int DEFAULT_IMAGE_WIDTH = 19;
46:
47:         /** default image height. */
48:         private static final int DEFAULT_IMAGE_HEIGHT = 19;
49:
50:         /** overlay image. */
51:         private final ImageDescriptor overlayDesc;
52:
53:         /** the position of the overlay image. */
54:         private final int overlayPos = LOWER_RIGHT;
55:
56:         private final int offset = 3;
57:
58:         private final ImageData backgroundData;
59:
60:         /**
61:          * OverlayImageDescriptor constructor.
62:          *
63:          * @param srcImage the base image
64:          * @param overlayDesc the overlay image
65:          * @param overlayPos the overlay position
66:          */
67:         public OverlayImageDescriptor(Image srcImage, ImageDescriptor overlayDesc, int overlayPos) {
68:•                assert null != srcImage;
69:•                assert null != overlayDesc;
70:                 backgroundData = srcImage.getImageData();
71:                 this.overlayDesc = overlayDesc;
72:         }
73:
74:         /**
75:          * OverlayImageDescriptor constructor.
76:          *
77:          * @param backgroundData the base ImageData
78:          * @param overlayDesc the overlay image
79:          * @param overlayPos the overlay position
80:          */
81:         public OverlayImageDescriptor(ImageData backgroundData, ImageDescriptor overlayDesc, int overlayPos) {
82:•                assert null != backgroundData;
83:•                assert null != overlayDesc;
84:                 this.backgroundData = backgroundData;
85:                 this.overlayDesc = overlayDesc;
86:         }
87:
88:         /**
89:          * Draws the given source image data into this composite image at the given position.
90:          *
91:          * @param width the width of the image.
92:          * @param height the height of the image.
93:          * @see org.eclipse.jface.resource.CompositeImageDescriptor#drawCompositeImage(int, int)
94:          */
95:         @Override
96:         protected void drawCompositeImage(int width, int height) {
97:                 // draw the base image
98:
99:•                if (backgroundData != null) {
100:                         drawImage(backgroundData, 0, 0);
101:                 }
102:
103:                 // draw the overlay image
104:                 final ImageData overlayData = overlayDesc.getImageData();
105:•                if (overlayData != null) {
106:                         Point pos = null;
107:•                        switch (overlayPos) {
108:                         case UPPER_LEFT:
109:                                 pos = new Point(-overlayData.width / 2, -overlayData.height / 2);
110:                                 break;
111:                         case UPPER_RIGHT:
112:                                 pos = new Point(backgroundData.width - overlayData.width / 2, 0);
113:                                 break;
114:                         case LOWER_RIGHT:
115:                                 pos = new Point(backgroundData.width - overlayData.width / 2, backgroundData.height
116:                                         - overlayData.height / 2);
117:                                 break;
118:                         // default = LOWER_LEFT
119:                         default:
120:                                 pos = new Point(0, backgroundData.height - overlayData.height / 2);
121:                                 break;
122:                         }
123:                         drawImage(overlayData, pos.x - offset, pos.y - offset);
124:                 }
125:         }
126:
127:         /**
128:          * Retrieve the size of this composite image.
129:          *
130:          * @return the x and y size of the image expressed as a point object
131:          * @see org.eclipse.jface.resource.CompositeImageDescriptor#getSize()
132:          */
133:         @Override
134:         protected Point getSize() {
135:                 return new Point(DEFAULT_IMAGE_WIDTH, DEFAULT_IMAGE_HEIGHT);
136:         }
137:
138: }