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