comparison dwtx/jface/viewers/DelegatingStyledCellLabelProvider.d @ 71:4878bef4a38e

Some fixing
author Frank Benoit <benoit@tionex.de>
date Thu, 22 May 2008 04:03:58 +0200
parents 46a6e0e6ccd4
children 5df4896124c7
comparison
equal deleted inserted replaced
70:46a6e0e6ccd4 71:4878bef4a38e
14 14
15 import dwt.graphics.Color; 15 import dwt.graphics.Color;
16 import dwt.graphics.Font; 16 import dwt.graphics.Font;
17 import dwt.graphics.Image; 17 import dwt.graphics.Image;
18 18
19 import dwt.dwthelper.utils;
20
19 /** 21 /**
20 * A {@link DelegatingStyledCellLabelProvider} is a 22 * A {@link DelegatingStyledCellLabelProvider} is a
21 * {@link StyledCellLabelProvider} that delegates requests for the styled string 23 * {@link StyledCellLabelProvider} that delegates requests for the styled string
22 * and the image to a 24 * and the image to a
23 * {@link DelegatingStyledCellLabelProvider.IStyledLabelProvider}. 25 * {@link DelegatingStyledCellLabelProvider.IStyledLabelProvider}.
24 * 26 *
25 * <p> 27 * <p>
26 * Existing label providers can be enhanced by implementing 28 * Existing label providers can be enhanced by implementing
27 * {@link DelegatingStyledCellLabelProvider.IStyledLabelProvider} so they can be 29 * {@link DelegatingStyledCellLabelProvider.IStyledLabelProvider} so they can be
28 * used in viewers with styled labels. 30 * used in viewers with styled labels.
29 * </p> 31 * </p>
30 * 32 *
31 * <p> 33 * <p>
32 * The {@link DelegatingStyledCellLabelProvider.IStyledLabelProvider} can 34 * The {@link DelegatingStyledCellLabelProvider.IStyledLabelProvider} can
33 * optionally implement {@link IColorProvider} and {@link IFontProvider} to 35 * optionally implement {@link IColorProvider} and {@link IFontProvider} to
34 * provide foreground and background color and a default font. 36 * provide foreground and background color and a default font.
35 * </p> 37 * </p>
36 * 38 *
37 * @since 3.4 39 * @since 3.4
38 */ 40 */
39 public class DelegatingStyledCellLabelProvider extends StyledCellLabelProvider { 41 public class DelegatingStyledCellLabelProvider : StyledCellLabelProvider {
40 42
41 /** 43 /**
42 * Interface marking a label provider that provides styled text labels and 44 * Interface marking a label provider that provides styled text labels and
43 * images. 45 * images.
44 * <p> 46 * <p>
45 * The {@link DelegatingStyledCellLabelProvider.IStyledLabelProvider} can 47 * The {@link DelegatingStyledCellLabelProvider.IStyledLabelProvider} can
46 * optionally implement {@link IColorProvider} and {@link IFontProvider} to 48 * optionally implement {@link IColorProvider} and {@link IFontProvider} to
47 * provide foreground and background color and a default font. 49 * provide foreground and background color and a default font.
48 * </p> 50 * </p>
49 */ 51 */
50 public static interface IStyledLabelProvider extends IBaseLabelProvider { 52 public static interface IStyledLabelProvider : IBaseLabelProvider {
51 53
52 /** 54 /**
53 * Returns the styled text label for the given element 55 * Returns the styled text label for the given element
54 * 56 *
55 * @param element 57 * @param element
56 * the element to evaluate the styled string for 58 * the element to evaluate the styled string for
57 * 59 *
58 * @return the styled string. 60 * @return the styled string.
59 */ 61 */
60 public StyledString getStyledText(Object element); 62 public StyledString getStyledText(Object element);
61 63
62 /** 64 /**
63 * Returns the image for the label of the given element. The image is 65 * Returns the image for the label of the given element. The image is
64 * owned by the label provider and must not be disposed directly. 66 * owned by the label provider and must not be disposed directly.
65 * Instead, dispose the label provider when no longer needed. 67 * Instead, dispose the label provider when no longer needed.
66 * 68 *
67 * @param element 69 * @param element
68 * the element for which to provide the label image 70 * the element for which to provide the label image
69 * @return the image used to label the element, or <code>null</code> 71 * @return the image used to label the element, or <code>null</code>
70 * if there is no image for the given object 72 * if there is no image for the given object
71 */ 73 */
76 78
77 /** 79 /**
78 * Creates a {@link DelegatingStyledCellLabelProvider} that delegates the 80 * Creates a {@link DelegatingStyledCellLabelProvider} that delegates the
79 * requests for the styled labels and the images to a 81 * requests for the styled labels and the images to a
80 * {@link IStyledLabelProvider}. 82 * {@link IStyledLabelProvider}.
81 * 83 *
82 * @param labelProvider 84 * @param labelProvider
83 * the label provider that provides the styled labels and the 85 * the label provider that provides the styled labels and the
84 * images 86 * images
85 */ 87 */
86 public DelegatingStyledCellLabelProvider(IStyledLabelProvider labelProvider) { 88 public this(IStyledLabelProvider labelProvider) {
87 if (labelProvider is null) 89 if (labelProvider is null)
88 throw new IllegalArgumentException( 90 throw new IllegalArgumentException(
89 "Label provider must not be null"); //$NON-NLS-1$ 91 "Label provider must not be null"); //$NON-NLS-1$
90 92
91 this.styledLabelProvider = labelProvider; 93 this.styledLabelProvider = labelProvider;
92 } 94 }
93 95
94 /* 96 /*
95 * (non-Javadoc) 97 * (non-Javadoc)
96 * 98 *
97 * @see dwtx.jface.viewers.StyledCellLabelProvider#update(dwtx.jface.viewers.ViewerCell) 99 * @see dwtx.jface.viewers.StyledCellLabelProvider#update(dwtx.jface.viewers.ViewerCell)
98 */ 100 */
99 public void update(ViewerCell cell) { 101 public void update(ViewerCell cell) {
100 Object element = cell.getElement(); 102 Object element = cell.getElement();
101 103
115 super.update(cell); 117 super.update(cell);
116 } 118 }
117 119
118 /** 120 /**
119 * Provides a foreground color for the given element. 121 * Provides a foreground color for the given element.
120 * 122 *
121 * @param element 123 * @param element
122 * the element 124 * the element
123 * @return the foreground color for the element, or <code>null</code> to 125 * @return the foreground color for the element, or <code>null</code> to
124 * use the default foreground color 126 * use the default foreground color
125 */ 127 */
126 public Color getForeground(Object element) { 128 public Color getForeground(Object element) {
127 if (this.styledLabelProvider instanceof IColorProvider) { 129 if (null !is cast(IColorProvider)this.styledLabelProvider ) {
128 return ((IColorProvider) this.styledLabelProvider) 130 return (cast(IColorProvider) this.styledLabelProvider)
129 .getForeground(element); 131 .getForeground(element);
130 } 132 }
131 return null; 133 return null;
132 } 134 }
133 135
134 /** 136 /**
135 * Provides a background color for the given element. 137 * Provides a background color for the given element.
136 * 138 *
137 * @param element 139 * @param element
138 * the element 140 * the element
139 * @return the background color for the element, or <code>null</code> to 141 * @return the background color for the element, or <code>null</code> to
140 * use the default background color 142 * use the default background color
141 */ 143 */
142 public Color getBackground(Object element) { 144 public Color getBackground(Object element) {
143 if (this.styledLabelProvider instanceof IColorProvider) { 145 if (null !is cast(IColorProvider)this.styledLabelProvider) {
144 return ((IColorProvider) this.styledLabelProvider) 146 return (cast(IColorProvider) this.styledLabelProvider)
145 .getBackground(element); 147 .getBackground(element);
146 } 148 }
147 return null; 149 return null;
148 } 150 }
149 151
150 /** 152 /**
151 * Provides a font for the given element. 153 * Provides a font for the given element.
152 * 154 *
153 * @param element 155 * @param element
154 * the element 156 * the element
155 * @return the font for the element, or <code>null</code> to use the 157 * @return the font for the element, or <code>null</code> to use the
156 * default font 158 * default font
157 */ 159 */
158 public Font getFont(Object element) { 160 public Font getFont(Object element) {
159 if (this.styledLabelProvider instanceof IFontProvider) { 161 if (null !is cast(IFontProvider)this.styledLabelProvider ) {
160 return ((IFontProvider) this.styledLabelProvider).getFont(element); 162 return (cast(IFontProvider) this.styledLabelProvider).getFont(element);
161 } 163 }
162 return null; 164 return null;
163 } 165 }
164 166
165 /** 167 /**
166 * Returns the image for the label of the given element. The image is owned 168 * Returns the image for the label of the given element. The image is owned
167 * by the label provider and must not be disposed directly. Instead, dispose 169 * by the label provider and must not be disposed directly. Instead, dispose
168 * the label provider when no longer needed. 170 * the label provider when no longer needed.
169 * 171 *
170 * @param element 172 * @param element
171 * the element for which to provide the label image 173 * the element for which to provide the label image
172 * @return the image used to label the element, or <code>null</code> if 174 * @return the image used to label the element, or <code>null</code> if
173 * there is no image for the given object 175 * there is no image for the given object
174 */ 176 */
176 return this.styledLabelProvider.getImage(element); 178 return this.styledLabelProvider.getImage(element);
177 } 179 }
178 180
179 /** 181 /**
180 * Returns the styled text for the label of the given element. 182 * Returns the styled text for the label of the given element.
181 * 183 *
182 * @param element 184 * @param element
183 * the element for which to provide the styled label text 185 * the element for which to provide the styled label text
184 * @return the styled text string used to label the element 186 * @return the styled text string used to label the element
185 */ 187 */
186 protected StyledString getStyledText(Object element) { 188 protected StyledString getStyledText(Object element) {
187 return this.styledLabelProvider.getStyledText(element); 189 return this.styledLabelProvider.getStyledText(element);
188 } 190 }
189 191
190 /** 192 /**
191 * Returns the styled string provider. 193 * Returns the styled string provider.
192 * 194 *
193 * @return the wrapped label provider 195 * @return the wrapped label provider
194 */ 196 */
195 public IStyledLabelProvider getStyledStringProvider() { 197 public IStyledLabelProvider getStyledStringProvider() {
196 return this.styledLabelProvider; 198 return this.styledLabelProvider;
197 } 199 }