1 package net.sourceforge.phpdt.sql.preferences;
4 import org.eclipse.jface.preference.ColorFieldEditor;
5 import org.eclipse.jface.preference.IPreferenceStore;
6 import org.eclipse.jface.preference.PreferenceConverter;
7 import org.eclipse.jface.preference.PreferencePage;
8 import org.eclipse.swt.SWT;
9 import org.eclipse.swt.events.SelectionEvent;
10 import org.eclipse.swt.events.SelectionListener;
11 import org.eclipse.swt.graphics.FontData;
12 import org.eclipse.swt.graphics.RGB;
13 import org.eclipse.swt.layout.GridData;
14 import org.eclipse.swt.layout.GridLayout;
15 import org.eclipse.swt.widgets.Button;
16 import org.eclipse.swt.widgets.Composite;
17 import org.eclipse.swt.widgets.Control;
18 import org.eclipse.swt.widgets.FontDialog;
19 import org.eclipse.swt.widgets.Label;
20 import org.eclipse.ui.IWorkbench;
21 import org.eclipse.ui.IWorkbenchPreferencePage;
23 import net.sourceforge.phpdt.sql.Messages;
24 import net.sourceforge.phpdt.sql.PHPEclipseSQLPlugin;
25 import net.sourceforge.phpdt.sql.editors.ColorManager;
26 import net.sourceforge.phpdt.sql.editors.SQLColorConstants;
28 public class PreferencesPage extends PreferencePage
29 implements IWorkbenchPreferencePage {
30 FontDialog fontDialog;
31 ColorFieldEditor backgroundColorEditor;
33 ColorFieldEditor textColorEditor;
35 ColorFieldEditor keywordColorEditor;
37 ColorFieldEditor stringColorEditor;
39 ColorFieldEditor numericColorEditor;
41 ColorFieldEditor commentColorEditor;
53 public void init(IWorkbench workbench) {
54 //Initialize the preference store
55 this.workbench = workbench;
56 setPreferenceStore(PHPEclipseSQLPlugin.getDefault().getPreferenceStore());
57 initializeColorDefaults(getPreferenceStore());
60 private void initializeColorDefaults(IPreferenceStore store) {
61 RGB BACKGROUND = new RGB(255, 255, 255);
62 RGB COMMENT = new RGB(88, 148, 64);
63 RGB KEYWORD = new RGB(126, 0, 75);
64 RGB STRING = new RGB(0, 0, 255);
65 RGB NUMERIC = new RGB(255, 0, 0);
66 RGB DEFAULT = new RGB(0, 0, 0);
67 PreferenceConverter.setDefault(store,
68 "phpeclipse.sql.background.color",BACKGROUND);
69 PreferenceConverter.setDefault(store,
70 "phpeclipse.sql.text.color", DEFAULT);
71 PreferenceConverter.setDefault(store,
72 "phpeclipse.sql.keyword.color",KEYWORD); //$NON-NLS-1$
73 PreferenceConverter.setDefault(store,
74 "phpeclipse.sql.comment.color",COMMENT); //$NON-NLS-1$
75 PreferenceConverter.setDefault(store,
76 "phpeclipse.sql.string.color",STRING); //$NON-NLS-1$
77 PreferenceConverter.setDefault(store,
78 "phpeclipse.sql.numeric.color",
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(), "phpeclipse.sql.font", fontData);
103 getPreferenceStore().setValue("phpeclipse.sql.text.bold", textFlag); //$NON-NLS-1$
104 getPreferenceStore().setValue("phpeclipse.sql.keyword.bold", keywordFlag); //$NON-NLS-1$
105 getPreferenceStore().setValue("phpeclipse.sql.string.bold", stringFlag); //$NON-NLS-1$
106 getPreferenceStore().setValue("phpeclipse.sql.comment.bold", commentFlag); //$NON-NLS-1$
107 getPreferenceStore().setValue("phpeclipse.sql.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);
124 PreferenceConverter.getFontData(
125 getPreferenceStore(),
126 "phpeclipse.sql.font");
127 textFlag = getPreferenceStore().getBoolean("phpeclipse.sql.text.bold");
129 getPreferenceStore().getBoolean("phpeclipse.sql.keyword.bold");
130 stringFlag = getPreferenceStore().getBoolean("phpeclipse.sql.string.bold");
132 getPreferenceStore().getBoolean("phpeclipse.sql.comment.bold");
134 getPreferenceStore().getBoolean("phpeclipse.sql.numeric.bold");
137 new FontDialog(workbench.getActiveWorkbenchWindow().getShell());
138 Button fontButton = new Button(main, SWT.PUSH);
139 fontButton.setText("Pick Font");
140 fontButton.addSelectionListener(new SelectionListener() {
141 public void widgetDefaultSelected(SelectionEvent e) {
143 public void widgetSelected(SelectionEvent e) {
144 if (fontData != null) {
145 fontDialog.setFontData(fontData);
147 FontData data = fontDialog.open();
154 Button defaultButton = new Button(main, SWT.PUSH);
155 defaultButton.setText(Messages.getString("PreferencesPage.DefaultFont")); //$NON-NLS-1$
156 defaultButton.addSelectionListener(new SelectionListener() {
157 public void widgetDefaultSelected(SelectionEvent e) {
159 public void widgetSelected(SelectionEvent e) {
165 fontDisplay = new Label(main, SWT.NULL);
166 GridData data = new GridData(GridData.FILL_HORIZONTAL);
167 data.grabExcessHorizontalSpace = true;
168 fontDisplay.setLayoutData(data);
171 ColorManager manager = new ColorManager();
173 Composite comp = new Composite(main, SWT.NULL);
174 GridData layoutData = new GridData();
175 layoutData.horizontalSpan = 2;
176 comp.setLayoutData(layoutData);
178 manager.getColor(SQLColorConstants.DEFAULT);
179 backgroundColorEditor =
180 new ColorFieldEditor(
181 "phpeclipse.sql.background.color", //$NON-NLS-1$
182 Messages.getString("PreferencesPage.BackgroundColor"), //$NON-NLS-1$
185 Composite temp = new Composite(main, SWT.NULL);
188 comp = new Composite(main, SWT.NULL);
189 layoutData = new GridData();
190 layoutData.horizontalSpan = 2;
191 comp.setLayoutData(layoutData);
194 new ColorFieldEditor(
195 "phpeclipse.sql.text.color", //$NON-NLS-1$
196 Messages.getString("PreferencesPage.DefaultTextColor"), //$NON-NLS-1$
199 boldText = new Button(main, SWT.CHECK);
200 boldText.setSelection(textFlag);
201 boldText.setText(Messages.getString("PreferencesPage.Bold")); //$NON-NLS-1$
202 boldText.addSelectionListener(new SelectionListener() {
203 public void widgetDefaultSelected(SelectionEvent e) {
205 public void widgetSelected(SelectionEvent e) {
206 textFlag = boldText.getSelection();
210 comp = new Composite(main, SWT.NULL);
211 layoutData = new GridData();
212 layoutData.horizontalSpan = 2;
213 comp.setLayoutData(layoutData);
216 new ColorFieldEditor(
217 "phpeclipse.sql.keyword.color", //$NON-NLS-1$
218 Messages.getString("PreferencesPage.KeywordTextColor"), //$NON-NLS-1$
221 boldKeyword = new Button(main, SWT.CHECK);
222 boldKeyword.setSelection(keywordFlag);
223 boldKeyword.setText(Messages.getString("PreferencesPage.Bold")); //$NON-NLS-1$
224 boldKeyword.addSelectionListener(new SelectionListener() {
225 public void widgetDefaultSelected(SelectionEvent e) {
227 public void widgetSelected(SelectionEvent e) {
228 keywordFlag = boldKeyword.getSelection();
232 comp = new Composite(main, SWT.NULL);
233 layoutData = new GridData();
234 layoutData.horizontalSpan = 2;
235 comp.setLayoutData(layoutData);
238 new ColorFieldEditor(
239 "phpeclipse.sql.comment.color", //$NON-NLS-1$
240 Messages.getString("PreferencesPage.CommentTextColor"), //$NON-NLS-1$
243 boldComment = new Button(main, SWT.CHECK);
244 boldComment.setSelection(commentFlag);
245 boldComment.setText(Messages.getString("PreferencesPage.Bold")); //$NON-NLS-1$
246 boldComment.addSelectionListener(new SelectionListener() {
247 public void widgetDefaultSelected(SelectionEvent e) {
249 public void widgetSelected(SelectionEvent e) {
250 commentFlag = boldComment.getSelection();
254 comp = new Composite(main, SWT.NULL);
255 layoutData = new GridData();
256 layoutData.horizontalSpan = 2;
257 comp.setLayoutData(layoutData);
260 new ColorFieldEditor(
261 "phpeclipse.sql.string.color", //$NON-NLS-1$
262 Messages.getString("PreferencesPage.StringTextColor"), //$NON-NLS-1$
265 boldString = new Button(main, SWT.CHECK);
266 boldString.setSelection(stringFlag);
267 boldString.setText(Messages.getString("PreferencesPage.Bold")); //$NON-NLS-1$
268 boldString.addSelectionListener(new SelectionListener() {
269 public void widgetDefaultSelected(SelectionEvent e) {
271 public void widgetSelected(SelectionEvent e) {
272 stringFlag = boldString.getSelection();
276 comp = new Composite(main, SWT.NULL);
277 layoutData = new GridData();
278 layoutData.horizontalSpan = 2;
279 comp.setLayoutData(layoutData);
282 new ColorFieldEditor(
283 "phpeclipse.sql.numeric.color", //$NON-NLS-1$
284 Messages.getString("PreferencesPage.NumericTextColor"), //$NON-NLS-1$
287 boldNumeric = new Button(main, SWT.CHECK);
288 boldNumeric.setSelection(numericFlag);
289 boldNumeric.setText(Messages.getString("PreferencesPage.Bold")); //$NON-NLS-1$
290 boldNumeric.addSelectionListener(new SelectionListener() {
291 public void widgetDefaultSelected(SelectionEvent e) {
293 public void widgetSelected(SelectionEvent e) {
294 numericFlag = boldNumeric.getSelection();
298 backgroundColorEditor.setPreferencePage(this);
299 backgroundColorEditor.setPreferenceStore(getPreferenceStore());
300 backgroundColorEditor.load();
302 textColorEditor.setPreferencePage(this);
303 textColorEditor.setPreferenceStore(getPreferenceStore());
304 textColorEditor.load();
306 keywordColorEditor.setPreferencePage(this);
307 keywordColorEditor.setPreferenceStore(getPreferenceStore());
308 keywordColorEditor.load();
310 commentColorEditor.setPreferencePage(this);
311 commentColorEditor.setPreferenceStore(getPreferenceStore());
312 commentColorEditor.load();
314 stringColorEditor.setPreferencePage(this);
315 stringColorEditor.setPreferenceStore(getPreferenceStore());
316 stringColorEditor.load();
318 numericColorEditor.setPreferencePage(this);
319 numericColorEditor.setPreferenceStore(getPreferenceStore());
320 numericColorEditor.load();
324 public void updateFontDisplay() {
325 if (fontData == null) {
326 fontDisplay.setText(Messages.getString("PreferencesPage.Font_Default")); //$NON-NLS-1$
328 String style = Messages.getString("PreferencesPage.regular"); //$NON-NLS-1$
329 if (fontData.getStyle() == SWT.BOLD) {
330 style = Messages.getString("PreferencesPage.bold"); //$NON-NLS-1$
331 } else if (fontData.getStyle() == SWT.ITALIC) {
332 style = Messages.getString("PreferencesPage.italic"); //$NON-NLS-1$
333 } else if (fontData.getStyle() == (SWT.BOLD | SWT.ITALIC)) {
334 style = Messages.getString("PreferencesPage.boldItalic"); //$NON-NLS-1$
336 fontDisplay.setText(Messages.getString("PreferencesPage.FontPrompt") + fontData.getName() + '-' + style + '-' + fontData.getHeight()); //$NON-NLS-1$
339 public void updateFlags() {
340 boldText.setSelection(textFlag);
341 boldKeyword.setSelection(keywordFlag);
342 boldString.setSelection(stringFlag);
343 boldNumeric.setSelection(numericFlag);
344 boldComment.setSelection(commentFlag);