KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > debug > ui > JDIImageDescriptor


1 /*******************************************************************************
2  * Copyright (c) 2000, 2007 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.jdt.internal.debug.ui;
12
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 JDIImageDescriptor consists 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 JDIImageDescriptor extends CompositeImageDescriptor {
24     
25     /** Flag to render the is out of synch adornment */
26     public final static int IS_OUT_OF_SYNCH= 0x0001;
27     /** Flag to render the may be out of synch adornment */
28     public final static int MAY_BE_OUT_OF_SYNCH= 0x0002;
29     /** Flag to render the installed breakpoint adornment */
30     public final static int INSTALLED= 0x0004;
31     /** Flag to render the entry method breakpoint adornment */
32     public final static int ENTRY= 0x0008;
33     /** Flag to render the exit method breakpoint adornment */
34     public final static int EXIT= 0x0010;
35     /** Flag to render the enabled breakpoint adornment */
36     public final static int ENABLED= 0x0020;
37     /** Flag to render the conditional breakpoint adornment */
38     public final static int CONDITIONAL= 0x0040;
39     /** Flag to render the caught breakpoint adornment */
40     public final static int CAUGHT= 0x0080;
41     /** Flag to render the uncaught breakpoint adornment */
42     public final static int UNCAUGHT= 0x0100;
43     /** Flag to render the scoped breakpoint adornment */
44     public final static int SCOPED= 0x0200;
45     
46     /** Flag to render the owning a monitor thread adornment */
47     public final static int OWNS_MONITOR= 0x0400;
48     /** Flag to render the owned monitor adornment */
49     public final static int OWNED_MONITOR= 0x0800;
50     /** Flag to render the in contention monitor adornment */
51     public final static int CONTENTED_MONITOR= 0x1000;
52     /** Flag to render the in contention for monitor thread adornment */
53     public final static int IN_CONTENTION_FOR_MONITOR= 0x2000;
54     /** Flag to render the in deadlock adornment */
55     public final static int IN_DEADLOCK= 0x8000;
56     
57     /** Flag to render the synchronized stack frame adornment */
58     public final static int SYNCHRONIZED= 0x4000;
59
60     private ImageDescriptor fBaseImage;
61     private int fFlags;
62     private Point fSize;
63     
64     /**
65      * Create a new JDIImageDescriptor.
66      *
67      * @param baseImage an image descriptor used as the base image
68      * @param flags flags indicating which adornments are to be rendered
69      *
70      */

71     public JDIImageDescriptor(ImageDescriptor baseImage, int flags) {
72         setBaseImage(baseImage);
73         setFlags(flags);
74     }
75     
76     /**
77      * @see CompositeImageDescriptor#getSize()
78      */

79     protected Point getSize() {
80         if (fSize == null) {
81             ImageData data= getBaseImage().getImageData();
82             setSize(new Point(data.width, data.height));
83         }
84         return fSize;
85     }
86     
87     /**
88      * @see Object#equals(java.lang.Object)
89      */

90     public boolean equals(Object JavaDoc object) {
91         if (!(object instanceof JDIImageDescriptor)){
92             return false;
93         }
94             
95         JDIImageDescriptor other= (JDIImageDescriptor)object;
96         return (getBaseImage().equals(other.getBaseImage()) && getFlags() == other.getFlags());
97     }
98     
99     /**
100      * @see Object#hashCode()
101      */

102     public int hashCode() {
103         return getBaseImage().hashCode() | getFlags();
104     }
105     
106     /**
107      * @see CompositeImageDescriptor#drawCompositeImage(int, int)
108      */

109     protected void drawCompositeImage(int width, int height) {
110         ImageData bg= getBaseImage().getImageData();
111         if (bg == null) {
112             bg= DEFAULT_IMAGE_DATA;
113         }
114         drawImage(bg, 0, 0);
115         drawOverlays();
116     }
117
118     private ImageData getImageData(String JavaDoc imageDescriptorKey) {
119         return JavaDebugImages.getImageDescriptor(imageDescriptorKey).getImageData();
120     }
121     /**
122      * Add any overlays to the image as specified in the flags.
123      */

124     protected void drawOverlays() {
125         int flags= getFlags();
126         int x= 0;
127         int y= 0;
128         ImageData data= null;
129         if ((flags & IS_OUT_OF_SYNCH) != 0) {
130             x= getSize().x;
131             y= 0;
132             data= getImageData(JavaDebugImages.IMG_OVR_OUT_OF_SYNCH);
133             x -= data.width;
134             drawImage(data, x, y);
135         } else if ((flags & MAY_BE_OUT_OF_SYNCH) != 0) {
136             x= getSize().x;
137             y= 0;
138             data= getImageData(JavaDebugImages.IMG_OVR_MAY_BE_OUT_OF_SYNCH);
139             x -= data.width;
140             drawImage(data, x, y);
141         } else if ((flags & SYNCHRONIZED) != 0) {
142             x= getSize().x;
143             y= 0;
144             data= getImageData(JavaDebugImages.IMG_OVR_SYNCHRONIZED);
145             x -= data.width;
146             drawImage(data, x, y);
147         } else {
148             if ((flags & IN_DEADLOCK) != 0) {
149                 x= 0;
150                 y= 0;
151                 data= getImageData(JavaDebugImages.IMG_OVR_IN_DEADLOCK);
152                 drawImage(data, x, y);
153             }
154             if ((flags & OWNED_MONITOR) != 0) {
155                 x= getSize().x;
156                 y= getSize().y;
157                 data= getImageData(JavaDebugImages.IMG_OVR_OWNED);
158                 x -= data.width;
159                 y -= data.height;
160                 drawImage(data, x, y);
161             } else if ((flags & CONTENTED_MONITOR) != 0) {
162                 x= getSize().x;
163                 y= getSize().y;
164                 data= getImageData(JavaDebugImages.IMG_OVR_IN_CONTENTION);
165                 x -= data.width;
166                 y -= data.height;
167                 drawImage(data, x, y);
168             } else if ((flags & OWNS_MONITOR) != 0) {
169                 x= getSize().x;
170                 y= 0;
171                 data= getImageData(JavaDebugImages.IMG_OVR_OWNS_MONITOR);
172                 x -= data.width;
173                 drawImage(data, x, y);
174             } else if ((flags & IN_CONTENTION_FOR_MONITOR) != 0) {
175                 x= getSize().x;
176                 y= 0;
177                 data= getImageData(JavaDebugImages.IMG_OVR_IN_CONTENTION_FOR_MONITOR);
178                 x -= data.width;
179                 drawImage(data, x, y);
180             } else {
181                 drawBreakpointOverlays();
182             }
183         }
184     }
185     
186     protected void drawBreakpointOverlays() {
187         int flags= getFlags();
188         int x= 0;
189         int y= 0;
190         ImageData data= null;
191         if ((flags & INSTALLED) != 0) {
192             x= 0;
193             y= getSize().y;
194             if ((flags & ENABLED) !=0) {
195                 data= getImageData(JavaDebugImages.IMG_OVR_BREAKPOINT_INSTALLED);
196             } else {
197                 data= getImageData(JavaDebugImages.IMG_OVR_BREAKPOINT_INSTALLED_DISABLED);
198             }
199                 
200             y -= data.height;
201             drawImage(data, x, y);
202         }
203         if ((flags & CAUGHT) != 0) {
204             if ((flags & ENABLED) !=0) {
205             data= getImageData(JavaDebugImages.IMG_OVR_CAUGHT_BREAKPOINT);
206             } else {
207                 data= getImageData(JavaDebugImages.IMG_OVR_CAUGHT_BREAKPOINT_DISABLED);
208             }
209             x= 0;
210             y= 0;
211             drawImage(data, x, y);
212         }
213         if ((flags & UNCAUGHT) != 0) {
214             if ((flags & ENABLED) !=0) {
215                 data= getImageData(JavaDebugImages.IMG_OVR_UNCAUGHT_BREAKPOINT);
216             } else {
217                 data= getImageData(JavaDebugImages.IMG_OVR_UNCAUGHT_BREAKPOINT_DISABLED);
218             }
219             x= data.width;
220             y= data.height;
221             drawImage(data, x, y);
222         }
223         if ((flags & SCOPED) != 0) {
224             if ((flags & ENABLED) !=0) {
225                 data= getImageData(JavaDebugImages.IMG_OVR_SCOPED_BREAKPOINT);
226             } else {
227                 data= getImageData(JavaDebugImages.IMG_OVR_SCOPED_BREAKPOINT_DISABLED);
228             }
229             x= 0;
230             y= getSize().y;
231             y-= data.height;
232             drawImage(data, x, y);
233         }
234         if ((flags & CONDITIONAL) != 0) {
235             if ((flags & ENABLED) !=0) {
236                 data= getImageData(JavaDebugImages.IMG_OVR_CONDITIONAL_BREAKPOINT);
237             } else {
238                 data= getImageData(JavaDebugImages.IMG_OVR_CONDITIONAL_BREAKPOINT_DISABLED);
239             }
240             x= 0;
241             y= 0;
242             drawImage(data, x, y);
243         }
244         if ((flags & ENTRY) != 0) {
245             x= getSize().x;
246             y= 0;
247             if ((flags & ENABLED) !=0) {
248                 data= getImageData(JavaDebugImages.IMG_OVR_METHOD_BREAKPOINT_ENTRY);
249             } else {
250                 data= getImageData(JavaDebugImages.IMG_OVR_METHOD_BREAKPOINT_ENTRY_DISABLED);
251             }
252             x -= data.width;
253             x = x - 2;
254             drawImage(data, x, y);
255         }
256         if ((flags & EXIT) != 0){
257             x= getSize().x;
258             y= getSize().y;
259             if ((flags & ENABLED) != 0) {
260                 data= getImageData(JavaDebugImages.IMG_OVR_METHOD_BREAKPOINT_EXIT);
261             } else {
262                 data= getImageData(JavaDebugImages.IMG_OVR_METHOD_BREAKPOINT_EXIT_DISABLED);
263             }
264             x -= data.width;
265             x = x - 2;
266             y -= data.height;
267             drawImage(data, x, y);
268         }
269     }
270     protected ImageDescriptor getBaseImage() {
271         return fBaseImage;
272     }
273
274     protected void setBaseImage(ImageDescriptor baseImage) {
275         fBaseImage = baseImage;
276     }
277
278     protected int getFlags() {
279         return fFlags;
280     }
281
282     protected void setFlags(int flags) {
283         fFlags = flags;
284     }
285
286     protected void setSize(Point size) {
287         fSize = size;
288     }
289 }
290
Popular Tags