1 package net.sourceforge.phpdt.sql.preferences;
4 import net.sourceforge.phpdt.sql.PHPEclipseSQLPlugin;
6 import org.eclipse.jface.preference.ColorFieldEditor;
7 import org.eclipse.jface.preference.IPreferenceStore;
8 import org.eclipse.jface.preference.PreferenceConverter;
9 import org.eclipse.jface.preference.PreferencePage;
10 import org.eclipse.swt.SWT;
11 import org.eclipse.swt.events.SelectionEvent;
12 import org.eclipse.swt.events.SelectionListener;
13 import org.eclipse.swt.graphics.Color;
14 import org.eclipse.swt.graphics.FontData;
15 import org.eclipse.swt.graphics.RGB;
16 import org.eclipse.swt.layout.GridData;
17 import org.eclipse.swt.layout.GridLayout;
18 import org.eclipse.swt.widgets.Button;
19 import org.eclipse.swt.widgets.Composite;
20 import org.eclipse.swt.widgets.Control;
21 import org.eclipse.swt.widgets.FontDialog;
22 import org.eclipse.swt.widgets.Label;
23 import org.eclipse.ui.IWorkbench;
24 import org.eclipse.ui.IWorkbenchPreferencePage;
26 import net.sourceforge.phpdt.sql.editors.ColorManager;
27 import net.sourceforge.phpdt.sql.editors.SQLColorConstants;
29 public class PreferencesPage extends PreferencePage
30 implements IWorkbenchPreferencePage {
31 FontDialog fontDialog;
32 ColorFieldEditor backgroundColorEditor;
34 ColorFieldEditor textColorEditor;
36 ColorFieldEditor keywordColorEditor;
38 ColorFieldEditor stringColorEditor;
40 ColorFieldEditor numericColorEditor;
42 ColorFieldEditor commentColorEditor;
54 public void init(IWorkbench workbench) {
55 //Initialize the preference store
56 this.workbench = workbench;
57 setPreferenceStore(PHPEclipseSQLPlugin.getDefault().getPreferenceStore());
58 initializeColorDefaults(getPreferenceStore());
61 private void initializeColorDefaults(IPreferenceStore store) {
62 RGB BACKGROUND = new RGB(255, 255, 255);
63 RGB COMMENT = new RGB(88, 148, 64);
64 RGB IDENTIFIER = new RGB(0, 0, 0);
65 RGB KEYWORD = new RGB(126, 0, 75);
66 RGB STRING = new RGB(0, 0, 255);
67 RGB NUMERIC = new RGB(255, 0, 0);
68 RGB DEFAULT = new RGB(0, 0, 0);
69 PreferenceConverter.setDefault(store,
70 "quantum.background.color", BACKGROUND);
71 PreferenceConverter.setDefault(store,
72 "quantum.text.color", DEFAULT);
73 PreferenceConverter.setDefault(store,
74 "quantum.keyword.color", KEYWORD);
75 PreferenceConverter.setDefault(store,
76 "quantum.comment.color", COMMENT);
77 PreferenceConverter.setDefault(store,
78 "quantum.string.color", STRING);
79 PreferenceConverter.setDefault(store,
80 "quantum.numeric.color", NUMERIC);
83 protected void performDefaults() {
92 backgroundColorEditor.loadDefault();
93 textColorEditor.loadDefault();
94 keywordColorEditor.loadDefault();
95 stringColorEditor.loadDefault();
96 commentColorEditor.loadDefault();
97 numericColorEditor.loadDefault();
100 * Save the preferences to the preference store.
102 public boolean performOk() {
103 PreferenceConverter.setValue(getPreferenceStore(), "quantum.font", fontData);
104 getPreferenceStore().setValue("quantum.text.bold", textFlag);
105 getPreferenceStore().setValue("quantum.keyword.bold", keywordFlag);
106 getPreferenceStore().setValue("quantum.string.bold", stringFlag);
107 getPreferenceStore().setValue("quantum.comment.bold", commentFlag);
108 getPreferenceStore().setValue("quantum.numeric.bold", numericFlag);
109 backgroundColorEditor.store();
110 textColorEditor.store();
111 keywordColorEditor.store();
112 stringColorEditor.store();
113 commentColorEditor.store();
114 numericColorEditor.store();
115 return super.performOk();
117 protected Control createContents(Composite parent) {
118 Composite main = new Composite(parent, SWT.NULL);
120 GridLayout innerLayout = new GridLayout();
121 innerLayout.numColumns = 4;
122 main.setLayout(innerLayout);
124 fontData = PreferenceConverter.getFontData(getPreferenceStore(), "quantum.font");
125 textFlag = getPreferenceStore().getBoolean("quantum.text.bold");
126 keywordFlag = getPreferenceStore().getBoolean("quantum.keyword.bold");
127 stringFlag = getPreferenceStore().getBoolean("quantum.string.bold");
128 commentFlag = getPreferenceStore().getBoolean("quantum.comment.bold");
129 numericFlag = getPreferenceStore().getBoolean("quantum.numeric.bold");
131 fontDialog = new FontDialog(workbench.getActiveWorkbenchWindow().getShell());
132 Button fontButton = new Button(main, SWT.PUSH);
133 fontButton.setText("Pick Font");
134 fontButton.addSelectionListener(new SelectionListener() {
135 public void widgetDefaultSelected(SelectionEvent e) {
137 public void widgetSelected(SelectionEvent e) {
138 if (fontData != null) {
139 fontDialog.setFontData(fontData);
141 FontData data = fontDialog.open();
148 Button defaultButton = new Button(main, SWT.PUSH);
149 defaultButton.setText("Default Font");
150 defaultButton.addSelectionListener(new SelectionListener() {
151 public void widgetDefaultSelected(SelectionEvent e) {
153 public void widgetSelected(SelectionEvent e) {
159 fontDisplay = new Label(main, SWT.NULL);
160 GridData data = new GridData(GridData.FILL_HORIZONTAL);
161 data.grabExcessHorizontalSpace = true;
162 fontDisplay.setLayoutData(data);
165 ColorManager manager = new ColorManager();
167 Composite comp = new Composite(main, SWT.NULL);
168 GridData layoutData = new GridData();
169 layoutData.horizontalSpan = 2;
170 comp.setLayoutData(layoutData);
172 Color defaultColor = manager.getColor(SQLColorConstants.DEFAULT);
173 backgroundColorEditor =
174 new ColorFieldEditor(
175 "quantum.background.color",
179 Composite temp = new Composite(main, SWT.NULL);
182 comp = new Composite(main, SWT.NULL);
183 layoutData = new GridData();
184 layoutData.horizontalSpan = 2;
185 comp.setLayoutData(layoutData);
188 new ColorFieldEditor(
189 "quantum.text.color",
190 "Default Text Color",
193 boldText = new Button(main, SWT.CHECK);
194 boldText.setSelection(textFlag);
195 boldText.setText("Bold");
196 boldText.addSelectionListener(new SelectionListener() {
197 public void widgetDefaultSelected(SelectionEvent e) {
199 public void widgetSelected(SelectionEvent e) {
200 textFlag = boldText.getSelection();
204 comp = new Composite(main, SWT.NULL);
205 layoutData = new GridData();
206 layoutData.horizontalSpan = 2;
207 comp.setLayoutData(layoutData);
210 new ColorFieldEditor(
211 "quantum.keyword.color",
212 "Keyword Text Color",
215 boldKeyword = new Button(main, SWT.CHECK);
216 boldKeyword.setSelection(keywordFlag);
217 boldKeyword.setText("Bold");
218 boldKeyword.addSelectionListener(new SelectionListener() {
219 public void widgetDefaultSelected(SelectionEvent e) {
221 public void widgetSelected(SelectionEvent e) {
222 keywordFlag = boldKeyword.getSelection();
226 comp = new Composite(main, SWT.NULL);
227 layoutData = new GridData();
228 layoutData.horizontalSpan = 2;
229 comp.setLayoutData(layoutData);
232 new ColorFieldEditor(
233 "quantum.comment.color",
234 "Comment Text Color",
237 boldComment = new Button(main, SWT.CHECK);
238 boldComment.setSelection(commentFlag);
239 boldComment.setText("Bold");
240 boldComment.addSelectionListener(new SelectionListener() {
241 public void widgetDefaultSelected(SelectionEvent e) {
243 public void widgetSelected(SelectionEvent e) {
244 commentFlag = boldComment.getSelection();
248 comp = new Composite(main, SWT.NULL);
249 layoutData = new GridData();
250 layoutData.horizontalSpan = 2;
251 comp.setLayoutData(layoutData);
254 new ColorFieldEditor(
255 "quantum.string.color",
259 boldString = new Button(main, SWT.CHECK);
260 boldString.setSelection(stringFlag);
261 boldString.setText("Bold");
262 boldString.addSelectionListener(new SelectionListener() {
263 public void widgetDefaultSelected(SelectionEvent e) {
265 public void widgetSelected(SelectionEvent e) {
266 stringFlag = boldString.getSelection();
270 comp = new Composite(main, SWT.NULL);
271 layoutData = new GridData();
272 layoutData.horizontalSpan = 2;
273 comp.setLayoutData(layoutData);
276 new ColorFieldEditor(
277 "quantum.numeric.color",
278 "Numeric Text Color",
281 boldNumeric = new Button(main, SWT.CHECK);
282 boldNumeric.setSelection(numericFlag);
283 boldNumeric.setText("Bold");
284 boldNumeric.addSelectionListener(new SelectionListener() {
285 public void widgetDefaultSelected(SelectionEvent e) {
287 public void widgetSelected(SelectionEvent e) {
288 numericFlag = boldNumeric.getSelection();
292 backgroundColorEditor.setPreferencePage(this);
293 backgroundColorEditor.setPreferenceStore(getPreferenceStore());
294 backgroundColorEditor.load();
296 textColorEditor.setPreferencePage(this);
297 textColorEditor.setPreferenceStore(getPreferenceStore());
298 textColorEditor.load();
300 keywordColorEditor.setPreferencePage(this);
301 keywordColorEditor.setPreferenceStore(getPreferenceStore());
302 keywordColorEditor.load();
304 commentColorEditor.setPreferencePage(this);
305 commentColorEditor.setPreferenceStore(getPreferenceStore());
306 commentColorEditor.load();
308 stringColorEditor.setPreferencePage(this);
309 stringColorEditor.setPreferenceStore(getPreferenceStore());
310 stringColorEditor.load();
312 numericColorEditor.setPreferencePage(this);
313 numericColorEditor.setPreferenceStore(getPreferenceStore());
314 numericColorEditor.load();
318 public void updateFontDisplay() {
319 if (fontData == null) {
320 fontDisplay.setText("Font: default");
322 String style = "regular";
323 if (fontData.getStyle() == SWT.BOLD) {
325 } else if (fontData.getStyle() == SWT.ITALIC) {
327 } else if (fontData.getStyle() == (SWT.BOLD | SWT.ITALIC)) {
328 style = "bold italic";
330 fontDisplay.setText("Font: " + fontData.getName() + '-' + style + '-' + fontData.getHeight());
333 public void updateFlags() {
334 boldText.setSelection(textFlag);
335 boldKeyword.setSelection(keywordFlag);
336 boldString.setSelection(stringFlag);
337 boldNumeric.setSelection(numericFlag);
338 boldComment.setSelection(commentFlag);