KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > update > internal > ui > parts > AbstractOverlayIcon


1 /*******************************************************************************
2  * Copyright (c) 2000, 2005 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.update.internal.ui.parts;
12
13 import org.eclipse.jface.resource.*;
14 import org.eclipse.swt.graphics.*;
15
16 /**
17  * An OverlayIcon consists of a main icon and several adornments.
18  */

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