* added a first PDF Exporter (menu File->Export...)
[phpeclipse.git] / archive / net.sourceforge.phpeclipse.quantum.sql / src / com / quantum / preferences / SQLEditorPreferences.java
index b1697ba..ec0c7e1 100644 (file)
@@ -1,92 +1,74 @@
 package com.quantum.preferences;
 
-
 import com.quantum.Messages;
+import com.quantum.PluginPreferences;
 import com.quantum.QuantumPlugin;
-import com.quantum.editors.ColorManager;
-import com.quantum.editors.SQLColorConstants;
 import com.quantum.util.versioning.VersioningHelper;
 
 import org.eclipse.jface.preference.ColorFieldEditor;
-import org.eclipse.jface.preference.IPreferenceStore;
 import org.eclipse.jface.preference.PreferenceConverter;
 import org.eclipse.jface.preference.PreferencePage;
 import org.eclipse.swt.SWT;
 import org.eclipse.swt.events.SelectionEvent;
 import org.eclipse.swt.events.SelectionListener;
 import org.eclipse.swt.graphics.FontData;
-import org.eclipse.swt.graphics.RGB;
 import org.eclipse.swt.layout.GridData;
 import org.eclipse.swt.layout.GridLayout;
 import org.eclipse.swt.widgets.Button;
 import org.eclipse.swt.widgets.Composite;
 import org.eclipse.swt.widgets.Control;
 import org.eclipse.swt.widgets.FontDialog;
+import org.eclipse.swt.widgets.Group;
 import org.eclipse.swt.widgets.Label;
 import org.eclipse.ui.IWorkbench;
 import org.eclipse.ui.IWorkbenchPreferencePage;
 
-public class SQLEditorPreferences extends PreferencePage
-       implements IWorkbenchPreferencePage {
-       FontDialog fontDialog;
-       ColorFieldEditor backgroundColorEditor;
+
+/**
+ * A preference page for font and colour preferences for the SQL
+ * Editor.  
+ * 
+ * @author Tom Schneider
+ */
+public class SQLEditorPreferences extends PreferencePage 
+               implements IWorkbenchPreferencePage {
+
+    private FontDialog fontDialog;
+
+    private ColorFieldEditor backgroundColorEditor;
+    private ColorFieldEditor textColorEditor;
+    private ColorFieldEditor keywordColorEditor;
+    private ColorFieldEditor stringColorEditor;
+    private ColorFieldEditor numericColorEditor;
+    private ColorFieldEditor commentColorEditor;
+
+    private boolean textFlag;
+    private boolean keywordFlag;
+    private boolean stringFlag;
+    private boolean numericFlag;
+    private boolean commentFlag;
        
-       ColorFieldEditor textColorEditor;
-       boolean textFlag;
-       ColorFieldEditor keywordColorEditor;
-       boolean keywordFlag;
-       ColorFieldEditor stringColorEditor;
-       boolean stringFlag;
-       ColorFieldEditor numericColorEditor;
-       boolean numericFlag;
-       ColorFieldEditor commentColorEditor;
-       boolean commentFlag;
+    private Button boldText;
+    private Button boldKeyword;
+    private Button boldString;
+    private Button boldNumeric;
+    private Button boldComment;
        
-       Button boldText;
-       Button boldKeyword;
-       Button boldString;
-       Button boldNumeric;
-       Button boldComment;
+       private FontData fontData;
+       private Label fontDisplay;
        
-       IWorkbench workbench;
-       FontData fontData;
-       Label fontDisplay;
        public void init(IWorkbench workbench) {
-               //Initialize the preference store
-               this.workbench = workbench;
                setPreferenceStore(QuantumPlugin.getDefault().getPreferenceStore());
-               initializeColorDefaults(getPreferenceStore());
-       }
-
-       private void initializeColorDefaults(IPreferenceStore store) {
-               RGB BACKGROUND = new RGB(255, 255, 255);
-               RGB COMMENT = new RGB(88, 148, 64);
-               RGB KEYWORD = new RGB(126, 0, 75);
-               RGB STRING = new RGB(0, 0, 255);
-               RGB NUMERIC = new RGB(255, 0, 0);
-               RGB DEFAULT = new RGB(0, 0, 0);
-               PreferenceConverter.setDefault(store,
-                       "quantum.background.color", BACKGROUND); //$NON-NLS-1$
-               PreferenceConverter.setDefault(store,
-                       "quantum.text.color", DEFAULT); //$NON-NLS-1$
-               PreferenceConverter.setDefault(store,
-                       "quantum.keyword.color", KEYWORD); //$NON-NLS-1$
-               PreferenceConverter.setDefault(store,
-                       "quantum.comment.color", COMMENT); //$NON-NLS-1$
-               PreferenceConverter.setDefault(store,
-                       "quantum.string.color", STRING); //$NON-NLS-1$
-               PreferenceConverter.setDefault(store,
-                       "quantum.numeric.color", NUMERIC); //$NON-NLS-1$
        }
 
        protected void performDefaults() {
-               fontData = null;
+               fontData = PluginPreferences.getDefaultFont();
                updateFontDisplay();
-               textFlag = false;
-               keywordFlag = true;
-               stringFlag = false;
-               numericFlag = false;
-               commentFlag = false;
+               this.textFlag = false;
+               this.keywordFlag = true;
+               this.stringFlag = false;
+               this.numericFlag = false;
+               this.commentFlag = false;
                updateFlags();
                backgroundColorEditor.loadDefault();
                textColorEditor.loadDefault();
@@ -113,86 +95,62 @@ public class SQLEditorPreferences extends PreferencePage
                numericColorEditor.store();
                return super.performOk();
        }
+       
        protected Control createContents(Composite parent) {
                Composite main = new Composite(parent, SWT.NULL);
+               main.setLayout(new GridLayout());
                
-               GridLayout innerLayout = new GridLayout();
-               innerLayout.numColumns = 4;
-               main.setLayout(innerLayout);
+        createFontSelectionArea(main);
+        Label label = new Label(main, SWT.NONE);
+        label.setText("");
+        
+               createColorSelectionArea(main);
 
-               fontData = PreferenceConverter.getFontData(getPreferenceStore(), "quantum.font"); //$NON-NLS-1$
-               textFlag = getPreferenceStore().getBoolean("quantum.text.bold"); //$NON-NLS-1$
-               keywordFlag = getPreferenceStore().getBoolean("quantum.keyword.bold"); //$NON-NLS-1$
-               stringFlag = getPreferenceStore().getBoolean("quantum.string.bold"); //$NON-NLS-1$
-               commentFlag = getPreferenceStore().getBoolean("quantum.comment.bold"); //$NON-NLS-1$
-               numericFlag = getPreferenceStore().getBoolean("quantum.numeric.bold"); //$NON-NLS-1$
-               
-               fontDialog = new FontDialog(workbench.getActiveWorkbenchWindow().getShell());
-               Button fontButton = new Button(main, SWT.PUSH);
-               fontButton.setText(Messages.getString("PreferencesPage.PickFont")); //$NON-NLS-1$
-               fontButton.addSelectionListener(new SelectionListener() {
-                       public void widgetDefaultSelected(SelectionEvent e) {
-                       }
-                       public void widgetSelected(SelectionEvent e) {
-                               if (fontData != null) {
-                    VersioningHelper.setFont(fontDialog, new FontData[] { fontData} );
-                               }
-                               FontData data = fontDialog.open();
-                               if (data != null) {
-                                       fontData = data;
-                                       updateFontDisplay();
-                               }
-                       }
-               });
-               Button defaultButton = new Button(main, SWT.PUSH);
-               defaultButton.setText(Messages.getString("PreferencesPage.DefaultFont")); //$NON-NLS-1$
-               defaultButton.addSelectionListener(new SelectionListener() {
-                       public void widgetDefaultSelected(SelectionEvent e) {
-                       }
-                       public void widgetSelected(SelectionEvent e) {
-                               fontData = null;
-                               updateFontDisplay();
-                       }
-               });
-
-               fontDisplay = new Label(main, SWT.NULL);
-               GridData data = new GridData(GridData.FILL_HORIZONTAL);
-               data.grabExcessHorizontalSpace = true;
-               fontDisplay.setLayoutData(data);
-               updateFontDisplay();
-
-               ColorManager manager = new ColorManager();
+               return main;
+       }
+       /**
+     * @param main
+     * @return
+     */
+    private void createColorSelectionArea(Composite parent) {
+        Composite main = new Composite(parent, SWT.NULL);
 
-               Composite comp = new Composite(main, SWT.NULL);
-               GridData layoutData = new GridData();
-               layoutData.horizontalSpan = 2;
-               comp.setLayoutData(layoutData);
+               this.textFlag = getPreferenceStore().getBoolean("quantum.text.bold"); //$NON-NLS-1$
+               this.keywordFlag = getPreferenceStore().getBoolean("quantum.keyword.bold"); //$NON-NLS-1$
+               this.stringFlag = getPreferenceStore().getBoolean("quantum.string.bold"); //$NON-NLS-1$
+               this.commentFlag = getPreferenceStore().getBoolean("quantum.comment.bold"); //$NON-NLS-1$
+               this.numericFlag = getPreferenceStore().getBoolean("quantum.numeric.bold"); //$NON-NLS-1$
+               
+        
+        GridLayout layout = new GridLayout();
+               
+               // the colour preference chooser really, really wants to take up a whole
+               // row, so we need to pretend that our row is only two cells wide, then
+               // pull a switcheroo later...
+               layout.numColumns = 2;
+               main.setLayout(layout);
                
-               manager.getColor(SQLColorConstants.DEFAULT);
                backgroundColorEditor =
                        new ColorFieldEditor(
-                               "quantum.background.color", //$NON-NLS-1$
-                               Messages.getString("PreferencesPage.BackgroundColor"), //$NON-NLS-1$
-                               comp);                          
+                               PluginPreferences.BACKGROUND_COLOR,
+                               Messages.getString(getClass(), "backgroundColor"), //$NON-NLS-1$
+                               main);  
 
-               Composite temp = new Composite(main, SWT.NULL);
-               temp.setSize(0, 0);
+               Label emptyLabel = new Label(main, SWT.NULL);
+               emptyLabel.setText("");
                
-               comp = new Composite(main, SWT.NULL);
-               layoutData = new GridData();
-               layoutData.horizontalSpan = 2;
-               comp.setLayoutData(layoutData);
+               createEmptyRow(main);
                
-               textColorEditor =
+               this.textColorEditor =
                        new ColorFieldEditor(
-                               "quantum.text.color", //$NON-NLS-1$
-                               Messages.getString("PreferencesPage.DefaultTextColor"), //$NON-NLS-1$
-                               comp);                          
+                               PluginPreferences.TEXT_COLOR,
+                               Messages.getString(getClass(), "defaultTextColor"), //$NON-NLS-1$
+                               main);                          
 
-               boldText = new Button(main, SWT.CHECK);
-               boldText.setSelection(textFlag);
-               boldText.setText(Messages.getString("PreferencesPage.Bold")); //$NON-NLS-1$
-               boldText.addSelectionListener(new SelectionListener() {
+               this.boldText = new Button(main, SWT.CHECK);
+               this.boldText.setSelection(textFlag);
+               this.boldText.setText(Messages.getString(getClass(), "bold")); //$NON-NLS-1$
+               this.boldText.addSelectionListener(new SelectionListener() {
                        public void widgetDefaultSelected(SelectionEvent e) {
                        }
                        public void widgetSelected(SelectionEvent e) {
@@ -200,20 +158,15 @@ public class SQLEditorPreferences extends PreferencePage
                        }
                });
 
-               comp = new Composite(main, SWT.NULL);
-               layoutData = new GridData();
-               layoutData.horizontalSpan = 2;
-               comp.setLayoutData(layoutData);
-
                keywordColorEditor =
                        new ColorFieldEditor(
-                               Messages.getString("PreferencesPage.quantum.keyword.color_26"), //$NON-NLS-1$
-                               Messages.getString("PreferencesPage.KeywordTextColor"), //$NON-NLS-1$
-                               comp);
+                               PluginPreferences.KEYWORD_COLOR,
+                               Messages.getString(getClass(), "keywordTextColor"), //$NON-NLS-1$
+                               main);
 
                boldKeyword = new Button(main, SWT.CHECK);
                boldKeyword.setSelection(keywordFlag);
-               boldKeyword.setText(Messages.getString("PreferencesPage.Bold")); //$NON-NLS-1$
+               boldKeyword.setText(Messages.getString(getClass(), "bold")); //$NON-NLS-1$
                boldKeyword.addSelectionListener(new SelectionListener() {
                        public void widgetDefaultSelected(SelectionEvent e) {
                        }
@@ -222,20 +175,15 @@ public class SQLEditorPreferences extends PreferencePage
                        }
                });
 
-               comp = new Composite(main, SWT.NULL);
-               layoutData = new GridData();
-               layoutData.horizontalSpan = 2;
-               comp.setLayoutData(layoutData);
-
                commentColorEditor =
                        new ColorFieldEditor(
-                               "quantum.comment.color", //$NON-NLS-1$
-                               Messages.getString("PreferencesPage.CommentTextColor"), //$NON-NLS-1$
-                               comp);
+                               PluginPreferences.COMMENT_COLOR,
+                               Messages.getString(getClass(), "commentTextColor"), //$NON-NLS-1$
+                               main);
 
                boldComment = new Button(main, SWT.CHECK);
                boldComment.setSelection(commentFlag);
-               boldComment.setText(Messages.getString("PreferencesPage.Bold")); //$NON-NLS-1$
+               boldComment.setText(Messages.getString(getClass(), "bold")); //$NON-NLS-1$
                boldComment.addSelectionListener(new SelectionListener() {
                        public void widgetDefaultSelected(SelectionEvent e) {
                        }
@@ -244,20 +192,15 @@ public class SQLEditorPreferences extends PreferencePage
                        }
                });
 
-               comp = new Composite(main, SWT.NULL);
-               layoutData = new GridData();
-               layoutData.horizontalSpan = 2;
-               comp.setLayoutData(layoutData);
-
                stringColorEditor =
                        new ColorFieldEditor(
-                               "quantum.string.color", //$NON-NLS-1$
-                               Messages.getString("PreferencesPage.StringTextColor"), //$NON-NLS-1$
-                               comp);
+                               PluginPreferences.STRING_COLOR,
+                               Messages.getString(getClass(), "stringTextColor"), //$NON-NLS-1$
+                               main);
 
                boldString = new Button(main, SWT.CHECK);
                boldString.setSelection(stringFlag);
-               boldString.setText(Messages.getString("PreferencesPage.Bold")); //$NON-NLS-1$
+               boldString.setText(Messages.getString(getClass(), "bold")); //$NON-NLS-1$
                boldString.addSelectionListener(new SelectionListener() {
                        public void widgetDefaultSelected(SelectionEvent e) {
                        }
@@ -266,20 +209,15 @@ public class SQLEditorPreferences extends PreferencePage
                        }
                });
 
-               comp = new Composite(main, SWT.NULL);
-               layoutData = new GridData();
-               layoutData.horizontalSpan = 2;
-               comp.setLayoutData(layoutData);
-
                numericColorEditor =
                        new ColorFieldEditor(
-                               "quantum.numeric.color", //$NON-NLS-1$
-                               Messages.getString("PreferencesPage.NumericTextColor"), //$NON-NLS-1$
-                               comp);
+                               PluginPreferences.NUMERIC_COLOR,
+                               Messages.getString(getClass(), "numericTextColor"), //$NON-NLS-1$
+                               main);
 
                boldNumeric = new Button(main, SWT.CHECK);
                boldNumeric.setSelection(numericFlag);
-               boldNumeric.setText(Messages.getString("PreferencesPage.Bold")); //$NON-NLS-1$
+               boldNumeric.setText(Messages.getString(getClass(), "bold")); //$NON-NLS-1$
                boldNumeric.addSelectionListener(new SelectionListener() {
                        public void widgetDefaultSelected(SelectionEvent e) {
                        }
@@ -311,29 +249,95 @@ public class SQLEditorPreferences extends PreferencePage
                numericColorEditor.setPreferencePage(this);
                numericColorEditor.setPreferenceStore(getPreferenceStore());
                numericColorEditor.load();
+               
+               // now for the switcheroo...
+               // reset the number of columns to 3
+               GridLayout innerLayout = new GridLayout();
+               innerLayout.numColumns = 3;
+               main.setLayout(innerLayout);
+    }
 
-               return main;
-       }
-       public void updateFontDisplay() {
+    /**
+     * @param main
+     */
+    private void createFontSelectionArea(Composite main) {
+        Group group = new Group(main, SWT.NONE);
+        group.setText(Messages.getString(getClass(), "font"));
+        GridLayout innerLayout = new GridLayout();
+               innerLayout.numColumns = 2;
+               group.setLayout(innerLayout);
+               group.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+
+               fontDisplay = new Label(group, SWT.NULL);
+               GridData data = new GridData(GridData.FILL_HORIZONTAL);
+               data.horizontalSpan = 2;
+               fontDisplay.setLayoutData(data);
+               
+               fontData = PreferenceConverter.getFontData(getPreferenceStore(), "quantum.font"); //$NON-NLS-1$
+               fontDialog = new FontDialog(getShell());
+               Button fontButton = new Button(group, SWT.PUSH);
+               fontButton.setText(Messages.getString(getClass(), "pickFont")); //$NON-NLS-1$
+               fontButton.addSelectionListener(new SelectionListener() {
+                       public void widgetDefaultSelected(SelectionEvent e) {
+                       }
+                       public void widgetSelected(SelectionEvent e) {
+                               if (fontData != null) {
+                    VersioningHelper.setFont(fontDialog, new FontData[] { fontData} );
+                               }
+                               FontData data = fontDialog.open();
+                               if (data != null) {
+                                       fontData = data;
+                                       updateFontDisplay();
+                               }
+                       }
+               });
+               Button defaultButton = new Button(group, SWT.PUSH);
+               defaultButton.setText(Messages.getString(getClass(), "defaultFont")); //$NON-NLS-1$
+               defaultButton.addSelectionListener(new SelectionListener() {
+                       public void widgetDefaultSelected(SelectionEvent e) {
+                       }
+                       public void widgetSelected(SelectionEvent e) {
+                               fontData = PluginPreferences.getDefaultFont();
+                               updateFontDisplay();
+                       }
+               });
+
+               updateFontDisplay();
+    }
+
+    /**
+     * @param main
+     */
+    private void createEmptyRow(Composite main) {
+        Label emptyLabel = new Label(main, SWT.NULL);
+               emptyLabel.setText("");
+               GridData gridData = new GridData();
+               gridData.horizontalSpan = 3;
+               emptyLabel.setLayoutData(gridData);
+    }
+
+    protected void updateFontDisplay() {
                if (fontData == null) {
-                       fontDisplay.setText(Messages.getString("PreferencesPage.Font_Default")); //$NON-NLS-1$
+                       fontDisplay.setText(Messages.getString(getClass(), "default")); //$NON-NLS-1$
                } else {
-                       String style = Messages.getString("PreferencesPage.regular"); //$NON-NLS-1$
+                       Object[] parameters = new Object[] { 
+                                       fontData.getName(), new Integer(fontData.getHeight()) };
+                       String style = Messages.getString(getClass(), "regularFont", parameters); //$NON-NLS-1$
                        if (fontData.getStyle() == SWT.BOLD) {
-                               style = Messages.getString("PreferencesPage.bold"); //$NON-NLS-1$
+                               style = Messages.getString(getClass(), "boldFont", parameters); //$NON-NLS-1$
                        } else if (fontData.getStyle() == SWT.ITALIC) {
-                               style = Messages.getString("PreferencesPage.italic"); //$NON-NLS-1$
+                               style = Messages.getString(getClass(), "italicFont", parameters); //$NON-NLS-1$
                        } else if (fontData.getStyle() == (SWT.BOLD | SWT.ITALIC)) {
-                               style = Messages.getString("PreferencesPage.boldItalic"); //$NON-NLS-1$
+                               style = Messages.getString(getClass(), "boldItalicFont", parameters); //$NON-NLS-1$
                        }
-                       fontDisplay.setText(Messages.getString("PreferencesPage.FontPrompt") + fontData.getName() + '-' + style + '-' + fontData.getHeight()); //$NON-NLS-1$
+                       fontDisplay.setText(style); //$NON-NLS-1$
                }
        }
-       public void updateFlags() {
-               boldText.setSelection(textFlag);
-               boldKeyword.setSelection(keywordFlag);
-               boldString.setSelection(stringFlag);
-               boldNumeric.setSelection(numericFlag);
-               boldComment.setSelection(commentFlag);
+       protected void updateFlags() {
+               this.boldText.setSelection(this.textFlag);
+               this.boldKeyword.setSelection(this.keywordFlag);
+               this.boldString.setSelection(this.stringFlag);
+               this.boldNumeric.setSelection(this.numericFlag);
+               this.boldComment.setSelection(this.commentFlag);
        }
 }