b1186e734655b5a493fe520111a6c5179f539723
[phpeclipse.git] /
1 /*
2  * Copyright (c) 2002-2004 Roberto Gonzalez Rocha 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  *     Roberto Gonzalez Rocha - Initial version
10  *     Igor Malinin - refactoring, minor changes
11  *
12  * $Id: XMLPreferenceInitializer.java,v 1.1 2004-09-02 18:28:03 jsurfer Exp $
13  */
14 package net.sourceforge.phpeclipse.xml.ui.internal.preferences;
15
16 import net.sourceforge.phpeclipse.ui.preferences.ITextStylePreferences;
17 import net.sourceforge.phpeclipse.xml.ui.XMLPlugin;
18 import net.sourceforge.phpeclipse.xml.ui.text.IXMLSyntaxConstants;
19
20 import org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer;
21 import org.eclipse.jface.preference.IPreferenceStore;
22 import org.eclipse.jface.preference.PreferenceConverter;
23 import org.eclipse.swt.SWT;
24 import org.eclipse.swt.widgets.Display;
25 import org.eclipse.ui.texteditor.AbstractTextEditor;
26
27
28 /**
29  * @author Igor Malinin
30  */
31 public class XMLPreferenceInitializer extends AbstractPreferenceInitializer {
32         /*
33          * @see org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer#initializeDefaultPreferences()
34          */
35         public void initializeDefaultPreferences() {
36                 IPreferenceStore store = XMLPlugin.getDefault().getPreferenceStore();
37
38                 // TODO: ChainedPreferenceStore does not work for preferences preview
39
40                 PreferenceConverter.setDefault(store,
41                         AbstractTextEditor.PREFERENCE_COLOR_FOREGROUND,
42                         Display.getDefault()
43                                 .getSystemColor(SWT.COLOR_LIST_FOREGROUND).getRGB());
44
45                 store.setDefault(
46                         AbstractTextEditor.PREFERENCE_COLOR_FOREGROUND_SYSTEM_DEFAULT,
47                         true);
48
49                 PreferenceConverter.setDefault(store,
50                         AbstractTextEditor.PREFERENCE_COLOR_BACKGROUND,
51                         Display.getDefault()
52                                 .getSystemColor(SWT.COLOR_LIST_BACKGROUND).getRGB());
53
54                 store.setDefault(
55                         AbstractTextEditor.PREFERENCE_COLOR_BACKGROUND_SYSTEM_DEFAULT,
56                         true);
57
58                 // end of common preferences
59
60                 setDefault(store, IXMLSyntaxConstants.XML_DEFAULT,
61                         "0,0,0", ITextStylePreferences.STYLE_NORMAL);
62
63                 setDefault(store, IXMLSyntaxConstants.XML_TAG,
64                         "127,0,127", ITextStylePreferences.STYLE_NORMAL);
65
66                 setDefault(store, IXMLSyntaxConstants.XML_ATT_NAME,
67                         "0,127,0", ITextStylePreferences.STYLE_NORMAL);
68
69                 setDefault(store, IXMLSyntaxConstants.XML_ATT_VALUE,
70                         "0,0,255", ITextStylePreferences.STYLE_NORMAL);
71
72                 setDefault(store, IXMLSyntaxConstants.XML_ENTITY,
73                         "127,127,0", ITextStylePreferences.STYLE_NORMAL);
74
75                 setDefault(store, IXMLSyntaxConstants.XML_CDATA,
76                         "127,127,0", ITextStylePreferences.STYLE_NORMAL);
77
78                 setDefault(store, IXMLSyntaxConstants.XML_PI,
79                         "127,127,127", ITextStylePreferences.STYLE_BOLD);
80
81                 setDefault(store, IXMLSyntaxConstants.XML_COMMENT,
82                         "127,0,0", ITextStylePreferences.STYLE_NORMAL);
83
84                 setDefault(store, IXMLSyntaxConstants.XML_DECL,
85                         "127,0,127", ITextStylePreferences.STYLE_BOLD);
86
87                 setDefault(store, IXMLSyntaxConstants.XML_SMARTY,
88                         "255,0,127", ITextStylePreferences.STYLE_BOLD); 
89                 
90                 setDefault(store, IXMLSyntaxConstants.DTD_CONDITIONAL,
91                         "127,127,0", ITextStylePreferences.STYLE_BOLD);
92         }
93
94         private static void setDefault(
95                 IPreferenceStore store, String constant, String color, String style
96         ) {
97                 store.setDefault(constant + ITextStylePreferences.SUFFIX_FOREGROUND, color);
98                 store.setDefault(constant + ITextStylePreferences.SUFFIX_STYLE, style);
99         }
100 }