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