KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > debug > internal > ui > launchConfigurations > LaunchConfigurationTabImageDescriptor


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.debug.internal.ui.launchConfigurations;
12
13
14 import org.eclipse.debug.ui.DebugUITools;
15 import org.eclipse.debug.ui.IDebugUIConstants;
16 import org.eclipse.jface.resource.CompositeImageDescriptor;
17 import org.eclipse.swt.graphics.Image;
18 import org.eclipse.swt.graphics.ImageData;
19 import org.eclipse.swt.graphics.Point;
20
21 /**
22  * A JDIImageDescriptor consists of a main icon and several adornments. The adornments
23  * are computed according to flags set on creation of the descriptor.
24  */

25 public class LaunchConfigurationTabImageDescriptor extends CompositeImageDescriptor {
26     
27     /** Flag to render the error adornment */
28     public final static int ERROR= 0x001;
29
30     private Image fBaseImage;
31     private int fFlags;
32     private Point fSize;
33     
34     /**
35      * Create a new JDIImageDescriptor.
36      *
37      * @param baseImage an image descriptor used as the base image
38      * @param flags flags indicating which adornments are to be rendered
39      *
40      */

41     public LaunchConfigurationTabImageDescriptor(Image baseImage, int flags) {
42         setBaseImage(baseImage);
43         setFlags(flags);
44     }
45     
46     /**
47      * @see CompositeImageDescriptor#getSize()
48      */

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

60     public boolean equals(Object JavaDoc object) {
61         if (!(object instanceof LaunchConfigurationTabImageDescriptor)){
62             return false;
63         }
64             
65         LaunchConfigurationTabImageDescriptor other= (LaunchConfigurationTabImageDescriptor)object;
66         return (getBaseImage().equals(other.getBaseImage()) && getFlags() == other.getFlags());
67     }
68     
69     /**
70      * @see Object#hashCode()
71      */

72     public int hashCode() {
73         return getBaseImage().hashCode() | getFlags();
74     }
75     
76     /**
77      * @see CompositeImageDescriptor#drawCompositeImage(int, int)
78      */

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

91     protected void drawOverlays() {
92         int flags= getFlags();
93         ImageData data= null;
94         if ((flags & ERROR) != 0) {
95             data= DebugUITools.getImage(IDebugUIConstants.IMG_OVR_ERROR).getImageData();
96             drawImage(data, 0, 0);
97         }
98     }
99     
100     protected Image getBaseImage() {
101         return fBaseImage;
102     }
103
104     protected void setBaseImage(Image baseImage) {
105         fBaseImage = baseImage;
106     }
107
108     protected int getFlags() {
109         return fFlags;
110     }
111
112     protected void setFlags(int flags) {
113         fFlags = flags;
114     }
115
116     protected void setSize(Point size) {
117         fSize = size;
118     }
119 }
120
Popular Tags