1 package com.quantum.preferences;
4 import com.quantum.Messages;
5 import com.quantum.QuantumPlugin;
6 import com.quantum.editors.ColorManager;
7 import com.quantum.editors.SQLColorConstants;
8 import com.quantum.util.versioning.VersioningHelper;
10 import org.eclipse.jface.preference.ColorFieldEditor;
11 import org.eclipse.jface.preference.IPreferenceStore;
12 import org.eclipse.jface.preference.PreferenceConverter;
13 import org.eclipse.jface.preference.PreferencePage;
14 import org.eclipse.swt.SWT;
15 import org.eclipse.swt.events.SelectionEvent;
16 import org.eclipse.swt.events.SelectionListener;
17 import org.eclipse.swt.graphics.FontData;
18 import org.eclipse.swt.graphics.RGB;
19 import org.eclipse.swt.layout.GridData;
20 import org.eclipse.swt.layout.GridLayout;
21 import org.eclipse.swt.widgets.Button;
22 import org.eclipse.swt.widgets.Composite;
23 import org.eclipse.swt.widgets.Control;
24 import org.eclipse.swt.widgets.FontDialog;
25 import org.eclipse.swt.widgets.Label;
26 import org.eclipse.ui.IWorkbench;
27 import org.eclipse.ui.IWorkbenchPreferencePage;
29 public class SQLEditorPreferences 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(QuantumPlugin.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 KEYWORD = new RGB(126, 0, 75);
65 RGB STRING = new RGB(0, 0, 255);
66 RGB NUMERIC = new RGB(255, 0, 0);
67 RGB DEFAULT = new RGB(0, 0, 0);
68 PreferenceConverter.setDefault(store,
69 "quantum.background.color", BACKGROUND); //$NON-NLS-1$
70 PreferenceConverter.setDefault(store,
71 "quantum.text.color", DEFAULT); //$NON-NLS-1$
72 PreferenceConverter.setDefault(store,
73 "quantum.keyword.color", KEYWORD); //$NON-NLS-1$
74 PreferenceConverter.setDefault(store,
75 "quantum.comment.color", COMMENT); //$NON-NLS-1$
76 PreferenceConverter.setDefault(store,
77 "quantum.string.color", STRING); //$NON-NLS-1$
78 PreferenceConverter.setDefault(store,
79 "quantum.numeric.color", NUMERIC); //$NON-NLS-1$
82 protected void performDefaults() {
91 backgroundColorEditor.loadDefault();
92 textColorEditor.loadDefault();
93 keywordColorEditor.loadDefault();
94 stringColorEditor.loadDefault();
95 commentColorEditor.loadDefault();
96 numericColorEditor.loadDefault();
99 * Save the preferences to the preference store.
101 public boolean performOk() {
102 PreferenceConverter.setValue(getPreferenceStore(), "quantum.font", fontData); //$NON-NLS-1$
103 getPreferenceStore().setValue("quantum.text.bold", textFlag); //$NON-NLS-1$
104 getPreferenceStore().setValue("quantum.keyword.bold", keywordFlag); //$NON-NLS-1$
105 getPreferenceStore().setValue("quantum.string.bold", stringFlag); //$NON-NLS-1$
106 getPreferenceStore().setValue("quantum.comment.bold", commentFlag); //$NON-NLS-1$
107 getPreferenceStore().setValue("quantum.numeric.bold", numericFlag); //$NON-NLS-1$
108 backgroundColorEditor.store();
109 textColorEditor.store();
110 keywordColorEditor.store();
111 stringColorEditor.store();
112 commentColorEditor.store();
113 numericColorEditor.store();
114 return super.performOk();
116 protected Control createContents(Composite parent) {
117 Composite main = new Composite(parent, SWT.NULL);
119 GridLayout innerLayout = new GridLayout();
120 innerLayout.numColumns = 4;
121 main.setLayout(innerLayout);
123 fontData = PreferenceConverter.getFontData(getPreferenceStore(), "quantum.font"); //$NON-NLS-1$
124 textFlag = getPreferenceStore().getBoolean("quantum.text.bold"); //$NON-NLS-1$
125 keywordFlag = getPreferenceStore().getBoolean("quantum.keyword.bold"); //$NON-NLS-1$
126 stringFlag = getPreferenceStore().getBoolean("quantum.string.bold"); //$NON-NLS-1$
127 commentFlag = getPreferenceStore().getBoolean("quantum.comment.bold"); //$NON-NLS-1$
128 numericFlag = getPreferenceStore().getBoolean("quantum.numeric.bold"); //$NON-NLS-1$
130 fontDialog = new FontDialog(workbench.getActiveWorkbenchWindow().getShell());
131 Button fontButton = new Button(main, SWT.PUSH);
132 fontButton.setText(Messages.getString("PreferencesPage.PickFont")); //$NON-NLS-1$
133 fontButton.addSelectionListener(new SelectionListener() {
134 public void widgetDefaultSelected(SelectionEvent e) {
136 public void widgetSelected(SelectionEvent e) {
137 if (fontData != null) {
138 VersioningHelper.setFont(fontDialog, new FontData[] { fontData} );
140 FontData data = fontDialog.open();
147 Button defaultButton = new Button(main, SWT.PUSH);
148 defaultButton.setText(Messages.getString("PreferencesPage.DefaultFont")); //$NON-NLS-1$
149 defaultButton.addSelectionListener(new SelectionListener() {
150 public void widgetDefaultSelected(SelectionEvent e) {
152 public void widgetSelected(SelectionEvent e) {
158 fontDisplay = new Label(main, SWT.NULL);
159 GridData data = new GridData(GridData.FILL_HORIZONTAL);
160 data.grabExcessHorizontalSpace = true;
161 fontDisplay.setLayoutData(data);
164 ColorManager manager = new ColorManager();
166 Composite comp = new Composite(main, SWT.NULL);
167 GridData layoutData = new GridData();
168 layoutData.horizontalSpan = 2;
169 comp.setLayoutData(layoutData);
171 manager.getColor(SQLColorConstants.DEFAULT);
172 backgroundColorEditor =
173 new ColorFieldEditor(
174 "quantum.background.color", //$NON-NLS-1$
175 Messages.getString("PreferencesPage.BackgroundColor"), //$NON-NLS-1$
178 Composite temp = new Composite(main, SWT.NULL);
181 comp = new Composite(main, SWT.NULL);
182 layoutData = new GridData();
183 layoutData.horizontalSpan = 2;
184 comp.setLayoutData(layoutData);
187 new ColorFieldEditor(
188 "quantum.text.color", //$NON-NLS-1$
189 Messages.getString("PreferencesPage.DefaultTextColor"), //$NON-NLS-1$
192 boldText = new Button(main, SWT.CHECK);
193 boldText.setSelection(textFlag);
194 boldText.setText(Messages.getString("PreferencesPage.Bold")); //$NON-NLS-1$
195 boldText.addSelectionListener(new SelectionListener() {
196 public void widgetDefaultSelected(SelectionEvent e) {
198 public void widgetSelected(SelectionEvent e) {
199 textFlag = boldText.getSelection();
203 comp = new Composite(main, SWT.NULL);
204 layoutData = new GridData();
205 layoutData.horizontalSpan = 2;
206 comp.setLayoutData(layoutData);
209 new ColorFieldEditor(
210 Messages.getString("PreferencesPage.quantum.keyword.color_26"), //$NON-NLS-1$
211 Messages.getString("PreferencesPage.KeywordTextColor"), //$NON-NLS-1$
214 boldKeyword = new Button(main, SWT.CHECK);
215 boldKeyword.setSelection(keywordFlag);
216 boldKeyword.setText(Messages.getString("PreferencesPage.Bold")); //$NON-NLS-1$
217 boldKeyword.addSelectionListener(new SelectionListener() {
218 public void widgetDefaultSelected(SelectionEvent e) {
220 public void widgetSelected(SelectionEvent e) {
221 keywordFlag = boldKeyword.getSelection();
225 comp = new Composite(main, SWT.NULL);
226 layoutData = new GridData();
227 layoutData.horizontalSpan = 2;
228 comp.setLayoutData(layoutData);
231 new ColorFieldEditor(
232 "quantum.comment.color", //$NON-NLS-1$
233 Messages.getString("PreferencesPage.CommentTextColor"), //$NON-NLS-1$
236 boldComment = new Button(main, SWT.CHECK);
237 boldComment.setSelection(commentFlag);
238 boldComment.setText(Messages.getString("PreferencesPage.Bold")); //$NON-NLS-1$
239 boldComment.addSelectionListener(new SelectionListener() {
240 public void widgetDefaultSelected(SelectionEvent e) {
242 public void widgetSelected(SelectionEvent e) {
243 commentFlag = boldComment.getSelection();
247 comp = new Composite(main, SWT.NULL);
248 layoutData = new GridData();
249 layoutData.horizontalSpan = 2;
250 comp.setLayoutData(layoutData);
253 new ColorFieldEditor(
254 "quantum.string.color", //$NON-NLS-1$
255 Messages.getString("PreferencesPage.StringTextColor"), //$NON-NLS-1$
258 boldString = new Button(main, SWT.CHECK);
259 boldString.setSelection(stringFlag);
260 boldString.setText(Messages.getString("PreferencesPage.Bold")); //$NON-NLS-1$
261 boldString.addSelectionListener(new SelectionListener() {
262 public void widgetDefaultSelected(SelectionEvent e) {
264 public void widgetSelected(SelectionEvent e) {
265 stringFlag = boldString.getSelection();
269 comp = new Composite(main, SWT.NULL);
270 layoutData = new GridData();
271 layoutData.horizontalSpan = 2;
272 comp.setLayoutData(layoutData);
275 new ColorFieldEditor(
276 "quantum.numeric.color", //$NON-NLS-1$
277 Messages.getString("PreferencesPage.NumericTextColor"), //$NON-NLS-1$
280 boldNumeric = new Button(main, SWT.CHECK);
281 boldNumeric.setSelection(numericFlag);
282 boldNumeric.setText(Messages.getString("PreferencesPage.Bold")); //$NON-NLS-1$
283 boldNumeric.addSelectionListener(new SelectionListener() {
284 public void widgetDefaultSelected(SelectionEvent e) {
286 public void widgetSelected(SelectionEvent e) {
287 numericFlag = boldNumeric.getSelection();
291 backgroundColorEditor.setPreferencePage(this);
292 backgroundColorEditor.setPreferenceStore(getPreferenceStore());
293 backgroundColorEditor.load();
295 textColorEditor.setPreferencePage(this);
296 textColorEditor.setPreferenceStore(getPreferenceStore());
297 textColorEditor.load();
299 keywordColorEditor.setPreferencePage(this);
300 keywordColorEditor.setPreferenceStore(getPreferenceStore());
301 keywordColorEditor.load();
303 commentColorEditor.setPreferencePage(this);
304 commentColorEditor.setPreferenceStore(getPreferenceStore());
305 commentColorEditor.load();
307 stringColorEditor.setPreferencePage(this);
308 stringColorEditor.setPreferenceStore(getPreferenceStore());
309 stringColorEditor.load();
311 numericColorEditor.setPreferencePage(this);
312 numericColorEditor.setPreferenceStore(getPreferenceStore());
313 numericColorEditor.load();
317 public void updateFontDisplay() {
318 if (fontData == null) {
319 fontDisplay.setText(Messages.getString("PreferencesPage.Font_Default")); //$NON-NLS-1$
321 String style = Messages.getString("PreferencesPage.regular"); //$NON-NLS-1$
322 if (fontData.getStyle() == SWT.BOLD) {
323 style = Messages.getString("PreferencesPage.bold"); //$NON-NLS-1$
324 } else if (fontData.getStyle() == SWT.ITALIC) {
325 style = Messages.getString("PreferencesPage.italic"); //$NON-NLS-1$
326 } else if (fontData.getStyle() == (SWT.BOLD | SWT.ITALIC)) {
327 style = Messages.getString("PreferencesPage.boldItalic"); //$NON-NLS-1$
329 fontDisplay.setText(Messages.getString("PreferencesPage.FontPrompt") + fontData.getName() + '-' + style + '-' + fontData.getHeight()); //$NON-NLS-1$
332 public void updateFlags() {
333 boldText.setSelection(textFlag);
334 boldKeyword.setSelection(keywordFlag);
335 boldString.setSelection(stringFlag);
336 boldNumeric.setSelection(numericFlag);
337 boldComment.setSelection(commentFlag);