]> gerrit.simantics Code Review - simantics/3d.git/blob - org.simantics.g3d/src/org/simantics/proconf/g3d/preferences/G3DPreferencesPage.java
185e959941daaa70723f56eb595974d924e828f1
[simantics/3d.git] / org.simantics.g3d / src / org / simantics / proconf / g3d / preferences / G3DPreferencesPage.java
1 /*******************************************************************************\r
2  * Copyright (c) 2007- VTT Technical Research Centre of Finland.\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
7  *\r
8  * Contributors:\r
9  *     VTT Technical Research Centre of Finland - initial API and implementation\r
10  *******************************************************************************/\r
11 package org.simantics.proconf.g3d.preferences;
12
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;
17
18
19 /**
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.
26  * <p>
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.
31  */
32
33 public class G3DPreferencesPage
34         extends FieldEditorPreferencePage
35         implements IWorkbenchPreferencePage {
36
37         public G3DPreferencesPage() {
38                 super(GRID);
39                 setPreferenceStore(Activator.getDefault().getPreferenceStore());
40                 setDescription("A demonstration of a preference page implementation");
41         }
42         
43         /**
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
47          * restore itself.
48          */
49         public void createFieldEditors() {
50 //              addField(new DirectoryFieldEditor(PreferenceConstants.P_PATH, 
51 //                              "&Directory preference:", getFieldEditorParent()));
52 //              addField(
53 //                      new BooleanFieldEditor(
54 //                              PreferenceConstants.P_BOOLEAN,
55 //                              "&An example of a boolean preference",
56 //                              getFieldEditorParent()));
57 //
58 //              addField(new RadioGroupFieldEditor(
59 //                              PreferenceConstants.P_CHOICE,
60 //                      "An example of a multiple-choice preference",
61 //                      1,
62 //                      new String[][] { { "&Choice 1", "choice1" }, {
63 //                              "C&hoice 2", "choice2" }
64 //              }, getFieldEditorParent()));
65 //              addField(
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;
75                         
76                         @Override
77                         protected void doStore() {
78                                 getPreferenceStore()
79                 .setValue(getPreferenceName(), scale.getSelection()*0.1);
80                         }
81                         
82                         @Override
83                         protected void doLoadDefault() {
84                                 if (scale != null) {
85                             double value = getPreferenceStore().getDefaultDouble(getPreferenceName());
86                             scale.setSelection((int)(value*10.0));
87                         }
88                         valueChanged();
89                         }
90                         
91                         @Override
92                         protected void doLoad() {
93                                 if (scale != null) {
94                                         double value = getPreferenceStore().getDouble(getPreferenceName());
95                             scale.setSelection((int)(value*10.0));
96                             oldValue = value;
97                         };
98                         }
99                         
100                         @Override
101                         protected void valueChanged() {
102                         setPresentsDefaultValue(false);
103
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));
109                             oldValue = newValue;
110                         }
111                     }
112                 });
113         }
114
115         /* (non-Javadoc)
116          * @see org.eclipse.ui.IWorkbenchPreferencePage#init(org.eclipse.ui.IWorkbench)
117          */
118         public void init(IWorkbench workbench) {
119         }
120         
121 }