001: /* uDig - User Friendly Desktop Internet GIS client
002: * http://udig.refractions.net
003: * (C) 2004, Refractions Research Inc.
004: *
005: * This library is free software; you can redistribute it and/or
006: * modify it under the terms of the GNU Lesser General Public
007: * License as published by the Free Software Foundation;
008: * version 2.1 of the License.
009: *
010: * This library is distributed in the hope that it will be useful,
011: * but WITHOUT ANY WARRANTY; without even the implied warranty of
012: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
013: * Lesser General Public License for more details.
014: */
015: package net.refractions.udig.tools.edit.preferences;
016:
017: import net.refractions.udig.project.ui.FeatureEditorFieldEditor;
018: import net.refractions.udig.tool.edit.internal.Messages;
019: import net.refractions.udig.tools.edit.EditPlugin;
020: import net.refractions.udig.tools.edit.support.SnapBehaviour;
021:
022: import org.eclipse.jface.preference.BooleanFieldEditor;
023: import org.eclipse.jface.preference.ColorFieldEditor;
024: import org.eclipse.jface.preference.FieldEditor;
025: import org.eclipse.jface.preference.FieldEditorPreferencePage;
026: import org.eclipse.jface.preference.IPreferenceStore;
027: import org.eclipse.jface.preference.IntegerFieldEditor;
028: import org.eclipse.jface.preference.RadioGroupFieldEditor;
029: import org.eclipse.swt.SWT;
030: import org.eclipse.swt.layout.GridData;
031: import org.eclipse.swt.widgets.Composite;
032: import org.eclipse.swt.widgets.Label;
033: import org.eclipse.swt.widgets.Text;
034: import org.eclipse.ui.IWorkbench;
035: import org.eclipse.ui.IWorkbenchPreferencePage;
036:
037: /**
038: * Preference page for all tools.
039: *
040: * @author Jesse
041: * @since 1.1.0
042: */
043: public class EditToolPreferences extends FieldEditorPreferencePage
044: implements IWorkbenchPreferencePage {
045:
046: public EditToolPreferences() {
047: super (GRID);
048: IPreferenceStore store = EditPlugin.getDefault()
049: .getPreferenceStore();
050: setPreferenceStore(store);
051: setDescription(Messages.EditToolPreferences_description);
052: }
053:
054: @Override
055: protected void createFieldEditors() {
056: addField(new BooleanFieldEditor(
057: PreferenceConstants.P_ADVANCED_ACTIVE,
058: Messages.EditToolPreferences_advanced_editing_name,
059: getFieldEditorParent()));
060: addField(new IntegerFieldEditor(
061: PreferenceConstants.P_SNAP_RADIUS,
062: Messages.EditToolPreferences_snapRadius,
063: getFieldEditorParent()));
064: addField(new RadioGroupFieldEditor(
065: PreferenceConstants.P_SNAP_BEHAVIOUR,
066: Messages.EditToolPreferences_behaviour,
067: 2,
068: new String[][] {
069: { Messages.EditToolPreferences_noSnapping,
070: SnapBehaviour.OFF.toString() },
071: { Messages.EditToolPreferences_selected,
072: SnapBehaviour.SELECTED.toString() },
073: { Messages.EditToolPreferences_current,
074: SnapBehaviour.CURRENT_LAYER.toString() },
075: { Messages.EditToolPreferences_all,
076: SnapBehaviour.ALL_LAYERS.toString() },
077: { Messages.EditToolPreferences_grid,
078: SnapBehaviour.GRID.toString() } },
079: getFieldEditorParent(), true));
080: addField(new IntegerFieldEditor(
081: PreferenceConstants.P_VERTEX_SIZE,
082: Messages.EditToolPreferences_vertexDiameter,
083: getFieldEditorParent()));
084:
085: addField(new ColorFieldEditor(
086: PreferenceConstants.P_VERTEX_OUTLINE_COLOR,
087: Messages.EditToolPreferences_vertexOutline,
088: getFieldEditorParent()));
089: addField(new ColorFieldEditor(
090: PreferenceConstants.P_SNAP_CIRCLE_COLOR,
091: Messages.EditToolPreferences_feedbackColor,
092: getFieldEditorParent()));
093:
094: addField(new FeatureEditorFieldEditor(getFieldEditorParent()));
095: }
096:
097: public void init(IWorkbench workbench) {
098: }
099:
100: static class DoubleFieldEditor extends FieldEditor {
101:
102: Label label;
103: Text text;
104:
105: public DoubleFieldEditor(String name, String labelText,
106: Composite parent) {
107: super (name, labelText, parent);
108: }
109:
110: protected void adjustForNumColumns(int numColumns) {
111:
112: }
113:
114: @Override
115: protected void doFillIntoGrid(Composite comp, int numColumns) {
116: label = new Label(comp, SWT.NONE);
117: label.setText(super .getLabelText());
118: label.setLayoutData(new GridData(SWT.FILL, SWT.NONE, false,
119: false));
120: text = new Text(comp, SWT.SINGLE | SWT.BORDER);
121: text.setLayoutData(new GridData(SWT.FILL, SWT.NONE, true,
122: false));
123: }
124:
125: @Override
126: protected void doLoad() {
127: text.setText(String.valueOf(getPreferenceStore().getDouble(
128: super .getPreferenceName())));
129: }
130:
131: @Override
132: protected void doLoadDefault() {
133: text.setText(String.valueOf(getPreferenceStore()
134: .getDefaultDouble(super .getPreferenceName())));
135: }
136:
137: @Override
138: protected void doStore() {
139: try {
140: getPreferenceStore().setValue(
141: super .getPreferenceName(),
142: Double.valueOf(text.getText()));
143: } catch (Exception e) {
144: // you've been warned
145: }
146: }
147:
148: @Override
149: public int getNumberOfControls() {
150: return 2;
151: }
152:
153: }
154: }
|