KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > runtime > OverlayIcon


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.runtime;
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 public class OverlayIcon 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 fBase;
27     private ImageDescriptor fOverlays[][];
28
29     public OverlayIcon(ImageDescriptor base, ImageDescriptor[][] overlays) {
30         fBase= base;
31         if (fBase == null)
32             fBase= ImageDescriptor.getMissingImageDescriptor();
33         fOverlays= overlays;
34         fSize= new Point(DEFAULT_WIDTH, DEFAULT_HEIGHT);
35     }
36     public OverlayIcon(ImageDescriptor base, ImageDescriptor[][] overlays, Point size) {
37         fBase= base;
38         if (fBase == null)
39             fBase= ImageDescriptor.getMissingImageDescriptor();
40         fOverlays= overlays;
41         fSize= size;
42     }
43     protected void drawBottomLeft(ImageDescriptor[] overlays) {
44         if (overlays == null)
45             return;
46         int length= overlays.length;
47         int x= 0;
48         for (int i= 0; i < 3; i++) {
49             if (i < length && overlays[i] != null) {
50                 ImageData id= overlays[i].getImageData();
51                 drawImage(id, x, getSize().y-id.height);
52                 x+= id.width;
53             }
54         }
55     }
56     protected void drawBottomRight(ImageDescriptor[] overlays) {
57         if (overlays == null)
58             return;
59         int length= overlays.length;
60         int x= getSize().x;
61         for (int i= 2; i >= 0; i--) {
62             if (i < length && overlays[i] != null) {
63                 ImageData id= overlays[i].getImageData();
64                 x-= id.width;
65                 drawImage(id, x, getSize().y-id.height);
66             }
67         }
68     }
69     protected void drawCompositeImage(int width, int height) {
70         ImageData bg= fBase.getImageData();
71         drawImage(bg, 0, 0);
72         
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     protected Point getSize() {
114         return fSize;
115     }
116 }
117
Popular Tags