KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ant > internal > ui > model > AntImageDescriptor


1 /*******************************************************************************
2  * Copyright (c) 2000, 2004 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Common Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/cpl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  * John-Mason P. Shackelford (john-mason.shackelford@pearson.com) - bug 49445
11  *******************************************************************************/

12 package org.eclipse.ant.internal.ui.model;
13
14 import org.eclipse.jface.resource.CompositeImageDescriptor;
15 import org.eclipse.jface.resource.ImageDescriptor;
16 import org.eclipse.swt.graphics.ImageData;
17 import org.eclipse.swt.graphics.Point;
18
19 /**
20  * A image descriptor consisting of a main icon and several adornments. The adornments
21  * are computed according to flags set on creation of the descriptor.
22  */

23 public class AntImageDescriptor extends CompositeImageDescriptor {
24     
25     /** Flag to render an error adornment */
26     public final static int HAS_ERRORS= 0x0001;
27
28     /** Flag to render an imported adornment */
29     public final static int IMPORTED= 0x0002;
30     
31     /** Flag to render an warning adornment */
32     public final static int HAS_WARNINGS= 0x0004;
33     
34     private ImageDescriptor fBaseImage;
35     private int fFlags;
36     private Point fSize;
37
38     /**
39      * Create a new AntImageDescriptor.
40      *
41      * @param baseImage an image descriptor used as the base image
42      * @param flags flags indicating which adornments are to be rendered
43      *
44      */

45     public AntImageDescriptor(ImageDescriptor baseImage, int flags) {
46         setBaseImage(baseImage);
47         setFlags(flags);
48     }
49     
50     /**
51      * @see CompositeImageDescriptor#getSize()
52      */

53     protected Point getSize() {
54         if (fSize == null) {
55             ImageData data= getBaseImage().getImageData();
56             setSize(new Point(data.width, data.height));
57         }
58         return fSize;
59     }
60     
61     /**
62      * @see Object#equals(java.lang.Object)
63      */

64     public boolean equals(Object JavaDoc object) {
65         if (!(object instanceof AntImageDescriptor)){
66             return false;
67         }
68             
69         AntImageDescriptor other= (AntImageDescriptor)object;
70         return (getBaseImage().equals(other.getBaseImage()) && getFlags() == other.getFlags());
71     }
72     
73     /**
74      * @see Object#hashCode()
75      */

76     public int hashCode() {
77         return getBaseImage().hashCode() | getFlags();
78     }
79     
80     /**
81      * @see CompositeImageDescriptor#drawCompositeImage(int, int)
82      */

83     protected void drawCompositeImage(int width, int height) {
84         ImageData bg= getBaseImage().getImageData();
85         if (bg == null) {
86             bg= DEFAULT_IMAGE_DATA;
87         }
88         drawImage(bg, 0, 0);
89         drawOverlays();
90     }
91
92     /**
93      * Add any overlays to the image as specified in the flags.
94      */

95     protected void drawOverlays() {
96         int flags= getFlags();
97         int y= 0;
98         ImageData data= null;
99         if ((flags & IMPORTED) != 0) {
100             data= AntUIImages.getImageDescriptor(IAntUIConstants.IMG_OVR_IMPORT).getImageData();
101             drawImage(data, 0, 0);
102         }
103         if ((flags & HAS_ERRORS) != 0) {
104             y= getSize().y;
105             data= AntUIImages.getImageDescriptor(IAntUIConstants.IMG_OVR_ERROR).getImageData();
106             y -= data.height;
107             drawImage(data, 0, y);
108         } else if ((flags & HAS_WARNINGS) != 0) {
109             y= getSize().y;
110             data= AntUIImages.getImageDescriptor(IAntUIConstants.IMG_OVR_WARNING).getImageData();
111             y -= data.height;
112             drawImage(data, 0, y);
113         }
114     }
115     
116     protected ImageDescriptor getBaseImage() {
117         return fBaseImage;
118     }
119
120     protected void setBaseImage(ImageDescriptor baseImage) {
121         fBaseImage = baseImage;
122     }
123
124     protected int getFlags() {
125         return fFlags;
126     }
127
128     protected void setFlags(int flags) {
129         fFlags = flags;
130     }
131
132     protected void setSize(Point size) {
133         fSize = size;
134     }
135 }
Popular Tags