KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ltk > internal > ui > refactoring > history > RefactoringDescriptorImageDescriptor


1 /*******************************************************************************
2  * Copyright (c) 2005, 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.ltk.internal.ui.refactoring.history;
12
13 import org.eclipse.ltk.internal.ui.refactoring.RefactoringPluginImages;
14 import org.eclipse.ltk.internal.ui.refactoring.RefactoringUIPlugin;
15
16 import org.eclipse.swt.graphics.ImageData;
17 import org.eclipse.swt.graphics.Point;
18
19 import org.eclipse.jface.resource.CompositeImageDescriptor;
20 import org.eclipse.jface.resource.ImageDescriptor;
21
22 /**
23  * Image descriptor for decorated refactoring descriptors.
24  *
25  * @since 3.2
26  */

27 public final class RefactoringDescriptorImageDescriptor extends CompositeImageDescriptor {
28
29     /** The workspace flag */
30     public static final int WORKSPACE= 1 << 1;
31
32     /** The image flags */
33     private final int fFlags;
34
35     /** The base image */
36     private final ImageDescriptor fImage;
37
38     /** The image size */
39     private final Point fSize;
40
41     /**
42      * Creates a new refactoring descriptor image descriptor.
43      *
44      * @param image
45      * the base image
46      * @param flags
47      * image flags
48      * @param size
49      * the size of the image
50      */

51     public RefactoringDescriptorImageDescriptor(final ImageDescriptor image, final int flags, final Point size) {
52         fImage= image;
53         fFlags= flags;
54         fSize= size;
55     }
56
57     /**
58      * Draws the bottom right image decorations.
59      */

60     private void drawBottomRight() {
61         final Point size= getSize();
62         int x= size.x;
63
64         if ((fFlags & WORKSPACE) != 0) {
65             ImageData data= getImageData(RefactoringPluginImages.DESC_OVR_WORKSPACE);
66             x-= data.width;
67             drawImage(data, x, size.y - data.height);
68         }
69     }
70
71     /**
72      * {@inheritDoc}
73      */

74     protected void drawCompositeImage(final int width, final int height) {
75         drawImage(getImageData(fImage), 0, 0);
76         drawBottomRight();
77     }
78
79     /**
80      * {@inheritDoc}
81      */

82     public boolean equals(final Object JavaDoc object) {
83         if (object == null || !RefactoringDescriptorImageDescriptor.class.equals(object.getClass()))
84             return false;
85         final RefactoringDescriptorImageDescriptor other= (RefactoringDescriptorImageDescriptor) object;
86         return (fImage.equals(other.fImage) && fFlags == other.fFlags && fSize.equals(other.fSize));
87     }
88
89     /**
90      * Returns the image data for the specified descriptor.
91      *
92      * @param descriptor
93      * the image descriptor
94      * @return the image data
95      */

96     private ImageData getImageData(final ImageDescriptor descriptor) {
97         ImageData data= descriptor.getImageData();
98         if (data == null) {
99             data= DEFAULT_IMAGE_DATA;
100             RefactoringUIPlugin.logErrorMessage("Image data not available: " + descriptor.toString()); //$NON-NLS-1$
101
}
102         return data;
103     }
104
105     /**
106      * {@inheritDoc}
107      */

108     protected Point getSize() {
109         return fSize;
110     }
111
112     /**
113      * {@inheritDoc}
114      */

115     public int hashCode() {
116         return fImage.hashCode() | fFlags | fSize.hashCode();
117     }
118 }
119
Popular Tags