62
|
1 module jface.PreferenceDlgTest;
|
|
2
|
|
3 import dwtx.jface.preference.BooleanFieldEditor;
|
|
4 import dwtx.jface.preference.ColorFieldEditor;
|
|
5 import dwtx.jface.preference.DirectoryFieldEditor;
|
|
6 import dwtx.jface.preference.FileFieldEditor;
|
|
7 import dwtx.jface.preference.FontFieldEditor;
|
|
8 import dwtx.jface.preference.FieldEditorPreferencePage;
|
|
9 import dwtx.jface.preference.RadioGroupFieldEditor;
|
|
10 import dwtx.jface.preference.PathEditor;
|
|
11 import dwtx.jface.preference.IntegerFieldEditor;
|
|
12 import dwtx.jface.preference.ScaleFieldEditor;
|
|
13 import dwtx.jface.preference.StringFieldEditor;
|
|
14 import dwtx.jface.preference.IPreferenceStore;
|
|
15 import dwtx.jface.preference.PreferenceManager;
|
|
16 import dwtx.jface.preference.PreferencePage;
|
|
17 import dwtx.jface.preference.PreferenceNode;
|
|
18 import dwtx.jface.preference.PreferenceStore;
|
|
19 import dwtx.jface.preference.PreferenceDialog;
|
|
20 import dwtx.jface.resource.ImageDescriptor;
|
|
21
|
|
22 import dwt.widgets.Display;
|
|
23 import dwt.widgets.Composite;
|
|
24 import dwt.widgets.Label;
|
|
25 import dwt.widgets.Button;
|
|
26 import dwt.widgets.Text;
|
|
27 import dwt.widgets.Control;
|
|
28 import dwt.events.SelectionAdapter;
|
|
29 import dwt.events.SelectionEvent;
|
|
30 import dwt.layout.RowLayout;
|
|
31 import dwt.layout.GridLayout;
|
|
32 import dwt.layout.GridData;
|
|
33 import dwt.DWT;
|
|
34 import dwt.dwthelper.utils;
|
|
35
|
|
36 import tango.io.File;
|
|
37 import tango.io.FilePath;
|
|
38
|
|
39 version(JIVE) import jive.stacktrace;
|
|
40
|
|
41 const char[] FILENAME = "showfieldprefs";
|
|
42
|
|
43 /**
|
|
44 * This class demonstrates field editors
|
|
45 */
|
|
46 public class FieldEditorPageOne : FieldEditorPreferencePage {
|
|
47 public this() {
|
|
48 // Use the "flat" layout
|
|
49 super(FLAT);
|
|
50 }
|
|
51
|
|
52 /**
|
|
53 * Creates the field editors
|
|
54 */
|
|
55 protected void createFieldEditors() {
|
|
56 // Add a bool field
|
|
57 BooleanFieldEditor bfe = new BooleanFieldEditor("myBoolean", "Boolean",
|
|
58 getFieldEditorParent());
|
|
59 addField(bfe);
|
|
60
|
|
61 // Add a color field
|
|
62 ColorFieldEditor cfe = new ColorFieldEditor("myColor", "Color:",
|
|
63 getFieldEditorParent());
|
|
64 addField(cfe);
|
|
65
|
|
66 // Add a directory field
|
|
67 DirectoryFieldEditor dfe = new DirectoryFieldEditor("myDirectory",
|
|
68 "Directory:", getFieldEditorParent());
|
|
69 addField(dfe);
|
|
70
|
|
71 // Add a file field
|
|
72 FileFieldEditor ffe = new FileFieldEditor("myFile", "File:",
|
|
73 getFieldEditorParent());
|
|
74 addField(ffe);
|
|
75
|
|
76 // Add a font field
|
|
77 FontFieldEditor fontFe = new FontFieldEditor("myFont", "Font:",
|
|
78 getFieldEditorParent());
|
|
79 addField(fontFe);
|
|
80
|
|
81 // Add a radio group field
|
|
82 RadioGroupFieldEditor rfe = new RadioGroupFieldEditor("myRadioGroup",
|
|
83 "Radio Group", 2, [ [ "First Value", "first"],
|
|
84 [ "Second Value", "second"], [ "Third Value", "third"],
|
|
85 [ "Fourth Value", "fourth"]], getFieldEditorParent(), true);
|
|
86 addField(rfe);
|
|
87
|
|
88 // Add a path field
|
|
89 PathEditor pe = new PathEditor("myPath", "Path:", "Choose a Path",
|
|
90 getFieldEditorParent());
|
|
91 addField(pe);
|
|
92 }
|
|
93 }
|
|
94
|
|
95
|
|
96 /**
|
|
97 * This class demonstrates field editors
|
|
98 */
|
|
99 public class FieldEditorPageTwo : FieldEditorPreferencePage {
|
|
100 public this() {
|
|
101 // Use the "grid" layout
|
|
102 super(GRID);
|
|
103 }
|
|
104
|
|
105 /**
|
|
106 * Creates the field editors
|
|
107 */
|
|
108 protected void createFieldEditors() {
|
|
109 // Add an integer field
|
|
110 IntegerFieldEditor ife = new IntegerFieldEditor("myInt", "Int:",
|
|
111 getFieldEditorParent());
|
|
112 addField(ife);
|
|
113
|
|
114 // Add a scale field
|
|
115 ScaleFieldEditor sfe = new ScaleFieldEditor("myScale", "Scale:",
|
|
116 getFieldEditorParent(), 0, 100, 1, 10);
|
|
117 addField(sfe);
|
|
118
|
|
119 // Add a string field
|
|
120 StringFieldEditor stringFe = new StringFieldEditor("myString", "String:",
|
|
121 getFieldEditorParent());
|
|
122 addField(stringFe);
|
|
123 }
|
|
124 }
|
|
125
|
|
126
|
|
127 /**
|
|
128 * This class demonstrates JFace preferences and field editors
|
|
129 */
|
|
130 public class ShowFieldPrefs {
|
|
131 /**
|
|
132 * Runs the application
|
|
133 */
|
|
134 public void run() {
|
|
135 // Display display = new Display();
|
|
136
|
|
137 // Create the preference manager
|
|
138 PreferenceManager mgr = new PreferenceManager();
|
|
139
|
|
140 // Create the nodes
|
|
141 PreferenceNode one = new PreferenceNode("one", "One", null,
|
|
142 FieldEditorPageOne.classinfo.name );
|
|
143 PreferenceNode two = new PreferenceNode("two", "Two", null,
|
|
144 FieldEditorPageTwo.classinfo.name );
|
|
145
|
|
146 // Add the nodes
|
|
147 mgr.addToRoot(one);
|
|
148 mgr.addToRoot(two);
|
|
149
|
|
150 // Create the preferences dialog
|
|
151 PreferenceDialog dlg = new PreferenceDialog(null, mgr);
|
|
152
|
|
153 // Set the preference store
|
|
154 PreferenceStore ps = new PreferenceStore(FILENAME);
|
|
155 try {
|
|
156 ps.load();
|
|
157 } catch (IOException e) {
|
|
158 // Ignore
|
|
159 }
|
|
160 dlg.setPreferenceStore(ps);
|
|
161
|
|
162 // Open the dialog
|
|
163 dlg.open();
|
|
164
|
|
165 try {
|
|
166 // Save the preferences
|
|
167 ps.save();
|
|
168 } catch (IOException e) {
|
|
169 ExceptionPrintStackTrace(e);
|
|
170 }
|
|
171 // display.dispose();
|
|
172 }
|
|
173
|
|
174 /**
|
|
175 * The application entry point
|
|
176 *
|
|
177 * @param args the command line arguments
|
|
178 */
|
|
179 public static void main(String[] args) {
|
|
180 (new ShowFieldPrefs()).run();
|
|
181 }
|
|
182 }
|
|
183
|
|
184
|
|
185 void main(){
|
|
186 scope fn = new FilePath( FILENAME );
|
|
187 if( !fn.exists ){
|
|
188 scope prefs = new File( fn );
|
|
189 version(linux){
|
|
190 prefs.write( import("jface.showfieldprefs.properties.linux" ));
|
|
191 }
|
|
192 version(Windows){
|
|
193 prefs.write( import("jface.showfieldprefs.properties.win" ));
|
|
194 }
|
|
195 }
|
|
196 ShowFieldPrefs.main( null );
|
|
197 }
|
|
198
|
|
199
|
|
200
|
|
201
|
|
202
|