1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 /***
19 * <p>Title: WSMO Studio</p>
20 * <p>Description: Semantic Web Service Editor</p>
21 * <p>Copyright: Copyright (c) 2004-2006</p>
22 * <p>Company: OntoText Lab. / SIRMA </p>
23 */
24
25 package org.wsmostudio.preferences;
26
27 import org.eclipse.jface.preference.ColorFieldEditor;
28 import org.eclipse.swt.SWT;
29 import org.eclipse.swt.widgets.*;
30
31 public class TextStyleFieldEditor extends ColorFieldEditor {
32
33 private Button boldCheck, italicsCheck;
34
35 public TextStyleFieldEditor(String name, String labelText, Composite parent) {
36 super(name, labelText, parent);
37 }
38
39 protected Button getChangeControl(Composite parent) {
40 Button result = super.getChangeControl(parent);
41
42 new Label(parent, SWT.NONE).setText(" ");
43
44 boldCheck = new Button(parent, SWT.CHECK);
45 boldCheck.setText("Bold");
46
47 italicsCheck = new Button(parent, SWT.CHECK);
48 italicsCheck.setText("Italics");
49
50 return result;
51 }
52
53 public void dispose() {
54 boldCheck.dispose();
55 italicsCheck.dispose();
56 super.dispose();
57 }
58
59 public int getNumberOfControls() {
60 return 5;
61 }
62 protected void doFillIntoGrid(Composite parent, int numColumns) {
63 super.doFillIntoGrid(parent, numColumns - 3);
64 }
65
66 protected void adjustForNumColumns(int numColumns) {
67 super.adjustForNumColumns(numColumns - 3);
68 }
69
70 protected void doLoad() {
71 super.doLoad();
72 int style = getPreferenceStore().getInt(getPreferenceName() + TextEditorColorsPage.STYLE_SUFFIX);
73 boldCheck.setSelection((style & SWT.BOLD) == SWT.BOLD);
74 italicsCheck.setSelection((style & SWT.ITALIC) == SWT.ITALIC);
75 }
76 protected void doLoadDefault() {
77 super.doLoadDefault();
78 int style = getPreferenceStore().getDefaultInt(getPreferenceName() + TextEditorColorsPage.STYLE_SUFFIX);
79 boldCheck.setSelection((style & SWT.BOLD) == SWT.BOLD);
80 italicsCheck.setSelection((style & SWT.ITALIC) == SWT.ITALIC);
81 }
82 protected void doStore() {
83 int newStyle = SWT.NONE;
84 if (boldCheck.getSelection() == true) {
85 newStyle = SWT.BOLD;
86 }
87 if (italicsCheck.getSelection() == true) {
88 newStyle |= SWT.ITALIC;
89 }
90 int oldStyle = getPreferenceStore().getInt(getPreferenceName() + TextEditorColorsPage.STYLE_SUFFIX);
91
92 if (oldStyle != newStyle) {
93 getPreferenceStore().setValue(getPreferenceName() + TextEditorColorsPage.STYLE_SUFFIX, newStyle);
94 }
95 super.doStore();
96 }
97 }
98
99
100
101
102
103
104
105