new icons
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpeclipse / PHPSyntaxEditorPreferencePage.java
1 package net.sourceforge.phpeclipse;
2
3 import java.util.HashMap;
4 import java.util.Iterator;
5 import java.util.Map;
6
7 import net.sourceforge.phpeclipse.preferences.ColorEditor;
8 import net.sourceforge.phpeclipse.preferences.OverlayPreferenceStore;
9 import net.sourceforge.phpeclipse.preferences.PHPPreferencesMessages;
10
11 import org.eclipse.core.runtime.IStatus;
12 import org.eclipse.jface.preference.BooleanFieldEditor;
13 import org.eclipse.jface.preference.FileFieldEditor;
14 import org.eclipse.jface.preference.IPreferenceStore;
15 import org.eclipse.jface.preference.IntegerFieldEditor;
16 import org.eclipse.jface.preference.PreferenceConverter;
17 import org.eclipse.jface.preference.PreferencePage;
18 import org.eclipse.jface.text.source.ISourceViewer;
19 import org.eclipse.swt.SWT;
20 import org.eclipse.swt.custom.StyledText;
21 import org.eclipse.swt.events.SelectionEvent;
22 import org.eclipse.swt.events.SelectionListener;
23 import org.eclipse.swt.graphics.Color;
24 import org.eclipse.swt.graphics.RGB;
25 import org.eclipse.swt.layout.GridData;
26 import org.eclipse.swt.layout.GridLayout;
27 import org.eclipse.swt.widgets.Button;
28 import org.eclipse.swt.widgets.Composite;
29 import org.eclipse.swt.widgets.Control;
30 import org.eclipse.swt.widgets.Display;
31 import org.eclipse.swt.widgets.Group;
32 import org.eclipse.swt.widgets.Label;
33 import org.eclipse.swt.widgets.List;
34 import org.eclipse.ui.IWorkbench;
35 import org.eclipse.ui.IWorkbenchPreferencePage;
36
37 /*
38  * The preference page for setting the PHP Editor options.
39  */
40 public class PHPSyntaxEditorPreferencePage extends PreferencePage implements IWorkbenchPreferencePage {
41
42   public final OverlayPreferenceStore.OverlayKey[] Keys =
43     new OverlayPreferenceStore.OverlayKey[] {
44       new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.STRING, IPreferenceConstants.PHP_MULTILINE_COMMENT),
45       new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, IPreferenceConstants.PHP_MULTILINE_COMMENT_BOLD),
46       new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, IPreferenceConstants.PHP_MULTILINE_COMMENT_ITALIC),
47       new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, IPreferenceConstants.PHP_MULTILINE_COMMENT_UNDERLINE),
48       new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.STRING, IPreferenceConstants.PHP_SINGLELINE_COMMENT),
49       new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, IPreferenceConstants.PHP_SINGLELINE_COMMENT_BOLD),
50       new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, IPreferenceConstants.PHP_SINGLELINE_COMMENT_ITALIC),
51       new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, IPreferenceConstants.PHP_SINGLELINE_COMMENT_UNDERLINE),
52       new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.STRING, IPreferenceConstants.PHP_KEYWORD),
53       new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, IPreferenceConstants.PHP_KEYWORD_BOLD),
54       new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, IPreferenceConstants.PHP_KEYWORD_ITALIC),
55       new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, IPreferenceConstants.PHP_KEYWORD_UNDERLINE),
56       new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.STRING, IPreferenceConstants.PHP_VARIABLE),
57       new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, IPreferenceConstants.PHP_VARIABLE_BOLD),
58       new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, IPreferenceConstants.PHP_VARIABLE_ITALIC),
59       new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, IPreferenceConstants.PHP_VARIABLE_UNDERLINE),
60       new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.STRING, IPreferenceConstants.PHP_TYPE),
61       new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, IPreferenceConstants.PHP_TYPE_BOLD),
62       new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, IPreferenceConstants.PHP_TYPE_ITALIC),
63       new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, IPreferenceConstants.PHP_TYPE_UNDERLINE),
64       new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.STRING, IPreferenceConstants.PHP_CONSTANT),
65       new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, IPreferenceConstants.PHP_CONSTANT_BOLD),
66       new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, IPreferenceConstants.PHP_CONSTANT_ITALIC),
67       new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, IPreferenceConstants.PHP_CONSTANT_UNDERLINE),
68       new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.STRING, IPreferenceConstants.PHP_FUNCTIONNAME),
69       new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, IPreferenceConstants.PHP_FUNCTIONNAME_BOLD),
70       new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, IPreferenceConstants.PHP_FUNCTIONNAME_ITALIC),
71       new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, IPreferenceConstants.PHP_FUNCTIONNAME_UNDERLINE),
72       new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.STRING, IPreferenceConstants.PHP_STRING),
73       new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, IPreferenceConstants.PHP_STRING_BOLD),
74       new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, IPreferenceConstants.PHP_STRING_ITALIC),
75       new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, IPreferenceConstants.PHP_STRING_UNDERLINE),
76       new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.STRING, IPreferenceConstants.PHP_DEFAULT),
77       new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, IPreferenceConstants.PHP_DEFAULT_BOLD),
78       new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, IPreferenceConstants.PHP_DEFAULT_ITALIC),
79       new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, IPreferenceConstants.PHP_DEFAULT_UNDERLINE),
80       
81                         new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.STRING, IPreferenceConstants.PHPDOC_KEYWORD),
82                         new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, IPreferenceConstants.PHPDOC_KEYWORD_BOLD),
83                         new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, IPreferenceConstants.PHPDOC_KEYWORD_ITALIC),
84                         new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, IPreferenceConstants.PHPDOC_KEYWORD_UNDERLINE),
85                         new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.STRING, IPreferenceConstants.PHPDOC_TAG),
86                         new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, IPreferenceConstants.PHPDOC_TAG_BOLD),
87                         new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, IPreferenceConstants.PHPDOC_TAG_ITALIC),
88                         new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, IPreferenceConstants.PHPDOC_TAG_UNDERLINE),
89                         new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.STRING, IPreferenceConstants.PHPDOC_LINK),
90                         new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, IPreferenceConstants.PHPDOC_LINK_BOLD),
91                         new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, IPreferenceConstants.PHPDOC_LINK_ITALIC),
92                         new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, IPreferenceConstants.PHPDOC_LINK_UNDERLINE),
93                         new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.STRING, IPreferenceConstants.PHPDOC_DEFAULT),
94                         new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, IPreferenceConstants.PHPDOC_DEFAULT_BOLD),
95                         new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, IPreferenceConstants.PHPDOC_DEFAULT_ITALIC),
96                         new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, IPreferenceConstants.PHPDOC_DEFAULT_UNDERLINE),
97       
98       new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.STRING, IPreferenceConstants.PHP_USERDEF_XMLFILE),
99   //    new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.STRING, IPreferenceConstants.PHP_EDITOR_BACKGROUND)
100   };
101
102   private final String[][] SyntaxColorListModel =
103     new String[][] {
104       {
105         PHPPreferencesMessages.getString("PHPEditorSyntaxPreferencePage.multiLineComment"),
106         IPreferenceConstants.PHP_MULTILINE_COMMENT },
107       {
108       PHPPreferencesMessages.getString("PHPEditorSyntaxPreferencePage.singleLineComment"),
109         IPreferenceConstants.PHP_SINGLELINE_COMMENT },
110         {
111       PHPPreferencesMessages.getString("PHPEditorSyntaxPreferencePage.keywords"), IPreferenceConstants.PHP_KEYWORD }, {
112       PHPPreferencesMessages.getString("PHPEditorSyntaxPreferencePage.variables"), IPreferenceConstants.PHP_VARIABLE }, {
113       PHPPreferencesMessages.getString("PHPEditorSyntaxPreferencePage.types"), IPreferenceConstants.PHP_TYPE }, {
114       PHPPreferencesMessages.getString("PHPEditorSyntaxPreferencePage.functions"), IPreferenceConstants.PHP_FUNCTIONNAME }, {
115       PHPPreferencesMessages.getString("PHPEditorSyntaxPreferencePage.constants"), IPreferenceConstants.PHP_CONSTANT }, {
116       PHPPreferencesMessages.getString("PHPEditorSyntaxPreferencePage.strings"), IPreferenceConstants.PHP_STRING }, {
117       PHPPreferencesMessages.getString("PHPEditorSyntaxPreferencePage.others"), IPreferenceConstants.PHP_DEFAULT }, {
118                         PHPPreferencesMessages.getString("PHPEditorSyntaxPreferencePage.phpdoc_keywords"), IPreferenceConstants.PHPDOC_KEYWORD }, {
119                         PHPPreferencesMessages.getString("PHPEditorSyntaxPreferencePage.phpdoc_tags"), IPreferenceConstants.PHPDOC_TAG }, {
120                         PHPPreferencesMessages.getString("PHPEditorSyntaxPreferencePage.phpdoc_links"), IPreferenceConstants.PHPDOC_LINK }, {
121                         PHPPreferencesMessages.getString("PHPEditorSyntaxPreferencePage.phpdoc_others"), IPreferenceConstants.PHPDOC_DEFAULT }
122   };
123
124   private OverlayPreferenceStore OverlayStore;
125
126   private Map ColorButtons = new HashMap();
127   private SelectionListener ColorButtonListener = new SelectionListener() {
128     public void widgetDefaultSelected(SelectionEvent e) {
129     }
130     public void widgetSelected(SelectionEvent e) {
131       ColorEditor editor = (ColorEditor) e.widget.getData();
132       PreferenceConverter.setValue(OverlayStore, (String) ColorButtons.get(editor), editor.getColorValue());
133     }
134   };
135
136   private Map CheckBoxes = new HashMap();
137   private SelectionListener CheckBoxListener = new SelectionListener() {
138     public void widgetDefaultSelected(SelectionEvent e) {
139     }
140     public void widgetSelected(SelectionEvent e) {
141       Button button = (Button) e.widget;
142       OverlayStore.setValue((String) CheckBoxes.get(button), button.getSelection());
143     }
144   };
145
146   private List SyntaxColorList;
147   /** The ColorEditor that choose the foreground color. */
148   private ColorEditor SyntaxForegroundColorEditor;
149   private Button BoldCheckBox;
150   private Button ItalicCheckBox;
151   private Button UnderlineCheckBox;
152   private FileFieldEditor userdefPHPSyntaxFileFFE;
153   // private BooleanFieldEditor showLineNumber;
154   // private IntegerFieldEditor formatterTabSize;
155   // private BooleanFieldEditor spacesForTabs;
156
157   public PHPSyntaxEditorPreferencePage() {
158     setDescription(PHPPreferencesMessages.getString("PHPEditorSyntaxPreferencePage.description")); //$NON-NLS-1$
159     setPreferenceStore(PHPeclipsePlugin.getDefault().getPreferenceStore());
160     OverlayStore = new OverlayPreferenceStore(getPreferenceStore(), Keys);
161   }
162
163   public void init(IWorkbench workbench) {
164   }
165
166   public void createControl(Composite parent) {
167     super.createControl(parent);
168   }
169
170   private void handleSyntaxColorListSelection() {
171     int i = SyntaxColorList.getSelectionIndex();
172     String key = SyntaxColorListModel[i][1];
173     RGB rgb = PreferenceConverter.getColor(OverlayStore, key);
174     SyntaxForegroundColorEditor.setColorValue(rgb);
175     BoldCheckBox.setSelection(OverlayStore.getBoolean(key + "_bold"));
176     ItalicCheckBox.setSelection(OverlayStore.getBoolean(key + "_italic"));
177     UnderlineCheckBox.setSelection(OverlayStore.getBoolean(key + "_underline"));
178   }
179
180   /**
181    * Create the group of options for other parameters (background color for example).
182    * @param parent the parent component
183    */
184   private void backgroundOptionPage(Composite parent) {
185     Label label = new Label(parent, SWT.LEFT);
186     label.setText(PHPPreferencesMessages.getString("PHPEditorSyntaxPreferencePage.color")); //$NON-NLS-1$
187     GridData gd = new GridData();
188     gd.horizontalAlignment = GridData.BEGINNING;
189     label.setLayoutData(gd);
190 //    final ColorEditor syntaxBackgroundColorEditor = new ColorEditor(parent);
191 //    RGB rgb = PreferenceConverter.getColor(OverlayStore, IPreferenceConstants.PHP_EDITOR_BACKGROUND);
192 //    syntaxBackgroundColorEditor.setColorValue(rgb);
193 //    Button backgroundColorButton = syntaxBackgroundColorEditor.getButton();
194 //    gd = new GridData(GridData.FILL_HORIZONTAL);
195 //    gd.horizontalAlignment = GridData.BEGINNING;
196 //    backgroundColorButton.setLayoutData(gd);
197 //    backgroundColorButton.addSelectionListener(new SelectionListener() {
198 //      public void widgetDefaultSelected(SelectionEvent e) {
199 //        // do nothing
200 //      }
201 //      public void widgetSelected(SelectionEvent e) {
202 //        PreferenceConverter.setValue(OverlayStore, IPreferenceConstants.PHP_EDITOR_BACKGROUND, syntaxBackgroundColorEditor.getColorValue());
203 //      }
204 //    });
205   }
206
207   /**
208    * Create the group of options for the syntax parameters.
209    * @param parent the parent component
210    * @return
211    */
212   private Control createSyntaxPage(Composite parent) {
213
214     Composite colorComposite = new Composite(parent, SWT.NULL);
215     colorComposite.setLayout(new GridLayout());
216
217     Label label = new Label(colorComposite, SWT.LEFT);
218     label.setText(PHPPreferencesMessages.getString("PHPEditorSyntaxPreferencePage.syntax")); //$NON-NLS-1$
219     label.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
220
221     Composite editorComposite = new Composite(colorComposite, SWT.NONE);
222     GridLayout layout = new GridLayout();
223     layout.numColumns = 2;
224     layout.marginHeight = 0;
225     layout.marginWidth = 0;
226     editorComposite.setLayout(layout);
227     GridData gd = new GridData(GridData.FILL_BOTH);
228     editorComposite.setLayoutData(gd);
229
230     SyntaxColorList = new List(editorComposite, SWT.SINGLE | SWT.V_SCROLL | SWT.BORDER);
231     gd = new GridData(GridData.FILL_BOTH);
232     gd.heightHint = convertHeightInCharsToPixels(5);
233     SyntaxColorList.setLayoutData(gd);
234
235     Composite stylesComposite = new Composite(editorComposite, SWT.NONE);
236     layout = new GridLayout();
237     layout.marginHeight = 0;
238     layout.marginWidth = 0;
239     layout.numColumns = 2;
240     stylesComposite.setLayout(layout);
241     stylesComposite.setLayoutData(new GridData(GridData.FILL_BOTH));
242
243     label = new Label(stylesComposite, SWT.LEFT);
244     label.setText(PHPPreferencesMessages.getString("PHPEditorSyntaxPreferencePage.color")); //$NON-NLS-1$
245     gd = new GridData();
246     gd.horizontalAlignment = GridData.BEGINNING;
247     label.setLayoutData(gd);
248
249     SyntaxForegroundColorEditor = new ColorEditor(stylesComposite);
250     Button foregroundColorButton = SyntaxForegroundColorEditor.getButton();
251     gd = new GridData(GridData.FILL_HORIZONTAL);
252     gd.horizontalAlignment = GridData.BEGINNING;
253     foregroundColorButton.setLayoutData(gd);
254
255     BoldCheckBox = new Button(stylesComposite, SWT.CHECK);
256     BoldCheckBox.setText(PHPPreferencesMessages.getString("PHPEditorSyntaxPreferencePage.bold")); //$NON-NLS-1$
257     gd = new GridData(GridData.FILL_HORIZONTAL);
258     gd.horizontalAlignment = GridData.BEGINNING;
259     gd.horizontalSpan = 2;
260     BoldCheckBox.setLayoutData(gd);
261
262     ItalicCheckBox = new Button(stylesComposite, SWT.CHECK);
263     ItalicCheckBox.setText(PHPPreferencesMessages.getString("PHPEditorSyntaxPreferencePage.italic")); //$NON-NLS-1$
264     ItalicCheckBox.setEnabled(false);
265     gd = new GridData(GridData.FILL_HORIZONTAL);
266     gd.horizontalAlignment = GridData.BEGINNING;
267     gd.horizontalSpan = 2;
268     ItalicCheckBox.setLayoutData(gd);
269
270     UnderlineCheckBox = new Button(stylesComposite, SWT.CHECK);
271     UnderlineCheckBox.setText(PHPPreferencesMessages.getString("PHPEditorSyntaxPreferencePage.underline")); //$NON-NLS-1$
272     UnderlineCheckBox.setEnabled(false);
273     gd = new GridData(GridData.FILL_HORIZONTAL);
274     gd.horizontalAlignment = GridData.BEGINNING;
275     gd.horizontalSpan = 2;
276     UnderlineCheckBox.setLayoutData(gd);
277
278     Composite customSyntaxComposite = new Composite(colorComposite, SWT.NONE);
279     layout = new GridLayout();
280     layout.marginHeight = 0;
281     layout.marginWidth = 0;
282     layout.numColumns = 3;
283     stylesComposite.setLayout(layout);
284     stylesComposite.setLayoutData(new GridData(GridData.FILL_BOTH));
285
286     userdefPHPSyntaxFileFFE =
287       new FileFieldEditor(
288         IPreferenceConstants.PHP_USERDEF_XMLFILE,
289         PHPPreferencesMessages.getString("PHPEditorSyntaxPreferencePage.syntaxdialog"),
290         colorComposite);
291     userdefPHPSyntaxFileFFE.setPreferencePage(this);
292     userdefPHPSyntaxFileFFE.setPreferenceStore(getPreferenceStore());
293     userdefPHPSyntaxFileFFE.load();
294
295     SyntaxColorList.addSelectionListener(new SelectionListener() {
296       public void widgetDefaultSelected(SelectionEvent e) {
297         // do nothing
298       }
299       public void widgetSelected(SelectionEvent e) {
300         handleSyntaxColorListSelection();
301       }
302     });
303
304     foregroundColorButton.addSelectionListener(new SelectionListener() {
305       public void widgetDefaultSelected(SelectionEvent e) {
306         // do nothing
307       }
308       public void widgetSelected(SelectionEvent e) {
309         int i = SyntaxColorList.getSelectionIndex();
310         String key = SyntaxColorListModel[i][1];
311
312         PreferenceConverter.setValue(OverlayStore, key, SyntaxForegroundColorEditor.getColorValue());
313       }
314     });
315     BoldCheckBox.addSelectionListener(new SelectionListener() {
316       public void widgetDefaultSelected(SelectionEvent e) {
317         // do nothing
318       }
319       public void widgetSelected(SelectionEvent e) {
320         int i = SyntaxColorList.getSelectionIndex();
321         String key = SyntaxColorListModel[i][1];
322         OverlayStore.setValue(key + "_bold", BoldCheckBox.getSelection());
323       }
324     });
325
326     ItalicCheckBox.addSelectionListener(new SelectionListener() {
327       public void widgetDefaultSelected(SelectionEvent e) {
328         // do nothing
329       }
330       public void widgetSelected(SelectionEvent e) {
331         int i = SyntaxColorList.getSelectionIndex();
332         String key = SyntaxColorListModel[i][1];
333         OverlayStore.setValue(key + "_italic", ItalicCheckBox.getSelection());
334       }
335     });
336
337     UnderlineCheckBox.addSelectionListener(new SelectionListener() {
338       public void widgetDefaultSelected(SelectionEvent e) {
339         // do nothing
340       }
341       public void widgetSelected(SelectionEvent e) {
342         int i = SyntaxColorList.getSelectionIndex();
343         String key = SyntaxColorListModel[i][1];
344         OverlayStore.setValue(key + "_underline", UnderlineCheckBox.getSelection());
345       }
346     });
347     return colorComposite;
348   }
349
350   private void initializeViewerColors(ISourceViewer viewer) {
351
352     IPreferenceStore store = OverlayStore;
353     if (store != null) {
354
355       StyledText styledText = viewer.getTextWidget();
356     }
357   }
358
359   private Color createColor(IPreferenceStore store, String key, Display display) {
360     RGB rgb = null;
361     if (store.contains(key)) {
362       if (store.isDefault(key))
363         rgb = PreferenceConverter.getDefaultColor(store, key);
364       else
365         rgb = PreferenceConverter.getColor(store, key);
366       if (rgb != null)
367         return new Color(display, rgb);
368     }
369     return null;
370   }
371
372   private static void setEnabled(Control control, boolean enable) {
373     control.setEnabled(enable);
374     if (control instanceof Composite) {
375       Composite composite = (Composite) control;
376       Control[] children = composite.getChildren();
377       for (int i = 0; i < children.length; i++)
378         setEnabled(children[i], enable);
379     }
380   }
381
382   private static void indent(Control control) {
383     GridData gridData = new GridData();
384     gridData.horizontalIndent = 20;
385     control.setLayoutData(gridData);
386   }
387
388   private static void createDependency(final Button master, final Control slave) {
389     indent(slave);
390     master.addSelectionListener(new SelectionListener() {
391       public void widgetSelected(SelectionEvent e) {
392         slave.setEnabled(master.getSelection());
393       }
394
395       public void widgetDefaultSelected(SelectionEvent e) {
396       }
397     });
398   }
399
400   protected Control createContents(Composite parent) {
401     OverlayStore.load();
402     OverlayStore.start();
403     //Create overall composite
404     Composite composite = new Composite(parent, SWT.NONE);
405     GridLayout layout = new GridLayout();
406     layout.marginHeight = 0;
407     layout.marginWidth = 0;
408     composite.setLayout(layout);
409     Composite syntaxComposite = new Composite(composite, SWT.NULL);
410     syntaxComposite.setLayout(new GridLayout());
411     layout = new GridLayout();
412     layout.numColumns = 3;
413     Group syntaxGroup = new Group(syntaxComposite, SWT.NONE);
414     syntaxGroup.setText(PHPPreferencesMessages.getString("PHPEditorSyntaxPreferencePage.foreground"));
415     syntaxGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
416     syntaxGroup.setLayout(layout);
417     createSyntaxPage(syntaxGroup);
418
419     Composite backgroundOptions = new Composite(composite,SWT.NULL);
420     backgroundOptions.setLayout(new GridLayout());
421     layout = new GridLayout();
422     layout.numColumns = 3;
423     Group backgroundOptionsGroup = new Group(backgroundOptions,SWT.NONE);
424     backgroundOptionsGroup.setText(PHPPreferencesMessages.getString("PHPEditorSyntaxPreferencePage.background"));
425     backgroundOptionsGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
426     backgroundOptionsGroup.setLayout(layout);
427     backgroundOptionPage(backgroundOptionsGroup);
428
429     initialize();
430     
431    
432 //    showLineNumber = new BooleanFieldEditor(PHPeclipsePlugin.LINE_NUMBER_RULER, 
433 //    "Show line numbers", composite);
434 //    showLineNumber.setPreferencePage(this);
435 //    showLineNumber.setPreferenceStore(getPreferenceStore());
436 //    showLineNumber.load();
437     
438 //    formatterTabSize = new IntegerFieldEditor(PHPeclipsePlugin.FORMATTER_TAB_SIZE, 
439 //    "Displayed tab width", composite, 3);
440 //    formatterTabSize.setPreferencePage(this);
441 //    formatterTabSize.setPreferenceStore(getPreferenceStore());
442 //    formatterTabSize.load();
443 //    
444 //    spacesForTabs = new BooleanFieldEditor(PHPeclipsePlugin.SPACES_FOR_TABS, 
445 //    "Spaces for Tabs", composite);
446 //    spacesForTabs.setPreferencePage(this);
447 //    spacesForTabs.setPreferenceStore(getPreferenceStore());
448 //    spacesForTabs.load();
449     return composite;
450   }
451
452   private void initialize() {
453     initializeFields();
454     for (int i = 0; i < SyntaxColorListModel.length; i++)
455       SyntaxColorList.add(SyntaxColorListModel[i][0]);
456     SyntaxColorList.getDisplay().asyncExec(new Runnable() {
457       public void run() {
458         if (SyntaxColorList != null && !SyntaxColorList.isDisposed()) {
459           SyntaxColorList.select(0);
460           handleSyntaxColorListSelection();
461         }
462       }
463     });
464   }
465
466   private void initializeFields() {
467
468     Iterator e = ColorButtons.keySet().iterator();
469     while (e.hasNext()) {
470       ColorEditor c = (ColorEditor) e.next();
471       String key = (String) ColorButtons.get(c);
472       RGB rgb = PreferenceConverter.getColor(OverlayStore, key);
473       c.setColorValue(rgb);
474     }
475
476     e = CheckBoxes.keySet().iterator();
477     while (e.hasNext()) {
478       Button b = (Button) e.next();
479       String key = (String) CheckBoxes.get(b);
480       b.setSelection(OverlayStore.getBoolean(key));
481     }
482   }
483
484   public boolean performOk() {
485     OverlayStore.propagate();
486     IPreferenceStore store = getPreferenceStore();
487     PHPeclipsePlugin.getDefault().savePluginPreferences();
488     userdefPHPSyntaxFileFFE.store();
489    // showLineNumber.store();
490    // spacesForTabs.store();
491    // formatterTabSize.store();
492     return true;
493   }
494
495   protected void performDefaults() {
496     OverlayStore.loadDefaults();
497     initializeFields();
498     handleSyntaxColorListSelection();
499     userdefPHPSyntaxFileFFE.loadDefault();
500   //  showLineNumber.loadDefault();
501   //  spacesForTabs.loadDefault();
502   //  showLineNumber.loadDefault();
503   //  formatterTabSize.loadDefault();
504     super.performDefaults();
505   }
506
507   public void dispose() {
508     if (OverlayStore != null) {
509       OverlayStore.stop();
510       OverlayStore = null;
511     }
512     super.dispose();
513   }
514
515   private Control addColorButton(Composite composite, String label, String key, int indentation) {
516     Label labelControl = new Label(composite, SWT.NONE);
517     labelControl.setText(label);
518     GridData gd = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
519     gd.horizontalIndent = indentation;
520     labelControl.setLayoutData(gd);
521     ColorEditor editor = new ColorEditor(composite);
522     Button button = editor.getButton();
523     button.setData(editor);
524     gd = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
525     button.setLayoutData(gd);
526     button.addSelectionListener(ColorButtonListener);
527     ColorButtons.put(editor, key);
528     return composite;
529   }
530
531   private Button addCheckBox(Composite parent, String label, String key, int indentation) {
532     Button checkBox = new Button(parent, SWT.CHECK);
533     checkBox.setText(label);
534     GridData gd = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
535     gd.horizontalIndent = indentation;
536     gd.horizontalSpan = 2;
537     checkBox.setLayoutData(gd);
538     checkBox.addSelectionListener(CheckBoxListener);
539     CheckBoxes.put(checkBox, key);
540     return checkBox;
541   }
542
543   private void updateStatus(IStatus status) {
544   }
545
546   /**
547    * @deprecated Inline to avoid reference to preference page
548    */
549   public static boolean indicateQuixFixableProblems() {
550     //          return PreferenceConstants.getPreferenceStore().getBoolean(PreferenceConstants.EDITOR_CORRECTION_INDICATION);
551     return false;
552   }
553
554   /**
555    * @deprecated Inline to avoid reference to preference page
556    */
557   static public boolean synchronizeOutlineOnCursorMove() {
558     //          return PreferenceConstants.getPreferenceStore().getBoolean(PreferenceConstants.EDITOR_SYNC_OUTLINE_ON_CURSOR_MOVE);
559     return false;
560   }
561
562 }