|
Lines 7-14
Link Here
|
| 7 |
* |
7 |
* |
| 8 |
* Contributors: |
8 |
* Contributors: |
| 9 |
* IBM Corporation - initial API and implementation |
9 |
* IBM Corporation - initial API and implementation |
| 10 |
* Michael Williamson (eclipse-bugs@magnaworks.com) - patch (see Bugzilla #92545) |
10 |
* Michael Williamson (eclipse-bugs@magnaworks.com) - patch (see Bugzilla #92545) |
| 11 |
* |
11 |
* |
| 12 |
*******************************************************************************/ |
12 |
*******************************************************************************/ |
| 13 |
package org.eclipse.ui.forms.widgets; |
13 |
package org.eclipse.ui.forms.widgets; |
| 14 |
|
14 |
|
|
Lines 20-27
Link Here
|
| 20 |
import org.eclipse.swt.graphics.Color; |
20 |
import org.eclipse.swt.graphics.Color; |
| 21 |
//import org.eclipse.swt.graphics.GC; |
21 |
//import org.eclipse.swt.graphics.GC; |
| 22 |
import org.eclipse.swt.graphics.Image; |
22 |
import org.eclipse.swt.graphics.Image; |
| 23 |
//import org.eclipse.swt.graphics.Point; |
23 |
import org.eclipse.swt.graphics.Point; |
| 24 |
//import org.eclipse.swt.graphics.Rectangle; |
24 |
import org.eclipse.swt.graphics.Rectangle; |
|
|
25 |
import org.eclipse.swt.internal.widgets.IWidgetGraphicsAdapter; |
| 25 |
import org.eclipse.swt.widgets.Composite; |
26 |
import org.eclipse.swt.widgets.Composite; |
| 26 |
import org.eclipse.swt.widgets.Control; |
27 |
import org.eclipse.swt.widgets.Control; |
| 27 |
import org.eclipse.swt.widgets.Event; |
28 |
import org.eclipse.swt.widgets.Event; |
|
Lines 47-53
Link Here
|
| 47 |
* typical way to take advantage of the new method is to set an instance of |
48 |
* typical way to take advantage of the new method is to set an instance of |
| 48 |
* <code>FormText</code> to provide for hyperlinks and images in the |
49 |
* <code>FormText</code> to provide for hyperlinks and images in the |
| 49 |
* description area. |
50 |
* description area. |
| 50 |
* |
51 |
* |
| 51 |
* @since 1.0 |
52 |
* @since 1.0 |
| 52 |
*/ |
53 |
*/ |
| 53 |
public class Section extends ExpandableComposite { |
54 |
public class Section extends ExpandableComposite { |
|
Lines 62-67
Link Here
|
| 62 |
|
63 |
|
| 63 |
private Hashtable titleColors; |
64 |
private Hashtable titleColors; |
| 64 |
|
65 |
|
|
|
66 |
// RAP [if] Title bar background gradient rendering |
| 67 |
private Composite titleBar; |
| 68 |
|
| 65 |
private static final String COLOR_BG = "bg"; //$NON-NLS-1$ |
69 |
private static final String COLOR_BG = "bg"; //$NON-NLS-1$ |
| 66 |
|
70 |
|
| 67 |
private static final String COLOR_GBG = "gbg"; //$NON-NLS-1$ |
71 |
private static final String COLOR_GBG = "gbg"; //$NON-NLS-1$ |
|
Lines 70-76
Link Here
|
| 70 |
|
74 |
|
| 71 |
/** |
75 |
/** |
| 72 |
* Creates a new section instance in the provided parent. |
76 |
* Creates a new section instance in the provided parent. |
| 73 |
* |
77 |
* |
| 74 |
* @param parent |
78 |
* @param parent |
| 75 |
* the parent composite |
79 |
* the parent composite |
| 76 |
* @param style |
80 |
* @param style |
|
Lines 88-93
Link Here
|
| 88 |
descriptionControl = new Text(this, SWT.READ_ONLY | SWT.WRAP | rtl); |
92 |
descriptionControl = new Text(this, SWT.READ_ONLY | SWT.WRAP | rtl); |
| 89 |
} |
93 |
} |
| 90 |
if ((style & TITLE_BAR) != 0) { |
94 |
if ((style & TITLE_BAR) != 0) { |
|
|
95 |
// RAP [if] Title bar background gradient rendering |
| 96 |
titleBar = new Composite( this, SWT.NONE ); |
| 97 |
// ENDRAP [if] |
| 91 |
Listener listener = new Listener() { |
98 |
Listener listener = new Listener() { |
| 92 |
public void handleEvent(Event e) { |
99 |
public void handleEvent(Event e) { |
| 93 |
Image image = Section.super.getBackgroundImage(); |
100 |
Image image = Section.super.getBackgroundImage(); |
|
Lines 95-100
Link Here
|
| 95 |
FormImages.getInstance().markFinished(image); |
102 |
FormImages.getInstance().markFinished(image); |
| 96 |
} |
103 |
} |
| 97 |
Section.super.setBackgroundImage(null); |
104 |
Section.super.setBackgroundImage(null); |
|
|
105 |
// RAP [if] Title bar background gradient rendering |
| 106 |
applyBackgroundGradient(); |
| 107 |
// ENDRAP [if] |
| 98 |
} |
108 |
} |
| 99 |
}; |
109 |
}; |
| 100 |
addListener(SWT.Dispose, listener); |
110 |
addListener(SWT.Dispose, listener); |
|
Lines 152-158
Link Here
|
| 152 |
/** |
162 |
/** |
| 153 |
* Sets the description text. Has no effect if DESCRIPTION style was not |
163 |
* Sets the description text. Has no effect if DESCRIPTION style was not |
| 154 |
* used to create the control. |
164 |
* used to create the control. |
| 155 |
* |
165 |
* |
| 156 |
* @param description |
166 |
* @param description |
| 157 |
*/ |
167 |
*/ |
| 158 |
public void setDescription(String description) { |
168 |
public void setDescription(String description) { |
|
Lines 162-168
Link Here
|
| 162 |
|
172 |
|
| 163 |
/** |
173 |
/** |
| 164 |
* Returns the current description text. |
174 |
* Returns the current description text. |
| 165 |
* |
175 |
* |
| 166 |
* @return description text or <code>null</code> if DESCRIPTION style was |
176 |
* @return description text or <code>null</code> if DESCRIPTION style was |
| 167 |
* not used to create the control. |
177 |
* not used to create the control. |
| 168 |
*/ |
178 |
*/ |
|
Lines 177-183
Link Here
|
| 177 |
* <samp>null </samp> and must be a direct child of this container. If |
187 |
* <samp>null </samp> and must be a direct child of this container. If |
| 178 |
* defined, separator will be placed below the title text and will remain |
188 |
* defined, separator will be placed below the title text and will remain |
| 179 |
* visible regardless of the expansion state. |
189 |
* visible regardless of the expansion state. |
| 180 |
* |
190 |
* |
| 181 |
* @param separator |
191 |
* @param separator |
| 182 |
* the separator that will be placed below the title text. |
192 |
* the separator that will be placed below the title text. |
| 183 |
*/ |
193 |
*/ |
|
Lines 189-195
Link Here
|
| 189 |
/** |
199 |
/** |
| 190 |
* Returns the control that is used as a separator betweeen the title and |
200 |
* Returns the control that is used as a separator betweeen the title and |
| 191 |
* the client, or <samp>null </samp> if not set. |
201 |
* the client, or <samp>null </samp> if not set. |
| 192 |
* |
202 |
* |
| 193 |
* @return separator control or <samp>null </samp> if not set. |
203 |
* @return separator control or <samp>null </samp> if not set. |
| 194 |
*/ |
204 |
*/ |
| 195 |
public Control getSeparatorControl() { |
205 |
public Control getSeparatorControl() { |
|
Lines 198-204
Link Here
|
| 198 |
|
208 |
|
| 199 |
/** |
209 |
/** |
| 200 |
* Sets the background of the section. |
210 |
* Sets the background of the section. |
| 201 |
* |
211 |
* |
| 202 |
* @param bg |
212 |
* @param bg |
| 203 |
* the new background |
213 |
* the new background |
| 204 |
*/ |
214 |
*/ |
|
Lines 207-217
Link Here
|
| 207 |
if (descriptionControl != null |
217 |
if (descriptionControl != null |
| 208 |
&& (getExpansionStyle() & DESCRIPTION) != 0) |
218 |
&& (getExpansionStyle() & DESCRIPTION) != 0) |
| 209 |
descriptionControl.setBackground(bg); |
219 |
descriptionControl.setBackground(bg); |
|
|
220 |
// RAP [if] Title bar background gradient rendering |
| 221 |
applyBackgroundGradient(); |
| 222 |
// ENDRAP [if] |
| 210 |
} |
223 |
} |
| 211 |
|
224 |
|
| 212 |
/** |
225 |
/** |
| 213 |
* Sets the foreground of the section. |
226 |
* Sets the foreground of the section. |
| 214 |
* |
227 |
* |
| 215 |
* @param fg |
228 |
* @param fg |
| 216 |
* the new foreground. |
229 |
* the new foreground. |
| 217 |
*/ |
230 |
*/ |
|
Lines 225-231
Link Here
|
| 225 |
/** |
238 |
/** |
| 226 |
* Returns the control used to render the description. In 3.1, this method |
239 |
* Returns the control used to render the description. In 3.1, this method |
| 227 |
* was promoted to public. |
240 |
* was promoted to public. |
| 228 |
* |
241 |
* |
| 229 |
* @return description control or <code>null</code> if DESCRIPTION style |
242 |
* @return description control or <code>null</code> if DESCRIPTION style |
| 230 |
* was not used to create the control and description control was |
243 |
* was not used to create the control and description control was |
| 231 |
* not set by the client. |
244 |
* not set by the client. |
|
Lines 244-250
Link Here
|
| 244 |
* This method and <code>DESCRIPTION</code> style are mutually exclusive. |
257 |
* This method and <code>DESCRIPTION</code> style are mutually exclusive. |
| 245 |
* Use the method only if you want to create the description control |
258 |
* Use the method only if you want to create the description control |
| 246 |
* yourself. |
259 |
* yourself. |
| 247 |
* |
260 |
* |
| 248 |
* @param descriptionControl |
261 |
* @param descriptionControl |
| 249 |
* the control that will be placed below the title text. |
262 |
* the control that will be placed below the title text. |
| 250 |
*/ |
263 |
*/ |
|
Lines 257-263
Link Here
|
| 257 |
|
270 |
|
| 258 |
/** |
271 |
/** |
| 259 |
* Sets the color of the title bar border when TITLE_BAR style is used. |
272 |
* Sets the color of the title bar border when TITLE_BAR style is used. |
| 260 |
* |
273 |
* |
| 261 |
* @param color |
274 |
* @param color |
| 262 |
* the title bar border color |
275 |
* the title bar border color |
| 263 |
*/ |
276 |
*/ |
|
Lines 268-286
Link Here
|
| 268 |
/** |
281 |
/** |
| 269 |
* Sets the color of the title bar background when TITLE_BAR style is used. |
282 |
* Sets the color of the title bar background when TITLE_BAR style is used. |
| 270 |
* This color is used as a starting color for the vertical gradient. |
283 |
* This color is used as a starting color for the vertical gradient. |
| 271 |
* |
284 |
* |
| 272 |
* @param color |
285 |
* @param color |
| 273 |
* the title bar border background |
286 |
* the title bar border background |
| 274 |
*/ |
287 |
*/ |
| 275 |
public void setTitleBarBackground(Color color) { |
288 |
public void setTitleBarBackground(Color color) { |
| 276 |
putTitleBarColor(COLOR_BG, color); |
289 |
putTitleBarColor(COLOR_BG, color); |
|
|
290 |
// RAP [if] Title bar background gradient rendering |
| 291 |
applyBackgroundGradient(); |
| 292 |
// ENDRAP [if] |
| 277 |
} |
293 |
} |
| 278 |
|
294 |
|
| 279 |
/** |
295 |
/** |
| 280 |
* Sets the color of the title bar gradient background when TITLE_BAR style |
296 |
* Sets the color of the title bar gradient background when TITLE_BAR style |
| 281 |
* is used. This color is used at the height where title controls end |
297 |
* is used. This color is used at the height where title controls end |
| 282 |
* (toggle, tool bar). |
298 |
* (toggle, tool bar). |
| 283 |
* |
299 |
* |
| 284 |
* @param color |
300 |
* @param color |
| 285 |
* the title bar gradient background |
301 |
* the title bar gradient background |
| 286 |
*/ |
302 |
*/ |
|
Lines 290-296
Link Here
|
| 290 |
|
306 |
|
| 291 |
/** |
307 |
/** |
| 292 |
* Returns the title bar border color when TITLE_BAR style is used. |
308 |
* Returns the title bar border color when TITLE_BAR style is used. |
| 293 |
* |
309 |
* |
| 294 |
* @return the title bar border color |
310 |
* @return the title bar border color |
| 295 |
*/ |
311 |
*/ |
| 296 |
public Color getTitleBarBorderColor() { |
312 |
public Color getTitleBarBorderColor() { |
|
Lines 302-308
Link Here
|
| 302 |
/** |
318 |
/** |
| 303 |
* Returns the title bar gradient background color when TITLE_BAR style is |
319 |
* Returns the title bar gradient background color when TITLE_BAR style is |
| 304 |
* used. |
320 |
* used. |
| 305 |
* |
321 |
* |
| 306 |
* @return the title bar gradient background |
322 |
* @return the title bar gradient background |
| 307 |
*/ |
323 |
*/ |
| 308 |
public Color getTitleBarGradientBackground() { |
324 |
public Color getTitleBarGradientBackground() { |
|
Lines 315-321
Link Here
|
| 315 |
|
331 |
|
| 316 |
/** |
332 |
/** |
| 317 |
* Returns the title bar background when TITLE_BAR style is used. |
333 |
* Returns the title bar background when TITLE_BAR style is used. |
| 318 |
* |
334 |
* |
| 319 |
* @return the title bar background |
335 |
* @return the title bar background |
| 320 |
*/ |
336 |
*/ |
| 321 |
public Color getTitleBarBackground() { |
337 |
public Color getTitleBarBackground() { |
|
Lines 471-474
Link Here
|
| 471 |
*/ |
487 |
*/ |
| 472 |
public final void setBackgroundImage(Image image) { |
488 |
public final void setBackgroundImage(Image image) { |
| 473 |
} |
489 |
} |
|
|
490 |
|
| 491 |
// RAP [if] Title bar background gradient rendering |
| 492 |
private final void applyBackgroundGradient() { |
| 493 |
if( titleBar != null ) { |
| 494 |
// Code start - onPaint |
| 495 |
Color bg = null; |
| 496 |
if (titleColors != null) { |
| 497 |
bg = (Color) titleColors.get(COLOR_BG); |
| 498 |
} |
| 499 |
if (bg == null) |
| 500 |
bg = getBackground(); |
| 501 |
Rectangle bounds = getClientArea(); |
| 502 |
int theight = 0; |
| 503 |
int gradientheight = 0; |
| 504 |
int tvmargin = IGAP; |
| 505 |
Point tsize = null; |
| 506 |
Point tcsize = null; |
| 507 |
if (toggle != null) |
| 508 |
tsize = toggle.getSize(); |
| 509 |
int twidth = bounds.width - marginWidth - marginWidth; |
| 510 |
if (tsize != null) |
| 511 |
twidth -= tsize.x + IGAP; |
| 512 |
if (getTextClient() != null) |
| 513 |
tcsize = getTextClient().getSize(); |
| 514 |
if (tcsize != null) |
| 515 |
twidth -= tcsize.x + IGAP; |
| 516 |
Point size = textLabel.getSize(); |
| 517 |
if (tsize != null) |
| 518 |
theight += Math.max(theight, tsize.y); |
| 519 |
gradientheight = theight; |
| 520 |
if (tcsize != null) { |
| 521 |
theight = Math.max(theight, tcsize.y); |
| 522 |
} |
| 523 |
theight = Math.max(theight, size.y); |
| 524 |
gradientheight = Math.max(gradientheight, size.y); |
| 525 |
theight += tvmargin + tvmargin; |
| 526 |
gradientheight += tvmargin + tvmargin; |
| 527 |
// Code end - onPaint |
| 528 |
|
| 529 |
titleBar.setBounds( 0, 0, bounds.width, gradientheight ); |
| 530 |
Object adapter = titleBar.getAdapter( IWidgetGraphicsAdapter.class ); |
| 531 |
IWidgetGraphicsAdapter gfxAdapter = ( IWidgetGraphicsAdapter )adapter; |
| 532 |
Color[] gradientColors = new Color[] { |
| 533 |
bg, |
| 534 |
getBackground() |
| 535 |
}; |
| 536 |
int[] percents = new int[] { 0, 100 }; |
| 537 |
gfxAdapter.setBackgroundGradient( gradientColors, percents ); |
| 538 |
} |
| 539 |
} |
| 540 |
// ENDRAP [if] |
| 474 |
} |
541 |
} |