Skip to content
Browse files

Reworking the preference system.

Parts of the old system, with the preference store overlay, are still in use.
The new system is cleaner, simpler, and easier to use and extend.
  • Loading branch information...
1 parent 3a300a2 commit 8d0358fd7fd4036f7fe33670743cf177d869c2e7 @ttencate ttencate committed Jun 22, 2009
View
109 ...lipsefp.haskell.ui/src/net/sf/eclipsefp/common/ui/preferences/AbstractPreferencePage.java
@@ -0,0 +1,109 @@
+package net.sf.eclipsefp.common.ui.preferences;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import net.sf.eclipsefp.haskell.ui.HaskellUIPlugin;
+
+import org.eclipse.core.runtime.preferences.InstanceScope;
+import org.eclipse.jface.preference.IPreferenceStore;
+import org.eclipse.jface.preference.PreferencePage;
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.IWorkbenchPreferencePage;
+import org.osgi.service.prefs.BackingStoreException;
+
+public abstract class AbstractPreferencePage extends PreferencePage
+implements IWorkbenchPreferencePage {
+
+ /**
+ * List of all preference controls managed by this object.
+ */
+ private final List<PreferenceControl> controls = new ArrayList<PreferenceControl>();
+
+ public AbstractPreferencePage() {
+ super();
+ }
+
+ public AbstractPreferencePage(final String title) {
+ super(title);
+ }
+
+ public AbstractPreferencePage(final String title, final ImageDescriptor image) {
+ super(title, image);
+ }
+
+ public void init(final IWorkbench workbench) {
+ // do nothing; subclasses may override
+ }
+
+ /**
+ * Loads the values of all {@link PreferenceControl}s on this page.
+ */
+ public void loadControlValues() {
+ IPreferenceStore prefStore = getPreferenceStore();
+ for (PreferenceControl control : controls) {
+ control.load(prefStore);
+ }
+ }
+
+ /**
+ * Stores preferences from the controls created by the createXxx methods
+ * into the preference store returned by {@link #getPreferenceStore},
+ * then saves the preference store.
+ *
+ * @return true if saving succeeded
+ */
+ @Override
+ public boolean performOk() {
+ IPreferenceStore prefStore = getPreferenceStore();
+ for (PreferenceControl control : controls) {
+ control.store(prefStore);
+ }
+ try {
+ new InstanceScope().getNode(HaskellUIPlugin.getPluginId()).flush();
+ } catch (BackingStoreException ex) {
+ return false;
+ }
+ return true;
+ }
+
+ /**
+ * Loads the default values into the controls.
+ */
+ @Override
+ public void performDefaults() {
+ IPreferenceStore prefStore = getPreferenceStore();
+ for (PreferenceControl control : controls) {
+ control.loadDefault(prefStore);
+ }
+ }
+
+ protected Label createLabel(final Composite parent, final String text) {
+ Label label = new Label(parent, SWT.LEFT);
+ label.setText(text);
+ return label;
+ }
+
+ protected CheckboxPreferenceControl createCheckboxControl(final Composite parent, final String text, final String name) {
+ CheckboxPreferenceControl control = new CheckboxPreferenceControl(parent, text, name);
+ controls.add(control);
+ return control;
+ }
+
+ protected StringPreferenceControl createStringControl(final Composite parent, final String label, final String name, final int maxLength) {
+ StringPreferenceControl control = new StringPreferenceControl(parent, label, name, maxLength);
+ controls.add(control);
+ return control;
+ }
+
+ protected IntegerPreferenceControl createIntegerControl(final Composite parent, final String label, final String name, final int maxLength) {
+ IntegerPreferenceControl control = new IntegerPreferenceControl(parent, label, name, maxLength);
+ controls.add(control);
+ return control;
+ }
+
+}
View
71 ...sefp.haskell.ui/src/net/sf/eclipsefp/common/ui/preferences/CheckboxPreferenceControl.java
@@ -0,0 +1,71 @@
+package net.sf.eclipsefp.common.ui.preferences;
+
+
+import org.eclipse.jface.preference.IPreferenceStore;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+
+public class CheckboxPreferenceControl extends PreferenceControl<Boolean> {
+
+ private final Button checkbox;
+
+ public CheckboxPreferenceControl(final Composite parent, final String text, final String name) {
+ super(name);
+
+ checkbox = new Button(parent, SWT.CHECK);
+ checkbox.setText(text);
+
+ checkbox.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(final SelectionEvent e) {
+ fireValueChanged();
+ }
+ });
+ }
+
+ @Override
+ protected Boolean doLoad(final IPreferenceStore prefStore) {
+ return new Boolean(prefStore.getBoolean(getName()));
+ }
+
+ @Override
+ protected Boolean doLoadDefault(final IPreferenceStore prefStore) {
+ return new Boolean(prefStore.getDefaultBoolean(getName()));
+ }
+
+ @Override
+ protected void doStore(final IPreferenceStore prefStore, final Boolean value) {
+ prefStore.setValue(getName(), value.booleanValue());
+ }
+
+ @Override
+ public Control getControl() {
+ return checkbox;
+ }
+
+ @Override
+ public boolean isEnabled() {
+ return checkbox.isEnabled();
+ }
+
+ @Override
+ public void setEnabled(final boolean enabled) {
+ checkbox.setEnabled(enabled);
+ }
+
+ @Override
+ public Boolean getValue() {
+ return new Boolean(checkbox.getSelection());
+ }
+
+ @Override
+ public void setValue(final Boolean value) {
+ checkbox.setSelection(value.booleanValue());
+ fireValueChanged();
+ }
+
+}
View
12 ...clipsefp.haskell.ui/src/net/sf/eclipsefp/common/ui/preferences/IValueChangedListener.java
@@ -0,0 +1,12 @@
+package net.sf.eclipsefp.common.ui.preferences;
+
+/**
+ * A listener that listens for changes in the value of a preference control.
+ *
+ * @author Thomas ten Cate
+ */
+public interface IValueChangedListener<T> {
+
+ public void valueChanged(PreferenceControl<T> control, T value);
+
+}
View
55 ...psefp.haskell.ui/src/net/sf/eclipsefp/common/ui/preferences/IntegerPreferenceControl.java
@@ -0,0 +1,55 @@
+package net.sf.eclipsefp.common.ui.preferences;
+
+import net.sf.eclipsefp.common.ui.util.DialogUtil;
+
+import org.eclipse.jface.preference.IPreferenceStore;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.widgets.Composite;
+
+public class IntegerPreferenceControl extends TextPreferenceControl<Integer> {
+
+ public IntegerPreferenceControl(final Composite parent, final String labelText,
+ final String name, final int maxLength) {
+ super(parent, labelText, name);
+
+ if (maxLength > 0) {
+ text.setTextLimit(maxLength);
+ GridData gd = new GridData();
+ gd.widthHint = DialogUtil.convertWidthInCharsToPixels(text, maxLength + 1);
+ text.setLayoutData(gd);
+ }
+ }
+
+ @Override
+ protected int getTextStyle() {
+ return super.getTextStyle() | SWT.RIGHT;
+ }
+
+ @Override
+ protected Integer doLoad(final IPreferenceStore prefStore) {
+ return new Integer(prefStore.getInt(getName()));
+ }
+
+ @Override
+ protected Integer doLoadDefault(final IPreferenceStore prefStore) {
+ return new Integer(prefStore.getDefaultInt(getName()));
+ }
+
+ @Override
+ protected void doStore(final IPreferenceStore prefStore, final Integer value) {
+ prefStore.setValue(getName(), value.intValue());
+ }
+
+ @Override
+ public Integer getValue() {
+ return new Integer(text.getText());
+ }
+
+ @Override
+ public void setValue(final Integer value) {
+ text.setText(value.toString());
+ fireValueChanged();
+ }
+
+}
View
130 ...sf.eclipsefp.haskell.ui/src/net/sf/eclipsefp/common/ui/preferences/PreferenceControl.java
@@ -0,0 +1,130 @@
+package net.sf.eclipsefp.common.ui.preferences;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.jface.preference.IPreferenceStore;
+import org.eclipse.swt.widgets.Control;
+
+/**
+ * A control that represents a preference on a preference page.
+ *
+ * @author Thomas ten Cate
+ */
+public abstract class PreferenceControl<T> {
+
+ private List<IValueChangedListener<T>> valueChangedListeners = null;
+ private final String name;
+
+ protected PreferenceControl(final String name) {
+ this.name = name;
+ }
+
+ /**
+ * Returns the name of the associated preference.
+ */
+ protected String getName() {
+ return name;
+ }
+
+ /**
+ * Loads the value from the preference store into the control.
+ */
+ public void load(final IPreferenceStore prefStore) {
+ setValue(doLoad(prefStore));
+ }
+
+ /**
+ * Loads the default value from the preference store into the control.
+ */
+ public void loadDefault(final IPreferenceStore prefStore) {
+ setValue(doLoadDefault(prefStore));
+ }
+
+ /**
+ * Saves the value from the control into the preference store.
+ */
+ public void store(final IPreferenceStore prefStore) {
+ doStore(prefStore, getValue());
+ }
+
+ /**
+ * Loads the value from the given preference store, and returns it.
+ * Does not change the actual value in the control.
+ */
+ protected abstract T doLoad(IPreferenceStore prefStore);
+
+ /**
+ * Loads the default value from the given preference store, and returns it.
+ * Does not change the actual value in the control.
+ */
+ protected abstract T doLoadDefault(IPreferenceStore prefStore);
+
+ /**
+ * Saves the given value to the given preference store.
+ * Does not read the actual value from the control.
+ */
+ protected abstract void doStore(IPreferenceStore prefStore, T value);
+
+ /**
+ * Returns the control implementing this preference.
+ */
+ public abstract Control getControl();
+
+ /**
+ * Returns whether the control is currently enabled.
+ */
+ public abstract boolean isEnabled();
+
+ /**
+ * Sets the enablement of the control.
+ */
+ public abstract void setEnabled(boolean enabled);
+
+ /**
+ * Returns the current value of this control.
+ */
+ public abstract T getValue();
+
+ /**
+ * Sets a new value for the control.
+ * Subclasses should probably cal {@link #fireValueChanged()} from their implementations.
+ */
+ public abstract void setValue(T value);
+
+ /**
+ * Adds a new listener that will be notified after the value of this
+ * control has changed.
+ * @param init If true, an event will be fired immediately to the new listener.
+ */
+ public void addValueChangedListener(final IValueChangedListener<T> listener, final boolean init) {
+ if (valueChangedListeners == null) {
+ valueChangedListeners = new ArrayList<IValueChangedListener<T>>();
+ }
+ valueChangedListeners.add(listener);
+ if (init) {
+ listener.valueChanged(this, getValue());
+ }
+ }
+
+ /**
+ * Removes a value-changed listener.
+ */
+ public void removeValueChangedListener(final IValueChangedListener listener) {
+ if (valueChangedListeners != null) {
+ valueChangedListeners.remove(listener);
+ }
+ }
+
+ /**
+ * Fires a value-changed event.
+ */
+ protected void fireValueChanged() {
+ if (valueChangedListeners != null) {
+ for (IValueChangedListener<T> listener : valueChangedListeners) {
+ listener.valueChanged(this, getValue());
+ }
+ }
+ }
+
+}
View
48 ...ipsefp.haskell.ui/src/net/sf/eclipsefp/common/ui/preferences/StringPreferenceControl.java
@@ -0,0 +1,48 @@
+package net.sf.eclipsefp.common.ui.preferences;
+
+import net.sf.eclipsefp.common.ui.util.DialogUtil;
+
+import org.eclipse.jface.preference.IPreferenceStore;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.widgets.Composite;
+
+public class StringPreferenceControl extends TextPreferenceControl<String> {
+
+ public StringPreferenceControl(final Composite parent, final String labelText, final String name, final int maxLength) {
+ super(parent, labelText, name);
+
+ if (maxLength > 0) {
+ text.setTextLimit(maxLength);
+ GridData gd = new GridData();
+ gd.widthHint = DialogUtil.convertWidthInCharsToPixels(text, maxLength + 1);
+ text.setLayoutData(gd);
+ }
+ }
+
+ @Override
+ public String getValue() {
+ return text.getText();
+ }
+
+ @Override
+ public void setValue(final String value) {
+ text.setText(value);
+ fireValueChanged();
+ }
+
+ @Override
+ public String doLoad(final IPreferenceStore prefStore) {
+ return prefStore.getString(getName());
+ }
+
+ @Override
+ public String doLoadDefault(final IPreferenceStore prefStore) {
+ return prefStore.getDefaultString(getName());
+ }
+
+ @Override
+ public void doStore(final IPreferenceStore prefStore, final String value) {
+ prefStore.setValue(getName(), value);
+ }
+
+}
View
72 ...clipsefp.haskell.ui/src/net/sf/eclipsefp/common/ui/preferences/TextPreferenceControl.java
@@ -0,0 +1,72 @@
+package net.sf.eclipsefp.common.ui.preferences;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.ModifyEvent;
+import org.eclipse.swt.events.ModifyListener;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Text;
+
+/**
+ * A preference control based on a text field.
+ *
+ * @author Thomas ten Cate
+ */
+public abstract class TextPreferenceControl<T> extends PreferenceControl<T> {
+
+ protected final Label label;
+ protected final Text text;
+ private final Composite composite;
+
+ public TextPreferenceControl(final Composite parent, final String labelText, final String name) {
+ super(name);
+
+ composite = new Composite(parent, SWT.NONE);
+ GridLayout gl = new GridLayout();
+ gl.numColumns = 2;
+ gl.marginWidth = gl.marginHeight = 0;
+ composite.setLayout(gl);
+
+ label = new Label(composite, SWT.NONE);
+ label.setText(labelText);
+ GridData gd = new GridData();
+ gd.grabExcessHorizontalSpace = true;
+ label.setLayoutData(gd);
+
+ text = new Text(composite, getTextStyle());
+ this.text.addModifyListener(new ModifyListener(){
+ public void modifyText(final ModifyEvent e) {
+ fireValueChanged();
+ }
+ });
+ }
+
+ /**
+ * Returns the style in which the text label should be created.
+ * Called from the {@link #TextPreferenceControl} constructor.
+ * Subclasses may override.
+ */
+ protected int getTextStyle() {
+ return SWT.BORDER | SWT.SINGLE;
+ }
+
+ @Override
+ public Control getControl() {
+ return composite;
+ }
+
+ @Override
+ public boolean isEnabled() {
+ return label.isEnabled();
+ }
+
+ @Override
+ public void setEnabled(final boolean enabled) {
+ label.setEnabled(enabled);
+ text.setEnabled(enabled);
+ }
+
+}
View
200 ...askell.ui/src/net/sf/eclipsefp/haskell/ui/internal/preferences/HaskellPreferencePage.java
@@ -1,194 +1,26 @@
// Copyright (c) 2003-2004 by Leif Frenzel - see http://leiffrenzel.de
package net.sf.eclipsefp.haskell.ui.internal.preferences;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Map;
-import net.sf.eclipsefp.common.ui.dialog.BooleanDialogField;
-import net.sf.eclipsefp.common.ui.dialog.DialogField;
-import net.sf.eclipsefp.common.ui.dialog.IDialogFieldListener;
-import net.sf.eclipsefp.common.ui.util.DialogUtil;
+import net.sf.eclipsefp.common.ui.preferences.AbstractPreferencePage;
import net.sf.eclipsefp.haskell.ui.HaskellUIPlugin;
+import org.eclipse.jface.preference.FieldEditorPreferencePage;
import org.eclipse.jface.preference.IPreferenceStore;
-import org.eclipse.jface.preference.PreferencePage;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.events.ModifyEvent;
-import org.eclipse.swt.events.ModifyListener;
-import org.eclipse.swt.events.SelectionAdapter;
-import org.eclipse.swt.events.SelectionEvent;
-import org.eclipse.swt.events.SelectionListener;
-import org.eclipse.swt.layout.GridData;
-import org.eclipse.swt.widgets.Button;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Control;
-import org.eclipse.swt.widgets.Label;
-import org.eclipse.swt.widgets.Text;
-import org.eclipse.ui.IWorkbench;
-import org.eclipse.ui.IWorkbenchPreferencePage;
-/** <p>the super class for all preference pages.</p>
- *
- * @author Leif Frenzel
- */
-public abstract class HaskellPreferencePage extends PreferencePage
-implements IWorkbenchPreferencePage, IPreferenceConstants {
-
- private final Map<Button, String> checkBoxes = new HashMap<Button, String>();
- private final Map<Control, Control> labels = new HashMap<Control, Control>();
- private final Map<Text, String> textFields = new HashMap<Text, String>();
-
- private final SelectionListener fCheckBoxListener = new SelectionAdapter() {
- @Override
- public void widgetSelected( final SelectionEvent event ) {
- Button button = ( Button )event.widget;
- String key = checkBoxes.get( button );
- getPreferenceStore().setValue( key, button.getSelection() );
- }
- };
-
- private final ModifyListener fTextFieldListener = new ModifyListener() {
- public void modifyText( final ModifyEvent event ) {
- Text text = ( Text )event.widget;
- String key = textFields.get( text );
- getPreferenceStore().setValue( key, text.getText() );
- }
- };
-
- public void init(final IWorkbench workbench) {
- // do nothing; subclasses may override
- }
-
- @Override
- protected IPreferenceStore doGetPreferenceStore() {
- return HaskellUIPlugin.getDefault().getPreferenceStore();
- }
-
- public void initializeFields() {
- initializeCheckboxes();
- initializeTexts();
- }
-
- @Override
- public boolean performOk() {
- HaskellUIPlugin.getDefault().savePluginPreferences();
- return true;
- }
-
- protected Control getLabel( final Control field ) {
- return labels.get( field );
- }
-
- // UI creation helping methods for subclasses
- /////////////////////////////////////////////
-
- protected void createLabel( final Composite parent, final String text ) {
- Label label = new Label( parent, SWT.LEFT );
- label.setText( text );
- GridData gridData = new GridData();
- gridData.horizontalAlignment = GridData.BEGINNING;
- label.setLayoutData( gridData );
- }
-
- protected final Button addBooleanField( final Composite parent,
- final String label,
- final String key,
- final int indentation ) {
- Button checkBox = new Button( parent, SWT.CHECK );
- checkBox.setText( label );
-
- GridData gd = new GridData( GridData.HORIZONTAL_ALIGN_BEGINNING );
- gd.horizontalIndent = indentation;
- gd.horizontalSpan = 2;
- checkBox.setLayoutData( gd );
- checkBox.addSelectionListener( fCheckBoxListener );
-
- checkBoxes.put( checkBox, key );
-
- return checkBox;
- }
-
- protected DialogField createBooleanField( final Composite parent,
- final String text,
- final String name ) {
- BooleanDialogField result = new BooleanDialogField( parent, text );
- result.addDialogFieldListener( new IDialogFieldListener() {
- public void infoChanged( final Object newInfo ) {
- boolean selected = ( ( Boolean )newInfo ).booleanValue();
- getPreferenceStore().setValue( name, selected );
- }
- } );
- result.setInfo( getFromStore( name ) );
- return result;
- }
-
- protected Control addIntegerField( final Composite composite,
- final String label,
- final String key,
- final int textLimit,
- final int indentation ) {
- Text result = addStringField( composite, label, textLimit, indentation );
- textFields.put( result, key );
- return result;
- }
-
- protected Control addTextField( final Composite composite,
- final String label,
- final String key,
- final int textLimit,
- final int indentation ) {
- Text result = addStringField( composite, label, textLimit, indentation );
- textFields.put( result, key );
- result.addModifyListener( fTextFieldListener );
- return result;
- }
-
- // helping methods
- //////////////////
-
- private Text addStringField( final Composite composite,
- final String label,
- final int textLimit,
- final int indentation ) {
- Label labelControl = new Label( composite, SWT.NONE );
- labelControl.setText( label );
- GridData gd = new GridData( GridData.HORIZONTAL_ALIGN_BEGINNING );
- gd.horizontalIndent = indentation;
- labelControl.setLayoutData( gd );
-
- Text textControl = new Text( composite, SWT.BORDER | SWT.SINGLE );
- gd = new GridData( GridData.HORIZONTAL_ALIGN_BEGINNING );
- gd.widthHint = DialogUtil.convertWidthInCharsToPixels( textControl,
- textLimit + 1 );
- textControl.setLayoutData( gd );
- textControl.setTextLimit( textLimit );
-
- labels.put( textControl, labelControl );
- return textControl;
- }
-
- private void initializeTexts() {
- Iterator<Text> iter = textFields.keySet().iterator();
- while( iter.hasNext() ) {
- Text text = iter.next();
- String key = textFields.get( text );
- text.setText( getPreferenceStore().getString( key ) );
- }
- }
-
- private void initializeCheckboxes() {
- Iterator<Button> iter = checkBoxes.keySet().iterator();
- while( iter.hasNext() ) {
- Button button = iter.next();
- String key = checkBoxes.get( button );
- button.setSelection( getPreferenceStore().getBoolean( key ) );
- }
- }
-
- private Boolean getFromStore( final String name ) {
- boolean value = getPreferenceStore().getBoolean( name );
- return ( value ) ? Boolean.TRUE : Boolean.FALSE;
- }
+/**
+ * A class similar to Eclipse's {@link FieldEditorPreferencePage},
+ * but with more flexibility.
+ *
+ * @author Leif Frenzel
+ * @author Thomas ten Cate
+ */
+public abstract class HaskellPreferencePage extends AbstractPreferencePage
+implements IPreferenceConstants {
+
+ @Override
+ protected IPreferenceStore doGetPreferenceStore() {
+ return HaskellUIPlugin.getDefault().getPreferenceStore();
+ }
}
View
422 ...haskell.ui/src/net/sf/eclipsefp/haskell/ui/internal/preferences/editor/AnnotationsPP.java
@@ -19,224 +19,224 @@
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
-import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.List;
import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.forms.widgets.ColumnLayout;
import org.eclipse.ui.texteditor.AnnotationPreference;
import org.eclipse.ui.texteditor.MarkerAnnotationPreferences;
/** <p>Preference page for the annotation color preference settings.</p>
- *
- * @author Leif Frenzel
- *
- * TODO: Preferences probably take effect immediately, instead of waiting for Apply.
- * TODO: Restore Defaults button does not work.
- * TODO: There are many unnecessary items in the list.
- */
+ *
+ * @author Leif Frenzel
+ *
+ * TODO: Preferences probably take effect immediately, instead of waiting for Apply.
+ * TODO: Restore Defaults button does not work.
+ * TODO: There are many unnecessary items in the list.
+ */
public class AnnotationsPP extends HaskellPreferencePage {
- private List colorList;
-
- private String[][] colorListModel;
- private ColorSelector colorSelector;
- private Button cbShowInText;
- private Button cbShowInOverviewRuler;
-
- @Override
- public void init(final IWorkbench workbench) {
- super.init(workbench);
- colorListModel = createAnnotationTypeListModel();
- }
-
- @Override
- public Control createContents( final Composite parent ) {
- Composite composite = new Composite( parent, SWT.NONE );
- GridLayout layout = new GridLayout();
- layout.numColumns = 2;
- composite.setLayout( layout );
-
- initializeAnnPresLabel( composite );
- Composite editorComposite = initializeEditorComposite( composite );
- initializeColorList( composite, editorComposite );
- Composite optionsComposite = initializeOptionsComposite( editorComposite );
- initializeShowInTextCB( optionsComposite );
- initializeShowInOverviewRulerCB( optionsComposite );
- createLabel( optionsComposite, "C&olor:" );
- initializeColorSelector( optionsComposite );
-
- initialize();
-
- return composite;
- }
-
- void addPreferences( final OverlayPreferenceStore store ) {
- MarkerAnnotationPreferences preferences = new MarkerAnnotationPreferences();
- Iterator iter = preferences.getAnnotationPreferences().iterator();
- while( iter.hasNext() ) {
- AnnotationPreference info = ( AnnotationPreference )iter.next();
- store.addStringKey( info.getColorPreferenceKey() );
- store.addBooleanKey( info.getTextPreferenceKey() );
- store.addBooleanKey( info.getOverviewRulerPreferenceKey() );
- }
- }
-
-
- // UI initialization methods
- ////////////////////////////
-
- private Composite initializeOptionsComposite( final Composite parent ) {
- Composite optionsComposite = new Composite( parent, SWT.NONE );
- GridLayout layout = new GridLayout();
- layout.marginHeight = 0;
- layout.marginWidth = 0;
- layout.numColumns = 2;
- optionsComposite.setLayout( layout );
- optionsComposite.setLayoutData( new GridData( GridData.FILL_BOTH ) );
- return optionsComposite;
- }
-
- private void initializeColorList( final Composite composite,
- final Composite parent ) {
- colorList = new List( parent, SWT.SINGLE | SWT.V_SCROLL | SWT.BORDER );
- GridData gridData = new GridData( GridData.VERTICAL_ALIGN_BEGINNING
- | GridData.FILL_HORIZONTAL );
- gridData.heightHint = DialogUtil.convertHeightInCharsToPixels( composite,
- 8 );
- colorList.setLayoutData( gridData );
- colorList.addSelectionListener( new SelectionAdapter() {
- @Override
- public void widgetSelected( final SelectionEvent e ) {
- handleAnnotationColorListSelection();
- }
- } );
- }
-
- private void initializeColorSelector( final Composite parent ) {
- colorSelector = new ColorSelector( parent );
- Button foregroundColorButton = colorSelector.getButton();
- GridData gridData = new GridData( GridData.FILL_HORIZONTAL );
- gridData.horizontalAlignment = GridData.BEGINNING;
- foregroundColorButton.setLayoutData( gridData );
- foregroundColorButton.addSelectionListener( new SelectionAdapter() {
- @Override
- public void widgetSelected( final SelectionEvent e ) {
- int i = colorList.getSelectionIndex();
- String key = colorListModel[ i ][ 1 ];
- RGB colorValue = colorSelector.getColorValue();
- PreferenceConverter.setValue( getPreferenceStore(), key, colorValue );
- }
- } );
- }
-
- private void initializeAnnPresLabel( final Composite parent ) {
- Label label = new Label( parent, SWT.LEFT );
- label.setText( "Annotation &presentation:" );
- GridData gridData = new GridData( GridData.HORIZONTAL_ALIGN_FILL );
- gridData.horizontalSpan = 2;
- label.setLayoutData( gridData );
- }
-
- private Composite initializeEditorComposite( final Composite parent ) {
- Composite editorComposite = new Composite( parent, SWT.NONE );
- GridLayout layout = new GridLayout();
- layout.numColumns = 2;
- layout.marginHeight = 0;
- layout.marginWidth = 0;
- editorComposite.setLayout( layout );
- GridData gridData = new GridData( GridData.HORIZONTAL_ALIGN_FILL
- | GridData.FILL_VERTICAL );
- gridData.horizontalSpan = 2;
- editorComposite.setLayoutData( gridData );
- return editorComposite;
- }
-
- private void initializeShowInOverviewRulerCB( final Composite parent ) {
- cbShowInOverviewRuler = new Button( parent, SWT.CHECK );
- cbShowInOverviewRuler.setText( "Show in overview &ruler" );
- GridData gridData = new GridData( GridData.FILL_HORIZONTAL );
- gridData.horizontalAlignment = GridData.BEGINNING;
- gridData.horizontalSpan = 2;
- cbShowInOverviewRuler.setLayoutData( gridData );
- cbShowInOverviewRuler.addSelectionListener( new SelectionAdapter() {
- @Override
- public void widgetSelected( final SelectionEvent e ) {
- int i = colorList.getSelectionIndex();
- String key = colorListModel[ i ][ 3 ];
- boolean selected = cbShowInOverviewRuler.getSelection();
- getPreferenceStore().setValue( key, selected );
- }
- } );
- }
-
- private void initializeShowInTextCB( final Composite parent ) {
- cbShowInText = new Button( parent, SWT.CHECK );
- cbShowInText.setText( "Show in &text" );
- GridData gridData = new GridData( GridData.FILL_HORIZONTAL );
- gridData.horizontalAlignment = GridData.BEGINNING;
- gridData.horizontalSpan = 2;
- cbShowInText.setLayoutData( gridData );
- cbShowInText.addSelectionListener( new SelectionAdapter() {
- @Override
- public void widgetSelected( final SelectionEvent e ) {
- int i = colorList.getSelectionIndex();
- String key = colorListModel[ i ][ 2 ];
- boolean selected = cbShowInText.getSelection();
- getPreferenceStore().setValue( key, selected );
- }
- } );
- }
-
-
- // helping methods
- //////////////////
-
- private void handleAnnotationColorListSelection() {
- int i = colorList.getSelectionIndex();
- String key = colorListModel[ i ][ 1 ];
- RGB rgb = PreferenceConverter.getColor( getPreferenceStore(), key );
- colorSelector.setColorValue( rgb );
- key = colorListModel[ i ][ 2 ];
- boolean sel = getPreferenceStore().getBoolean( key );
- cbShowInText.setSelection( sel );
- key = colorListModel[ i ][ 3 ];
- cbShowInOverviewRuler.setSelection( sel );
- }
-
- private String[][] createAnnotationTypeListModel() {
- MarkerAnnotationPreferences preferences = new MarkerAnnotationPreferences();
- ArrayList<String[]> listModelItems = new ArrayList<String[]>();
- Iterator i = preferences.getAnnotationPreferences().iterator();
- while( i.hasNext() ) {
- AnnotationPreference info = ( AnnotationPreference )i.next();
- listModelItems.add( new String[] {
- info.getPreferenceLabel(),
- info.getColorPreferenceKey(),
- info.getTextPreferenceKey(),
- info.getOverviewRulerPreferenceKey() }
- );
- }
-
- String[][] listModel = new String[ listModelItems.size() ][];
- listModelItems.toArray( listModel );
- return listModel;
- }
-
- private void initialize() {
- for( int i = 0; i < colorListModel.length; i++ ) {
- String color = colorListModel[ i ][ 0 ];
- if( color != null ) {
- colorList.add( color );
- }
- }
- colorList.getDisplay().asyncExec( new Runnable() {
- public void run() {
- if( ( colorList != null ) && !colorList.isDisposed() ) {
- colorList.select( 0 );
- handleAnnotationColorListSelection();
- }
- }
- } );
- initializeFields();
- }
+ private List colorList;
+
+ private String[][] colorListModel;
+ private ColorSelector colorSelector;
+ private Button cbShowInText;
+ private Button cbShowInOverviewRuler;
+
+ @Override
+ public void init(final IWorkbench workbench) {
+ super.init(workbench);
+ colorListModel = createAnnotationTypeListModel();
+ }
+
+ @Override
+ protected Control createContents( final Composite parent ) {
+ Composite composite = new Composite( parent, SWT.NONE );
+ ColumnLayout layout = new ColumnLayout();
+ layout.maxNumColumns = 1;
+ composite.setLayout(layout);
+
+ createAppearanceGroup(composite);
+
+ initialize();
+ return composite;
+ }
+
+ void addPreferences( final OverlayPreferenceStore store ) {
+ MarkerAnnotationPreferences preferences = new MarkerAnnotationPreferences();
+ Iterator iter = preferences.getAnnotationPreferences().iterator();
+ while( iter.hasNext() ) {
+ AnnotationPreference info = ( AnnotationPreference )iter.next();
+ store.addStringKey( info.getColorPreferenceKey() );
+ store.addBooleanKey( info.getTextPreferenceKey() );
+ store.addBooleanKey( info.getOverviewRulerPreferenceKey() );
+ }
+ }
+
+
+ // UI initialization methods
+ ////////////////////////////
+
+ private void createAppearanceGroup(final Composite parent) {
+ Group group = new Group(parent, SWT.SHADOW_ETCHED_IN);
+ group.setText("Appearance");
+ GridLayout groupLayout = new GridLayout();
+ groupLayout.numColumns = 1;
+ group.setLayout(groupLayout);
+
+ Composite editorComposite = initializeEditorComposite(group);
+ initializeColorList(group, editorComposite );
+ Composite optionsComposite = initializeOptionsComposite( editorComposite );
+ initializeShowInTextCB( optionsComposite );
+ initializeShowInOverviewRulerCB( optionsComposite );
+ createLabel( optionsComposite, "C&olor:" );
+ initializeColorSelector( optionsComposite );
+ }
+
+ private Composite initializeOptionsComposite( final Composite parent ) {
+ Composite optionsComposite = new Composite( parent, SWT.NONE );
+ GridLayout layout = new GridLayout();
+ layout.marginHeight = 0;
+ layout.marginWidth = 0;
+ layout.numColumns = 2;
+ optionsComposite.setLayout( layout );
+ optionsComposite.setLayoutData( new GridData( GridData.FILL_BOTH ) );
+ return optionsComposite;
+ }
+
+ private void initializeColorList( final Composite composite,
+ final Composite parent ) {
+ colorList = new List( parent, SWT.SINGLE | SWT.V_SCROLL | SWT.BORDER );
+ GridData gridData = new GridData( GridData.VERTICAL_ALIGN_BEGINNING
+ | GridData.FILL_HORIZONTAL );
+ gridData.heightHint = DialogUtil.convertHeightInCharsToPixels( composite,
+ 8 );
+ colorList.setLayoutData( gridData );
+ colorList.addSelectionListener( new SelectionAdapter() {
+ @Override
+ public void widgetSelected( final SelectionEvent e ) {
+ handleAnnotationColorListSelection();
+ }
+ } );
+ }
+
+ private void initializeColorSelector( final Composite parent ) {
+ colorSelector = new ColorSelector( parent );
+ Button foregroundColorButton = colorSelector.getButton();
+ GridData gridData = new GridData( GridData.FILL_HORIZONTAL );
+ gridData.horizontalAlignment = GridData.BEGINNING;
+ foregroundColorButton.setLayoutData( gridData );
+ foregroundColorButton.addSelectionListener( new SelectionAdapter() {
+ @Override
+ public void widgetSelected( final SelectionEvent e ) {
+ int i = colorList.getSelectionIndex();
+ String key = colorListModel[ i ][ 1 ];
+ RGB colorValue = colorSelector.getColorValue();
+ PreferenceConverter.setValue( getPreferenceStore(), key, colorValue );
+ }
+ } );
+ }
+
+ private Composite initializeEditorComposite( final Composite parent ) {
+ Composite editorComposite = new Composite( parent, SWT.NONE );
+ GridLayout layout = new GridLayout();
+ layout.numColumns = 2;
+ layout.horizontalSpacing = 10;
+ editorComposite.setLayout( layout );
+ GridData gridData = new GridData( GridData.HORIZONTAL_ALIGN_FILL
+ | GridData.FILL_VERTICAL );
+ gridData.horizontalSpan = 2;
+ editorComposite.setLayoutData( gridData );
+ return editorComposite;
+ }
+
+ private void initializeShowInOverviewRulerCB( final Composite parent ) {
+ cbShowInOverviewRuler = new Button( parent, SWT.CHECK );
+ cbShowInOverviewRuler.setText( "Show in overview &ruler" );
+ GridData gridData = new GridData( GridData.FILL_HORIZONTAL );
+ gridData.horizontalAlignment = GridData.BEGINNING;
+ gridData.horizontalSpan = 2;
+ cbShowInOverviewRuler.setLayoutData( gridData );
+ cbShowInOverviewRuler.addSelectionListener( new SelectionAdapter() {
+ @Override
+ public void widgetSelected( final SelectionEvent e ) {
+ int i = colorList.getSelectionIndex();
+ String key = colorListModel[ i ][ 3 ];
+ boolean selected = cbShowInOverviewRuler.getSelection();
+ getPreferenceStore().setValue( key, selected );
+ }
+ } );
+ }
+
+ private void initializeShowInTextCB( final Composite parent ) {
+ cbShowInText = new Button( parent, SWT.CHECK );
+ cbShowInText.setText( "Show in &text" );
+ GridData gridData = new GridData( GridData.FILL_HORIZONTAL );
+ gridData.horizontalAlignment = GridData.BEGINNING;
+ gridData.horizontalSpan = 2;
+ cbShowInText.setLayoutData( gridData );
+ cbShowInText.addSelectionListener( new SelectionAdapter() {
+ @Override
+ public void widgetSelected( final SelectionEvent e ) {
+ int i = colorList.getSelectionIndex();
+ String key = colorListModel[ i ][ 2 ];
+ boolean selected = cbShowInText.getSelection();
+ getPreferenceStore().setValue( key, selected );
+ }
+ } );
+ }
+
+
+ // helping methods
+ //////////////////
+
+ private void handleAnnotationColorListSelection() {
+ int i = colorList.getSelectionIndex();
+ String key = colorListModel[ i ][ 1 ];
+ RGB rgb = PreferenceConverter.getColor( getPreferenceStore(), key );
+ colorSelector.setColorValue( rgb );
+ key = colorListModel[ i ][ 2 ];
+ boolean sel = getPreferenceStore().getBoolean( key );
+ cbShowInText.setSelection( sel );
+ key = colorListModel[ i ][ 3 ];
+ cbShowInOverviewRuler.setSelection( sel );
+ }
+
+ private String[][] createAnnotationTypeListModel() {
+ MarkerAnnotationPreferences preferences = new MarkerAnnotationPreferences();
+ ArrayList<String[]> listModelItems = new ArrayList<String[]>();
+ Iterator i = preferences.getAnnotationPreferences().iterator();
+ while( i.hasNext() ) {
+ AnnotationPreference info = ( AnnotationPreference )i.next();
+ listModelItems.add( new String[] {
+ info.getPreferenceLabel(),
+ info.getColorPreferenceKey(),
+ info.getTextPreferenceKey(),
+ info.getOverviewRulerPreferenceKey() }
+ );
+ }
+
+ String[][] listModel = new String[ listModelItems.size() ][];
+ listModelItems.toArray( listModel );
+ return listModel;
+ }
+
+ private void initialize() {
+ for( int i = 0; i < colorListModel.length; i++ ) {
+ String color = colorListModel[ i ][ 0 ];
+ if( color != null ) {
+ colorList.add( color );
+ }
+ }
+ colorList.getDisplay().asyncExec( new Runnable() {
+ public void run() {
+ if( ( colorList != null ) && !colorList.isDisposed() ) {
+ colorList.select( 0 );
+ handleAnnotationColorListSelection();
+ }
+ }
+ } );
+ loadControlValues();
+ }
}
View
341 ...skell.ui/src/net/sf/eclipsefp/haskell/ui/internal/preferences/editor/ContentAssistPP.java
@@ -1,6 +1,9 @@
// Copyright (c) 2003-2005 by Leif Frenzel - see http://leiffrenzel.de
package net.sf.eclipsefp.haskell.ui.internal.preferences.editor;
+import net.sf.eclipsefp.common.ui.preferences.CheckboxPreferenceControl;
+import net.sf.eclipsefp.common.ui.preferences.IValueChangedListener;
+import net.sf.eclipsefp.common.ui.preferences.PreferenceControl;
import net.sf.eclipsefp.common.ui.util.DialogUtil;
import net.sf.eclipsefp.haskell.ui.internal.preferences.HaskellPreferencePage;
@@ -15,177 +18,179 @@
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
-import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.List;
+import org.eclipse.ui.forms.widgets.ColumnLayout;
/** <p>Preference page for the content assist preference settings.</p>
- *
- * @author Leif Frenzel
- *
- * TODO: None of these preferences have any effect yet, I think.
- * TODO: Preferences take effect immediately, instead of waiting for Apply.
- * TODO: Restore Defaults button does not work.
- */
+ *
+ * @author Leif Frenzel
+ *
+ * TODO: None of these preferences have any effect yet, I think.
+ * TODO: Preferences take effect immediately, instead of waiting for Apply.
+ * TODO: Restore Defaults button does not work.
+ */
public class ContentAssistPP extends HaskellPreferencePage implements IEditorPreferenceNames {
- private final ColorListEntry[] colorListModel = new ColorListEntry[] {
- new ColorListEntry( "Completion proposal background",
- CA_PROPOSALS_BACKGROUND ),
- new ColorListEntry( "Completion proposal foreground",
- CA_PROPOSALS_FOREGROUND ) };
-
- private List colorList;
- private ColorSelector colorSelector;
- private Control txtAutoActDelay;
- private Control txtActTriggers;
-
- @Override
- public Control createContents( final Composite parent ) {
- Composite composite = new Composite( parent, SWT.NONE );
- GridLayout layout = new GridLayout();
- layout.numColumns = 2;
- composite.setLayout( layout );
-
- createFields( composite );
- createOptionsLabel( composite );
- Composite editorComposite = createEditorComposite( composite );
- createColorList( composite, editorComposite );
- Composite stylesComposite = createStylesComposite( editorComposite );
- createLabel( stylesComposite, "C&olor:" );
- createColorSelector( stylesComposite );
- initialize();
- return composite;
- }
-
-
- // UI creation methods
- //////////////////////
-
- private void createColorList( final Composite composite,
- final Composite editorComposite ) {
- int style = SWT.SINGLE | SWT.V_SCROLL | SWT.BORDER;
- colorList = new List( editorComposite, style );
- GridData gridData = new GridData( GridData.VERTICAL_ALIGN_BEGINNING
- | GridData.FILL_HORIZONTAL );
- gridData.heightHint = DialogUtil.convertHeightInCharsToPixels( composite,
- 8 );
- colorList.setLayoutData( gridData );
- colorList.addSelectionListener( new SelectionAdapter() {
- @Override
- public void widgetSelected( final SelectionEvent e ) {
- handleColorListSelection();
- }
- } );
- }
-
- private void createColorSelector( final Composite parent ) {
- colorSelector = new ColorSelector( parent );
- Button colorButton = colorSelector.getButton();
- GridData gridData = new GridData( GridData.FILL_HORIZONTAL );
- gridData.horizontalAlignment = GridData.BEGINNING;
- colorButton.setLayoutData( gridData );
- colorButton.addSelectionListener( new SelectionAdapter() {
- @Override
- public void widgetSelected( final SelectionEvent e ) {
- int i = colorList.getSelectionIndex();
- String key = colorListModel[ i ].getColorKey();
- RGB colorValue = colorSelector.getColorValue();
- PreferenceConverter.setValue( getPreferenceStore(), key, colorValue );
- }
- } );
- }
-
- private Composite createStylesComposite( final Composite parent ) {
- GridLayout layout;
- Composite stylesComposite = new Composite( parent, SWT.NONE );
- layout = new GridLayout();
- layout.marginHeight = 0;
- layout.marginWidth = 0;
- layout.numColumns = 2;
- stylesComposite.setLayout( layout );
- stylesComposite.setLayoutData( new GridData( GridData.FILL_BOTH ) );
- return stylesComposite;
- }
-
- private Composite createEditorComposite( final Composite parent ) {
- Composite editorComposite = new Composite( parent, SWT.NONE );
- GridLayout layout = new GridLayout();
- layout.numColumns = 2;
- layout.marginHeight = 0;
- layout.marginWidth = 0;
- editorComposite.setLayout( layout );
- GridData gridData = new GridData( GridData.HORIZONTAL_ALIGN_FILL
- | GridData.FILL_VERTICAL );
- gridData.horizontalSpan = 2;
- editorComposite.setLayoutData( gridData );
- return editorComposite;
- }
-
- private void createOptionsLabel( final Composite parent ) {
- Label label = new Label( parent, SWT.LEFT );
- label.setText( "Content assist colo&r options:" );
- GridData gridData = new GridData( GridData.HORIZONTAL_ALIGN_FILL );
- gridData.horizontalSpan = 2;
- label.setLayoutData( gridData );
- }
-
- private void createFields( final Composite parent ) {
- String aiKey = CA_AUTOINSERT;
- String aiText = "Insert single &proposals automatically";
- createBooleanField( parent, aiText, aiKey );
- String aoText = "Present proposals in &alphabetical order";
- createBooleanField( parent, aoText, CA_ORDER_PROPOSALS );
- String aaText = "&Enable auto activation";
- String aaKey = CA_AUTOACTIVATION;
- Button autoActButton = addBooleanField( parent, aaText, aaKey, 0 );
- autoActButton.addSelectionListener( new SelectionAdapter() {
- @Override
- public void widgetSelected( final SelectionEvent e ) {
- updateAutoactivationControls();
- }
- } );
-
- String adText = "Auto activation dela&y:";
- String adKey = CA_AUTOACTIVATION_DELAY;
- txtAutoActDelay = addTextField( parent, adText, adKey, 4, 0 );
-
- String atText = "Auto activation &triggers:";
- String atKey = CA_AUTOACTIVATION_TRIGGERS;
- txtActTriggers = addTextField( parent, atText, atKey, 4, 0 );
- }
-
-
- // helping methods
- //////////////////
-
- private void handleColorListSelection() {
- int i = colorList.getSelectionIndex();
- String key = colorListModel[ i ].getColorKey();
- RGB rgb = PreferenceConverter.getColor( getPreferenceStore(), key );
- colorSelector.setColorValue( rgb );
- }
-
- private void initialize() {
- for( int i = 0; i < colorListModel.length; i++ ) {
- colorList.add( colorListModel[ i ].getLabel() );
- }
- colorList.getDisplay().asyncExec( new Runnable() {
- public void run() {
- if( ( colorList != null ) && !colorList.isDisposed() ) {
- colorList.select( 0 );
- handleColorListSelection();
- }
- }
- } );
- initializeFields();
- }
-
- private void updateAutoactivationControls() {
- boolean enabled = getPreferenceStore().getBoolean(
- IEditorPreferenceNames.CA_AUTOACTIVATION );
- txtAutoActDelay.setEnabled( enabled );
- getLabel( txtAutoActDelay ).setEnabled( enabled );
- txtActTriggers.setEnabled( enabled );
- getLabel( txtActTriggers ).setEnabled( enabled );
- }
+ private final ColorListEntry[] colorListModel = new ColorListEntry[] {
+ new ColorListEntry( "Completion proposal background",
+ CA_PROPOSALS_BACKGROUND ),
+ new ColorListEntry( "Completion proposal foreground",
+ CA_PROPOSALS_FOREGROUND ) };
+
+ private List colorList;
+ private ColorSelector colorSelector;
+ private PreferenceControl txtAutoActDelay;
+ private PreferenceControl txtActTriggers;
+
+ @Override
+ protected Control createContents( final Composite parent ) {
+ Composite control = new Composite( parent, SWT.NONE );
+ ColumnLayout layout = new ColumnLayout();
+ layout.maxNumColumns = 1;
+ control.setLayout(layout);
+
+ createBehaviorGroup(control);
+ createAppearanceGroup(control);
+
+ initialize();
+ return control;
+ }
+
+ // UI creation methods
+ //////////////////////
+
+ private void createBehaviorGroup(final Composite parent) {
+ Group group = new Group(parent, SWT.SHADOW_ETCHED_IN);
+ group.setText("Behavior");
+ GridLayout layout = new GridLayout();
+ layout.numColumns = 1;
+ group.setLayout(layout);
+
+ createCheckboxControl(group, "Insert single &proposals automatically", CA_AUTOINSERT);
+ createCheckboxControl(group, "Present proposals in &alphabetical order", CA_ORDER_PROPOSALS);
+
+ CheckboxPreferenceControl autoActButton = createCheckboxControl(group, "&Enable auto activation", CA_AUTOACTIVATION);
+ Composite aa = new Composite(group, SWT.NONE);
+ GridLayout aal = new GridLayout();
+ aal.numColumns = 1;
+ aal.marginWidth = aal.marginHeight = 0;
+ aal.marginLeft = 28;
+ aa.setLayout(aal);
+ txtAutoActDelay = createStringControl(aa, "Auto activation dela&y:", CA_AUTOACTIVATION_DELAY, 4);
+ GridData gd = new GridData();
+ gd.horizontalAlignment = SWT.FILL;
+ txtAutoActDelay.getControl().setLayoutData(gd);
+ txtActTriggers = createStringControl(aa, "Auto activation &triggers:", CA_AUTOACTIVATION_TRIGGERS, 4);
+ gd = new GridData();
+ gd.horizontalAlignment = SWT.FILL;
+ txtActTriggers.getControl().setLayoutData(gd);
+ autoActButton.addValueChangedListener(new IValueChangedListener<Boolean>() {
+ public void valueChanged(final PreferenceControl control, final Boolean value) {
+ boolean enabled = value.booleanValue();
+ txtAutoActDelay.setEnabled(enabled);
+ txtActTriggers.setEnabled(enabled);
+ }
+ }, true);
+ }
+
+ private void createAppearanceGroup(final Composite parent) {
+ Group group = new Group(parent, SWT.SHADOW_ETCHED_IN);
+ group.setText("Appearance");
+ GridLayout layout = new GridLayout();
+ layout.numColumns = 1;
+ group.setLayout(layout);
+
+ Composite editorComposite = createEditorComposite(group);
+ createColorList(group, editorComposite );
+ Composite stylesComposite = createStylesComposite( editorComposite );
+ createLabel( stylesComposite, "C&olor:" );
+ createColorSelector( stylesComposite );
+ }
+
+ private void createColorList( final Composite composite,
+ final Composite editorComposite ) {
+ int style = SWT.SINGLE | SWT.V_SCROLL | SWT.BORDER;
+ colorList = new List( editorComposite, style );
+ GridData gridData = new GridData( GridData.VERTICAL_ALIGN_BEGINNING
+ | GridData.FILL_HORIZONTAL );
+ gridData.heightHint = DialogUtil.convertHeightInCharsToPixels( composite,
+ 8 );
+ colorList.setLayoutData( gridData );
+ colorList.addSelectionListener( new SelectionAdapter() {
+ @Override
+ public void widgetSelected( final SelectionEvent e ) {
+ handleColorListSelection();
+ }
+ } );
+ }
+
+ private void createColorSelector( final Composite parent ) {
+ colorSelector = new ColorSelector( parent );
+ Button colorButton = colorSelector.getButton();
+ GridData gridData = new GridData( GridData.FILL_HORIZONTAL );
+ gridData.horizontalAlignment = GridData.BEGINNING;
+ colorButton.setLayoutData( gridData );
+ colorButton.addSelectionListener( new SelectionAdapter() {
+ @Override
+ public void widgetSelected( final SelectionEvent e ) {
+ int i = colorList.getSelectionIndex();
+ String key = colorListModel[ i ].getColorKey();
+ RGB colorValue = colorSelector.getColorValue();
+ PreferenceConverter.setValue( getPreferenceStore(), key, colorValue );
+ }
+ } );
+ }
+
+ private Composite createStylesComposite( final Composite parent ) {
+ GridLayout layout;
+ Composite stylesComposite = new Composite( parent, SWT.NONE );
+ layout = new GridLayout();
+ layout.marginHeight = 0;
+ layout.marginWidth = 0;
+ layout.numColumns = 2;
+ stylesComposite.setLayout( layout );
+ stylesComposite.setLayoutData( new GridData( GridData.FILL_BOTH ) );
+ return stylesComposite;
+ }
+
+ private Composite createEditorComposite( final Composite parent ) {
+ Composite editorComposite = new Composite( parent, SWT.NONE );
+ GridLayout layout = new GridLayout();
+ layout.numColumns = 2;
+ layout.horizontalSpacing = 10;
+ editorComposite.setLayout( layout );
+ GridData gridData = new GridData( GridData.HORIZONTAL_ALIGN_FILL
+ | GridData.FILL_VERTICAL );
+ gridData.horizontalSpan = 2;
+ editorComposite.setLayoutData( gridData );
+ return editorComposite;
+ }
+
+
+ // helping methods
+ //////////////////
+
+ private void handleColorListSelection() {
+ int i = colorList.getSelectionIndex();
+ String key = colorListModel[ i ].getColorKey();
+ RGB rgb = PreferenceConverter.getColor( getPreferenceStore(), key );
+ colorSelector.setColorValue( rgb );
+ }
+
+ private void initialize() {
+ for( int i = 0; i < colorListModel.length; i++ ) {
+ colorList.add( colorListModel[ i ].getLabel() );
+ }
+ colorList.getDisplay().asyncExec( new Runnable() {
+ public void run() {
+ if( ( colorList != null ) && !colorList.isDisposed() ) {
+ colorList.select( 0 );
+ handleColorListSelection();
+ }
+ }
+ } );
+ loadControlValues();
+ }
+
}
View
335 ...skell.ui/src/net/sf/eclipsefp/haskell/ui/internal/preferences/editor/HaskellEditorPP.java
@@ -1,6 +1,10 @@
// Copyright (c) 2003-2005 by Leif Frenzel - see http://leiffrenzel.de
package net.sf.eclipsefp.haskell.ui.internal.preferences.editor;
+import net.sf.eclipsefp.common.ui.preferences.CheckboxPreferenceControl;
+import net.sf.eclipsefp.common.ui.preferences.IValueChangedListener;
+import net.sf.eclipsefp.common.ui.preferences.IntegerPreferenceControl;
+import net.sf.eclipsefp.common.ui.preferences.PreferenceControl;
import net.sf.eclipsefp.common.ui.util.DialogUtil;
import net.sf.eclipsefp.haskell.ui.internal.preferences.HaskellPreferencePage;
@@ -16,9 +20,10 @@
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
-import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.List;
import org.eclipse.ui.editors.text.TextEditorPreferenceConstants;
+import org.eclipse.ui.forms.widgets.ColumnLayout;
/** <p>the preference page for common editor preference settings.</p>
*
@@ -31,162 +36,174 @@
*/
public class HaskellEditorPP extends HaskellPreferencePage implements IEditorPreferenceNames {
- private final ColorListEntry[] colorListModel = new ColorListEntry[] {
- new ColorListEntry( "Line number foreground",
- EDITOR_LINE_NUMBER_RULER_COLOR ),
- new ColorListEntry( "Matching brackets highlight",
- EDITOR_MATCHING_BRACKETS_COLOR ),
- new ColorListEntry( "Current line highlight", EDITOR_CURRENT_LINE_COLOR ),
- new ColorListEntry( "Print margin", EDITOR_PRINT_MARGIN_COLOR ) };
-
- private List colorList;
- private ColorSelector colorSelector;
-
- @Override
- public Control createContents( final Composite parent ) {
- Composite control = new Composite( parent, SWT.NONE );
- GridLayout layout = new GridLayout();
- layout.numColumns = 2;
- control.setLayout( layout );
-
- addFields( control );
- createSpacer( control );
- createAppearanceColorLabel( control );
- Composite editorComposite = createEditorComposite( control );
- createColorList( control, editorComposite );
- Composite stylesComposite = createStylesComposite( editorComposite );
- createLabel( stylesComposite, "C&olor:" );
- createColorSelector( stylesComposite );
- String prefName = IEditorPreferenceNames.EDITOR_SPACES_FOR_TABS;
- createBooleanField( control, "Ins&ert space for tabs", prefName );
-
- initialize();
-
- return control;
- }
-
- public static void initializeDefaultValues(final IPreferenceStore store) {
- TextEditorPreferenceConstants.initializeDefaultValues( store );
- DefaultEditorPreferenceInitializer.initializeDefaultValues( store );
- }
-
-
- // UI creation methods
- //////////////////////
-
- private void createColorSelector( final Composite parent ) {
- colorSelector = new ColorSelector( parent );
- Button foregroundColorButton = colorSelector.getButton();
- GridData gridData = new GridData( GridData.FILL_HORIZONTAL );
- gridData.horizontalAlignment = GridData.BEGINNING;
- foregroundColorButton.setLayoutData( gridData );
- foregroundColorButton.addSelectionListener( new SelectionAdapter() {
- @Override
- public void widgetSelected( final SelectionEvent e ) {
- int i = colorList.getSelectionIndex();
- String key = colorListModel[ i ].getColorKey();
- RGB colorValue = colorSelector.getColorValue();
- PreferenceConverter.setValue( getPreferenceStore(), key, colorValue );
- }
- } );
- }
-
- private Composite createStylesComposite( final Composite parent ) {
- Composite stylesComposite = new Composite( parent, SWT.NONE );
- GridLayout layout = new GridLayout();
- layout.marginHeight = 0;
- layout.marginWidth = 0;
- layout.numColumns = 2;
- stylesComposite.setLayout( layout );
- stylesComposite.setLayoutData( new GridData( GridData.FILL_BOTH ) );
- return stylesComposite;
- }
-
- private void createColorList( final Composite parent,
- final Composite editorComposite ) {
- int style = SWT.SINGLE | SWT.V_SCROLL | SWT.BORDER;
- colorList = new List( editorComposite, style );
- GridData gridData = new GridData( GridData.VERTICAL_ALIGN_BEGINNING
- | GridData.FILL_HORIZONTAL );
- gridData.heightHint = DialogUtil.convertHeightInCharsToPixels( parent, 8 );
- colorList.setLayoutData( gridData );
- colorList.addSelectionListener( new SelectionAdapter() {
- @Override
- public void widgetSelected( final SelectionEvent e ) {
- handleColorListSelection();
- }
- } );
- }
-
- private Composite createEditorComposite( final Composite parent ) {
- Composite editorComposite = new Composite( parent, SWT.NONE );
- GridLayout layout = new GridLayout();
- layout.numColumns = 2;
- layout.marginHeight = 0;
- layout.marginWidth = 0;
- editorComposite.setLayout( layout );
- GridData gridData = new GridData( GridData.HORIZONTAL_ALIGN_FILL
- | GridData.FILL_VERTICAL );
- gridData.horizontalSpan = 2;
- editorComposite.setLayoutData( gridData );
- return editorComposite;
- }
-
- private void createAppearanceColorLabel( final Composite parent ) {
- Label label = new Label( parent, SWT.LEFT );
- label.setText( "Appearance co&lor options:" );
- GridData gridData = new GridData( GridData.HORIZONTAL_ALIGN_FILL );
- gridData.horizontalSpan = 2;
- label.setLayoutData( gridData );
- }
-
- private void createSpacer( final Composite parent ) {
- Label label = new Label( parent, SWT.LEFT );
- GridData gridData = new GridData( GridData.HORIZONTAL_ALIGN_FILL );
- gridData.horizontalSpan = 2;
- int height = DialogUtil.convertHeightInCharsToPixels( parent, 1 );
- gridData.heightHint = height / 2;
- label.setLayoutData( gridData );
- }
-
- private void addFields( final Composite parent ) {
- String pmKey = EDITOR_PRINT_MARGIN_COLUMN;
- addTextField( parent, "Print margin col&umn:", pmKey, 3, 0 );
- String orKey = EDITOR_OVERVIEW_RULER;
- createBooleanField( parent, "Show overview &ruler", orKey );
- String lnrKey = EDITOR_LINE_NUMBER_RULER;
- createBooleanField( parent, "Show lin&e numbers", lnrKey );
- String mbKey = EDITOR_MATCHING_BRACKETS;
- createBooleanField( parent, "Highlight &matching brackets", mbKey );
- String clKey = EDITOR_CURRENT_LINE;
- createBooleanField( parent, "Hi&ghlight current line", clKey );
- createBooleanField( parent, "Sho&w print margin", EDITOR_PRINT_MARGIN );
- }
-
-
- // helping methods
- //////////////////
-
- private void handleColorListSelection() {
- int i = colorList.getSelectionIndex();
- String key = colorListModel[ i ].getColorKey();
- RGB rgb = PreferenceConverter.getColor( getPreferenceStore(), key );
- colorSelector.setColorValue( rgb );
- }
-
- private void initialize() {
- for( int i = 0; i < colorListModel.length; i++ ) {
- colorList.add( colorListModel[ i ].getLabel() );
- }
- colorList.getDisplay().asyncExec( new Runnable() {
-
- public void run() {
- if( ( colorList != null ) && !colorList.isDisposed() ) {
- colorList.select( 0 );
- handleColorListSelection();
- }
- }
- } );
- initializeFields();
- }
+ private final ColorListEntry[] colorListModel = new ColorListEntry[] {
+ new ColorListEntry( "Line number foreground",
+ EDITOR_LINE_NUMBER_RULER_COLOR ),
+ new ColorListEntry( "Matching brackets highlight",
+ EDITOR_MATCHING_BRACKETS_COLOR ),
+ new ColorListEntry( "Current line highlight", EDITOR_CURRENT_LINE_COLOR ),
+ new ColorListEntry( "Print margin", EDITOR_PRINT_MARGIN_COLOR ) };
+
+ private IntegerPreferenceControl printMarginColumn;
+ private List colorList;
+ private ColorSelector colorSelector;
+
+ @Override
+ protected Control createContents( final Composite parent ) {
+ Composite control = new Composite( parent, SWT.NONE );
+ ColumnLayout layout = new ColumnLayout();
+ layout.maxNumColumns = 1;
+ control.setLayout(layout);
+
+ createEditingGroup(control);
+ createAppearanceGroup(control);
+ createColorsGroup(control);
+
+ initialize();
+ return control;
+ }
+
+ public static void initializeDefaultValues(final IPreferenceStore store) {
+ TextEditorPreferenceConstants.initializeDefaultValues( store );
+ DefaultEditorPreferenceInitializer.initializeDefaultValues( store );
+ }
+
+
+ // UI creation methods
+ //////////////////////
+
+ private Group createEditingGroup(final Composite parent) {
+ Group group = new Group(parent, SWT.SHADOW_ETCHED_IN);
+ group.setText("Editing");
+ GridLayout layout = new GridLayout();
+ layout.numColumns = 1;
+ group.setLayout(layout);
+
+ createCheckboxControl(group, "Ins&ert space for tabs", IEditorPreferenceNames.EDITOR_SPACES_FOR_TABS);
+
+ return group;
+ }
+
+ private Group createAppearanceGroup(final Composite parent) {
+ Group group = new Group(parent, SWT.SHADOW_ETCHED_IN);
+ group.setText("Appearance");
+ GridLayout groupLayout = new GridLayout();
+ groupLayout.numColumns = 2;
+ group.setLayout(groupLayout);
+
+ CheckboxPreferenceControl spm = createCheckboxControl(group, "Sho&w print margin", EDITOR_PRINT_MARGIN);
+ printMarginColumn = createIntegerControl(group, "Print margin col&umn:", EDITOR_PRINT_MARGIN_COLUMN, 3);
+ spm.addValueChangedListener(new IValueChangedListener<Boolean>() {
+ public void valueChanged(final PreferenceControl<Boolean> control, final Boolean value) {
+ boolean enabled = value.booleanValue();
+ printMarginColumn.setEnabled(enabled);
+ }
+ }, true );
+
+ createCheckboxControl(group, "Show lin&e numbers", EDITOR_LINE_NUMBER_RULER);
+ createCheckboxControl(group, "Show overview &ruler", EDITOR_OVERVIEW_RULER);
+ createCheckboxControl(group, "Highlight &matching brackets", EDITOR_MATCHING_BRACKETS);
+ createCheckboxControl(group, "Hi&ghlight current line", EDITOR_CURRENT_LINE);
+
+ return group;
+ }
+
+ private Group createColorsGroup(final Composite parent) {
+ Group group = new Group(parent, SWT.SHADOW_ETCHED_IN);
+ group.setText("Colors");
+ GridLayout groupLayout = new GridLayout();
+ groupLayout.numColumns = 1;
+ group.setLayout(groupLayout);
+
+ Composite editorComposite = createEditorComposite( group );
+ createColorList( group, editorComposite );
+ Composite stylesComposite = createStylesComposite( editorComposite );
+ createLabel( stylesComposite, "C&olor:" );
+ createColorSelector( stylesComposite );
+
+ return group;
+ }
+
+ private void createColorSelector( final Composite parent ) {
+ colorSelector = new ColorSelector( parent );
+ Button foregroundColorButton = colorSelector.getButton();
+ GridData gridData = new GridData( GridData.FILL_HORIZONTAL );
+ gridData.horizontalAlignment = GridData.BEGINNING;
+ foregroundColorButton.setLayoutData( gridData );
+ foregroundColorButton.addSelectionListener( new SelectionAdapter() {
+ @Override
+ public void widgetSelected( final SelectionEvent e ) {
+ int i = colorList.getSelectionIndex();
+ String key = colorListModel[ i ].getColorKey();
+ RGB colorValue = colorSelector.getColorValue();
+ PreferenceConverter.setValue( getPreferenceStore(), key, colorValue );
+ }
+ } );
+ }
+
+ private Composite createStylesComposite( final Composite parent ) {
+ Composite stylesComposite = new Composite( parent, SWT.NONE );
+ GridLayout layout = new GridLayout();
+ layout.marginHeight = 0;
+ layout.marginWidth = 0;
+ layout.numColumns = 2;
+ stylesComposite.setLayout( layout );
+ stylesComposite.setLayoutData( new GridData( GridData.FILL_BOTH ) );
+ return stylesComposite;
+ }
+
+ private void createColorList( final Composite parent,
+ final Composite editorComposite ) {
+ int style = SWT.SINGLE | SWT.V_SCROLL | SWT.BORDER;
+ colorList = new List( editorComposite, style );
+ GridData gridData = new GridData( GridData.VERTICAL_ALIGN_BEGINNING
+ | GridData.FILL_HORIZONTAL );
+ gridData.heightHint = DialogUtil.convertHeightInCharsToPixels( parent, 8 );
+ colorList.setLayoutData( gridData );
+ colorList.addSelectionListener( new SelectionAdapter() {
+ @Override
+ public void widgetSelected( final SelectionEvent e ) {
+ handleColorListSelection();
+ }
+ } );
+ }
+
+ private Composite createEditorComposite( final Composite parent ) {
+ Composite editorComposite = new Composite( parent, SWT.NONE );
+ GridLayout layout = new GridLayout();
+ layout.numColumns = 2;
+ layout.horizontalSpacing = 10;
+ editorComposite.setLayout( layout );
+ GridData gridData = new GridData( GridData.HORIZONTAL_ALIGN_FILL
+ | GridData.FILL_VERTICAL );
+ gridData.horizontalSpan = 2;
+ editorComposite.setLayoutData( gridData );
+ return editorComposite;
+ }
+
+ // helping methods
+ //////////////////
+
+ private void handleColorListSelection() {
+ int i = colorList.getSelectionIndex();
+ String key = colorListModel[ i ].getColorKey();
+ RGB rgb = PreferenceConverter.getColor( getPreferenceStore(), key );
+ colorSelector.setColorValue( rgb );
+ }
+
+ private void initialize() {
+ for( int i = 0; i < colorListModel.length; i++ ) {
+ colorList.add( colorListModel[ i ].getLabel() );
+ }
+ colorList.getDisplay().asyncExec( new Runnable() {
+
+ public void run() {
+ if( ( colorList != null ) && !colorList.isDisposed() ) {
+ colorList.select( 0 );
+ handleColorListSelection();
+ }
+ }
+ } );
+ loadControlValues();
+ }
}
View
451 ...kell.ui/src/net/sf/eclipsefp/haskell/ui/internal/preferences/editor/SyntaxColoringPP.java
@@ -14,228 +14,249 @@
import org.eclipse.swt.graphics.RGB;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
-import org.eclipse.swt.layout.RowLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Group;
-import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.List;
+import org.eclipse.ui.forms.widgets.ColumnLayout;
/** <p>tab for syntax coloring preference settings.</p>
- *
- * @author Leif Frenzel
- *
- * TODO: The colours on this page take effect immediately, instead of waiting for Apply.
- * TODO: The Restore Defaults button does not work.
- */
+ *
+ * @author Leif Frenzel
+ *
+ * TODO: The colours on this page take effect immediately, instead of waiting for Apply.
+ * TODO: The Restore Defaults button does not work.
+ */
public class SyntaxColoringPP extends HaskellPreferencePage implements IEditorPreferenceNames {
- private Button rbBackgroundDefault;
- private Button rbBackgroundCustom;
- private ColorSelector backgroundColorSelector;
- private ColorSelector colorSelector;
- private Button cbBold;
- private List colorList;
-
- private final ColorListEntry[] colorListModel = new ColorListEntry[] {
- new ColorListEntry( "Comments", EDITOR_COMMENT_COLOR, EDITOR_COMMENT_BOLD ),
- new ColorListEntry( "Literate Comments",
- EDITOR_LITERATE_COMMENT_COLOR,
- EDITOR_LITERATE_COMMENT_BOLD ),
- new ColorListEntry( "Strings", EDITOR_STRING_COLOR, EDITOR_STRING_BOLD ),
- new ColorListEntry( "Characters", EDITOR_CHAR_COLOR, EDITOR_CHAR_BOLD ),
- new ColorListEntry( "Functions",
- EDITOR_FUNCTION_COLOR,
- EDITOR_FUNCTION_BOLD ),
- new ColorListEntry( "Keywords", EDITOR_KEYWORD_COLOR, EDITOR_KEYWORD_BOLD ),
- new ColorListEntry( "Others", EDITOR_DEFAULT_COLOR, EDITOR_DEFAULT_BOLD ) };
-
- @Override
- public Control createContents( final Composite parent ) {
- Composite composite = new Composite( parent, SWT.NONE );
- composite.setLayout( new GridLayout() );
-
- Group backgroundComposite = initializeBackgroundGroup( composite );
- initializeBackgroundColorSelector( backgroundComposite );
- initializeForeGroundLabel( composite );
- Composite editorComposite = initializeEditorComposite( composite );
- initializeColorList( composite, editorComposite );
- Composite stylesComposite = initializeStylesComposite( editorComposite );
- createLabel( stylesComposite, "C&olor:" );
- initializeColorSelector( stylesComposite );
- initializeBoldCheckBox( stylesComposite );
-
- createPreviewer( composite );
- initialize();
-
- return composite;
- }
-
- @Override
- public void initializeFields() {
- super.initializeFields();
- IPreferenceStore ps = getPreferenceStore();
- RGB rgb = PreferenceConverter.getColor( ps, EDITOR_BACKGROUND_COLOR );
- backgroundColorSelector.setColorValue( rgb );
- boolean defaultBackgroud = ps.getBoolean( EDITOR_BACKGROUND_DEFAULT_COLOR );
- rbBackgroundDefault.setSelection( defaultBackgroud );
- rbBackgroundCustom.setSelection( !defaultBackgroud );
- backgroundColorSelector.setEnabled( !defaultBackgroud );
- }
-
-
- // ui initialization methods
- ////////////////////////////
- private void initializeColorList( final Composite composite,
- final Composite editorComposite ) {
- colorList = new List( editorComposite,
- SWT.SINGLE | SWT.V_SCROLL | SWT.BORDER );
- GridData gridData = new GridData( GridData.FILL_BOTH );
- gridData.heightHint = DialogUtil.convertHeightInCharsToPixels( composite,
- 5 );
- colorList.setLayoutData( gridData );
- colorList.addSelectionListener( new SelectionAdapter() {
- @Override
- public void widgetSelected( final SelectionEvent e ) {
- handleSyntaxColorListSelection();
- }
- } );
- }
-
- private Composite initializeStylesComposite( final Composite parent ) {
- Composite stylesComposite = new Composite( parent, SWT.NONE );
- GridLayout layout = new GridLayout();
- layout.marginHeight = 0;
- layout.marginWidth = 0;
- layout.numColumns = 2;
- stylesComposite.setLayout( layout );
- stylesComposite.setLayoutData( new GridData( GridData.FILL_BOTH ) );
- return stylesComposite;
- }
-
- private void initializeBoldCheckBox( final Composite parent ) {
- cbBold = new Button( parent, SWT.CHECK );
- cbBold.setText( "&Bold" );
- GridData gridData = new GridData( GridData.FILL_HORIZONTAL );
- gridData.horizontalAlignment = GridData.BEGINNING;
- gridData.horizontalSpan = 2;
- cbBold.setLayoutData( gridData );
- cbBold.addSelectionListener( new SelectionAdapter() {
- @Override
- public void widgetSelected( final SelectionEvent e ) {
- int i = colorList.getSelectionIndex();
- String key = colorListModel[ i ].getBoldKey();
- getPreferenceStore().setValue( key, cbBold.getSelection() );
- }
- } );
- }
-
- private Composite initializeEditorComposite( final Composite parent ) {
- Composite editorComposite = new Composite( parent, SWT.NONE );
- GridLayout layout = new GridLayout();
- layout.numColumns = 2;
- layout.marginHeight = 0;
- layout.marginWidth = 0;
- editorComposite.setLayout( layout );
- GridData gridData = new GridData( GridData.FILL_BOTH );
- editorComposite.setLayoutData( gridData );
- return editorComposite;
- }
-
- private void initializeForeGroundLabel( final Composite parent ) {
- Label label = new Label( parent, SWT.LEFT );
- label.setText( "Foreground:" );
- label.setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) );
- }
-
- private Group initializeBackgroundGroup( final Composite parent ) {
- Group backgroundComposite = new Group( parent, SWT.SHADOW_ETCHED_IN );
- backgroundComposite.setLayout( new RowLayout() );
- backgroundComposite.setText( "Background color" );
- SelectionListener bgSelectionListener = new SelectionAdapter() {
- @Override
- public void widgetSelected( final SelectionEvent e ) {
- boolean custom = rbBackgroundCustom.getSelection();
- backgroundColorSelector.setEnabled( custom );
- getPreferenceStore().setValue(
- IEditorPreferenceNames.EDITOR_BACKGROUND_DEFAULT_COLOR, !custom );
- }
- };
- int style = SWT.RADIO | SWT.LEFT;
- rbBackgroundDefault = new Button( backgroundComposite, style );
- rbBackgroundDefault.setText( "System default" );
- rbBackgroundDefault.addSelectionListener( bgSelectionListener );
- rbBackgroundCustom = new Button( backgroundComposite, style );
- rbBackgroundCustom.setText( "Custom:" );
- rbBackgroundCustom.addSelectionListener( bgSelectionListener );
- return backgroundComposite;
- }
-
- private void initializeBackgroundColorSelector( final Group parent ) {
- backgroundColorSelector = new ColorSelector( parent );
- Button backgroundColorButton = backgroundColorSelector.getButton();
- backgroundColorButton.addSelectionListener( new SelectionAdapter() {
- @Override
- public void widgetSelected( final SelectionEvent e ) {
- String name = IEditorPreferenceNames.EDITOR_BACKGROUND_COLOR;
- RGB colorValue = backgroundColorSelector.getColorValue();
- PreferenceConverter.setValue( getPreferenceStore(), name, colorValue );
- }
- } );
- }
-
- private void initializeColorSelector( final Composite parent ) {
- colorSelector = new ColorSelector( parent );
- Button foregroundColorButton = colorSelector.getButton();
- GridData gridData = new GridData( GridData.FILL_HORIZONTAL );
- gridData.horizontalAlignment = GridData.BEGINNING;
- foregroundColorButton.setLayoutData( gridData );
- foregroundColorButton.addSelectionListener( new SelectionAdapter() {
- @Override
- public void widgetSelected( final SelectionEvent e ) {
- int i = colorList.getSelectionIndex();
- String key = colorListModel[ i ].getColorKey();
- RGB colorValue = colorSelector.getColorValue();
- PreferenceConverter.setValue( getPreferenceStore(), key, colorValue );
- }
- } );
- }
-
- private void createPreviewer( final Composite parent ) {
- IPreferenceStore preferenceStore = getPreferenceStore();
- SyntaxPreviewer previewer = new SyntaxPreviewer( parent, preferenceStore );
- GridData gridData = new GridData( GridData.FILL_BOTH );
- gridData.widthHint = DialogUtil.convertWidthInCharsToPixels( parent, 20 );
- gridData.heightHint = DialogUtil.convertHeightInCharsToPixels( parent, 5 );
- previewer.getControl().setLayoutData( gridData );
- }
-
-
- // helping methods
- //////////////////
-
- private void handleSyntaxColorListSelection() {
- int index = colorList.getSelectionIndex();
- String key = colorListModel[ index ].getColorKey();
- RGB rgb = PreferenceConverter.getColor( getPreferenceStore(), key );
- colorSelector.setColorValue( rgb );
- key = colorListModel[ index ].getBoldKey();
- cbBold.setSelection( getPreferenceStore().getBoolean( key ) );
- }
-
- private void initialize() {
- for( int i = 0; i < colorListModel.length; i++ ) {
- colorList.add( colorListModel[ i ].getLabel() );
- }
- colorList.getDisplay().asyncExec( new Runnable() {
- public void run() {
- if( ( colorList != null ) && !colorList.isDisposed() ) {
- colorList.select( 0 );
- handleSyntaxColorListSelection();
- }
- }
- } );
- initializeFields();
- }
+ private Button rbBackgroundDefault;
+ private Button rbBackgroundCustom;
+ private ColorSelector backgroundColorSelector;
+ private ColorSelector colorSelector;
+ private Button cbBold;
+ private List colorList;
+
+ private final ColorListEntry[] colorListModel = new ColorListEntry[] {
+ new ColorListEntry( "Comments", EDITOR_COMMENT_COLOR, EDITOR_COMMENT_BOLD ),
+ new ColorListEntry( "Literate Comments",
+ EDITOR_LITERATE_COMMENT_COLOR,
+ EDITOR_LITERATE_COMMENT_BOLD ),
+ new ColorListEntry( "Strings", EDITOR_STRING_COLOR, EDITOR_STRING_BOLD ),
+ new ColorListEntry( "Characters", EDITOR_CHAR_COLOR, EDITOR_CHAR_BOLD ),
+ new ColorListEntry( "Functions",
+ EDITOR_FUNCTION_COLOR,
+ EDITOR_FUNCTION_BOLD ),
+ new ColorListEntry( "Keywords", EDITOR_KEYWORD_COLOR, EDITOR_KEYWORD_BOLD ),
+ new ColorListEntry( "Others", EDITOR_DEFAULT_COLOR, EDITOR_DEFAULT_BOLD ) };
+
+ @Override
+ protected Control createContents( final Composite parent ) {
+ Composite composite = new Composite( parent, SWT.NONE );
+ ColumnLayout layout = new ColumnLayout();
+ layout.maxNumColumns = 1;
+ composite.setLayout(layout);
+
+ createBackgroundGroup(composite);
+ createForegroundGroup(composite);
+
+ initialize();
+
+ return composite;
+ }
+
+ @Override
+ public void loadControlValues() {
+ super.loadControlValues();
+ IPreferenceStore ps = getPreferenceStore();
+ RGB rgb = PreferenceConverter.getColor( ps, EDITOR_BACKGROUND_COLOR );
+ backgroundColorSelector.setColorValue( rgb );
+ boolean defaultBackgroud = ps.getBoolean( EDITOR_BACKGROUND_DEFAULT_COLOR );
+ rbBackgroundDefault.setSelection( defaultBackgroud );
+ rbBackgroundCustom.setSelection( !defaultBackgroud );
+ backgroundColorSelector.setEnabled( !defaultBackgroud );
+ }
+
+
+ // ui initialization methods
+ ////////////////////////////
+
+ private void createBackgroundGroup(final Composite parent) {
+ Group group = new Group(parent, SWT.SHADOW_ETCHED_IN);
+ group.setText("Background");
+ GridLayout layout = new GridLayout();
+ layout.numColumns = 2;
+ layout.marginHeight = 0;
+ layout.marginWidth = 10;
+ group.setLayout(layout);
+
+ initializeBackgroundGroup(group);
+ }
+
+ private void createForegroundGroup(final Composite parent) {
+ Group group = new Group(parent, SWT.SHADOW_ETCHED_IN);
+ group.setText("Foreground");
+ GridLayout layout = new GridLayout();
+ layout.numColumns = 1;
+ layout.marginWidth = layout.marginHeight = 10;
+ layout.verticalSpacing = 10;
+ group.setLayout(layout);
+
+ Composite editorComposite = initializeEditorComposite(group);
+ initializeColorList(group, editorComposite);
+ Composite stylesComposite = initializeStylesComposite(editorComposite);
+ createLabel(stylesComposite, "C&olor:");
+ initializeColorSelector(stylesComposite);
+ initializeBoldCheckBox(stylesComposite);
+
+ createPreviewer(group);
+ }
+
+ private void initializeColorList( final Composite composite,
+ final Composite editorComposite ) {
+ colorList = new List( editorComposite,
+ SWT.SINGLE | SWT.V_SCROLL | SWT.BORDER );
+ GridData gridData = new GridData( GridData.FILL_BOTH );
+ gridData.heightHint = DialogUtil.convertHeightInCharsToPixels( composite,
+ 5 );
+ colorList.setLayoutData( gridData );
+ colorList.addSelectionListener( new SelectionAdapter() {
+ @Override
+ public void widgetSelected( final SelectionEvent e ) {
+ handleSyntaxColorListSelection();
+ }
+ } );
+ }
+
+ private Composite initializeStylesComposite( final Composite parent ) {
+ Composite stylesComposite = new Composite( parent, SWT.NONE );
+ GridLayout layout = new GridLayout();
+ layout.marginHeight = 0;
+ layout.marginWidth = 0;
+ layout.numColumns = 2;
+ stylesComposite.setLayout( layout );
+ stylesComposite.setLayoutData( new GridData( GridData.FILL_BOTH ) );
+ return stylesComposite;
+ }
+
+ private void initializeBoldCheckBox( final Composite parent ) {
+ cbBold = new Button( parent, SWT.CHECK );
+ cbBold.setText( "&Bold" );
+ GridData gridData = new GridData( GridData.FILL_HORIZONTAL );
+ gridData.horizontalAlignment = GridData.BEGINNING;
+ gridData.horizontalSpan = 2;
+ cbBold.setLayoutData( gridData );
+ cbBold.addSelectionListener( new SelectionAdapter() {
+ @Override
+ public void widgetSelected( final SelectionEvent e ) {
+ int i = colorList.getSelectionIndex();
+ String key = colorListModel[ i ].getBoldKey();
+ getPreferenceStore().setValue( key, cbBold.getSelection() );
+ }
+ } );
+ }
+
+ private Composite initializeEditorComposite( final Composite parent ) {
+ Composite editorComposite = new Composite( parent, SWT.NONE );
+ GridLayout layout = new GridLayout();
+ layout.numColumns = 2;
+ layout.marginHeight = layout.marginWidth = 0;
+ layout.horizontalSpacing = 10;
+ editorComposite.setLayout( layout );
+ GridData gridData = new GridData( GridData.FILL_BOTH );
+ editorComposite.setLayoutData( gridData );
+ return editorComposite;
+ }
+
+ private void initializeBackgroundGroup(final Composite group) {
+ SelectionListener bgSelectionListener = new SelectionAdapter() {
+ @Override
+ public void widgetSelected( final SelectionEvent e ) {
+ boolean custom = rbBackgroundCustom.getSelection();
+ backgroundColorSelector.setEnabled( custom );
+ getPreferenceStore().setValue(
+ IEditorPreferenceNames.EDITOR_BACKGROUND_DEFAULT_COLOR, !custom );
+ }
+ };
+ int style = SWT.RADIO | SWT.LEFT;
+ rbBackgroundDefault = new Button( group, style );
+ rbBackgroundDefault.setText( "System default" );
+ rbBackgroundDefault.addSelectionListener( bgSelectionListener );
+
+ Composite bcc = new Composite(group, SWT.NONE);
+ GridLayout bccl = new GridLayout();
+ bccl.numColumns = 2;
+ bcc.setLayout(bccl);
+ rbBackgroundCustom = new Button(bcc, style);
+ rbBackgroundCustom.setText("Custom:");
+ rbBackgroundCustom.addSelectionListener(bgSelectionListener);
+ initializeBackgroundColorSelector(bcc);
+ }
+
+ private void initializeBackgroundColorSelector( final Composite parent ) {
+ backgroundColorSelector = new ColorSelector( parent );
+ Button backgroundColorButton = backgroundColorSelector.getButton();
+ backgroundColorButton.addSelectionListener( new SelectionAdapter() {
+ @Override
+ public void widgetSelected( final SelectionEvent e ) {
+ String name = IEditorPreferenceNames.EDITOR_BACKGROUND_COLOR;
+ RGB colorValue = backgroundColorSelector.getColorValue();
+ PreferenceConverter.setValue( getPreferenceStore(), name, colorValue );
+ }
+ } );
+ }
+
+ private void initializeColorSelector( final Composite parent ) {
+ colorSelector = new ColorSelector( parent );
+ Button foregroundColorButton = colorSelector.getButton();
+ GridData gridData = new GridData( GridData.FILL_HORIZONTAL );
+ gridData.horizontalAlignment = GridData.BEGINNING;
+ foregroundColorButton.setLayoutData( gridData );
+ foregroundColorButton.addSelectionListener( new SelectionAdapter() {
+ @Override
+ public void widgetSelected( final SelectionEvent e ) {
+ int i = colorList.getSelectionIndex();
+ String key = colorListModel[ i ].getColorKey();
+ RGB colorValue = colorSelector.getColorValue();
+ PreferenceConverter.setValue( getPreferenceStore(), key, colorValue );
+ }
+ } );
+ }
+
+ private void createPreviewer( final Composite parent ) {
+ IPreferenceStore preferenceStore = getPreferenceStore();
+ SyntaxPreviewer previewer = new SyntaxPreviewer( parent, preferenceStore );
+ GridData gridData = new GridData( GridData.FILL_BOTH );
+ gridData.widthHint = DialogUtil.convertWidthInCharsToPixels( parent, 20 );
+ gridData.heightHint = DialogUtil.convertHeightInCharsToPixels( parent, 5 );
+ previewer.getControl().setLayoutData( gridData );
+ }
+
+
+ // helping methods
+ //////////////////
+
+ private void handleSyntaxColorListSelection() {
+ int index = colorList.getSelectionIndex();
+ String key = colorListModel[ index ].getColorKey();
+ RGB rgb = PreferenceConverter.getColor( getPreferenceStore(), key );
+ colorSelector.setColorValue( rgb );
+ key = colorListModel[ index ].getBoldKey();
+ cbBold.setSelection( getPreferenceStore().getBoolean( key ) );
+ }
+
+ private void initialize() {
+ for( int i = 0; i < colorListModel.length; i++ ) {
+ colorList.add( colorListModel[ i ].getLabel() );
+ }
+ colorList.getDisplay().asyncExec( new Runnable() {
+ public void run() {
+ if( ( colorList != null ) && !colorList.isDisposed() ) {
+ colorList.select( 0 );
+ handleSyntaxColorListSelection();
+ }
+ }
+ } );
+ loadControlValues();
+ }
}

0 comments on commit 8d0358f