Started with PHP/HTML Formatter menu => doesn't work right now
[phpeclipse.git] / archive / net.sourceforge.phpeclipse.sql / src / net / sourceforge / phpdt / sql / preferences / PreferencesPage.java
index 55129f0..1173afd 100644 (file)
@@ -1,6 +1,5 @@
 package net.sourceforge.phpdt.sql.preferences;
 
-
 import net.sourceforge.phpdt.sql.PHPEclipseSQLPlugin;
 
 import org.eclipse.jface.preference.ColorFieldEditor;
@@ -26,315 +25,342 @@ import org.eclipse.ui.IWorkbenchPreferencePage;
 import net.sourceforge.phpdt.sql.editors.ColorManager;
 import net.sourceforge.phpdt.sql.editors.SQLColorConstants;
 
-public class PreferencesPage extends PreferencePage
-       implements IWorkbenchPreferencePage {
-       FontDialog fontDialog;
-       ColorFieldEditor backgroundColorEditor;
-       
-       ColorFieldEditor textColorEditor;
-       boolean textFlag;
-       ColorFieldEditor keywordColorEditor;
-       boolean keywordFlag;
-       ColorFieldEditor stringColorEditor;
-       boolean stringFlag;
-       ColorFieldEditor numericColorEditor;
-       boolean numericFlag;
-       ColorFieldEditor commentColorEditor;
-       boolean commentFlag;
-       
-       Button boldText;
-       Button boldKeyword;
-       Button boldString;
-       Button boldNumeric;
-       Button boldComment;
-       
-       IWorkbench workbench;
-       FontData fontData;
-       Label fontDisplay;
-       public void init(IWorkbench workbench) {
-               //Initialize the preference store
-               this.workbench = workbench;
-               setPreferenceStore(PHPEclipseSQLPlugin.getDefault().getPreferenceStore());
-               initializeColorDefaults(getPreferenceStore());
-       }
-
-       private void initializeColorDefaults(IPreferenceStore store) {
-               RGB BACKGROUND = new RGB(255, 255, 255);
-               RGB COMMENT = new RGB(88, 148, 64);
-               RGB IDENTIFIER = new RGB(0, 0, 0);
-               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);
-               PreferenceConverter.setDefault(store,
-                       "quantum.text.color", DEFAULT);
-               PreferenceConverter.setDefault(store,
-                       "quantum.keyword.color", KEYWORD);
-               PreferenceConverter.setDefault(store,
-                       "quantum.comment.color", COMMENT);
-               PreferenceConverter.setDefault(store,
-                       "quantum.string.color", STRING);
-               PreferenceConverter.setDefault(store,
-                       "quantum.numeric.color", NUMERIC);
-       }
-
-       protected void performDefaults() {
-               fontData = null;
-               updateFontDisplay();
-               textFlag = false;
-               keywordFlag = true;
-               stringFlag = false;
-               numericFlag = false;
-               commentFlag = false;
-               updateFlags();
-               backgroundColorEditor.loadDefault();
-               textColorEditor.loadDefault();
-               keywordColorEditor.loadDefault();
-               stringColorEditor.loadDefault();
-               commentColorEditor.loadDefault();
-               numericColorEditor.loadDefault();
-       }
-       /** 
-        * Save the preferences to the preference store.
-        */
-       public boolean performOk() {
-               PreferenceConverter.setValue(getPreferenceStore(), "quantum.font", fontData);
-               getPreferenceStore().setValue("quantum.text.bold", textFlag);
-               getPreferenceStore().setValue("quantum.keyword.bold", keywordFlag);
-               getPreferenceStore().setValue("quantum.string.bold", stringFlag);
-               getPreferenceStore().setValue("quantum.comment.bold", commentFlag);
-               getPreferenceStore().setValue("quantum.numeric.bold", numericFlag);
-               backgroundColorEditor.store();
-               textColorEditor.store();
-               keywordColorEditor.store();
-               stringColorEditor.store();
-               commentColorEditor.store();
-               numericColorEditor.store();
-               return super.performOk();
-       }
-       protected Control createContents(Composite parent) {
-               Composite main = new Composite(parent, SWT.NULL);
-               
-               GridLayout innerLayout = new GridLayout();
-               innerLayout.numColumns = 4;
-               main.setLayout(innerLayout);
-
-               fontData = PreferenceConverter.getFontData(getPreferenceStore(), "quantum.font");
-               textFlag = getPreferenceStore().getBoolean("quantum.text.bold");
-               keywordFlag = getPreferenceStore().getBoolean("quantum.keyword.bold");
-               stringFlag = getPreferenceStore().getBoolean("quantum.string.bold");
-               commentFlag = getPreferenceStore().getBoolean("quantum.comment.bold");
-               numericFlag = getPreferenceStore().getBoolean("quantum.numeric.bold");
-               
-               fontDialog = new FontDialog(workbench.getActiveWorkbenchWindow().getShell());
-               Button fontButton = new Button(main, SWT.PUSH);
-               fontButton.setText("Pick Font");
-               fontButton.addSelectionListener(new SelectionListener() {
-                       public void widgetDefaultSelected(SelectionEvent e) {
-                       }
-                       public void widgetSelected(SelectionEvent e) {
-                               if (fontData != null) {
-                                       fontDialog.setFontData(fontData);
-                               }
-                               FontData data = fontDialog.open();
-                               if (data != null) {
-                                       fontData = data;
-                                       updateFontDisplay();
-                               }
-                       }
-               });
-               Button defaultButton = new Button(main, SWT.PUSH);
-               defaultButton.setText("Default Font");
-               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();
-
-               Composite comp = new Composite(main, SWT.NULL);
-               GridData layoutData = new GridData();
-               layoutData.horizontalSpan = 2;
-               comp.setLayoutData(layoutData);
-               
-               Color defaultColor = manager.getColor(SQLColorConstants.DEFAULT);
-               backgroundColorEditor =
-                       new ColorFieldEditor(
-                               "quantum.background.color",
-                               "Background Color",
-                               comp);                          
-
-               Composite temp = new Composite(main, SWT.NULL);
-               temp.setSize(0, 0);
-               
-               comp = new Composite(main, SWT.NULL);
-               layoutData = new GridData();
-               layoutData.horizontalSpan = 2;
-               comp.setLayoutData(layoutData);
-               
-               textColorEditor =
-                       new ColorFieldEditor(
-                               "quantum.text.color",
-                               "Default Text Color",
-                               comp);                          
-
-               boldText = new Button(main, SWT.CHECK);
-               boldText.setSelection(textFlag);
-               boldText.setText("Bold");
-               boldText.addSelectionListener(new SelectionListener() {
-                       public void widgetDefaultSelected(SelectionEvent e) {
-                       }
-                       public void widgetSelected(SelectionEvent e) {
-                               textFlag = boldText.getSelection();
-                       }
-               });
-
-               comp = new Composite(main, SWT.NULL);
-               layoutData = new GridData();
-               layoutData.horizontalSpan = 2;
-               comp.setLayoutData(layoutData);
-
-               keywordColorEditor =
-                       new ColorFieldEditor(
-                               "quantum.keyword.color",
-                               "Keyword Text Color",
-                               comp);
-
-               boldKeyword = new Button(main, SWT.CHECK);
-               boldKeyword.setSelection(keywordFlag);
-               boldKeyword.setText("Bold");
-               boldKeyword.addSelectionListener(new SelectionListener() {
-                       public void widgetDefaultSelected(SelectionEvent e) {
-                       }
-                       public void widgetSelected(SelectionEvent e) {
-                               keywordFlag = boldKeyword.getSelection();
-                       }
-               });
-
-               comp = new Composite(main, SWT.NULL);
-               layoutData = new GridData();
-               layoutData.horizontalSpan = 2;
-               comp.setLayoutData(layoutData);
-
-               commentColorEditor =
-                       new ColorFieldEditor(
-                               "quantum.comment.color",
-                               "Comment Text Color",
-                               comp);
-
-               boldComment = new Button(main, SWT.CHECK);
-               boldComment.setSelection(commentFlag);
-               boldComment.setText("Bold");
-               boldComment.addSelectionListener(new SelectionListener() {
-                       public void widgetDefaultSelected(SelectionEvent e) {
-                       }
-                       public void widgetSelected(SelectionEvent e) {
-                               commentFlag = boldComment.getSelection();
-                       }
-               });
-
-               comp = new Composite(main, SWT.NULL);
-               layoutData = new GridData();
-               layoutData.horizontalSpan = 2;
-               comp.setLayoutData(layoutData);
-
-               stringColorEditor =
-                       new ColorFieldEditor(
-                               "quantum.string.color",
-                               "String Text Color",
-                               comp);
-
-               boldString = new Button(main, SWT.CHECK);
-               boldString.setSelection(stringFlag);
-               boldString.setText("Bold");
-               boldString.addSelectionListener(new SelectionListener() {
-                       public void widgetDefaultSelected(SelectionEvent e) {
-                       }
-                       public void widgetSelected(SelectionEvent e) {
-                               stringFlag = boldString.getSelection();
-                       }
-               });
-
-               comp = new Composite(main, SWT.NULL);
-               layoutData = new GridData();
-               layoutData.horizontalSpan = 2;
-               comp.setLayoutData(layoutData);
-
-               numericColorEditor =
-                       new ColorFieldEditor(
-                               "quantum.numeric.color",
-                               "Numeric Text Color",
-                               comp);
-
-               boldNumeric = new Button(main, SWT.CHECK);
-               boldNumeric.setSelection(numericFlag);
-               boldNumeric.setText("Bold");
-               boldNumeric.addSelectionListener(new SelectionListener() {
-                       public void widgetDefaultSelected(SelectionEvent e) {
-                       }
-                       public void widgetSelected(SelectionEvent e) {
-                               numericFlag = boldNumeric.getSelection();
-                       }
-               });
-
-               backgroundColorEditor.setPreferencePage(this);
-               backgroundColorEditor.setPreferenceStore(getPreferenceStore());
-               backgroundColorEditor.load();
-               
-               textColorEditor.setPreferencePage(this);
-               textColorEditor.setPreferenceStore(getPreferenceStore());
-               textColorEditor.load();
-               
-               keywordColorEditor.setPreferencePage(this);
-               keywordColorEditor.setPreferenceStore(getPreferenceStore());
-               keywordColorEditor.load();
-               
-               commentColorEditor.setPreferencePage(this);
-               commentColorEditor.setPreferenceStore(getPreferenceStore());
-               commentColorEditor.load();
-               
-               stringColorEditor.setPreferencePage(this);
-               stringColorEditor.setPreferenceStore(getPreferenceStore());
-               stringColorEditor.load();
-
-               numericColorEditor.setPreferencePage(this);
-               numericColorEditor.setPreferenceStore(getPreferenceStore());
-               numericColorEditor.load();
-
-               return main;
-       }
-       public void updateFontDisplay() {
-               if (fontData == null) {
-                       fontDisplay.setText("Font: default");
-               } else {
-                       String style = "regular";
-                       if (fontData.getStyle() == SWT.BOLD) {
-                               style = "bold";
-                       } else if (fontData.getStyle() == SWT.ITALIC) {
-                               style = "italic";
-                       } else if (fontData.getStyle() == (SWT.BOLD | SWT.ITALIC)) {
-                               style = "bold italic";
-                       }
-                       fontDisplay.setText("Font: " + fontData.getName() + '-' + style + '-' + fontData.getHeight());
-               }
-       }
-       public void updateFlags() {
-               boldText.setSelection(textFlag);
-               boldKeyword.setSelection(keywordFlag);
-               boldString.setSelection(stringFlag);
-               boldNumeric.setSelection(numericFlag);
-               boldComment.setSelection(commentFlag);
-       }
+public class PreferencesPage
+  extends PreferencePage
+  implements IWorkbenchPreferencePage {
+  FontDialog fontDialog;
+  ColorFieldEditor backgroundColorEditor;
+
+  ColorFieldEditor textColorEditor;
+  boolean textFlag;
+  ColorFieldEditor keywordColorEditor;
+  boolean keywordFlag;
+  ColorFieldEditor stringColorEditor;
+  boolean stringFlag;
+  ColorFieldEditor numericColorEditor;
+  boolean numericFlag;
+  ColorFieldEditor commentColorEditor;
+  boolean commentFlag;
+
+  Button boldText;
+  Button boldKeyword;
+  Button boldString;
+  Button boldNumeric;
+  Button boldComment;
+
+  IWorkbench workbench;
+  FontData fontData;
+  Label fontDisplay;
+  public void init(IWorkbench workbench) {
+    //Initialize the preference store
+    this.workbench = workbench;
+    setPreferenceStore(PHPEclipseSQLPlugin.getDefault().getPreferenceStore());
+    initializeColorDefaults(getPreferenceStore());
+  }
+
+  private void initializeColorDefaults(IPreferenceStore store) {
+    RGB BACKGROUND = new RGB(255, 255, 255);
+    RGB COMMENT = new RGB(88, 148, 64);
+    RGB IDENTIFIER = new RGB(0, 0, 0);
+    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,
+      "phpeclipse.sql.background.color",
+      BACKGROUND);
+    PreferenceConverter.setDefault(store, "phpeclipse.sql.text.color", DEFAULT);
+    PreferenceConverter.setDefault(
+      store,
+      "phpeclipse.sql.keyword.color",
+      KEYWORD);
+    PreferenceConverter.setDefault(
+      store,
+      "phpeclipse.sql.comment.color",
+      COMMENT);
+    PreferenceConverter.setDefault(
+      store,
+      "phpeclipse.sql.string.color",
+      STRING);
+    PreferenceConverter.setDefault(
+      store,
+      "phpeclipse.sql.numeric.color",
+      NUMERIC);
+  }
+
+  protected void performDefaults() {
+    fontData = null;
+    updateFontDisplay();
+    textFlag = false;
+    keywordFlag = true;
+    stringFlag = false;
+    numericFlag = false;
+    commentFlag = false;
+    updateFlags();
+    backgroundColorEditor.loadDefault();
+    textColorEditor.loadDefault();
+    keywordColorEditor.loadDefault();
+    stringColorEditor.loadDefault();
+    commentColorEditor.loadDefault();
+    numericColorEditor.loadDefault();
+  }
+  /** 
+   * Save the preferences to the preference store.
+   */
+  public boolean performOk() {
+    PreferenceConverter.setValue(
+      getPreferenceStore(),
+      "phpeclipse.sql.font",
+      fontData);
+    getPreferenceStore().setValue("phpeclipse.sql.text.bold", textFlag);
+    getPreferenceStore().setValue("phpeclipse.sql.keyword.bold", keywordFlag);
+    getPreferenceStore().setValue("phpeclipse.sql.string.bold", stringFlag);
+    getPreferenceStore().setValue("phpeclipse.sql.comment.bold", commentFlag);
+    getPreferenceStore().setValue("phpeclipse.sql.numeric.bold", numericFlag);
+    backgroundColorEditor.store();
+    textColorEditor.store();
+    keywordColorEditor.store();
+    stringColorEditor.store();
+    commentColorEditor.store();
+    numericColorEditor.store();
+    return super.performOk();
+  }
+  
+  protected Control createContents(Composite parent) {
+    Composite composite = new Composite(parent, SWT.NULL);
+
+    GridLayout innerLayout = new GridLayout();
+    innerLayout.numColumns = 4;
+    composite.setLayout(innerLayout);
+
+    fontData =
+      PreferenceConverter.getFontData(
+        getPreferenceStore(),
+        "phpeclipse.sql.font");
+    textFlag = getPreferenceStore().getBoolean("phpeclipse.sql.text.bold");
+    keywordFlag =
+      getPreferenceStore().getBoolean("phpeclipse.sql.keyword.bold");
+    stringFlag = getPreferenceStore().getBoolean("phpeclipse.sql.string.bold");
+    commentFlag =
+      getPreferenceStore().getBoolean("phpeclipse.sql.comment.bold");
+    numericFlag =
+      getPreferenceStore().getBoolean("phpeclipse.sql.numeric.bold");
+
+    fontDialog =
+      new FontDialog(workbench.getActiveWorkbenchWindow().getShell());
+    Button fontButton = new Button(composite, SWT.PUSH);
+    fontButton.setText("Pick Font");
+    fontButton.addSelectionListener(new SelectionListener() {
+      public void widgetDefaultSelected(SelectionEvent e) {
+      }
+      public void widgetSelected(SelectionEvent e) {
+        if (fontData != null) {
+          fontDialog.setFontData(fontData);
+        }
+        FontData data = fontDialog.open();
+        if (data != null) {
+          fontData = data;
+          updateFontDisplay();
+        }
+      }
+    });
+    Button defaultButton = new Button(composite, SWT.PUSH);
+    defaultButton.setText("Default Font");
+    defaultButton.addSelectionListener(new SelectionListener() {
+      public void widgetDefaultSelected(SelectionEvent e) {
+      }
+      public void widgetSelected(SelectionEvent e) {
+        fontData = null;
+        updateFontDisplay();
+      }
+    });
+
+    fontDisplay = new Label(composite, SWT.NULL);
+    GridData data = new GridData(GridData.FILL_HORIZONTAL);
+    data.grabExcessHorizontalSpace = true;
+    fontDisplay.setLayoutData(data);
+    updateFontDisplay();
+
+    ColorManager manager = new ColorManager();
+
+    Composite comp = new Composite(composite, SWT.NULL);
+    GridData layoutData = new GridData();
+    layoutData.horizontalSpan = 2;
+    comp.setLayoutData(layoutData);
+
+    Color defaultColor = manager.getColor(SQLColorConstants.DEFAULT);
+    backgroundColorEditor =
+      new ColorFieldEditor(
+        "phpeclipse.sql.background.color",
+        "Background Color",
+        comp);
+
+    Composite temp = new Composite(composite, SWT.NULL);
+    temp.setSize(0, 0);
+
+    comp = new Composite(composite, SWT.NULL);
+    layoutData = new GridData();
+    layoutData.horizontalSpan = 2;
+    comp.setLayoutData(layoutData);
+
+    textColorEditor =
+      new ColorFieldEditor(
+        "phpeclipse.sql.text.color",
+        "Default Text Color",
+        comp);
+
+    boldText = new Button(composite, SWT.CHECK);
+    boldText.setSelection(textFlag);
+    boldText.setText("Bold");
+    boldText.addSelectionListener(new SelectionListener() {
+      public void widgetDefaultSelected(SelectionEvent e) {
+      }
+      public void widgetSelected(SelectionEvent e) {
+        textFlag = boldText.getSelection();
+      }
+    });
+
+    comp = new Composite(composite, SWT.NULL);
+    layoutData = new GridData();
+    layoutData.horizontalSpan = 2;
+    comp.setLayoutData(layoutData);
+
+    keywordColorEditor =
+      new ColorFieldEditor(
+        "phpeclipse.sql.keyword.color",
+        "Keyword Text Color",
+        comp);
+
+    boldKeyword = new Button(composite, SWT.CHECK);
+    boldKeyword.setSelection(keywordFlag);
+    boldKeyword.setText("Bold");
+    boldKeyword.addSelectionListener(new SelectionListener() {
+      public void widgetDefaultSelected(SelectionEvent e) {
+      }
+      public void widgetSelected(SelectionEvent e) {
+        keywordFlag = boldKeyword.getSelection();
+      }
+    });
+
+    comp = new Composite(composite, SWT.NULL);
+    layoutData = new GridData();
+    layoutData.horizontalSpan = 2;
+    comp.setLayoutData(layoutData);
+
+    commentColorEditor =
+      new ColorFieldEditor(
+        "phpeclipse.sql.comment.color",
+        "Comment Text Color",
+        comp);
+
+    boldComment = new Button(composite, SWT.CHECK);
+    boldComment.setSelection(commentFlag);
+    boldComment.setText("Bold");
+    boldComment.addSelectionListener(new SelectionListener() {
+      public void widgetDefaultSelected(SelectionEvent e) {
+      }
+      public void widgetSelected(SelectionEvent e) {
+        commentFlag = boldComment.getSelection();
+      }
+    });
+
+    comp = new Composite(composite, SWT.NULL);
+    layoutData = new GridData();
+    layoutData.horizontalSpan = 2;
+    comp.setLayoutData(layoutData);
+
+    stringColorEditor =
+      new ColorFieldEditor(
+        "phpeclipse.sql.string.color",
+        "String Text Color",
+        comp);
+
+    boldString = new Button(composite, SWT.CHECK);
+    boldString.setSelection(stringFlag);
+    boldString.setText("Bold");
+    boldString.addSelectionListener(new SelectionListener() {
+      public void widgetDefaultSelected(SelectionEvent e) {
+      }
+      public void widgetSelected(SelectionEvent e) {
+        stringFlag = boldString.getSelection();
+      }
+    });
+
+    comp = new Composite(composite, SWT.NULL);
+    layoutData = new GridData();
+    layoutData.horizontalSpan = 2;
+    comp.setLayoutData(layoutData);
+
+    numericColorEditor =
+      new ColorFieldEditor(
+        "phpeclipse.sql.numeric.color",
+        "Numeric Text Color",
+        comp);
+
+    boldNumeric = new Button(composite, SWT.CHECK);
+    boldNumeric.setSelection(numericFlag);
+    boldNumeric.setText("Bold");
+    boldNumeric.addSelectionListener(new SelectionListener() {
+      public void widgetDefaultSelected(SelectionEvent e) {
+      }
+      public void widgetSelected(SelectionEvent e) {
+        numericFlag = boldNumeric.getSelection();
+      }
+    });
+
+    backgroundColorEditor.setPreferencePage(this);
+    backgroundColorEditor.setPreferenceStore(getPreferenceStore());
+    backgroundColorEditor.load();
+
+    textColorEditor.setPreferencePage(this);
+    textColorEditor.setPreferenceStore(getPreferenceStore());
+    textColorEditor.load();
+
+    keywordColorEditor.setPreferencePage(this);
+    keywordColorEditor.setPreferenceStore(getPreferenceStore());
+    keywordColorEditor.load();
+
+    commentColorEditor.setPreferencePage(this);
+    commentColorEditor.setPreferenceStore(getPreferenceStore());
+    commentColorEditor.load();
+
+    stringColorEditor.setPreferencePage(this);
+    stringColorEditor.setPreferenceStore(getPreferenceStore());
+    stringColorEditor.load();
+
+    numericColorEditor.setPreferencePage(this);
+    numericColorEditor.setPreferenceStore(getPreferenceStore());
+    numericColorEditor.load();
+
+    return composite;
+  }
+  public void updateFontDisplay() {
+    if (fontData == null) {
+      fontDisplay.setText("Font: default");
+    } else {
+      String style = "regular";
+      if (fontData.getStyle() == SWT.BOLD) {
+        style = "bold";
+      } else if (fontData.getStyle() == SWT.ITALIC) {
+        style = "italic";
+      } else if (fontData.getStyle() == (SWT.BOLD | SWT.ITALIC)) {
+        style = "bold italic";
+      }
+      fontDisplay.setText(
+        "Font: "
+          + fontData.getName()
+          + '-'
+          + style
+          + '-'
+          + fontData.getHeight());
+    }
+  }
+  public void updateFlags() {
+    boldText.setSelection(textFlag);
+    boldKeyword.setSelection(keywordFlag);
+    boldString.setSelection(stringFlag);
+    boldNumeric.setSelection(numericFlag);
+    boldComment.setSelection(commentFlag);
+  }
 }