~ubuntu-branches/ubuntu/trusty/netbeans/trusty

« back to all changes in this revision

Viewing changes to editor/demosrc/properties-addon/org/netbeans/editor/example/PropertiesSettingsInitializer.java

  • Committer: Bazaar Package Importer
  • Author(s): Marek Slama
  • Date: 2008-01-29 14:11:22 UTC
  • Revision ID: james.westby@ubuntu.com-20080129141122-fnzjbo11ntghxfu7
Tags: upstream-6.0.1
ImportĀ upstreamĀ versionĀ 6.0.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
 
3
 *
 
4
 * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
 
5
 *
 
6
 * The contents of this file are subject to the terms of either the GNU
 
7
 * General Public License Version 2 only ("GPL") or the Common
 
8
 * Development and Distribution License("CDDL") (collectively, the
 
9
 * "License"). You may not use this file except in compliance with the
 
10
 * License. You can obtain a copy of the License at
 
11
 * http://www.netbeans.org/cddl-gplv2.html
 
12
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
 
13
 * specific language governing permissions and limitations under the
 
14
 * License.  When distributing the software, include this License Header
 
15
 * Notice in each file and include the License file at
 
16
 * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
 
17
 * particular file as subject to the "Classpath" exception as provided
 
18
 * by Sun in the GPL Version 2 section of the License file that
 
19
 * accompanied this code. If applicable, add the following below the
 
20
 * License Header, with the fields enclosed by brackets [] replaced by
 
21
 * your own identifying information:
 
22
 * "Portions Copyrighted [year] [name of copyright owner]"
 
23
 *
 
24
 * Contributor(s):
 
25
 *
 
26
 * The Original Software is NetBeans. The Initial Developer of the Original
 
27
 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
 
28
 * Microsystems, Inc. All Rights Reserved.
 
29
 *
 
30
 * If you wish your version of this file to be governed by only the CDDL
 
31
 * or only the GPL Version 2, indicate your decision by adding
 
32
 * "[Contributor] elects to include this software in this distribution
 
33
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
 
34
 * single choice of license, a recipient has the option to distribute
 
35
 * your version of this file under either the CDDL, the GPL Version 2 or
 
36
 * to extend the choice of license to its licensees as provided above.
 
37
 * However, if you add GPL Version 2 code and therefore, elected the GPL
 
38
 * Version 2 license, then the option applies only if the new code is
 
39
 * made subject to such option by the copyright holder.
 
40
 */
 
41
 
 
42
package org.netbeans.editor.example;
 
43
 
 
44
import java.awt.Font;
 
45
import java.awt.Color;
 
46
import java.awt.SystemColor;
 
47
import java.util.*;
 
48
 
 
49
import org.netbeans.editor.Settings;
 
50
import org.netbeans.editor.SettingsNames;
 
51
import org.netbeans.editor.SettingsUtil;
 
52
import org.netbeans.editor.Coloring;
 
53
import org.netbeans.editor.SettingsDefaults;
 
54
import org.netbeans.editor.Syntax;
 
55
import org.netbeans.editor.BaseKit;
 
56
import org.netbeans.editor.TokenContext;
 
57
import org.netbeans.editor.TokenContextPath;
 
58
import org.netbeans.editor.TokenCategory;
 
59
import org.netbeans.modules.properties.syntax.*;
 
60
 
 
61
 
 
62
public class PropertiesSettingsInitializer extends Settings.AbstractInitializer {
 
63
 
 
64
    /** Name assigned to initializer */
 
65
    public static final String NAME = "properties-settings-initializer"; // NOI18N
 
66
    private Class propertiesClass;
 
67
 
 
68
    public PropertiesSettingsInitializer( Class propertiesClass ) {
 
69
        super(NAME);
 
70
        this.propertiesClass = propertiesClass;
 
71
    }
 
72
 
 
73
    public void updateSettingsMap (Class kitClass, Map settingsMap) {
 
74
        
 
75
        // Properties colorings
 
76
        if (kitClass == BaseKit.class) {
 
77
            new PropertiesTokenColoringInitializer().updateSettingsMap(kitClass, settingsMap);
 
78
 
 
79
        }
 
80
 
 
81
        if (kitClass == propertiesClass) {
 
82
            settingsMap.put (org.netbeans.editor.SettingsNames.ABBREV_MAP, getPropertiesAbbrevMap());
 
83
 
 
84
            SettingsUtil.updateListSetting(settingsMap, SettingsNames.TOKEN_CONTEXT_LIST,
 
85
                new TokenContext[] {
 
86
                    PropertiesTokenContext.context
 
87
                }
 
88
            );
 
89
 
 
90
        }
 
91
 
 
92
    }
 
93
 
 
94
 
 
95
    Map getPropertiesAbbrevMap() {
 
96
        Map propertiesAbbrevMap = new TreeMap ();
 
97
        return propertiesAbbrevMap;
 
98
    }
 
99
 
 
100
    static class PropertiesTokenColoringInitializer
 
101
    extends SettingsUtil.TokenColoringInitializer {
 
102
 
 
103
        Font boldFont = SettingsDefaults.defaultFont.deriveFont(Font.BOLD);
 
104
        Font italicFont = SettingsDefaults.defaultFont.deriveFont(Font.ITALIC);
 
105
 
 
106
        Coloring emptyColoring = new Coloring(null, null, null);
 
107
        Coloring commentColoring = new Coloring(italicFont, Coloring.FONT_MODE_APPLY_STYLE,
 
108
                            Color.gray, null);
 
109
 
 
110
        Coloring numbersColoring = new Coloring(null, Color.red, null);
 
111
 
 
112
        public PropertiesTokenColoringInitializer() {
 
113
            super(PropertiesTokenContext.context);
 
114
        }
 
115
 
 
116
        public Object getTokenColoring(TokenContextPath tokenContextPath,
 
117
        TokenCategory tokenIDOrCategory, boolean printingSet) {
 
118
 
 
119
            if (!printingSet) {
 
120
                switch (tokenIDOrCategory.getNumericID()) {
 
121
                    case PropertiesTokenContext.KEY_ID:
 
122
                        return new Coloring(boldFont, Coloring.FONT_MODE_APPLY_STYLE,
 
123
                                Color.blue, null);
 
124
 
 
125
                    case PropertiesTokenContext.EQ_ID:
 
126
                    case PropertiesTokenContext.TEXT_ID:
 
127
                        return emptyColoring;
 
128
 
 
129
                    case PropertiesTokenContext.LINE_COMMENT_ID:
 
130
                        return new Coloring(italicFont, Coloring.FONT_MODE_APPLY_STYLE,
 
131
                                Color.gray, null);
 
132
 
 
133
                    case PropertiesTokenContext.VALUE_ID:
 
134
                        return new Coloring(null, Color.magenta, null);
 
135
                }
 
136
 
 
137
 
 
138
 
 
139
            } else { // printing set
 
140
                switch (tokenIDOrCategory.getNumericID()) {
 
141
 
 
142
                    default:
 
143
                         return SettingsUtil.defaultPrintColoringEvaluator;
 
144
                }
 
145
 
 
146
            }
 
147
 
 
148
            return null;
 
149
 
 
150
        }
 
151
 
 
152
    }
 
153
 
 
154
}