KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > ui > util > AbstractOverlayIcon


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.pde.internal.ui.util;
12
13 import org.eclipse.jface.resource.CompositeImageDescriptor;
14 import org.eclipse.jface.resource.ImageDescriptor;
15 import org.eclipse.swt.graphics.ImageData;
16 import org.eclipse.swt.graphics.Point;
17
18 /**
19  * An OverlayIcon consists of a main icon and several adornments.
20  */

21 public abstract class AbstractOverlayIcon extends CompositeImageDescriptor {
22
23     static final int DEFAULT_WIDTH = 16;
24     static final int DEFAULT_HEIGHT = 16;
25
26     private Point fSize = null;
27
28     private ImageDescriptor fOverlays[][];
29
30     public AbstractOverlayIcon(ImageDescriptor[][] overlays) {
31         this(overlays, null);
32     }
33
34     public AbstractOverlayIcon(ImageDescriptor[][] overlays, Point size) {
35         fOverlays = overlays;
36         if (size != null)
37             fSize = size;
38         else
39             fSize = new Point(DEFAULT_WIDTH, DEFAULT_HEIGHT);
40     }
41     protected void drawBottomLeft(ImageDescriptor[] overlays) {
42         if (overlays == null)
43             return;
44         int length = overlays.length;
45         int x = 0;
46         for (int i = 0; i < 3; i++) {
47             if (i < length && overlays[i] != null) {
48                 ImageData id = overlays[i].getImageData();
49                 drawImage(id, x, getSize().y - id.height);
50                 x += id.width;
51             }
52         }
53     }
54     protected void drawBottomRight(ImageDescriptor[] overlays) {
55         if (overlays == null)
56             return;
57         int length = overlays.length;
58         int x = getSize().x;
59         for (int i = 2; i >= 0; i--) {
60             if (i < length && overlays[i] != null) {
61                 ImageData id = overlays[i].getImageData();
62                 x -= id.width;
63                 drawImage(id, x, getSize().y - id.height);
64             }
65         }
66     }
67
68     protected abstract ImageData getBaseImageData();
69
70     protected void drawCompositeImage(int width, int height) {
71         ImageData base = getBaseImageData();
72         drawImage(base, 0, 0);
73         if (fOverlays != null) {
74             if (fOverlays.length > 0)
75                 drawTopRight(fOverlays[0]);
76
77             if (fOverlays.length > 1)
78                 drawBottomRight(fOverlays[1]);
79
80             if (fOverlays.length > 2)
81                 drawBottomLeft(fOverlays[2]);
82
83             if (fOverlays.length > 3)
84                 drawTopLeft(fOverlays[3]);
85         }
86     }
87     protected void drawTopLeft(ImageDescriptor[] overlays) {
88         if (overlays == null)
89             return;
90         int length = overlays.length;
91         int x = 0;
92         for (int i = 0; i < 3; i++) {
93             if (i < length && overlays[i] != null) {
94                 ImageData id = overlays[i].getImageData();
95                 drawImage(id, x, 0);
96                 x += id.width;
97             }
98         }
99     }
100     protected void drawTopRight(ImageDescriptor[] overlays) {
101         if (overlays == null)
102             return;
103         int length = overlays.length;
104         int x = getSize().x;
105         for (int i = 2; i >= 0; i--) {
106             if (i < length && overlays[i] != null) {
107                 ImageData id = overlays[i].getImageData();
108                 x -= id.width;
109                 drawImage(id, x, 0);
110             }
111         }
112     }
113
114     protected Point getSize() {
115         return fSize;
116     }
117 }
118
Popular Tags