added StringAutoIndentStrategy for single quoted strings
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / internal / ui / preferences / JavaEditorPreferencePage.java
1 /*******************************************************************************
2  * Copyright (c) 2000, 2003 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials 
4  * are made available under the terms of the Common Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/cpl-v10.html
7  * 
8  * Contributors:
9  *     IBM Corporation - initial API and implementation
10  *******************************************************************************/
11 package net.sourceforge.phpdt.internal.ui.preferences;
12
13 import java.io.BufferedReader;
14 import java.io.IOException;
15 import java.io.InputStreamReader;
16 import java.text.Collator;
17 import java.util.ArrayList;
18 import java.util.Comparator;
19 import java.util.HashMap;
20 import java.util.Iterator;
21 import java.util.Map;
22 import java.util.SortedSet;
23 import java.util.StringTokenizer;
24 import java.util.TreeSet;
25
26 import net.sourceforge.phpdt.core.JavaCore;
27 import net.sourceforge.phpdt.internal.ui.IJavaHelpContextIds;
28 import net.sourceforge.phpdt.internal.ui.dialogs.StatusInfo;
29 import net.sourceforge.phpdt.internal.ui.dialogs.StatusUtil;
30 import net.sourceforge.phpdt.internal.ui.text.IPHPPartitions;
31 import net.sourceforge.phpdt.internal.ui.text.PreferencesAdapter;
32 import net.sourceforge.phpdt.internal.ui.util.TabFolderLayout;
33 import net.sourceforge.phpdt.ui.PreferenceConstants;
34 import net.sourceforge.phpdt.ui.text.JavaTextTools;
35 import net.sourceforge.phpdt.ui.text.PHPSourceViewerConfiguration;
36 import net.sourceforge.phpeclipse.PHPeclipsePlugin;
37 import net.sourceforge.phpeclipse.phpeditor.EditorUtility;
38 import net.sourceforge.phpeclipse.phpeditor.JavaSourceViewer;
39 import net.sourceforge.phpeclipse.preferences.ColorEditor;
40
41 import org.eclipse.core.runtime.IStatus;
42 import org.eclipse.core.runtime.Preferences;
43 import org.eclipse.jface.dialogs.Dialog;
44 import org.eclipse.jface.preference.IPreferenceStore;
45 import org.eclipse.jface.preference.PreferenceConverter;
46 import org.eclipse.jface.preference.PreferencePage;
47 import org.eclipse.jface.resource.JFaceResources;
48 import org.eclipse.jface.text.Document;
49 import org.eclipse.jface.text.IDocument;
50 import org.eclipse.jface.text.source.SourceViewer;
51 import org.eclipse.swt.SWT;
52 import org.eclipse.swt.events.ModifyEvent;
53 import org.eclipse.swt.events.ModifyListener;
54 import org.eclipse.swt.events.SelectionEvent;
55 import org.eclipse.swt.events.SelectionListener;
56 import org.eclipse.swt.graphics.Color;
57 import org.eclipse.swt.graphics.Font;
58 import org.eclipse.swt.graphics.RGB;
59 import org.eclipse.swt.layout.GridData;
60 import org.eclipse.swt.layout.GridLayout;
61 import org.eclipse.swt.layout.RowLayout;
62 import org.eclipse.swt.widgets.Button;
63 import org.eclipse.swt.widgets.Combo;
64 import org.eclipse.swt.widgets.Composite;
65 import org.eclipse.swt.widgets.Control;
66 import org.eclipse.swt.widgets.Group;
67 import org.eclipse.swt.widgets.Label;
68 import org.eclipse.swt.widgets.List;
69 import org.eclipse.swt.widgets.TabFolder;
70 import org.eclipse.swt.widgets.TabItem;
71 import org.eclipse.swt.widgets.Text;
72 import org.eclipse.ui.IWorkbench;
73 import org.eclipse.ui.IWorkbenchPreferencePage;
74 import org.eclipse.ui.editors.text.EditorsUI;
75 import org.eclipse.ui.help.WorkbenchHelp;
76 import org.eclipse.ui.texteditor.AbstractDecoratedTextEditorPreferenceConstants;
77 import org.eclipse.ui.texteditor.AnnotationPreference;
78 import org.eclipse.ui.texteditor.ChainedPreferenceStore;
79 import org.eclipse.ui.texteditor.MarkerAnnotationPreferences;
80
81 /**
82  * The page for setting the editor options.
83  */
84 public class JavaEditorPreferencePage extends PreferencePage implements IWorkbenchPreferencePage {
85   private static final String BOLD = PreferenceConstants.EDITOR_BOLD_SUFFIX;
86
87   private static final String COMPILER_TASK_TAGS = JavaCore.COMPILER_TASK_TAGS;
88
89   private static final String DELIMITER = PreferencesMessages.getString("JavaEditorPreferencePage.navigation.delimiter"); //$NON-NLS-1$
90
91   /** The keys of the overlay store. */
92   public final OverlayPreferenceStore.OverlayKey[] fKeys;
93
94   private final String[][] fSyntaxColorListModel = new String[][] {
95       { PreferencesMessages.getString("JavaEditorPreferencePage.multiLineComment"),
96           PreferenceConstants.EDITOR_MULTI_LINE_COMMENT_COLOR },
97       //$NON-NLS-1$
98       { PreferencesMessages.getString("JavaEditorPreferencePage.singleLineComment"),
99           PreferenceConstants.EDITOR_SINGLE_LINE_COMMENT_COLOR },
100       //$NON-NLS-1$
101       { PreferencesMessages.getString("JavaEditorPreferencePage.tags"), PreferenceConstants.EDITOR_PHP_TAG_COLOR },
102       //$NON-NLS-1$
103       { PreferencesMessages.getString("JavaEditorPreferencePage.keywords"), PreferenceConstants.EDITOR_JAVA_KEYWORD_COLOR },
104       { PreferencesMessages.getString("JavaEditorPreferencePage.functionNames"), PreferenceConstants.EDITOR_PHP_FUNCTIONNAME_COLOR },
105       //$NON-NLS-1$
106       { PreferencesMessages.getString("JavaEditorPreferencePage.variables"), PreferenceConstants.EDITOR_PHP_VARIABLE_COLOR },
107       //$NON-NLS-1$
108       { PreferencesMessages.getString("JavaEditorPreferencePage.constants"), PreferenceConstants.EDITOR_PHP_CONSTANT_COLOR },
109       //$NON-NLS-1$
110       { PreferencesMessages.getString("JavaEditorPreferencePage.types"), PreferenceConstants.EDITOR_PHP_TYPE_COLOR },
111       //$NON-NLS-1$
112       { PreferencesMessages.getString("JavaEditorPreferencePage.strings"), PreferenceConstants.EDITOR_STRING_COLOR },
113       //$NON-NLS-1$
114       { PreferencesMessages.getString("JavaEditorPreferencePage.others"), PreferenceConstants.EDITOR_JAVA_DEFAULT_COLOR }, //$NON-NLS-1$
115       { PreferencesMessages.getString("JavaEditorPreferencePage.operators"), PreferenceConstants.EDITOR_PHP_OPERATOR_COLOR },
116       //$NON-NLS-1$
117       { PreferencesMessages.getString("JavaEditorPreferencePage.returnKeyword"),
118           PreferenceConstants.EDITOR_PHP_KEYWORD_RETURN_COLOR },
119       //$NON-NLS-1$
120       { PreferencesMessages.getString("JavaEditorPreferencePage.phpDocKeywords"), PreferenceConstants.EDITOR_JAVADOC_KEYWORD_COLOR },
121       //$NON-NLS-1$
122       { PreferencesMessages.getString("JavaEditorPreferencePage.phpDocHtmlTags"), PreferenceConstants.EDITOR_JAVADOC_TAG_COLOR },
123       //$NON-NLS-1$
124       { PreferencesMessages.getString("JavaEditorPreferencePage.phpDocLinks"), PreferenceConstants.EDITOR_JAVADOC_LINKS_COLOR },
125       //$NON-NLS-1$
126       { PreferencesMessages.getString("JavaEditorPreferencePage.phpDocOthers"), PreferenceConstants.EDITOR_JAVADOC_DEFAULT_COLOR } //$NON-NLS-1$
127   };
128
129   private final String[][] fAppearanceColorListModel = new String[][] {
130       { PreferencesMessages.getString("JavaEditorPreferencePage.lineNumberForegroundColor"),
131           AbstractDecoratedTextEditorPreferenceConstants.EDITOR_LINE_NUMBER_RULER_COLOR },
132       //$NON-NLS-1$
133       { PreferencesMessages.getString("JavaEditorPreferencePage.matchingBracketsHighlightColor2"),
134           PreferenceConstants.EDITOR_MATCHING_BRACKETS_COLOR },
135       //$NON-NLS-1$
136       { PreferencesMessages.getString("JavaEditorPreferencePage.currentLineHighlighColor"),
137           AbstractDecoratedTextEditorPreferenceConstants.EDITOR_CURRENT_LINE_COLOR },
138       //$NON-NLS-1$
139       { PreferencesMessages.getString("JavaEditorPreferencePage.printMarginColor2"),
140           AbstractDecoratedTextEditorPreferenceConstants.EDITOR_PRINT_MARGIN_COLOR },
141       //$NON-NLS-1$
142       { PreferencesMessages.getString("JavaEditorPreferencePage.findScopeColor2"), PreferenceConstants.EDITOR_FIND_SCOPE_COLOR },
143       //$NON-NLS-1$
144       { PreferencesMessages.getString("JavaEditorPreferencePage.linkColor2"), PreferenceConstants.EDITOR_LINK_COLOR }, //$NON-NLS-1$
145   };
146
147   //  private final String[][] fAnnotationColorListModel;
148
149   //  private final String[][] fAnnotationDecorationListModel = new String[][]{
150   //      {
151   //          PreferencesMessages
152   //              .getString("JavaEditorPreferencePage.AnnotationDecoration.NONE"),
153   //          AnnotationPreference.STYLE_NONE},
154   //      //$NON-NLS-1$
155   //      {
156   //          PreferencesMessages
157   //              .getString("JavaEditorPreferencePage.AnnotationDecoration.SQUIGGLIES"),
158   //          AnnotationPreference.STYLE_SQUIGGLIES},
159   //      //$NON-NLS-1$
160   //      {
161   //          PreferencesMessages
162   //              .getString("JavaEditorPreferencePage.AnnotationDecoration.UNDERLINE"),
163   //          AnnotationPreference.STYLE_UNDERLINE},
164   //      //$NON-NLS-1$
165   //      {
166   //          PreferencesMessages
167   //              .getString("JavaEditorPreferencePage.AnnotationDecoration.BOX"),
168   //          AnnotationPreference.STYLE_BOX},
169   //      //$NON-NLS-1$
170   //      {
171   //          PreferencesMessages
172   //              .getString("JavaEditorPreferencePage.AnnotationDecoration.IBEAM"),
173   //          AnnotationPreference.STYLE_IBEAM} //$NON-NLS-1$
174   //  };
175   private OverlayPreferenceStore fOverlayStore;
176
177   private JavaTextTools fJavaTextTools;
178
179   private JavaEditorHoverConfigurationBlock fJavaEditorHoverConfigurationBlock;
180
181   private FoldingConfigurationBlock fFoldingConfigurationBlock;
182
183   private Map fColorButtons = new HashMap();
184
185   private Map fCheckBoxes = new HashMap();
186
187   private SelectionListener fCheckBoxListener = new SelectionListener() {
188     public void widgetDefaultSelected(SelectionEvent e) {
189     }
190
191     public void widgetSelected(SelectionEvent e) {
192       Button button = (Button) e.widget;
193       fOverlayStore.setValue((String) fCheckBoxes.get(button), button.getSelection());
194     }
195   };
196
197   private Map fTextFields = new HashMap();
198
199   private ModifyListener fTextFieldListener = new ModifyListener() {
200     public void modifyText(ModifyEvent e) {
201       Text text = (Text) e.widget;
202       fOverlayStore.setValue((String) fTextFields.get(text), text.getText());
203     }
204   };
205
206   private ArrayList fNumberFields = new ArrayList();
207
208   private ModifyListener fNumberFieldListener = new ModifyListener() {
209     public void modifyText(ModifyEvent e) {
210       numberFieldChanged((Text) e.widget);
211     }
212   };
213
214   private List fSyntaxColorList;
215
216   private List fAppearanceColorList;
217
218   //  private List fContentAssistColorList;
219   private List fAnnotationList;
220
221   private ColorEditor fSyntaxForegroundColorEditor;
222
223   private ColorEditor fAppearanceColorEditor;
224
225   private ColorEditor fAnnotationForegroundColorEditor;
226
227   private ColorEditor fContentAssistColorEditor;
228
229   private ColorEditor fBackgroundColorEditor;
230
231   private Button fBackgroundDefaultRadioButton;
232
233   private Button fBackgroundCustomRadioButton;
234
235   private Button fBackgroundColorButton;
236
237   private Button fBoldCheckBox;
238
239   //  private Button fAddJavaDocTagsButton;
240
241   private Button fEscapeStringsButtonDQ;
242   
243   private Button fEscapeStringsButtonSQ;
244
245   //    private Button fGuessMethodArgumentsButton;
246   private SourceViewer fPreviewViewer;
247
248   private Color fBackgroundColor;
249
250   private Control fAutoInsertDelayText;
251
252   private Control fAutoInsertJavaTriggerText;
253
254   private Control fAutoInsertJavaDocTriggerText;
255
256   private Label fAutoInsertDelayLabel;
257
258   private Label fAutoInsertJavaTriggerLabel;
259
260   private Label fAutoInsertJavaDocTriggerLabel;
261
262   private Button fShowInTextCheckBox;
263
264   private Combo fDecorationStyleCombo;
265
266   private Button fHighlightInTextCheckBox;
267
268   private Button fShowInOverviewRulerCheckBox;
269
270   private Button fShowInVerticalRulerCheckBox;
271
272   //    private Text fBrowserLikeLinksKeyModifierText;
273   //    private Button fBrowserLikeLinksCheckBox;
274   //    private StatusInfo fBrowserLikeLinksKeyModifierStatus;
275   //    private Button fCompletionInsertsRadioButton;
276   //    private Button fCompletionOverwritesRadioButton;
277   //    private Button fStickyOccurrencesButton;
278   /**
279    * Creates a new preference page.
280    */
281   public JavaEditorPreferencePage() {
282     setDescription(PreferencesMessages.getString("JavaEditorPreferencePage.description")); //$NON-NLS-1$
283     setPreferenceStore(PHPeclipsePlugin.getDefault().getPreferenceStore());
284     MarkerAnnotationPreferences markerAnnotationPreferences = new MarkerAnnotationPreferences();
285     fKeys = createOverlayStoreKeys(markerAnnotationPreferences);
286     fOverlayStore = new OverlayPreferenceStore(getPreferenceStore(), fKeys);
287     //    fAnnotationColorListModel =
288     // createAnnotationTypeListModel(markerAnnotationPreferences);
289   }
290
291   private OverlayPreferenceStore.OverlayKey[] createOverlayStoreKeys(MarkerAnnotationPreferences preferences) {
292     ArrayList overlayKeys = new ArrayList();
293     Iterator e = preferences.getAnnotationPreferences().iterator();
294     overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.STRING,
295         PreferenceConstants.EDITOR_FOREGROUND_COLOR));
296     overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN,
297         PreferenceConstants.EDITOR_FOREGROUND_DEFAULT_COLOR));
298     overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.STRING,
299         PreferenceConstants.EDITOR_BACKGROUND_COLOR));
300     overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN,
301         PreferenceConstants.EDITOR_BACKGROUND_DEFAULT_COLOR));
302     overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.INT, PreferenceConstants.EDITOR_TAB_WIDTH));
303     overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.STRING,
304         PreferenceConstants.EDITOR_MULTI_LINE_COMMENT_COLOR));
305     overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN,
306         PreferenceConstants.EDITOR_MULTI_LINE_COMMENT_BOLD));
307     overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.STRING,
308         PreferenceConstants.EDITOR_SINGLE_LINE_COMMENT_COLOR));
309     overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN,
310         PreferenceConstants.EDITOR_SINGLE_LINE_COMMENT_BOLD));
311     overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.STRING,
312         PreferenceConstants.EDITOR_JAVA_KEYWORD_COLOR));
313     overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN,
314         PreferenceConstants.EDITOR_JAVA_KEYWORD_BOLD));
315
316     overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.STRING, PreferenceConstants.EDITOR_PHP_TAG_COLOR));
317     overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, PreferenceConstants.EDITOR_PHP_TAG_BOLD));
318     overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.STRING,
319         PreferenceConstants.EDITOR_PHP_FUNCTIONNAME_COLOR));
320     overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN,
321         PreferenceConstants.EDITOR_PHP_FUNCTIONNAME_BOLD));
322     overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.STRING,
323         PreferenceConstants.EDITOR_PHP_VARIABLE_COLOR));
324     overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN,
325         PreferenceConstants.EDITOR_PHP_VARIABLE_BOLD));
326     overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.STRING,
327         PreferenceConstants.EDITOR_PHP_CONSTANT_COLOR));
328     overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN,
329         PreferenceConstants.EDITOR_PHP_CONSTANT_BOLD));
330     overlayKeys
331         .add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.STRING, PreferenceConstants.EDITOR_PHP_TYPE_COLOR));
332     overlayKeys
333         .add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, PreferenceConstants.EDITOR_PHP_TYPE_BOLD));
334
335     overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.STRING, PreferenceConstants.EDITOR_STRING_COLOR));
336     overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, PreferenceConstants.EDITOR_STRING_BOLD));
337     overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.STRING,
338         PreferenceConstants.EDITOR_JAVA_DEFAULT_COLOR));
339     overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN,
340         PreferenceConstants.EDITOR_JAVA_DEFAULT_BOLD));
341     overlayKeys
342         .add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.STRING, PreferenceConstants.EDITOR_TASK_TAG_COLOR));
343     overlayKeys
344         .add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, PreferenceConstants.EDITOR_TASK_TAG_BOLD));
345     //          overlayKeys.add(new
346     // OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.STRING,
347     // PreferenceConstants.EDITOR_JAVA_METHOD_NAME_COLOR));
348     //          overlayKeys.add(new
349     // OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN,
350     // PreferenceConstants.EDITOR_JAVA_METHOD_NAME_BOLD));
351     overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.STRING,
352         PreferenceConstants.EDITOR_PHP_OPERATOR_COLOR));
353     overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN,
354         PreferenceConstants.EDITOR_PHP_OPERATOR_BOLD));
355     overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.STRING,
356         PreferenceConstants.EDITOR_PHP_KEYWORD_RETURN_COLOR));
357     overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN,
358         PreferenceConstants.EDITOR_PHP_KEYWORD_RETURN_BOLD));
359     overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.STRING,
360         PreferenceConstants.EDITOR_JAVADOC_KEYWORD_COLOR));
361     overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN,
362         PreferenceConstants.EDITOR_JAVADOC_KEYWORD_BOLD));
363     overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.STRING,
364         PreferenceConstants.EDITOR_JAVADOC_TAG_COLOR));
365     overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN,
366         PreferenceConstants.EDITOR_JAVADOC_TAG_BOLD));
367     overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.STRING,
368         PreferenceConstants.EDITOR_JAVADOC_LINKS_COLOR));
369     overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN,
370         PreferenceConstants.EDITOR_JAVADOC_LINKS_BOLD));
371     overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.STRING,
372         PreferenceConstants.EDITOR_JAVADOC_DEFAULT_COLOR));
373     overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN,
374         PreferenceConstants.EDITOR_JAVADOC_DEFAULT_BOLD));
375     overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.STRING,
376         PreferenceConstants.EDITOR_MATCHING_BRACKETS_COLOR));
377     overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN,
378         PreferenceConstants.EDITOR_MATCHING_BRACKETS));
379     overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.STRING,
380         AbstractDecoratedTextEditorPreferenceConstants.EDITOR_CURRENT_LINE_COLOR));
381     overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN,
382         AbstractDecoratedTextEditorPreferenceConstants.EDITOR_CURRENT_LINE));
383     overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.STRING,
384         AbstractDecoratedTextEditorPreferenceConstants.EDITOR_PRINT_MARGIN_COLOR));
385     overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.INT,
386         AbstractDecoratedTextEditorPreferenceConstants.EDITOR_PRINT_MARGIN_COLUMN));
387     overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN,
388         AbstractDecoratedTextEditorPreferenceConstants.EDITOR_PRINT_MARGIN));
389     //          overlayKeys.add(new
390     // OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN,
391     // PreferenceConstants.EDITOR_MARK_OCCURRENCES));
392     //          overlayKeys.add(new
393     // OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN,
394     // PreferenceConstants.EDITOR_STICKY_OCCURRENCES));
395     overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.STRING,
396         PreferenceConstants.EDITOR_FIND_SCOPE_COLOR));
397     overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.STRING, PreferenceConstants.EDITOR_LINK_COLOR));
398     overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN,
399         PreferenceConstants.EDITOR_CORRECTION_INDICATION));
400     overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN,
401         PreferenceConstants.EDITOR_EVALUTE_TEMPORARY_PROBLEMS));
402     overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN,
403         AbstractDecoratedTextEditorPreferenceConstants.EDITOR_OVERVIEW_RULER));
404     overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.STRING,
405         AbstractDecoratedTextEditorPreferenceConstants.EDITOR_LINE_NUMBER_RULER_COLOR));
406     overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN,
407         AbstractDecoratedTextEditorPreferenceConstants.EDITOR_LINE_NUMBER_RULER));
408     overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN,
409         PreferenceConstants.EDITOR_SPACES_FOR_TABS));
410     overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN,
411         PreferenceConstants.CODEASSIST_AUTOACTIVATION));
412     overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.INT,
413         PreferenceConstants.CODEASSIST_AUTOACTIVATION_DELAY));
414     overlayKeys
415         .add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, PreferenceConstants.CODEASSIST_AUTOINSERT));
416     overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.STRING,
417         PreferenceConstants.CODEASSIST_PROPOSALS_BACKGROUND));
418     overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.STRING,
419         PreferenceConstants.CODEASSIST_PROPOSALS_FOREGROUND));
420     overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.STRING,
421         PreferenceConstants.CODEASSIST_PARAMETERS_BACKGROUND));
422     overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.STRING,
423         PreferenceConstants.CODEASSIST_PARAMETERS_FOREGROUND));
424     overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.STRING,
425         PreferenceConstants.CODEASSIST_REPLACEMENT_BACKGROUND));
426     overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.STRING,
427         PreferenceConstants.CODEASSIST_REPLACEMENT_FOREGROUND));
428     overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.STRING,
429         PreferenceConstants.CODEASSIST_AUTOACTIVATION_TRIGGERS_JAVA));
430     overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.STRING,
431         PreferenceConstants.CODEASSIST_AUTOACTIVATION_TRIGGERS_JAVADOC));
432     overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN,
433         PreferenceConstants.CODEASSIST_SHOW_VISIBLE_PROPOSALS));
434     overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN,
435         PreferenceConstants.CODEASSIST_ORDER_PROPOSALS));
436     overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN,
437         PreferenceConstants.CODEASSIST_CASE_SENSITIVITY));
438     overlayKeys
439         .add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, PreferenceConstants.CODEASSIST_ADDIMPORT));
440     overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN,
441         PreferenceConstants.CODEASSIST_INSERT_COMPLETION));
442     overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN,
443         PreferenceConstants.CODEASSIST_FILL_ARGUMENT_NAMES));
444     overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN,
445         PreferenceConstants.CODEASSIST_GUESS_METHOD_ARGUMENTS));
446     overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, PreferenceConstants.EDITOR_SMART_PASTE));
447     overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN,
448         PreferenceConstants.EDITOR_CLOSE_STRINGS_DQ_PHP));
449     overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN,
450         PreferenceConstants.EDITOR_CLOSE_STRINGS_SQ_PHP));
451     overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN,
452         PreferenceConstants.EDITOR_CLOSE_BRACKETS_PHP));
453     //    overlayKeys
454     //        .add(new OverlayPreferenceStore.OverlayKey(
455     //            OverlayPreferenceStore.BOOLEAN,
456     //            PreferenceConstants.EDITOR_CLOSE_BRACES));
457     //    overlayKeys.add(new OverlayPreferenceStore.OverlayKey(
458     //        OverlayPreferenceStore.BOOLEAN,
459     //        PreferenceConstants.EDITOR_CLOSE_JAVADOCS));
460     overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, PreferenceConstants.EDITOR_WRAP_STRINGS_DQ));
461     overlayKeys
462         .add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, PreferenceConstants.EDITOR_ESCAPE_STRINGS_DQ));
463     overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, PreferenceConstants.EDITOR_WRAP_STRINGS_SQ));
464     overlayKeys
465         .add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, PreferenceConstants.EDITOR_ESCAPE_STRINGS_SQ));
466     
467     overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN,
468         PreferenceConstants.EDITOR_ADD_JAVADOC_TAGS));
469     overlayKeys
470         .add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, PreferenceConstants.EDITOR_SMART_HOME_END));
471     overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN,
472         PreferenceConstants.EDITOR_SUB_WORD_NAVIGATION));
473     overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN,
474         PreferenceConstants.EDITOR_DISABLE_OVERWRITE_MODE));
475     //          overlayKeys.add(new
476     // OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN,
477     // PreferenceConstants.EDITOR_SHOW_TEXT_HOVER_AFFORDANCE));
478     overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.STRING,
479         PreferenceConstants.EDITOR_TEXT_HOVER_MODIFIERS));
480     overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.STRING,
481         PreferenceConstants.EDITOR_TEXT_HOVER_MODIFIER_MASKS));
482     overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN,
483         PreferenceConstants.EDITOR_BROWSER_LIKE_LINKS));
484     overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.STRING,
485         PreferenceConstants.EDITOR_BROWSER_LIKE_LINKS_KEY_MODIFIER));
486     overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.STRING,
487         PreferenceConstants.EDITOR_BROWSER_LIKE_LINKS_KEY_MODIFIER_MASK));
488     while (e.hasNext()) {
489       AnnotationPreference info = (AnnotationPreference) e.next();
490       overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.STRING, info.getColorPreferenceKey()));
491       overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, info.getTextPreferenceKey()));
492       if (info.getHighlightPreferenceKey() != null)
493         overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, info.getHighlightPreferenceKey()));
494       overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, info.getOverviewRulerPreferenceKey()));
495       if (info.getVerticalRulerPreferenceKey() != null)
496         overlayKeys
497             .add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, info.getVerticalRulerPreferenceKey()));
498       if (info.getTextStylePreferenceKey() != null)
499         overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.STRING, info.getTextStylePreferenceKey()));
500     }
501     OverlayPreferenceStore.OverlayKey[] keys = new OverlayPreferenceStore.OverlayKey[overlayKeys.size()];
502     overlayKeys.toArray(keys);
503     return keys;
504   } /*
505      * @see IWorkbenchPreferencePage#init()
506      */
507
508   public void init(IWorkbench workbench) {
509   }
510
511   /*
512    * @see PreferencePage#createControl(Composite)
513    */
514   public void createControl(Composite parent) {
515     super.createControl(parent);
516     WorkbenchHelp.setHelp(getControl(), IJavaHelpContextIds.JAVA_EDITOR_PREFERENCE_PAGE);
517   }
518
519   private void handleSyntaxColorListSelection() {
520     int i = fSyntaxColorList.getSelectionIndex();
521     String key = fSyntaxColorListModel[i][1];
522     RGB rgb = PreferenceConverter.getColor(fOverlayStore, key);
523     fSyntaxForegroundColorEditor.setColorValue(rgb);
524     fBoldCheckBox.setSelection(fOverlayStore.getBoolean(key + BOLD));
525   }
526
527   private void handleAppearanceColorListSelection() {
528     int i = fAppearanceColorList.getSelectionIndex();
529     String key = fAppearanceColorListModel[i][1];
530     RGB rgb = PreferenceConverter.getColor(fOverlayStore, key);
531     fAppearanceColorEditor.setColorValue(rgb);
532   }
533
534   //  private void handleAnnotationListSelection() {
535   //    int i = fAnnotationList.getSelectionIndex();
536   //    String key = fAnnotationColorListModel[i][1];
537   //    RGB rgb = PreferenceConverter.getColor(fOverlayStore, key);
538   //    fAnnotationForegroundColorEditor.setColorValue(rgb);
539   //    key = fAnnotationColorListModel[i][2];
540   //    boolean showInText = fOverlayStore.getBoolean(key);
541   //    fShowInTextCheckBox.setSelection(showInText);
542   //    key = fAnnotationColorListModel[i][6];
543   //    if (key != null) {
544   //      fDecorationStyleCombo.setEnabled(showInText);
545   //      for (int j = 0; j < fAnnotationDecorationListModel.length; j++) {
546   //        String value = fOverlayStore.getString(key);
547   //        if (fAnnotationDecorationListModel[j][1].equals(value)) {
548   //          fDecorationStyleCombo.setText(fAnnotationDecorationListModel[j][0]);
549   //          break;
550   //        }
551   //      }
552   //    } else {
553   //      fDecorationStyleCombo.setEnabled(false);
554   //      fDecorationStyleCombo.setText(fAnnotationDecorationListModel[1][0]); // set
555   //                                                                           // selection
556   //                                                                           // to
557   //                                                                           // squigglies
558   //                                                                           // if
559   //                                                                           // the
560   //                                                                           // key
561   //                                                                           // is
562   //                                                                           // not
563   //                                                                           // there
564   //                                                                           // (legacy
565   //                                                                           // support)
566   //    }
567   //    key = fAnnotationColorListModel[i][3];
568   //    fShowInOverviewRulerCheckBox.setSelection(fOverlayStore.getBoolean(key));
569   //    key = fAnnotationColorListModel[i][4];
570   //    if (key != null) {
571   //      fHighlightInTextCheckBox.setSelection(fOverlayStore.getBoolean(key));
572   //      fHighlightInTextCheckBox.setEnabled(true);
573   //    } else
574   //      fHighlightInTextCheckBox.setEnabled(false);
575   //    key = fAnnotationColorListModel[i][5];
576   //    if (key != null) {
577   //      fShowInVerticalRulerCheckBox.setSelection(fOverlayStore.getBoolean(key));
578   //      fShowInVerticalRulerCheckBox.setEnabled(true);
579   //    } else {
580   //      fShowInVerticalRulerCheckBox.setSelection(true);
581   //      fShowInVerticalRulerCheckBox.setEnabled(false);
582   //    }
583   //  }
584   private Control createSyntaxPage(Composite parent) {
585     Composite colorComposite = new Composite(parent, SWT.NULL);
586     colorComposite.setLayout(new GridLayout());
587     Group backgroundComposite = new Group(colorComposite, SWT.SHADOW_ETCHED_IN);
588     backgroundComposite.setLayout(new RowLayout());
589     backgroundComposite.setText(PreferencesMessages.getString("JavaEditorPreferencePage.backgroundColor"));//$NON-NLS-1$
590     SelectionListener backgroundSelectionListener = new SelectionListener() {
591       public void widgetSelected(SelectionEvent e) {
592         boolean custom = fBackgroundCustomRadioButton.getSelection();
593         fBackgroundColorButton.setEnabled(custom);
594         fOverlayStore.setValue(PreferenceConstants.EDITOR_BACKGROUND_DEFAULT_COLOR, !custom);
595       }
596
597       public void widgetDefaultSelected(SelectionEvent e) {
598       }
599     };
600     fBackgroundDefaultRadioButton = new Button(backgroundComposite, SWT.RADIO | SWT.LEFT);
601     fBackgroundDefaultRadioButton.setText(PreferencesMessages.getString("JavaEditorPreferencePage.systemDefault")); //$NON-NLS-1$
602     fBackgroundDefaultRadioButton.addSelectionListener(backgroundSelectionListener);
603     fBackgroundCustomRadioButton = new Button(backgroundComposite, SWT.RADIO | SWT.LEFT);
604     fBackgroundCustomRadioButton.setText(PreferencesMessages.getString("JavaEditorPreferencePage.custom")); //$NON-NLS-1$
605     fBackgroundCustomRadioButton.addSelectionListener(backgroundSelectionListener);
606     fBackgroundColorEditor = new ColorEditor(backgroundComposite);
607     fBackgroundColorButton = fBackgroundColorEditor.getButton();
608     Label label = new Label(colorComposite, SWT.LEFT);
609     label.setText(PreferencesMessages.getString("JavaEditorPreferencePage.foreground")); //$NON-NLS-1$
610     label.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
611     Composite editorComposite = new Composite(colorComposite, SWT.NONE);
612     GridLayout layout = new GridLayout();
613     layout.numColumns = 2;
614     layout.marginHeight = 0;
615     layout.marginWidth = 0;
616     editorComposite.setLayout(layout);
617     GridData gd = new GridData(GridData.FILL_BOTH);
618     editorComposite.setLayoutData(gd);
619     fSyntaxColorList = new List(editorComposite, SWT.SINGLE | SWT.V_SCROLL | SWT.BORDER);
620     gd = new GridData(GridData.FILL_BOTH);
621     gd.heightHint = convertHeightInCharsToPixels(5);
622     fSyntaxColorList.setLayoutData(gd);
623     Composite stylesComposite = new Composite(editorComposite, SWT.NONE);
624     layout = new GridLayout();
625     layout.marginHeight = 0;
626     layout.marginWidth = 0;
627     layout.numColumns = 2;
628     stylesComposite.setLayout(layout);
629     stylesComposite.setLayoutData(new GridData(GridData.FILL_BOTH));
630     label = new Label(stylesComposite, SWT.LEFT);
631     label.setText(PreferencesMessages.getString("JavaEditorPreferencePage.color")); //$NON-NLS-1$
632     gd = new GridData();
633     gd.horizontalAlignment = GridData.BEGINNING;
634     label.setLayoutData(gd);
635     fSyntaxForegroundColorEditor = new ColorEditor(stylesComposite);
636     Button foregroundColorButton = fSyntaxForegroundColorEditor.getButton();
637     gd = new GridData(GridData.FILL_HORIZONTAL);
638     gd.horizontalAlignment = GridData.BEGINNING;
639     foregroundColorButton.setLayoutData(gd);
640     fBoldCheckBox = new Button(stylesComposite, SWT.CHECK);
641     fBoldCheckBox.setText(PreferencesMessages.getString("JavaEditorPreferencePage.bold")); //$NON-NLS-1$
642     gd = new GridData(GridData.FILL_HORIZONTAL);
643     gd.horizontalAlignment = GridData.BEGINNING;
644     gd.horizontalSpan = 2;
645     fBoldCheckBox.setLayoutData(gd);
646     label = new Label(colorComposite, SWT.LEFT);
647     label.setText(PreferencesMessages.getString("JavaEditorPreferencePage.preview")); //$NON-NLS-1$
648     label.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
649     Control previewer = createPreviewer(colorComposite);
650     gd = new GridData(GridData.FILL_BOTH);
651     gd.widthHint = convertWidthInCharsToPixels(20);
652     gd.heightHint = convertHeightInCharsToPixels(5);
653     previewer.setLayoutData(gd);
654     fSyntaxColorList.addSelectionListener(new SelectionListener() {
655       public void widgetDefaultSelected(SelectionEvent e) {
656         // do nothing
657       }
658
659       public void widgetSelected(SelectionEvent e) {
660         handleSyntaxColorListSelection();
661       }
662     });
663     foregroundColorButton.addSelectionListener(new SelectionListener() {
664       public void widgetDefaultSelected(SelectionEvent e) {
665         // do nothing
666       }
667
668       public void widgetSelected(SelectionEvent e) {
669         int i = fSyntaxColorList.getSelectionIndex();
670         String key = fSyntaxColorListModel[i][1];
671         PreferenceConverter.setValue(fOverlayStore, key, fSyntaxForegroundColorEditor.getColorValue());
672       }
673     });
674     fBackgroundColorButton.addSelectionListener(new SelectionListener() {
675       public void widgetDefaultSelected(SelectionEvent e) {
676         // do nothing
677       }
678
679       public void widgetSelected(SelectionEvent e) {
680         PreferenceConverter.setValue(fOverlayStore, PreferenceConstants.EDITOR_BACKGROUND_COLOR, fBackgroundColorEditor
681             .getColorValue());
682       }
683     });
684     fBoldCheckBox.addSelectionListener(new SelectionListener() {
685       public void widgetDefaultSelected(SelectionEvent e) {
686         // do nothing
687       }
688
689       public void widgetSelected(SelectionEvent e) {
690         int i = fSyntaxColorList.getSelectionIndex();
691         String key = fSyntaxColorListModel[i][1];
692         fOverlayStore.setValue(key + BOLD, fBoldCheckBox.getSelection());
693       }
694     });
695     return colorComposite;
696   }
697
698   private Control createPreviewer(Composite parent) {
699     Preferences coreStore = createTemporaryCorePreferenceStore();
700     fJavaTextTools = new JavaTextTools(fOverlayStore, coreStore, false);
701     IPreferenceStore generalTextStore = EditorsUI.getPreferenceStore();
702     IPreferenceStore store = new ChainedPreferenceStore(new IPreferenceStore[] { fOverlayStore,
703         new PreferencesAdapter(createTemporaryCorePreferenceStore()), generalTextStore });
704
705     fPreviewViewer = new JavaSourceViewer(parent, null, null, false, SWT.V_SCROLL | SWT.H_SCROLL | SWT.BORDER, store);
706     JavaTextTools tools= PHPeclipsePlugin.getDefault().getJavaTextTools();
707         PHPSourceViewerConfiguration configuration= new PHPSourceViewerConfiguration(tools.getColorManager(), store, null, IPHPPartitions.PHP_PARTITIONING);
708 //    PHPSourceViewerConfiguration configuration =new PHPSourceViewerConfiguration(fJavaTextTools, null, IPHPPartitions.PHP_PARTITIONING);
709     fPreviewViewer.configure(configuration);
710      
711     Font font= JFaceResources.getFont(PreferenceConstants.EDITOR_TEXT_FONT);
712         fPreviewViewer.getTextWidget().setFont(font);
713     new JavaSourcePreviewerUpdater(fPreviewViewer, configuration, store);
714         fPreviewViewer.setEditable(false);
715     String content = loadPreviewContentFromFile("ColorSettingPreviewCode.txt"); //$NON-NLS-1$
716     IDocument document = new Document(content);
717     fJavaTextTools.setupJavaDocumentPartitioner(document, IPHPPartitions.PHP_PARTITIONING);
718     fPreviewViewer.setDocument(document);
719     return fPreviewViewer.getControl();
720   }
721
722   private Preferences createTemporaryCorePreferenceStore() {
723     Preferences result = new Preferences();
724     result.setValue(COMPILER_TASK_TAGS, "TASK"); //$NON-NLS-1$
725     return result;
726   }
727
728   private Control createAppearancePage(Composite parent) {
729     Composite appearanceComposite = new Composite(parent, SWT.NONE);
730     GridLayout layout = new GridLayout();
731     layout.numColumns = 2;
732     appearanceComposite.setLayout(layout);
733     String label = PreferencesMessages.getString("JavaEditorPreferencePage.displayedTabWidth"); //$NON-NLS-1$
734     addTextField(appearanceComposite, label, PreferenceConstants.EDITOR_TAB_WIDTH, 3, 0, true);
735     label = PreferencesMessages.getString("JavaEditorPreferencePage.printMarginColumn"); //$NON-NLS-1$
736     addTextField(appearanceComposite, label, AbstractDecoratedTextEditorPreferenceConstants.EDITOR_PRINT_MARGIN_COLUMN, 3, 0, true);
737     label = PreferencesMessages.getString("JavaEditorPreferencePage.showOverviewRuler"); //$NON-NLS-1$
738     addCheckBox(appearanceComposite, label, AbstractDecoratedTextEditorPreferenceConstants.EDITOR_OVERVIEW_RULER, 0);
739     label = PreferencesMessages.getString("JavaEditorPreferencePage.showLineNumbers"); //$NON-NLS-1$
740     addCheckBox(appearanceComposite, label, AbstractDecoratedTextEditorPreferenceConstants.EDITOR_LINE_NUMBER_RULER, 0);
741     label = PreferencesMessages.getString("JavaEditorPreferencePage.highlightMatchingBrackets"); //$NON-NLS-1$
742     addCheckBox(appearanceComposite, label, PreferenceConstants.EDITOR_MATCHING_BRACKETS, 0);
743     label = PreferencesMessages.getString("JavaEditorPreferencePage.highlightCurrentLine"); //$NON-NLS-1$
744     addCheckBox(appearanceComposite, label, AbstractDecoratedTextEditorPreferenceConstants.EDITOR_CURRENT_LINE, 0);
745     label = PreferencesMessages.getString("JavaEditorPreferencePage.showPrintMargin"); //$NON-NLS-1$
746     addCheckBox(appearanceComposite, label, AbstractDecoratedTextEditorPreferenceConstants.EDITOR_PRINT_MARGIN, 0);
747     label = PreferencesMessages.getString("JavaEditorPreferencePage.markOccurrences"); //$NON-NLS-1$
748     //          Button master= addCheckBox(appearanceComposite, label,
749     // PreferenceConstants.EDITOR_MARK_OCCURRENCES, 0); //$NON-NLS-1$
750     label = PreferencesMessages.getString("JavaEditorPreferencePage.stickyOccurrences"); //$NON-NLS-1$
751     //          fStickyOccurrencesButton= addCheckBox(appearanceComposite, label,
752     // PreferenceConstants.EDITOR_STICKY_OCCURRENCES, 0); //$NON-NLS-1$
753     //          createDependency(master, fStickyOccurrencesButton);
754     Label l = new Label(appearanceComposite, SWT.LEFT);
755     GridData gd = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
756     gd.horizontalSpan = 2;
757     gd.heightHint = convertHeightInCharsToPixels(1) / 2;
758     l.setLayoutData(gd);
759     l = new Label(appearanceComposite, SWT.LEFT);
760     l.setText(PreferencesMessages.getString("JavaEditorPreferencePage.appearanceOptions")); //$NON-NLS-1$
761     gd = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
762     gd.horizontalSpan = 2;
763     l.setLayoutData(gd);
764     Composite editorComposite = new Composite(appearanceComposite, SWT.NONE);
765     layout = new GridLayout();
766     layout.numColumns = 2;
767     layout.marginHeight = 0;
768     layout.marginWidth = 0;
769     editorComposite.setLayout(layout);
770     gd = new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.FILL_VERTICAL);
771     gd.horizontalSpan = 2;
772     editorComposite.setLayoutData(gd);
773     fAppearanceColorList = new List(editorComposite, SWT.SINGLE | SWT.V_SCROLL | SWT.BORDER);
774     gd = new GridData(GridData.VERTICAL_ALIGN_BEGINNING | GridData.FILL_HORIZONTAL);
775     gd.heightHint = convertHeightInCharsToPixels(8);
776     fAppearanceColorList.setLayoutData(gd);
777     Composite stylesComposite = new Composite(editorComposite, SWT.NONE);
778     layout = new GridLayout();
779     layout.marginHeight = 0;
780     layout.marginWidth = 0;
781     layout.numColumns = 2;
782     stylesComposite.setLayout(layout);
783     stylesComposite.setLayoutData(new GridData(GridData.FILL_BOTH));
784     l = new Label(stylesComposite, SWT.LEFT);
785     l.setText(PreferencesMessages.getString("JavaEditorPreferencePage.color")); //$NON-NLS-1$
786     gd = new GridData();
787     gd.horizontalAlignment = GridData.BEGINNING;
788     l.setLayoutData(gd);
789     fAppearanceColorEditor = new ColorEditor(stylesComposite);
790     Button foregroundColorButton = fAppearanceColorEditor.getButton();
791     gd = new GridData(GridData.FILL_HORIZONTAL);
792     gd.horizontalAlignment = GridData.BEGINNING;
793     foregroundColorButton.setLayoutData(gd);
794     fAppearanceColorList.addSelectionListener(new SelectionListener() {
795       public void widgetDefaultSelected(SelectionEvent e) {
796         // do nothing
797       }
798
799       public void widgetSelected(SelectionEvent e) {
800         handleAppearanceColorListSelection();
801       }
802     });
803     foregroundColorButton.addSelectionListener(new SelectionListener() {
804       public void widgetDefaultSelected(SelectionEvent e) {
805         // do nothing
806       }
807
808       public void widgetSelected(SelectionEvent e) {
809         int i = fAppearanceColorList.getSelectionIndex();
810         String key = fAppearanceColorListModel[i][1];
811         PreferenceConverter.setValue(fOverlayStore, key, fAppearanceColorEditor.getColorValue());
812       }
813     });
814     return appearanceComposite;
815   }
816
817   //  private Control createAnnotationsPage(Composite parent) {
818   //    Composite composite = new Composite(parent, SWT.NULL);
819   //    GridLayout layout = new GridLayout();
820   //    layout.numColumns = 2;
821   //    composite.setLayout(layout);
822   //    String text = PreferencesMessages
823   //        .getString("JavaEditorPreferencePage.analyseAnnotationsWhileTyping");
824   // //$NON-NLS-1$
825   //    addCheckBox(composite, text,
826   //        PreferenceConstants.EDITOR_EVALUTE_TEMPORARY_PROBLEMS, 0);
827   //    text = PreferencesMessages
828   //        .getString("JavaEditorPreferencePage.showQuickFixables"); //$NON-NLS-1$
829   //    addCheckBox(composite, text,
830   //        PreferenceConstants.EDITOR_CORRECTION_INDICATION, 0);
831   //    addFiller(composite);
832   //    Label label = new Label(composite, SWT.LEFT);
833   //    label.setText(PreferencesMessages
834   //        .getString("JavaEditorPreferencePage.annotationPresentationOptions"));
835   // //$NON-NLS-1$
836   //    GridData gd = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
837   //    gd.horizontalSpan = 2;
838   //    label.setLayoutData(gd);
839   //    Composite editorComposite = new Composite(composite, SWT.NONE);
840   //    layout = new GridLayout();
841   //    layout.numColumns = 2;
842   //    layout.marginHeight = 0;
843   //    layout.marginWidth = 0;
844   //    editorComposite.setLayout(layout);
845   //    gd = new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.FILL_VERTICAL);
846   //    gd.horizontalSpan = 2;
847   //    editorComposite.setLayoutData(gd);
848   //    fAnnotationList = new List(editorComposite, SWT.SINGLE | SWT.V_SCROLL
849   //        | SWT.BORDER);
850   //    gd = new GridData(GridData.VERTICAL_ALIGN_BEGINNING
851   //        | GridData.FILL_HORIZONTAL);
852   //    gd.heightHint = convertHeightInCharsToPixels(10);
853   //    fAnnotationList.setLayoutData(gd);
854   //    Composite optionsComposite = new Composite(editorComposite, SWT.NONE);
855   //    layout = new GridLayout();
856   //    layout.marginHeight = 0;
857   //    layout.marginWidth = 0;
858   //    layout.numColumns = 2;
859   //    optionsComposite.setLayout(layout);
860   //    optionsComposite.setLayoutData(new GridData(GridData.FILL_BOTH));
861   //    fShowInTextCheckBox = new Button(optionsComposite, SWT.CHECK);
862   //    fShowInTextCheckBox.setText(PreferencesMessages
863   //        .getString("JavaEditorPreferencePage.annotations.showInText"));
864   // //$NON-NLS-1$
865   //    gd = new GridData(GridData.FILL_HORIZONTAL);
866   //    gd.horizontalAlignment = GridData.BEGINNING;
867   //    gd.horizontalSpan = 2;
868   //    fShowInTextCheckBox.setLayoutData(gd);
869   //    fDecorationStyleCombo = new Combo(optionsComposite, SWT.READ_ONLY);
870   //    for (int i = 0; i < fAnnotationDecorationListModel.length; i++)
871   //      fDecorationStyleCombo.add(fAnnotationDecorationListModel[i][0]);
872   //    gd = new GridData(GridData.FILL_HORIZONTAL);
873   //    gd.horizontalAlignment = GridData.BEGINNING;
874   //    gd.horizontalSpan = 2;
875   //    gd.horizontalIndent = 20;
876   //    fDecorationStyleCombo.setLayoutData(gd);
877   //    fHighlightInTextCheckBox = new Button(optionsComposite, SWT.CHECK);
878   //    fHighlightInTextCheckBox.setText(PreferencesMessages
879   //        .getString("TextEditorPreferencePage.annotations.highlightInText"));
880   // //$NON-NLS-1$
881   //    gd = new GridData(GridData.FILL_HORIZONTAL);
882   //    gd.horizontalAlignment = GridData.BEGINNING;
883   //    gd.horizontalSpan = 2;
884   //    fHighlightInTextCheckBox.setLayoutData(gd);
885   //    fShowInOverviewRulerCheckBox = new Button(optionsComposite, SWT.CHECK);
886   //    fShowInOverviewRulerCheckBox.setText(PreferencesMessages
887   //        .getString("JavaEditorPreferencePage.annotations.showInOverviewRuler"));
888   // //$NON-NLS-1$
889   //    gd = new GridData(GridData.FILL_HORIZONTAL);
890   //    gd.horizontalAlignment = GridData.BEGINNING;
891   //    gd.horizontalSpan = 2;
892   //    fShowInOverviewRulerCheckBox.setLayoutData(gd);
893   //    fShowInVerticalRulerCheckBox = new Button(optionsComposite, SWT.CHECK);
894   //    fShowInVerticalRulerCheckBox.setText(PreferencesMessages
895   //        .getString("JavaEditorPreferencePage.annotations.showInVerticalRuler"));
896   // //$NON-NLS-1$
897   //    gd = new GridData(GridData.FILL_HORIZONTAL);
898   //    gd.horizontalAlignment = GridData.BEGINNING;
899   //    gd.horizontalSpan = 2;
900   //    fShowInVerticalRulerCheckBox.setLayoutData(gd);
901   //    label = new Label(optionsComposite, SWT.LEFT);
902   //    label.setText(PreferencesMessages
903   //        .getString("JavaEditorPreferencePage.annotations.color")); //$NON-NLS-1$
904   //    gd = new GridData();
905   //    gd.horizontalAlignment = GridData.BEGINNING;
906   //    label.setLayoutData(gd);
907   //    fAnnotationForegroundColorEditor = new ColorEditor(optionsComposite);
908   //    Button foregroundColorButton =
909   // fAnnotationForegroundColorEditor.getButton();
910   //    gd = new GridData(GridData.FILL_HORIZONTAL);
911   //    gd.horizontalAlignment = GridData.BEGINNING;
912   //    foregroundColorButton.setLayoutData(gd);
913   //    fAnnotationList.addSelectionListener(new SelectionListener() {
914   //      public void widgetDefaultSelected(SelectionEvent e) {
915   //        // do nothing
916   //      }
917   //      public void widgetSelected(SelectionEvent e) {
918   //        handleAnnotationListSelection();
919   //      }
920   //    });
921   //    fShowInTextCheckBox.addSelectionListener(new SelectionListener() {
922   //      public void widgetDefaultSelected(SelectionEvent e) {
923   //        // do nothing
924   //      }
925   //      public void widgetSelected(SelectionEvent e) {
926   //        int i = fAnnotationList.getSelectionIndex();
927   //        String key = fAnnotationColorListModel[i][2];
928   //        fOverlayStore.setValue(key, fShowInTextCheckBox.getSelection());
929   //        String decorationKey = fAnnotationColorListModel[i][6];
930   //        fDecorationStyleCombo.setEnabled(decorationKey != null
931   //            && fShowInTextCheckBox.getSelection());
932   //      }
933   //    });
934   //    fHighlightInTextCheckBox.addSelectionListener(new SelectionListener() {
935   //      public void widgetDefaultSelected(SelectionEvent e) {
936   //        // do nothing
937   //      }
938   //      public void widgetSelected(SelectionEvent e) {
939   //        int i = fAnnotationList.getSelectionIndex();
940   //        String key = fAnnotationColorListModel[i][4];
941   //        fOverlayStore.setValue(key, fHighlightInTextCheckBox.getSelection());
942   //      }
943   //    });
944   //    fShowInOverviewRulerCheckBox.addSelectionListener(new SelectionListener() {
945   //      public void widgetDefaultSelected(SelectionEvent e) {
946   //        // do nothing
947   //      }
948   //      public void widgetSelected(SelectionEvent e) {
949   //        int i = fAnnotationList.getSelectionIndex();
950   //        String key = fAnnotationColorListModel[i][3];
951   //        fOverlayStore
952   //            .setValue(key, fShowInOverviewRulerCheckBox.getSelection());
953   //      }
954   //    });
955   //    fShowInVerticalRulerCheckBox.addSelectionListener(new SelectionListener() {
956   //      public void widgetDefaultSelected(SelectionEvent e) {
957   //        // do nothing
958   //      }
959   //      public void widgetSelected(SelectionEvent e) {
960   //        int i = fAnnotationList.getSelectionIndex();
961   //        String key = fAnnotationColorListModel[i][5];
962   //        fOverlayStore
963   //            .setValue(key, fShowInVerticalRulerCheckBox.getSelection());
964   //      }
965   //    });
966   //    foregroundColorButton.addSelectionListener(new SelectionListener() {
967   //      public void widgetDefaultSelected(SelectionEvent e) {
968   //        // do nothing
969   //      }
970   //      public void widgetSelected(SelectionEvent e) {
971   //        int i = fAnnotationList.getSelectionIndex();
972   //        String key = fAnnotationColorListModel[i][1];
973   //        PreferenceConverter.setValue(fOverlayStore, key,
974   //            fAnnotationForegroundColorEditor.getColorValue());
975   //      }
976   //    });
977   //    fDecorationStyleCombo.addSelectionListener(new SelectionListener() {
978   //      /**
979   //       * {@inheritdoc}
980   //       */
981   //      public void widgetDefaultSelected(SelectionEvent e) {
982   //        // do nothing
983   //      }
984   //      /**
985   //       * {@inheritdoc}
986   //       */
987   //      public void widgetSelected(SelectionEvent e) {
988   //        int i = fAnnotationList.getSelectionIndex();
989   //        String key = fAnnotationColorListModel[i][6];
990   //        if (key != null) {
991   //          for (int j = 0; j < fAnnotationDecorationListModel.length; j++) {
992   //            if (fAnnotationDecorationListModel[j][0]
993   //                .equals(fDecorationStyleCombo.getText())) {
994   //              fOverlayStore.setValue(key, fAnnotationDecorationListModel[j][1]);
995   //              break;
996   //            }
997   //          }
998   //        }
999   //      }
1000   //    });
1001   //    return composite;
1002   //  }
1003   private String[][] createAnnotationTypeListModel(MarkerAnnotationPreferences preferences) {
1004     ArrayList listModelItems = new ArrayList();
1005     SortedSet sortedPreferences = new TreeSet(new Comparator() {
1006       /*
1007        * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
1008        */
1009       public int compare(Object o1, Object o2) {
1010         if (!(o2 instanceof AnnotationPreference))
1011           return -1;
1012         if (!(o1 instanceof AnnotationPreference))
1013           return 1;
1014         AnnotationPreference a1 = (AnnotationPreference) o1;
1015         AnnotationPreference a2 = (AnnotationPreference) o2;
1016         return Collator.getInstance().compare(a1.getPreferenceLabel(), a2.getPreferenceLabel());
1017       }
1018     });
1019     sortedPreferences.addAll(preferences.getAnnotationPreferences());
1020     Iterator e = sortedPreferences.iterator();
1021     while (e.hasNext()) {
1022       AnnotationPreference info = (AnnotationPreference) e.next();
1023       listModelItems.add(new String[] { info.getPreferenceLabel(), info.getColorPreferenceKey(), info.getTextPreferenceKey(),
1024           info.getOverviewRulerPreferenceKey(), info.getHighlightPreferenceKey(), info.getVerticalRulerPreferenceKey(),
1025           info.getTextStylePreferenceKey() });
1026     }
1027     String[][] items = new String[listModelItems.size()][];
1028     listModelItems.toArray(items);
1029     return items;
1030   }
1031
1032   private Control createTypingPage(Composite parent) {
1033     Composite composite = new Composite(parent, SWT.NONE);
1034     GridLayout layout = new GridLayout();
1035     layout.numColumns = 1;
1036     composite.setLayout(layout);
1037     String label;
1038     //    label = PreferencesMessages
1039     //        .getString("JavaEditorPreferencePage.overwriteMode");
1040     //    //$NON-NLS-1$
1041     //    addCheckBox(composite, label,
1042     //        PreferenceConstants.EDITOR_DISABLE_OVERWRITE_MODE, 1);
1043     //    addFiller(composite);
1044     //
1045     //    label = PreferencesMessages
1046     //        .getString("JavaEditorPreferencePage.smartHomeEnd");
1047     //    //$NON-NLS-1$
1048     //    addCheckBox(composite, label, PreferenceConstants.EDITOR_SMART_HOME_END, 1);
1049     //
1050     //    label = PreferencesMessages
1051     //        .getString("JavaEditorPreferencePage.subWordNavigation");
1052     //    //$NON-NLS-1$
1053     //    addCheckBox(composite, label,
1054     //        PreferenceConstants.EDITOR_SUB_WORD_NAVIGATION, 1);
1055     //    addFiller(composite);
1056     Group group = new Group(composite, SWT.NONE);
1057     layout = new GridLayout();
1058     layout.numColumns = 2;
1059     group.setLayout(layout);
1060     group.setText(PreferencesMessages.getString("JavaEditorPreferencePage.typing.description")); //$NON-NLS-1$
1061
1062     label = PreferencesMessages.getString("JavaEditorPreferencePage.wrapStringsDQ");//$NON-NLS-1$
1063     Button button = addCheckBox(group, label, PreferenceConstants.EDITOR_WRAP_STRINGS_DQ, 1);
1064
1065     label = PreferencesMessages.getString("JavaEditorPreferencePage.escapeStringsDQ");//$NON-NLS-1$
1066     fEscapeStringsButtonDQ = addCheckBox(group, label, PreferenceConstants.EDITOR_ESCAPE_STRINGS_DQ, 1);
1067     createDependency(button, fEscapeStringsButtonDQ);
1068
1069     label = PreferencesMessages.getString("JavaEditorPreferencePage.wrapStringsSQ");//$NON-NLS-1$
1070     addCheckBox(group, label, PreferenceConstants.EDITOR_WRAP_STRINGS_SQ, 1);
1071
1072     label = PreferencesMessages.getString("JavaEditorPreferencePage.escapeStringsSQ");
1073     //$NON-NLS-1$
1074     fEscapeStringsButtonSQ = addCheckBox(group, label, PreferenceConstants.EDITOR_ESCAPE_STRINGS_SQ, 1);
1075     createDependency(button, fEscapeStringsButtonSQ);
1076     
1077     label = PreferencesMessages.getString("JavaEditorPreferencePage.smartPaste");
1078     //$NON-NLS-1$
1079     addCheckBox(group, label, PreferenceConstants.EDITOR_SMART_PASTE, 1);
1080
1081     label = PreferencesMessages.getString("JavaEditorPreferencePage.insertSpaceForTabs");
1082     //$NON-NLS-1$
1083     addCheckBox(group, label, PreferenceConstants.EDITOR_SPACES_FOR_TABS, 1);
1084
1085     label = PreferencesMessages.getString("JavaEditorPreferencePage.closeStringsDQ");
1086     //$NON-NLS-1$
1087     addCheckBox(group, label, PreferenceConstants.EDITOR_CLOSE_STRINGS_DQ_PHP, 1);
1088     label = PreferencesMessages.getString("JavaEditorPreferencePage.closeStringsSQ");
1089     //$NON-NLS-1$
1090     addCheckBox(group, label, PreferenceConstants.EDITOR_CLOSE_STRINGS_SQ_PHP, 1);
1091
1092     label = PreferencesMessages.getString("JavaEditorPreferencePage.closeBrackets");
1093     //$NON-NLS-1$
1094     addCheckBox(group, label, PreferenceConstants.EDITOR_CLOSE_BRACKETS_PHP, 1);
1095
1096     //    label = PreferencesMessages
1097     //        .getString("JavaEditorPreferencePage.closeBraces");
1098     //    //$NON-NLS-1$
1099     //    addCheckBox(group, label, PreferenceConstants.EDITOR_CLOSE_BRACES, 1);
1100
1101     //    label = PreferencesMessages
1102     //        .getString("JavaEditorPreferencePage.closeJavaDocs");
1103     //    //$NON-NLS-1$
1104     //    button = addCheckBox(group, label,
1105     //        PreferenceConstants.EDITOR_CLOSE_JAVADOCS, 1);
1106     //
1107     //    label = PreferencesMessages
1108     //        .getString("JavaEditorPreferencePage.addJavaDocTags");
1109     //    //$NON-NLS-1$
1110     //    fAddJavaDocTagsButton = addCheckBox(group, label,
1111     //        PreferenceConstants.EDITOR_ADD_JAVADOC_TAGS, 1);
1112     //    createDependency(button, fAddJavaDocTagsButton);
1113     return composite;
1114   }
1115
1116   private void addFiller(Composite composite) {
1117     Label filler = new Label(composite, SWT.LEFT);
1118     GridData gd = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
1119     gd.horizontalSpan = 2;
1120     gd.heightHint = convertHeightInCharsToPixels(1) / 2;
1121     filler.setLayoutData(gd);
1122   }
1123
1124   private static void indent(Control control) {
1125     GridData gridData = new GridData();
1126     gridData.horizontalIndent = 20;
1127     control.setLayoutData(gridData);
1128   }
1129
1130   private static void createDependency(final Button master, final Control slave) {
1131     indent(slave);
1132     master.addSelectionListener(new SelectionListener() {
1133       public void widgetSelected(SelectionEvent e) {
1134         slave.setEnabled(master.getSelection());
1135       }
1136
1137       public void widgetDefaultSelected(SelectionEvent e) {
1138       }
1139     });
1140   }
1141
1142   private void addCompletionRadioButtons(Composite contentAssistComposite) {
1143     Composite completionComposite = new Composite(contentAssistComposite, SWT.NONE);
1144     GridData ccgd = new GridData();
1145     ccgd.horizontalSpan = 2;
1146     completionComposite.setLayoutData(ccgd);
1147     GridLayout ccgl = new GridLayout();
1148     ccgl.marginWidth = 0;
1149     ccgl.numColumns = 2;
1150     completionComposite.setLayout(ccgl);
1151     //          SelectionListener completionSelectionListener= new SelectionAdapter() {
1152     //                  public void widgetSelected(SelectionEvent e) {
1153     //                          boolean insert= fCompletionInsertsRadioButton.getSelection();
1154     //                          fOverlayStore.setValue(PreferenceConstants.CODEASSIST_INSERT_COMPLETION,
1155     // insert);
1156     //                  }
1157     //          };
1158     //          
1159     //          fCompletionInsertsRadioButton= new Button(completionComposite, SWT.RADIO
1160     // | SWT.LEFT);
1161     //          fCompletionInsertsRadioButton.setText(PreferencesMessages.getString("JavaEditorPreferencePage.completionInserts"));
1162     // //$NON-NLS-1$
1163     //          fCompletionInsertsRadioButton.setLayoutData(new GridData());
1164     //          fCompletionInsertsRadioButton.addSelectionListener(completionSelectionListener);
1165     //          
1166     //          fCompletionOverwritesRadioButton= new Button(completionComposite,
1167     // SWT.RADIO | SWT.LEFT);
1168     //          fCompletionOverwritesRadioButton.setText(PreferencesMessages.getString("JavaEditorPreferencePage.completionOverwrites"));
1169     // //$NON-NLS-1$
1170     //          fCompletionOverwritesRadioButton.setLayoutData(new GridData());
1171     //          fCompletionOverwritesRadioButton.addSelectionListener(completionSelectionListener);
1172   }
1173
1174   private Control createNavigationPage(Composite parent) {
1175     Composite composite = new Composite(parent, SWT.NULL);
1176     GridLayout layout = new GridLayout();
1177     layout.numColumns = 2;
1178     composite.setLayout(layout);
1179     //          String text=
1180     // PreferencesMessages.getString("JavaEditorPreferencePage.navigation.browserLikeLinks");
1181     // //$NON-NLS-1$
1182     //          fBrowserLikeLinksCheckBox= addCheckBox(composite, text,
1183     // PreferenceConstants.EDITOR_BROWSER_LIKE_LINKS, 0);
1184     //          fBrowserLikeLinksCheckBox.addSelectionListener(new SelectionListener() {
1185     //                  public void widgetSelected(SelectionEvent e) {
1186     //                          boolean state= fBrowserLikeLinksCheckBox.getSelection();
1187     //                          fBrowserLikeLinksKeyModifierText.setEnabled(state);
1188     //                          handleBrowserLikeLinksKeyModifierModified();
1189     //                  }
1190     //                  public void widgetDefaultSelected(SelectionEvent e) {
1191     //                  }
1192     //          });
1193     // Text field for modifier string
1194     //          text=
1195     // PreferencesMessages.getString("JavaEditorPreferencePage.navigation.browserLikeLinksKeyModifier");
1196     // //$NON-NLS-1$
1197     //          fBrowserLikeLinksKeyModifierText= addTextField(composite, text,
1198     // PreferenceConstants.EDITOR_BROWSER_LIKE_LINKS_KEY_MODIFIER, 20, 0,
1199     // false);
1200     //          fBrowserLikeLinksKeyModifierText.setTextLimit(Text.LIMIT);
1201     //          
1202     //          if
1203     // (computeStateMask(fOverlayStore.getString(PreferenceConstants.EDITOR_BROWSER_LIKE_LINKS_KEY_MODIFIER))
1204     // == -1) {
1205     //                  // Fix possible illegal modifier string
1206     //                  int stateMask=
1207     // fOverlayStore.getInt(PreferenceConstants.EDITOR_BROWSER_LIKE_LINKS_KEY_MODIFIER_MASK);
1208     //                  if (stateMask == -1)
1209     //                          fBrowserLikeLinksKeyModifierText.setText(""); //$NON-NLS-1$
1210     //                  else
1211     //                          fBrowserLikeLinksKeyModifierText.setText(EditorUtility.getModifierString(stateMask));
1212     //          }
1213     //          fBrowserLikeLinksKeyModifierText.addKeyListener(new KeyListener() {
1214     //                  private boolean isModifierCandidate;
1215     //                  public void keyPressed(KeyEvent e) {
1216     //                          isModifierCandidate= e.keyCode > 0 && e.character == 0 && e.stateMask ==
1217     // 0;
1218     //                  }
1219     //          
1220     //                  public void keyReleased(KeyEvent e) {
1221     //                          if (isModifierCandidate && e.stateMask > 0 && e.stateMask == e.stateMask
1222     // && e.character == 0) {// && e.time -time < 1000) {
1223     //                                  String modifierString= fBrowserLikeLinksKeyModifierText.getText();
1224     //                                  Point selection= fBrowserLikeLinksKeyModifierText.getSelection();
1225     //                                  int i= selection.x - 1;
1226     //                                  while (i > -1 && Character.isWhitespace(modifierString.charAt(i))) {
1227     //                                          i--;
1228     //                                  }
1229     //                                  boolean needsPrefixDelimiter= i > -1 &&
1230     // !String.valueOf(modifierString.charAt(i)).equals(DELIMITER);
1231     //
1232     //                                  i= selection.y;
1233     //                                  while (i < modifierString.length() &&
1234     // Character.isWhitespace(modifierString.charAt(i))) {
1235     //                                          i++;
1236     //                                  }
1237     //                                  boolean needsPostfixDelimiter= i < modifierString.length() &&
1238     // !String.valueOf(modifierString.charAt(i)).equals(DELIMITER);
1239     //
1240     //                                  String insertString;
1241     //
1242     //                                  if (needsPrefixDelimiter && needsPostfixDelimiter)
1243     //                                          insertString=
1244     // PreferencesMessages.getFormattedString("JavaEditorPreferencePage.navigation.insertDelimiterAndModifierAndDelimiter",
1245     // new String[] {Action.findModifierString(e.stateMask)}); //$NON-NLS-1$
1246     //                                  else if (needsPrefixDelimiter)
1247     //                                          insertString=
1248     // PreferencesMessages.getFormattedString("JavaEditorPreferencePage.navigation.insertDelimiterAndModifier",
1249     // new String[] {Action.findModifierString(e.stateMask)}); //$NON-NLS-1$
1250     //                                  else if (needsPostfixDelimiter)
1251     //                                          insertString=
1252     // PreferencesMessages.getFormattedString("JavaEditorPreferencePage.navigation.insertModifierAndDelimiter",
1253     // new String[] {Action.findModifierString(e.stateMask)}); //$NON-NLS-1$
1254     //                                  else
1255     //                                          insertString= Action.findModifierString(e.stateMask);
1256     //
1257     //                                  fBrowserLikeLinksKeyModifierText.insert(insertString);
1258     //                          }
1259     //                  }
1260     //          });
1261     //
1262     //          fBrowserLikeLinksKeyModifierText.addModifyListener(new ModifyListener()
1263     // {
1264     //                  public void modifyText(ModifyEvent e) {
1265     //                          handleBrowserLikeLinksKeyModifierModified();
1266     //                  }
1267     //          });
1268     return composite;
1269   }
1270
1271   private void handleBrowserLikeLinksKeyModifierModified() {
1272     //          String modifiers= fBrowserLikeLinksKeyModifierText.getText();
1273     //          int stateMask= computeStateMask(modifiers);
1274     //          if (fBrowserLikeLinksCheckBox.getSelection() && (stateMask == -1 ||
1275     // (stateMask & SWT.SHIFT) != 0)) {
1276     //                  if (stateMask == -1)
1277     //                          fBrowserLikeLinksKeyModifierStatus= new StatusInfo(IStatus.ERROR,
1278     // PreferencesMessages.getFormattedString("JavaEditorPreferencePage.navigation.modifierIsNotValid",
1279     // modifiers)); //$NON-NLS-1$
1280     //                  else
1281     //                          fBrowserLikeLinksKeyModifierStatus= new StatusInfo(IStatus.ERROR,
1282     // PreferencesMessages.getString("JavaEditorPreferencePage.navigation.shiftIsDisabled"));
1283     // //$NON-NLS-1$
1284     //                  setValid(false);
1285     //                  StatusUtil.applyToStatusLine(this, fBrowserLikeLinksKeyModifierStatus);
1286     //          } else {
1287     //                  fBrowserLikeLinksKeyModifierStatus= new StatusInfo();
1288     //                  updateStatus(fBrowserLikeLinksKeyModifierStatus);
1289     //          }
1290   }
1291
1292   //    private IStatus getBrowserLikeLinksKeyModifierStatus() {
1293   //            if (fBrowserLikeLinksKeyModifierStatus == null)
1294   //            fBrowserLikeLinksKeyModifierStatus= new StatusInfo();
1295   //            return fBrowserLikeLinksKeyModifierStatus;
1296   //    }
1297   /**
1298    * Computes the state mask for the given modifier string.
1299    * 
1300    * @param modifiers
1301    *          the string with the modifiers, separated by '+', '-', ';', ',' or '.'
1302    * @return the state mask or -1 if the input is invalid
1303    */
1304   private int computeStateMask(String modifiers) {
1305     if (modifiers == null)
1306       return -1;
1307     if (modifiers.length() == 0)
1308       return SWT.NONE;
1309     int stateMask = 0;
1310     StringTokenizer modifierTokenizer = new StringTokenizer(modifiers, ",;.:+-* "); //$NON-NLS-1$
1311     while (modifierTokenizer.hasMoreTokens()) {
1312       int modifier = EditorUtility.findLocalizedModifier(modifierTokenizer.nextToken());
1313       if (modifier == 0 || (stateMask & modifier) == modifier)
1314         return -1;
1315       stateMask = stateMask | modifier;
1316     }
1317     return stateMask;
1318   }
1319
1320   /*
1321    * @see PreferencePage#createContents(Composite)
1322    */
1323   protected Control createContents(Composite parent) {
1324     initializeDefaultColors();
1325     fFoldingConfigurationBlock = new FoldingConfigurationBlock(fOverlayStore);
1326     fOverlayStore.load();
1327     fOverlayStore.start();
1328     TabFolder folder = new TabFolder(parent, SWT.NONE);
1329     folder.setLayout(new TabFolderLayout());
1330     folder.setLayoutData(new GridData(GridData.FILL_BOTH));
1331     TabItem item = new TabItem(folder, SWT.NONE);
1332     item.setText(PreferencesMessages.getString("JavaEditorPreferencePage.general")); //$NON-NLS-1$
1333     item.setControl(createAppearancePage(folder));
1334     item = new TabItem(folder, SWT.NONE);
1335     item.setText(PreferencesMessages.getString("JavaEditorPreferencePage.colors")); //$NON-NLS-1$
1336     item.setControl(createSyntaxPage(folder));
1337
1338     //    item = new TabItem(folder, SWT.NONE);
1339     //    item.setText(PreferencesMessages
1340     //        .getString("JavaEditorPreferencePage.annotationsTab.title"));
1341     // //$NON-NLS-1$
1342     //    item.setControl(createAnnotationsPage(folder));
1343     item = new TabItem(folder, SWT.NONE);
1344     item.setText(PreferencesMessages.getString("JavaEditorPreferencePage.typing.tabTitle"));
1345     //$NON-NLS-1$
1346     item.setControl(createTypingPage(folder));
1347
1348     item = new TabItem(folder, SWT.NONE);
1349     item.setText(PreferencesMessages.getString("JavaEditorPreferencePage.hoverTab.title"));
1350     //$NON-NLS-1$
1351     fJavaEditorHoverConfigurationBlock = new JavaEditorHoverConfigurationBlock(this, fOverlayStore);
1352     item.setControl(fJavaEditorHoverConfigurationBlock.createControl(folder));
1353     //                  item= new TabItem(folder, SWT.NONE);
1354     //                  item.setText(PreferencesMessages.getString("JavaEditorPreferencePage.navigationTab.title"));
1355     // //$NON-NLS-1$
1356     //                  item.setControl(createNavigationPage(folder));
1357     item = new TabItem(folder, SWT.NONE);
1358     item.setText(PreferencesMessages.getString("JavaEditorPreferencePage.folding.title")); //$NON-NLS-1$
1359     item.setControl(fFoldingConfigurationBlock.createControl(folder));
1360
1361     initialize();
1362     Dialog.applyDialogFont(folder);
1363     return folder;
1364   }
1365
1366   private void initialize() {
1367     initializeFields();
1368     for (int i = 0; i < fSyntaxColorListModel.length; i++)
1369       fSyntaxColorList.add(fSyntaxColorListModel[i][0]);
1370     fSyntaxColorList.getDisplay().asyncExec(new Runnable() {
1371       public void run() {
1372         if (fSyntaxColorList != null && !fSyntaxColorList.isDisposed()) {
1373           fSyntaxColorList.select(0);
1374           handleSyntaxColorListSelection();
1375         }
1376       }
1377     });
1378     for (int i = 0; i < fAppearanceColorListModel.length; i++)
1379       fAppearanceColorList.add(fAppearanceColorListModel[i][0]);
1380     fAppearanceColorList.getDisplay().asyncExec(new Runnable() {
1381       public void run() {
1382         if (fAppearanceColorList != null && !fAppearanceColorList.isDisposed()) {
1383           fAppearanceColorList.select(0);
1384           handleAppearanceColorListSelection();
1385         }
1386       }
1387     });
1388     //    for (int i = 0; i < fAnnotationColorListModel.length; i++)
1389     //      fAnnotationList.add(fAnnotationColorListModel[i][0]);
1390     //    fAnnotationList.getDisplay().asyncExec(new Runnable() {
1391     //      public void run() {
1392     //        if (fAnnotationList != null && !fAnnotationList.isDisposed()) {
1393     //          fAnnotationList.select(0);
1394     //          handleAnnotationListSelection();
1395     //        }
1396     //      }
1397     //    });
1398     //          for (int i= 0; i < fContentAssistColorListModel.length; i++)
1399     //                  fContentAssistColorList.add(fContentAssistColorListModel[i][0]);
1400     //          fContentAssistColorList.getDisplay().asyncExec(new Runnable() {
1401     //                  public void run() {
1402     //                          if (fContentAssistColorList != null &&
1403     // !fContentAssistColorList.isDisposed()) {
1404     //                                  fContentAssistColorList.select(0);
1405     //                                  handleContentAssistColorListSelection();
1406     //                          }
1407     //                  }
1408     //          });
1409     fFoldingConfigurationBlock.initialize();
1410   }
1411
1412   private void initializeFields() {
1413     Iterator e = fColorButtons.keySet().iterator();
1414     while (e.hasNext()) {
1415       ColorEditor c = (ColorEditor) e.next();
1416       String key = (String) fColorButtons.get(c);
1417       RGB rgb = PreferenceConverter.getColor(fOverlayStore, key);
1418       c.setColorValue(rgb);
1419     }
1420     e = fCheckBoxes.keySet().iterator();
1421     while (e.hasNext()) {
1422       Button b = (Button) e.next();
1423       String key = (String) fCheckBoxes.get(b);
1424       b.setSelection(fOverlayStore.getBoolean(key));
1425     }
1426     e = fTextFields.keySet().iterator();
1427     while (e.hasNext()) {
1428       Text t = (Text) e.next();
1429       String key = (String) fTextFields.get(t);
1430       t.setText(fOverlayStore.getString(key));
1431     }
1432     RGB rgb = PreferenceConverter.getColor(fOverlayStore, PreferenceConstants.EDITOR_BACKGROUND_COLOR);
1433     fBackgroundColorEditor.setColorValue(rgb);
1434     boolean default_ = fOverlayStore.getBoolean(PreferenceConstants.EDITOR_BACKGROUND_DEFAULT_COLOR);
1435     fBackgroundDefaultRadioButton.setSelection(default_);
1436     fBackgroundCustomRadioButton.setSelection(!default_);
1437     fBackgroundColorButton.setEnabled(!default_);
1438     //    boolean closeJavaDocs = fOverlayStore
1439     //        .getBoolean(PreferenceConstants.EDITOR_CLOSE_JAVADOCS);
1440     //    fAddJavaDocTagsButton.setEnabled(closeJavaDocs);
1441     fEscapeStringsButtonDQ.setEnabled(fOverlayStore.getBoolean(PreferenceConstants.EDITOR_WRAP_STRINGS_DQ));
1442     fEscapeStringsButtonSQ.setEnabled(fOverlayStore.getBoolean(PreferenceConstants.EDITOR_WRAP_STRINGS_SQ));
1443     //          boolean fillMethodArguments=
1444     // fOverlayStore.getBoolean(PreferenceConstants.CODEASSIST_FILL_ARGUMENT_NAMES);
1445     //          fGuessMethodArgumentsButton.setEnabled(fillMethodArguments);
1446     //          boolean completionInserts=
1447     // fOverlayStore.getBoolean(PreferenceConstants.CODEASSIST_INSERT_COMPLETION);
1448     //          fCompletionInsertsRadioButton.setSelection(completionInserts);
1449     //          fCompletionOverwritesRadioButton.setSelection(! completionInserts);
1450     //          
1451     //          fBrowserLikeLinksKeyModifierText.setEnabled(fBrowserLikeLinksCheckBox.getSelection());
1452     //          boolean markOccurrences=
1453     // fOverlayStore.getBoolean(PreferenceConstants.EDITOR_MARK_OCCURRENCES);
1454     //          fStickyOccurrencesButton.setEnabled(markOccurrences);
1455     updateAutoactivationControls();
1456   }
1457
1458   private void initializeDefaultColors() {
1459     if (!getPreferenceStore().contains(PreferenceConstants.EDITOR_BACKGROUND_COLOR)) {
1460       RGB rgb = getControl().getDisplay().getSystemColor(SWT.COLOR_LIST_BACKGROUND).getRGB();
1461       PreferenceConverter.setDefault(fOverlayStore, PreferenceConstants.EDITOR_BACKGROUND_COLOR, rgb);
1462       PreferenceConverter.setDefault(getPreferenceStore(), PreferenceConstants.EDITOR_BACKGROUND_COLOR, rgb);
1463     }
1464     if (!getPreferenceStore().contains(PreferenceConstants.EDITOR_FOREGROUND_COLOR)) {
1465       RGB rgb = getControl().getDisplay().getSystemColor(SWT.COLOR_LIST_FOREGROUND).getRGB();
1466       PreferenceConverter.setDefault(fOverlayStore, PreferenceConstants.EDITOR_FOREGROUND_COLOR, rgb);
1467       PreferenceConverter.setDefault(getPreferenceStore(), PreferenceConstants.EDITOR_FOREGROUND_COLOR, rgb);
1468     }
1469   }
1470
1471   private void updateAutoactivationControls() {
1472     //        boolean autoactivation=
1473     // fOverlayStore.getBoolean(PreferenceConstants.CODEASSIST_AUTOACTIVATION);
1474     //        fAutoInsertDelayText.setEnabled(autoactivation);
1475     //          fAutoInsertDelayLabel.setEnabled(autoactivation);
1476     //        fAutoInsertJavaTriggerText.setEnabled(autoactivation);
1477     //          fAutoInsertJavaTriggerLabel.setEnabled(autoactivation);
1478     //
1479     //        fAutoInsertJavaDocTriggerText.setEnabled(autoactivation);
1480     //          fAutoInsertJavaDocTriggerLabel.setEnabled(autoactivation);
1481   }
1482
1483   /*
1484    * @see PreferencePage#performOk()
1485    */
1486   public boolean performOk() {
1487     //          fJavaEditorHoverConfigurationBlock.performOk();
1488     fFoldingConfigurationBlock.performOk();
1489     //          fOverlayStore.setValue(PreferenceConstants.EDITOR_BROWSER_LIKE_LINKS_KEY_MODIFIER_MASK,
1490     // computeStateMask(fBrowserLikeLinksKeyModifierText.getText()));
1491     fOverlayStore.propagate();
1492     PHPeclipsePlugin.getDefault().savePluginPreferences();
1493     return true;
1494   }
1495
1496   /*
1497    * @see PreferencePage#performDefaults()
1498    */
1499   protected void performDefaults() {
1500     fOverlayStore.loadDefaults();
1501     initializeFields();
1502     handleSyntaxColorListSelection();
1503     handleAppearanceColorListSelection();
1504     //    handleAnnotationListSelection();
1505     //          handleContentAssistColorListSelection();
1506     //          fJavaEditorHoverConfigurationBlock.performDefaults();
1507     fFoldingConfigurationBlock.performDefaults();
1508     super.performDefaults();
1509     fPreviewViewer.invalidateTextPresentation();
1510   }
1511
1512   /*
1513    * @see DialogPage#dispose()
1514    */
1515   public void dispose() {
1516     fFoldingConfigurationBlock.dispose();
1517
1518     if (fJavaTextTools != null) {
1519       fJavaTextTools.dispose();
1520       fJavaTextTools = null;
1521     }
1522     if (fOverlayStore != null) {
1523       fOverlayStore.stop();
1524       fOverlayStore = null;
1525     }
1526     if (fBackgroundColor != null && !fBackgroundColor.isDisposed())
1527       fBackgroundColor.dispose();
1528     super.dispose();
1529   }
1530
1531   private Button addCheckBox(Composite parent, String label, String key, int indentation) {
1532     Button checkBox = new Button(parent, SWT.CHECK);
1533     checkBox.setText(label);
1534     GridData gd = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
1535     gd.horizontalIndent = indentation;
1536     gd.horizontalSpan = 2;
1537     checkBox.setLayoutData(gd);
1538     checkBox.addSelectionListener(fCheckBoxListener);
1539     fCheckBoxes.put(checkBox, key);
1540     return checkBox;
1541   }
1542
1543   private Text addTextField(Composite composite, String label, String key, int textLimit, int indentation, boolean isNumber) {
1544     return getTextControl(addLabelledTextField(composite, label, key, textLimit, indentation, isNumber));
1545   }
1546
1547   private static Label getLabelControl(Control[] labelledTextField) {
1548     return (Label) labelledTextField[0];
1549   }
1550
1551   private static Text getTextControl(Control[] labelledTextField) {
1552     return (Text) labelledTextField[1];
1553   }
1554
1555   /**
1556    * Returns an array of size 2: - first element is of type <code>Label</code>- second element is of type <code>Text</code> Use
1557    * <code>getLabelControl</code> and <code>getTextControl</code> to get the 2 controls.
1558    */
1559   private Control[] addLabelledTextField(Composite composite, String label, String key, int textLimit, int indentation,
1560       boolean isNumber) {
1561     Label labelControl = new Label(composite, SWT.NONE);
1562     labelControl.setText(label);
1563     GridData gd = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
1564     gd.horizontalIndent = indentation;
1565     labelControl.setLayoutData(gd);
1566     Text textControl = new Text(composite, SWT.BORDER | SWT.SINGLE);
1567     gd = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
1568     gd.widthHint = convertWidthInCharsToPixels(textLimit + 1);
1569     textControl.setLayoutData(gd);
1570     textControl.setTextLimit(textLimit);
1571     fTextFields.put(textControl, key);
1572     if (isNumber) {
1573       fNumberFields.add(textControl);
1574       textControl.addModifyListener(fNumberFieldListener);
1575     } else {
1576       textControl.addModifyListener(fTextFieldListener);
1577     }
1578     return new Control[] { labelControl, textControl };
1579   }
1580
1581   private String loadPreviewContentFromFile(String filename) {
1582     String line;
1583     String separator = System.getProperty("line.separator"); //$NON-NLS-1$
1584     StringBuffer buffer = new StringBuffer(512);
1585     BufferedReader reader = null;
1586     try {
1587       reader = new BufferedReader(new InputStreamReader(getClass().getResourceAsStream(filename)));
1588       while ((line = reader.readLine()) != null) {
1589         buffer.append(line);
1590         buffer.append(separator);
1591       }
1592     } catch (IOException io) {
1593       PHPeclipsePlugin.log(io);
1594     } finally {
1595       if (reader != null) {
1596         try {
1597           reader.close();
1598         } catch (IOException e) {
1599         }
1600       }
1601     }
1602     return buffer.toString();
1603   }
1604
1605   private void numberFieldChanged(Text textControl) {
1606     String number = textControl.getText();
1607     IStatus status = validatePositiveNumber(number);
1608     if (!status.matches(IStatus.ERROR))
1609       fOverlayStore.setValue((String) fTextFields.get(textControl), number);
1610     updateStatus(status);
1611   }
1612
1613   private IStatus validatePositiveNumber(String number) {
1614     StatusInfo status = new StatusInfo();
1615     if (number.length() == 0) {
1616       status.setError(PreferencesMessages.getString("JavaEditorPreferencePage.empty_input")); //$NON-NLS-1$
1617     } else {
1618       try {
1619         int value = Integer.parseInt(number);
1620         if (value < 0)
1621           status.setError(PreferencesMessages.getFormattedString("JavaEditorPreferencePage.invalid_input", number)); //$NON-NLS-1$
1622       } catch (NumberFormatException e) {
1623         status.setError(PreferencesMessages.getFormattedString("JavaEditorPreferencePage.invalid_input", number)); //$NON-NLS-1$
1624       }
1625     }
1626     return status;
1627   }
1628
1629   void updateStatus(IStatus status) {
1630     if (!status.matches(IStatus.ERROR)) {
1631       for (int i = 0; i < fNumberFields.size(); i++) {
1632         Text text = (Text) fNumberFields.get(i);
1633         IStatus s = validatePositiveNumber(text.getText());
1634         status = StatusUtil.getMoreSevere(s, status);
1635       }
1636     }
1637     //          status=
1638     // StatusUtil.getMoreSevere(fJavaEditorHoverConfigurationBlock.getStatus(),
1639     // status);
1640     //          status= StatusUtil.getMoreSevere(getBrowserLikeLinksKeyModifierStatus(),
1641     // status);
1642     setValid(!status.matches(IStatus.ERROR));
1643     StatusUtil.applyToStatusLine(this, status);
1644   }
1645 }