KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > debug > internal > ui > CompositeDebugImageDescriptor


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;
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 CompositeDebugImageDescriptor extends CompositeImageDescriptor {
26     
27     /** Flag to render the skip breakpoint adornment */
28     public final static int SKIP_BREAKPOINT= 0x0001;
29     
30     private Image fBaseImage;
31     private int fFlags;
32     private Point fSize;
33     
34     /**
35      * Create a new composite image descriptor.
36      *
37      * @param baseImage an image used as the base image
38      * @param flags flags indicating which adornments are to be rendered
39      *
40      */

41     public CompositeDebugImageDescriptor(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 CompositeDebugImageDescriptor)){
62             return false;
63         }
64         CompositeDebugImageDescriptor other= (CompositeDebugImageDescriptor)object;
65         return (getBaseImage().equals(other.getBaseImage()) && getFlags() == other.getFlags());
66     }
67     
68     /**
69      * @see Object#hashCode()
70      */

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

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

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