1 /*******************************************************************************
\r
2 * Copyright (c) 2007 VTT Technical Research Centre of Finland and others.
\r
3 * All rights reserved. This program and the accompanying materials
\r
4 * are made available under the terms of the Eclipse Public License v1.0
\r
5 * which accompanies this distribution, and is available at
\r
6 * http://www.eclipse.org/legal/epl-v10.html
\r
9 * VTT Technical Research Centre of Finland - initial API and implementation
\r
10 *******************************************************************************/
\r
11 package org.simantics.proconf.g3d.preferences;
13 import org.eclipse.jface.preference.*;
14 import org.eclipse.ui.IWorkbenchPreferencePage;
15 import org.eclipse.ui.IWorkbench;
16 import org.simantics.proconf.g3d.Activator;
20 * This class represents a preference page that
21 * is contributed to the Preferences dialog. By
22 * subclassing <samp>FieldEditorPreferencePage</samp>, we
23 * can use the field support built into JFace that allows
24 * us to create a page that is small and knows how to
25 * save, restore and apply itself.
27 * This page is used to modify preferences only. They
28 * are stored in the preference store that belongs to
29 * the main plug-in class. That way, preferences can
30 * be accessed directly via the preference store.
33 public class G3DPreferencesPage
34 extends FieldEditorPreferencePage
35 implements IWorkbenchPreferencePage {
37 public G3DPreferencesPage() {
39 setPreferenceStore(Activator.getDefault().getPreferenceStore());
40 setDescription("A demonstration of a preference page implementation");
44 * Creates the field editors. Field editors are abstractions of
45 * the common GUI blocks needed to manipulate various types
46 * of preferences. Each field editor knows how to save and
49 public void createFieldEditors() {
50 // addField(new DirectoryFieldEditor(PreferenceConstants.P_PATH,
51 // "&Directory preference:", getFieldEditorParent()));
53 // new BooleanFieldEditor(
54 // PreferenceConstants.P_BOOLEAN,
55 // "&An example of a boolean preference",
56 // getFieldEditorParent()));
58 // addField(new RadioGroupFieldEditor(
59 // PreferenceConstants.P_CHOICE,
60 // "An example of a multiple-choice preference",
62 // new String[][] { { "&Choice 1", "choice1" }, {
63 // "C&hoice 2", "choice2" }
64 // }, getFieldEditorParent()));
66 // new StringFieldEditor(PreferenceConstants.P_STRING, "A &text preference:", getFieldEditorParent()));
67 addField(new BooleanFieldEditor(PreferenceConstants.SHADOWS,"Use Shadows",getFieldEditorParent()));
68 addField(new RadioGroupFieldEditor(PreferenceConstants.POST_PROCESS, "Post Processing", 1,
69 new String[][] { { "None", "none" },
70 { "Sketch", "sketch" },
71 { "Bloom", "bloom" }},
72 getFieldEditorParent()));
73 addField(new ScaleFieldEditor(PreferenceConstants.GIZMO_SCALE,"Gizmo scale",getFieldEditorParent(),5,100,1,10) {
74 private double oldValue;
77 protected void doStore() {
79 .setValue(getPreferenceName(), scale.getSelection()*0.1);
83 protected void doLoadDefault() {
85 double value = getPreferenceStore().getDefaultDouble(getPreferenceName());
86 scale.setSelection((int)(value*10.0));
92 protected void doLoad() {
94 double value = getPreferenceStore().getDouble(getPreferenceName());
95 scale.setSelection((int)(value*10.0));
101 protected void valueChanged() {
102 setPresentsDefaultValue(false);
104 double newValue = scale.getSelection()*0.1;
105 if (newValue != oldValue) {
106 fireStateChanged(IS_VALID, false, true);
107 fireValueChanged(VALUE, new Double(oldValue),
108 new Double(newValue));
116 * @see org.eclipse.ui.IWorkbenchPreferencePage#init(org.eclipse.ui.IWorkbench)
118 public void init(IWorkbench workbench) {