author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Wed, 15 Sep 2010 12:05:25 +0300 | |
branch | RCL_3 |
changeset 77 | 7cee158cb8cd |
parent 66 | 2455ef1f5bbc |
permissions | -rw-r--r-- |
66 | 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 |
* Lynne Kues (IBM Corp) - modified to reflect eSWT API subset |
|
11 |
* Nokia Corporation - S60 implementation |
|
12 |
*******************************************************************************/ |
|
13 |
package org.eclipse.swt.widgets; |
|
14 |
||
15 |
||
16 |
import org.eclipse.swt.SWT; |
|
17 |
import org.eclipse.swt.events.SelectionEvent; |
|
18 |
import org.eclipse.swt.events.SelectionListener; |
|
19 |
import org.eclipse.swt.widgets.Shell; |
|
20 |
import org.eclipse.swt.widgets.Combo; |
|
21 |
import org.eclipse.swt.widgets.Button; |
|
22 |
import org.eclipse.swt.widgets.Label; |
|
23 |
import org.eclipse.swt.graphics.Font; |
|
24 |
import org.eclipse.swt.graphics.FontData; |
|
25 |
import org.eclipse.swt.graphics.Color; |
|
26 |
import org.eclipse.swt.graphics.Image; |
|
27 |
import org.eclipse.swt.graphics.GC; |
|
28 |
import org.eclipse.swt.graphics.RGB; |
|
29 |
import org.eclipse.swt.graphics.Rectangle; |
|
30 |
import org.eclipse.swt.layout.FillLayout; |
|
31 |
import org.eclipse.swt.layout.GridData; |
|
32 |
import org.eclipse.swt.layout.GridLayout; |
|
33 |
import org.eclipse.ercp.swt.expanded.internal.OS; |
|
34 |
||
35 |
||
36 |
/** |
|
37 |
* Instances of this class allow the user to select a font |
|
38 |
* from all available fonts in the system. |
|
39 |
* <dl> |
|
40 |
* <dt><b>Styles:</b></dt> |
|
41 |
* <dd>(none)</dd> |
|
42 |
* <dt><b>Events:</b></dt> |
|
43 |
* <dd>(none)</dd> |
|
44 |
* </dl> |
|
45 |
* <p> |
|
46 |
* IMPORTANT: This class is intended to be subclassed <em>only</em> |
|
47 |
* within the SWT implementation. |
|
48 |
* </p> |
|
49 |
*/ |
|
50 |
public class FontDialog extends Dialog |
|
51 |
{ |
|
52 |
// Constants |
|
53 |
private final int[] HEIGHTS = {4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 16, 24, 36, 48, 72}; |
|
54 |
private final String BOLD = "B"; |
|
55 |
private final String ITALIC = "I"; |
|
56 |
||
57 |
// Components |
|
58 |
private Shell shell; |
|
59 |
private Combo faceCombo; |
|
60 |
private Combo heightCombo; |
|
61 |
private Label previewLabel; |
|
62 |
private Button weightButton; |
|
63 |
private Button styleButton; |
|
64 |
private Button colorButton; |
|
65 |
private Composite row4; |
|
66 |
Button lsk; |
|
67 |
Button rsk; |
|
68 |
||
69 |
// Component data |
|
70 |
private String title = ""; |
|
71 |
private String stringOk = ""; |
|
72 |
private String stringCancel = ""; |
|
73 |
private Font previewFont; |
|
74 |
private Color previewColor; |
|
75 |
private Image colorButtonImg; |
|
76 |
private Font weightButtonFont; |
|
77 |
private Font styleButtonFont; |
|
78 |
private FontData defFontData; |
|
79 |
||
80 |
// Result data |
|
81 |
private FontData resFontData = null; |
|
82 |
private RGB resRgb = null; |
|
83 |
private boolean resRgbChanged = false; |
|
84 |
||
85 |
// Flags |
|
86 |
private boolean isOpen = false; |
|
87 |
||
88 |
// Platform fonts |
|
89 |
private String[] platformFonts; |
|
90 |
||
91 |
// Listeners |
|
92 |
private Listener settingsListener; |
|
93 |
private Listener skListener; |
|
94 |
||
95 |
/** |
|
96 |
* Constructs a new instance of this class given its parent |
|
97 |
* and a style value describing its behavior and appearance. |
|
98 |
* <p> |
|
99 |
* The style value is either one of the style constants defined in |
|
100 |
* class <code>SWT</code> which is applicable to instances of this |
|
101 |
* class, or must be built by <em>bitwise OR</em>'ing together |
|
102 |
* (that is, using the <code>int</code> "|" operator) two or more |
|
103 |
* of those <code>SWT</code> style constants. The class description |
|
104 |
* lists the style constants that are applicable to the class. |
|
105 |
* Style bits are also inherited from superclasses. |
|
106 |
* </p> |
|
107 |
* |
|
108 |
* @param parent a shell which will be the parent of the new instance |
|
109 |
* @param style the style of dialog to construct |
|
110 |
* |
|
111 |
* @exception IllegalArgumentException <ul> |
|
112 |
* <li>ERROR_NULL_ARGUMENT - if the parent is null</li> |
|
113 |
* </ul> |
|
114 |
* @exception SWTException <ul> |
|
115 |
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li> |
|
116 |
* <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li> |
|
117 |
* </ul> |
|
118 |
*/ |
|
119 |
public FontDialog(Shell parent) |
|
120 |
{ |
|
121 |
this(parent, SWT.NONE); |
|
122 |
} |
|
123 |
||
124 |
/** |
|
125 |
* Constructs a new instance of this class given only its parent. |
|
126 |
* |
|
127 |
* @param parent a shell which will be the parent of the new instance |
|
128 |
* |
|
129 |
* @exception IllegalArgumentException <ul> |
|
130 |
* <li>ERROR_NULL_ARGUMENT - if the parent is null</li> |
|
131 |
* </ul> |
|
132 |
* @exception SWTException <ul> |
|
133 |
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li> |
|
134 |
* <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li> |
|
135 |
* </ul> |
|
136 |
*/ |
|
137 |
public FontDialog(Shell parent, int style) |
|
138 |
{ |
|
139 |
super(parent, style); |
|
140 |
checkSubclass(); |
|
141 |
stringOk = OS.FontDialog_GetCommandOkTitle(); |
|
142 |
stringCancel = OS.FontDialog_GetCommandCancelTitle(); |
|
143 |
platformFonts = OS.FontDialog_GetFontNames(true); |
|
144 |
defFontData = parent.getDisplay().getSystemFont().getFontData()[0]; |
|
145 |
} |
|
146 |
||
147 |
/** |
|
148 |
* Returns a FontData set describing the font that was |
|
149 |
* selected in the dialog, or null if none is available. |
|
150 |
* |
|
151 |
* @return the FontData for the selected font, or null |
|
152 |
* @since 2.1.1 |
|
153 |
*/ |
|
154 |
public FontData[] getFontList() |
|
155 |
{ |
|
156 |
if (resFontData == null) |
|
157 |
{ |
|
158 |
return null; |
|
159 |
} |
|
160 |
else |
|
161 |
{ |
|
162 |
return new FontData[] {resFontData}; |
|
163 |
} |
|
164 |
} |
|
165 |
||
166 |
/** |
|
167 |
* Returns the currently selected color in the receiver. |
|
168 |
* |
|
169 |
* @return the RGB value for the selected color, may be null |
|
170 |
* |
|
171 |
* @see PaletteData#getRGBs |
|
172 |
* |
|
173 |
* @since 2.1 |
|
174 |
*/ |
|
175 |
public RGB getRGB() |
|
176 |
{ |
|
177 |
return resRgb; |
|
178 |
} |
|
179 |
||
180 |
/** |
|
181 |
* Makes the dialog visible and brings it to the front |
|
182 |
* of the display. |
|
183 |
* |
|
184 |
* @return a FontData object describing the font that was selected, |
|
185 |
* or null if the dialog was cancelled or an error occurred |
|
186 |
* |
|
187 |
* @exception SWTException <ul> |
|
188 |
* <li>ERROR_WIDGET_DISPOSED - if the dialog has been disposed</li> |
|
189 |
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the dialog</li> |
|
190 |
* </ul> |
|
191 |
*/ |
|
192 |
public FontData open() |
|
193 |
{ |
|
194 |
// Check thread access |
|
195 |
if (!parent.getDisplay().isValidThread()) |
|
196 |
{ |
|
197 |
error(SWT.ERROR_THREAD_INVALID_ACCESS); |
|
198 |
} |
|
199 |
||
200 |
// Dialog shell |
|
201 |
int flags = SWT.BORDER | SWT.APPLICATION_MODAL | SWT.ON_TOP; |
|
202 |
if (title != null && title.length() > 0) |
|
203 |
flags |= SWT.TITLE; |
|
204 |
shell = new Shell(getParent(), flags); |
|
205 |
shell.setText(title); |
|
206 |
||
207 |
if (org.eclipse.swt.internal.symbian.OS.windowServer |
|
208 |
< org.eclipse.swt.internal.symbian.OS.WS_SYMBIAN_S60_92) |
|
209 |
{ |
|
210 |
// On 5.0 the modal Shell needs to be made visible before Combo is created. |
|
211 |
shell.open(); |
|
212 |
} |
|
213 |
||
214 |
// Listen to skin and resolution changes |
|
215 |
settingsListener = new Listener() |
|
216 |
{ |
|
217 |
public void handleEvent(Event ev) |
|
218 |
{ |
|
219 |
if (resRgb == null || !resRgbChanged) |
|
220 |
{ |
|
221 |
resRgb = Display.getDefault().getSystemColor(SWT.COLOR_WIDGET_FOREGROUND).getRGB(); |
|
222 |
updatePreviewColor(); |
|
223 |
} |
|
224 |
Rectangle rect = shell.internal_getDefaultBounds(); // default dialog bounds |
|
225 |
Rectangle screenRect = parent.getDisplay().getBounds(); |
|
226 |
rect.height += row4.computeSize(shell.getClientArea().width, SWT.DEFAULT).y; |
|
227 |
if (screenRect.height > screenRect.width) |
|
228 |
{ |
|
229 |
// Bottom position for portrait orientation |
|
230 |
rect.y = screenRect.height - rect.height; |
|
231 |
} |
|
232 |
else |
|
233 |
{ |
|
234 |
// Vertical middle position for landscape orientation |
|
235 |
rect.y = (screenRect.height - rect.height) / 2; |
|
236 |
} |
|
237 |
||
238 |
shell.setBounds(rect); |
|
239 |
updatePreviewFont(); |
|
240 |
} |
|
241 |
}; |
|
242 |
shell.getDisplay().addListener(SWT.Settings, settingsListener); |
|
243 |
||
244 |
// Listen to softkey presses and deliver them to the buttons |
|
245 |
skListener = new Listener(){ |
|
246 |
public void handleEvent(Event event) { |
|
247 |
switch(event.keyCode) { |
|
248 |
case -6: // LSK |
|
249 |
isOpen = false; |
|
250 |
break; |
|
251 |
case -7: // RSK |
|
252 |
resFontData = null; |
|
253 |
resRgb = null; |
|
254 |
isOpen = false; |
|
255 |
break; |
|
256 |
default: |
|
257 |
break; |
|
258 |
} |
|
259 |
}}; |
|
260 |
parent.getDisplay().addFilter(SWT.KeyDown, skListener); |
|
261 |
||
262 |
// Create default results if not already set |
|
263 |
if (resFontData == null) |
|
264 |
{ |
|
265 |
resFontData = defFontData; |
|
266 |
} |
|
267 |
if (resRgb == null || !resRgbChanged) |
|
268 |
{ |
|
269 |
resRgb = Display.getDefault().getSystemColor(SWT.COLOR_WIDGET_FOREGROUND).getRGB(); |
|
270 |
} |
|
271 |
||
272 |
GridLayout layout0 = new GridLayout(); |
|
273 |
layout0.marginTop = 0; |
|
274 |
layout0.marginBottom = 0; |
|
275 |
layout0.marginLeft = 0; |
|
276 |
layout0.marginRight = 0; |
|
277 |
layout0.marginWidth = 0; |
|
278 |
layout0.marginHeight = 0; |
|
279 |
layout0.horizontalSpacing = 1; |
|
280 |
layout0.verticalSpacing = 1; |
|
281 |
shell.setLayout(layout0); |
|
282 |
||
283 |
// Row 1 |
|
284 |
createFaceControl(shell); |
|
285 |
||
286 |
// Row 2 |
|
287 |
Composite row2 = new Composite(shell, 0); |
|
288 |
row2.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); |
|
289 |
GridLayout layout2 = new GridLayout(5, true); |
|
290 |
layout2.marginTop = 0; |
|
291 |
layout2.marginBottom = 0; |
|
292 |
layout2.marginLeft = 0; |
|
293 |
layout2.marginRight = 0; |
|
294 |
layout2.marginWidth = 0; |
|
295 |
layout2.marginHeight = 0; |
|
296 |
layout2.horizontalSpacing = 1; |
|
297 |
layout2.verticalSpacing = 1; |
|
298 |
row2.setLayout(layout2); |
|
299 |
createHeightControl(row2); |
|
300 |
createWeightControl(row2); |
|
301 |
createStyleControl(row2); |
|
302 |
createColorControl(row2); |
|
303 |
||
304 |
// Row 3 |
|
305 |
createPreviewControl(shell); |
|
306 |
||
307 |
// Row 4 |
|
308 |
row4 = new Composite(shell, 0); |
|
309 |
row4.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); |
|
310 |
row4.setLayout(new FillLayout(SWT.HORIZONTAL)); |
|
311 |
||
312 |
createButtons(row4); |
|
313 |
||
314 |
Rectangle rect = shell.getBounds(); // default dialog bounds |
|
315 |
Rectangle screenRect = parent.getDisplay().getBounds(); |
|
316 |
rect.height += row4.computeSize(shell.getClientArea().width, SWT.DEFAULT).y; |
|
317 |
if (screenRect.height > screenRect.width) |
|
318 |
{ |
|
319 |
// Bottom position for portrait orientation |
|
320 |
rect.y = screenRect.height - rect.height; |
|
321 |
} |
|
322 |
else |
|
323 |
{ |
|
324 |
// Vertical middle position for landscape orientation |
|
325 |
rect.y = (screenRect.height - rect.height) / 2; |
|
326 |
} |
|
327 |
||
328 |
shell.setBounds(rect); |
|
329 |
||
330 |
if (org.eclipse.swt.internal.symbian.OS.windowServer |
|
331 |
>= org.eclipse.swt.internal.symbian.OS.WS_SYMBIAN_S60_92) |
|
332 |
{ |
|
333 |
shell.open(); |
|
334 |
} |
|
335 |
||
336 |
// Block till submited |
|
337 |
isOpen = true; |
|
338 |
Display display = shell.getDisplay(); |
|
339 |
while (isOpen) |
|
340 |
{ |
|
341 |
if (!display.readAndDispatch()) |
|
342 |
{ |
|
343 |
display.sleep(); |
|
344 |
} |
|
345 |
} |
|
346 |
destroyControls(); |
|
347 |
||
348 |
return resFontData; |
|
349 |
} |
|
350 |
||
351 |
/** |
|
352 |
* Sets a set of FontData objects describing the font to |
|
353 |
* be selected by default in the dialog, or null to let |
|
354 |
* the platform choose one. |
|
355 |
* |
|
356 |
* @param fontData the set of FontData objects to use initially, or null |
|
357 |
* @since 2.1.1 |
|
358 |
*/ |
|
359 |
public void setFontList(FontData [] fontData) |
|
360 |
{ |
|
361 |
if (fontData != null && fontData.length > 0) |
|
362 |
{ |
|
363 |
resFontData = fontData[0]; |
|
364 |
} |
|
365 |
else |
|
366 |
{ |
|
367 |
resFontData = null; |
|
368 |
} |
|
369 |
} |
|
370 |
||
371 |
/** |
|
372 |
* Sets the receiver's selected color to be the argument. |
|
373 |
* |
|
374 |
* @param rgb the new RGB value for the selected color, may be |
|
375 |
* null to let the platform to select a default when |
|
376 |
* open() is called |
|
377 |
* |
|
378 |
* @see PaletteData#getRGBs |
|
379 |
* |
|
380 |
* @since 2.1 |
|
381 |
*/ |
|
382 |
public void setRGB(RGB rgb) |
|
383 |
{ |
|
384 |
resRgb = rgb; |
|
77
7cee158cb8cd
Revision: v2.2.13
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
66
diff
changeset
|
385 |
resRgbChanged = true; |
66 | 386 |
} |
387 |
||
388 |
/** |
|
389 |
* Sets the receiver's text, which is the string that the |
|
390 |
* window manager will typically display as the receiver's |
|
391 |
* <em>title</em>, to the argument, which must not be null. |
|
392 |
* |
|
393 |
* @param string the new text |
|
394 |
* |
|
395 |
* @exception IllegalArgumentException <ul> |
|
396 |
* <li>ERROR_NULL_ARGUMENT - if the text is null</li> |
|
397 |
* </ul> |
|
398 |
* @exception SWTException <ul> |
|
399 |
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> |
|
400 |
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> |
|
401 |
* </ul> |
|
402 |
*/ |
|
403 |
public void setText(String string) |
|
404 |
{ |
|
405 |
super.setText(string); |
|
406 |
title = string; |
|
407 |
} |
|
408 |
||
409 |
private void createButtons(final Composite parent) { |
|
410 |
lsk = new Button(parent, 0); |
|
411 |
shell.setDefaultButton(lsk); |
|
412 |
lsk.setText(stringOk); |
|
413 |
lsk.addSelectionListener( |
|
414 |
new SelectionListener() |
|
415 |
{ |
|
416 |
public void widgetDefaultSelected(SelectionEvent ev) |
|
417 |
{ |
|
418 |
} |
|
419 |
public void widgetSelected(SelectionEvent ev) |
|
420 |
{ |
|
421 |
isOpen = false; |
|
422 |
} |
|
423 |
}); |
|
424 |
||
425 |
rsk = new Button(parent, 0); |
|
426 |
rsk.setText(stringCancel); |
|
427 |
rsk.addSelectionListener( |
|
428 |
new SelectionListener() |
|
429 |
{ |
|
430 |
public void widgetDefaultSelected(SelectionEvent ev) |
|
431 |
{ |
|
432 |
} |
|
433 |
public void widgetSelected(SelectionEvent ev) |
|
434 |
{ |
|
435 |
resFontData = null; |
|
436 |
resRgb = null; |
|
437 |
isOpen = false; |
|
438 |
} |
|
439 |
}); |
|
440 |
} |
|
441 |
||
442 |
private void createColorControl(final Composite parent) { |
|
443 |
// Control |
|
444 |
colorButton = new Button(parent, SWT.PUSH); |
|
445 |
colorButton.addSelectionListener( |
|
446 |
new SelectionListener() |
|
447 |
{ |
|
448 |
public void widgetDefaultSelected(SelectionEvent ev) |
|
449 |
{ |
|
450 |
} |
|
451 |
public void widgetSelected(SelectionEvent ev) |
|
452 |
{ |
|
453 |
ColorDialog dlg = new ColorDialog(parent.getShell(), SWT.NONE); |
|
454 |
RGB rgb = dlg.open(); |
|
455 |
fontColorChanged(rgb); |
|
456 |
} |
|
457 |
}); |
|
458 |
||
459 |
// Layout |
|
460 |
colorButton.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false)); |
|
461 |
} |
|
462 |
||
463 |
private void createFaceControl(final Shell parent) { |
|
464 |
// Control |
|
465 |
faceCombo = new Combo(parent, SWT.READ_ONLY); |
|
466 |
faceCombo.addSelectionListener( |
|
467 |
new SelectionListener() |
|
468 |
{ |
|
469 |
public void widgetDefaultSelected(SelectionEvent ev) |
|
470 |
{ |
|
471 |
} |
|
472 |
public void widgetSelected(SelectionEvent ev) |
|
473 |
{ |
|
474 |
fontFaceChanged(); |
|
475 |
} |
|
476 |
}); |
|
477 |
||
478 |
// Items |
|
479 |
faceCombo.setItems(platformFonts); |
|
480 |
||
481 |
// Defaults |
|
482 |
int index = faceCombo.indexOf(resFontData.getName()); |
|
483 |
if (index >= 0) |
|
484 |
{ |
|
485 |
faceCombo.select(index); |
|
486 |
} |
|
487 |
||
488 |
// Layout |
|
489 |
faceCombo.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); |
|
490 |
} |
|
491 |
||
492 |
private void createHeightControl(final Composite parent) { |
|
493 |
// Control |
|
494 |
heightCombo = new Combo(parent, SWT.READ_ONLY); |
|
495 |
heightCombo.addSelectionListener( |
|
496 |
new SelectionListener() |
|
497 |
{ |
|
498 |
public void widgetDefaultSelected(SelectionEvent ev) |
|
499 |
{ |
|
500 |
} |
|
501 |
public void widgetSelected(SelectionEvent ev) |
|
502 |
{ |
|
503 |
fontHeightChanged(); |
|
504 |
} |
|
505 |
}); |
|
506 |
||
507 |
// Items |
|
508 |
String[] items = new String[HEIGHTS.length]; |
|
509 |
for (int i = 0; i < HEIGHTS.length; i++) |
|
510 |
{ |
|
511 |
items[i] = Integer.toString(HEIGHTS[i]); |
|
512 |
} |
|
513 |
heightCombo.setItems(items); |
|
514 |
||
515 |
// Defaults |
|
516 |
int pos = -1; |
|
517 |
for (int i = 0; i < HEIGHTS.length; i++) |
|
518 |
{ |
|
519 |
if (resFontData.getHeight() <= HEIGHTS[i]) |
|
520 |
{ |
|
521 |
pos = i; |
|
522 |
break; |
|
523 |
} |
|
524 |
} |
|
525 |
if (pos >= 0) |
|
526 |
{ |
|
527 |
heightCombo.select(pos); |
|
528 |
} |
|
529 |
||
530 |
// Layout |
|
531 |
heightCombo.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 2, 1)); |
|
532 |
} |
|
533 |
||
534 |
private void createStyleControl(final Composite parent) { |
|
535 |
// Control |
|
536 |
styleButton = new Button(parent, SWT.TOGGLE); |
|
537 |
styleButtonFont = new Font(parent.getDisplay(), |
|
538 |
new FontData(defFontData.getName(), defFontData.getHeight(), SWT.ITALIC)); |
|
539 |
styleButton.setFont(styleButtonFont); |
|
540 |
styleButton.setText(this.ITALIC); |
|
541 |
styleButton.addSelectionListener( |
|
542 |
new SelectionListener() |
|
543 |
{ |
|
544 |
public void widgetDefaultSelected(SelectionEvent ev) |
|
545 |
{ |
|
546 |
} |
|
547 |
public void widgetSelected(SelectionEvent ev) |
|
548 |
{ |
|
549 |
fontStyleChanged(); |
|
550 |
} |
|
551 |
}); |
|
552 |
||
553 |
// Defaults |
|
554 |
if ((resFontData.getStyle() & SWT.ITALIC) != 0) |
|
555 |
{ |
|
556 |
styleButton.setSelection(true); |
|
557 |
} |
|
558 |
||
559 |
// Layout |
|
560 |
styleButton.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false)); |
|
561 |
} |
|
562 |
||
563 |
private void createWeightControl(final Composite parent) { |
|
564 |
// Control |
|
565 |
weightButton = new Button(parent, SWT.TOGGLE); |
|
566 |
weightButtonFont = new Font(parent.getDisplay(), |
|
567 |
new FontData(defFontData.getName(), defFontData.getHeight(), SWT.BOLD)); |
|
568 |
weightButton.setFont(weightButtonFont); |
|
569 |
weightButton.setText(this.BOLD); |
|
570 |
weightButton.addSelectionListener( |
|
571 |
new SelectionListener() |
|
572 |
{ |
|
573 |
public void widgetDefaultSelected(SelectionEvent ev) |
|
574 |
{ |
|
575 |
} |
|
576 |
public void widgetSelected(SelectionEvent ev) |
|
577 |
{ |
|
578 |
fontWeightChanged(); |
|
579 |
} |
|
580 |
}); |
|
581 |
||
582 |
// Defaults |
|
583 |
if ((resFontData.getStyle() & SWT.BOLD) != 0) |
|
584 |
{ |
|
585 |
weightButton.setSelection(true); |
|
586 |
} |
|
587 |
||
588 |
// Layout |
|
589 |
weightButton.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false)); |
|
590 |
} |
|
591 |
||
592 |
private void createPreviewControl(final Shell parent) { |
|
593 |
previewLabel = new Label(parent, SWT.CENTER | SWT.BORDER); |
|
594 |
previewLabel.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); |
|
595 |
updatePreviewText(); |
|
596 |
updatePreviewFont(); |
|
597 |
updatePreviewColor(); |
|
598 |
} |
|
599 |
||
600 |
private void destroyControls() |
|
601 |
{ |
|
602 |
shell.getDisplay().removeListener(SWT.Settings, settingsListener); |
|
603 |
shell.getDisplay().removeListener(SWT.KeyDown, skListener); |
|
604 |
||
605 |
shell.dispose(); |
|
606 |
shell = null; |
|
607 |
||
608 |
faceCombo = null; |
|
609 |
heightCombo = null; |
|
610 |
previewLabel = null; |
|
611 |
weightButton = null; |
|
612 |
styleButton = null; |
|
613 |
colorButton = null; |
|
614 |
row4 = null; |
|
615 |
lsk = null; |
|
616 |
rsk = null; |
|
617 |
||
618 |
if (previewFont != null) |
|
619 |
{ |
|
620 |
previewFont.dispose(); |
|
621 |
previewFont = null; |
|
622 |
} |
|
623 |
if (previewColor != null) |
|
624 |
{ |
|
625 |
previewColor.dispose(); |
|
626 |
previewColor = null; |
|
627 |
} |
|
628 |
if (colorButtonImg != null) |
|
629 |
{ |
|
630 |
colorButtonImg.dispose(); |
|
631 |
colorButtonImg = null; |
|
632 |
} |
|
633 |
if (weightButtonFont != null) |
|
634 |
{ |
|
635 |
weightButtonFont.dispose(); |
|
636 |
weightButtonFont = null; |
|
637 |
} |
|
638 |
if (styleButtonFont != null) |
|
639 |
{ |
|
640 |
styleButtonFont.dispose(); |
|
641 |
styleButtonFont = null; |
|
642 |
} |
|
643 |
} |
|
644 |
||
645 |
private void fontColorChanged(RGB newRGB) |
|
646 |
{ |
|
647 |
if (newRGB == null) |
|
648 |
{ |
|
649 |
return; |
|
650 |
} |
|
651 |
resRgb = newRGB; |
|
652 |
resRgbChanged = true; |
|
653 |
updatePreviewColor(); |
|
654 |
} |
|
655 |
||
656 |
private void fontFaceChanged() |
|
657 |
{ |
|
658 |
int index = faceCombo.getSelectionIndex(); |
|
659 |
if (index >= 0) |
|
660 |
{ |
|
661 |
String fontFace = faceCombo.getItem(index); |
|
662 |
resFontData.setName(fontFace); |
|
663 |
updatePreviewText(); |
|
664 |
updatePreviewFont(); |
|
665 |
} |
|
666 |
} |
|
667 |
||
668 |
private void fontHeightChanged() |
|
669 |
{ |
|
670 |
int index = heightCombo.getSelectionIndex(); |
|
671 |
if (index >= 0 && index < HEIGHTS.length) |
|
672 |
{ |
|
673 |
resFontData.setHeight(HEIGHTS[index]); |
|
674 |
updatePreviewFont(); |
|
675 |
} |
|
676 |
} |
|
677 |
||
678 |
private void fontStyleChanged() |
|
679 |
{ |
|
680 |
if (styleButton.getSelection()) |
|
681 |
{ |
|
682 |
resFontData.setStyle(resFontData.getStyle() | SWT.ITALIC); |
|
683 |
} |
|
684 |
else |
|
685 |
{ |
|
686 |
resFontData.setStyle(resFontData.getStyle() & (~SWT.ITALIC)); |
|
687 |
} |
|
688 |
updatePreviewFont(); |
|
689 |
} |
|
690 |
||
691 |
private void fontWeightChanged() |
|
692 |
{ |
|
693 |
if (weightButton.getSelection()) |
|
694 |
{ |
|
695 |
resFontData.setStyle(resFontData.getStyle() | SWT.BOLD); |
|
696 |
} |
|
697 |
else |
|
698 |
{ |
|
699 |
resFontData.setStyle(resFontData.getStyle() & (~SWT.BOLD)); |
|
700 |
} |
|
701 |
updatePreviewFont(); |
|
702 |
} |
|
703 |
||
704 |
private void updatePreviewColor() |
|
705 |
{ |
|
706 |
// Create new color based on result rgb |
|
707 |
Color color = new Color(shell.getDisplay(), resRgb); |
|
708 |
||
709 |
// Set new color to preview label |
|
710 |
if (previewLabel != null) |
|
711 |
{ |
|
712 |
previewLabel.setForeground(color); |
|
713 |
} |
|
714 |
||
715 |
// Set new color to color button image |
|
716 |
Image img = null; |
|
717 |
int h = weightButton.getSize().y / 2; |
|
718 |
if (h <= 0) |
|
719 |
h = weightButton.computeSize(-1, -1).y / 2; |
|
720 |
img = new Image(shell.getDisplay(), h, h); |
|
721 |
GC gc = new GC(img); |
|
722 |
gc.setBackground(color); |
|
723 |
gc.fillRectangle(0, 0, h, h); |
|
724 |
gc.dispose(); |
|
725 |
colorButton.setImage(img); |
|
726 |
||
727 |
// Replace old preview color |
|
728 |
if (previewColor != null) |
|
729 |
{ |
|
730 |
previewColor.dispose(); |
|
731 |
} |
|
732 |
previewColor = color; |
|
733 |
||
734 |
// Replace old color button image |
|
735 |
if (colorButtonImg != null) |
|
736 |
{ |
|
737 |
colorButtonImg.dispose(); |
|
738 |
} |
|
739 |
colorButtonImg = img; |
|
740 |
} |
|
741 |
||
742 |
private void updatePreviewFont() |
|
743 |
{ |
|
744 |
Font font = new Font(shell.getDisplay(), resFontData); |
|
745 |
if (previewLabel != null) |
|
746 |
{ |
|
747 |
previewLabel.setFont(font); |
|
748 |
} |
|
749 |
if (previewFont != null) |
|
750 |
{ |
|
751 |
previewFont.dispose(); |
|
752 |
} |
|
753 |
previewFont = font; |
|
754 |
} |
|
755 |
||
756 |
private void updatePreviewText() |
|
757 |
{ |
|
758 |
if (previewLabel != null) |
|
759 |
{ |
|
760 |
previewLabel.setText(resFontData.getName()); |
|
761 |
} |
|
762 |
} |
|
763 |
||
764 |
} |