KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > decorators > DecorationResult


1 /*******************************************************************************
2  * Copyright (c) 2000, 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.ui.internal.decorators;
12
13 import java.util.List JavaDoc;
14 import java.util.ListIterator JavaDoc;
15
16 import org.eclipse.jface.resource.ImageDescriptor;
17 import org.eclipse.swt.graphics.Color;
18 import org.eclipse.swt.graphics.Font;
19 import org.eclipse.swt.graphics.Image;
20
21 /**
22  * The Decoration Result is the result of a decoration.
23  */

24 public class DecorationResult {
25
26     private List JavaDoc prefixes;
27
28     private List JavaDoc suffixes;
29
30     private ImageDescriptor[] descriptors;
31     
32     private Color foregroundColor;
33     
34     private Color backgroundColor;
35     
36     private Font font;
37
38     DecorationResult(List JavaDoc prefixList, List JavaDoc suffixList,
39             ImageDescriptor[] imageDescriptors,
40             Color resultForegroundColor,
41             Color resultBackgroundColor,
42             Font resultFont) {
43         prefixes = prefixList;
44         suffixes = suffixList;
45
46         //Don't set the field if there are no entries
47
if (hasOverlays(imageDescriptors)) {
48             descriptors = imageDescriptors;
49         }
50         foregroundColor = resultForegroundColor;
51         backgroundColor = resultBackgroundColor;
52         font = resultFont;
53     }
54
55     /**
56      * Return whether or not any of the imageDescriptors
57      * are non-null.
58      * @param imageDescriptors
59      * @return <code>true</code> if there are some non-null
60      * overlays
61      */

62     private boolean hasOverlays(ImageDescriptor[] imageDescriptors) {
63         for (int i = 0; i < imageDescriptors.length; i++) {
64             if (imageDescriptors[i] != null) {
65                 return true;
66             }
67         }
68         return false;
69     }
70
71     /**
72      * Decorate the Image supplied with the overlays.
73      * @param image
74      * @param overlayCache
75      * @return Image
76      */

77     Image decorateWithOverlays(Image image, OverlayCache overlayCache) {
78
79         //Do not try to do anything if there is no source or overlays
80
if (image == null || descriptors == null) {
81             return image;
82         }
83
84         return overlayCache.applyDescriptors(image, descriptors);
85     }
86
87     /**
88      * Decorate the String supplied with the prefixes and suffixes.
89      * This method is public for use by the test suites and is not intended
90      * to be referenced by other workbench internals.
91      * @param text
92      * @return String
93      */

94     public String JavaDoc decorateWithText(String JavaDoc text) {
95
96         if (prefixes.isEmpty() && suffixes.isEmpty()) {
97             return text;
98         }
99
100         StringBuffer JavaDoc result = new StringBuffer JavaDoc();
101
102         ListIterator JavaDoc prefixIterator = prefixes.listIterator();
103
104         while (prefixIterator.hasNext()) {
105             result.append(prefixIterator.next());
106         }
107
108         result.append(text);
109
110         ListIterator JavaDoc suffixIterator = suffixes.listIterator();
111
112         while (suffixIterator.hasNext()) {
113             result.append(suffixIterator.next());
114         }
115
116         return result.toString();
117     }
118
119     /**
120      * Get the descriptor array for the receiver.
121      * @return ImageDescriptor[] or <code>null</code>
122      */

123     ImageDescriptor[] getDescriptors() {
124         return descriptors;
125     }
126
127     /**
128      * Get the prefixes for the receiver.
129      * @return List
130      */

131     List JavaDoc getPrefixes() {
132         return prefixes;
133     }
134
135     /**
136      * Get the suffixes for the receiver.
137      * @return List
138      */

139     List JavaDoc getSuffixes() {
140         return suffixes;
141     }
142
143     /**
144      * Return the background Color for the result.
145      * @return Color
146      */

147     Color getBackgroundColor() {
148         return backgroundColor;
149     }
150     /**
151      * Return the font for the result.
152      * @return Font
153      */

154     Font getFont() {
155         return font;
156     }
157     /**
158      * Return the foreground color for the result.
159      * @return Color
160      */

161     Color getForegroundColor() {
162         return foregroundColor;
163     }
164 }
165
Popular Tags