alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

What this is

This file is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Other links

The source code

/*
 *                 Sun Public License Notice
 * 
 * The contents of this file are subject to the Sun Public License
 * Version 1.0 (the "License"). You may not use this file except in
 * compliance with the License. A copy of the License is available at
 * http://www.sun.com/
 * 
 * The Original Code is NetBeans. The Initial Developer of the Original
 * Code is Sun Microsystems, Inc. Portions Copyright 1997-2002 Sun
 * Microsystems, Inc. All Rights Reserved.
 */
package org.netbeans.modules.css.text.syntax;

import java.awt.Font;
import java.awt.Color;
import java.util.Map;
import java.util.TreeMap;
import java.util.List;
import java.util.ArrayList;
import java.util.Arrays;

import org.openide.actions.ToolsAction;
import org.openide.windows.TopComponent;

import org.netbeans.editor.*;
import org.netbeans.editor.ext.ExtSettingsNames;

import org.netbeans.modules.css.actions.*;
import org.netbeans.modules.css.text.syntax.CSSTokenContext;

/**
 * Settings.Initializer for CSSEditor
 *
 * @author  Petr Kuzel
 * @version 1.0
 */
public class CSSEditorSettings extends Settings.AbstractInitializer {

    /** Name assigned to initializer */
    public static final String NAME = "css-settings-initializer"; // NOI18N

    static final Font boldFont = SettingsDefaults.defaultFont.deriveFont(Font.BOLD);
    static final Font italicFont = SettingsDefaults.defaultFont.deriveFont(Font.ITALIC);

    /** Creates new CSSEditorSettings */
    public CSSEditorSettings() {
        super(NAME);
    }

    /** Update map filled with the settings from the previous initializer
     * @param kitClass kit class for which the settings are being updated.
     *  It is always non-null value.
     * @param settingsMap map with settings to update. It can be null if all
     *  the previous initializers didn't need to create any settings
     *  for the given kit class.
     * @return map containing the desired settings or null if no settings
     *  are defined for the given kit
     */
    public void updateSettingsMap(Class kitClass, Map settingsMap) {

        // editor breaks the contact, handle it somehow
        if (kitClass == null) return;
        
        if (kitClass == BaseKit.class) {

            new CSSTokenColoringInitializer().updateSettingsMap(kitClass, settingsMap);
            // coloring has to be present in base kit

        }

        // #21053
        if ("org.netbeans.modules.css.text.syntax.CSSEditorKit".equals(kitClass.getName())) {
            
            // popup menu
            
            List cssActionNames = new ArrayList
                (Arrays.asList (new String[] {
                    CopyStyleAction.XML.class.getName(),
                    CopyStyleAction.HTML.class.getName(),
                    CheckStyleAction.class.getName(),
                    null,
//  Wait for indent engine.
//                     BaseKit.formatAction,
//                     null,
// 
                    TopComponent.class.getName(),
                    null,
                    BaseKit.cutAction,
                    BaseKit.copyAction,
                    BaseKit.pasteAction,
                    null,
                    BaseKit.removeSelectionAction,
                    null,
                    ToolsAction.class.getName(),
                }));
            
            settingsMap.put (ExtSettingsNames.POPUP_MENU_ACTION_NAME_LIST, cssActionNames);

            // abbrevirations
            settingsMap.put (SettingsNames.ABBREV_MAP, getCSSAbbrevMap());

            SettingsUtil.updateListSetting (settingsMap, SettingsNames.TOKEN_CONTEXT_LIST,
                    new TokenContext[] { CSSTokenContext.context });

        }

    }

    /** @return Map of common CSS abbrevirations.
    */
    private Map getCSSAbbrevMap() {
        Map map = new TreeMap();

        map.put ("bg", "background: "); // NOI18N
        map.put ("fg", "foreground: "); // NOI18N

        return map;
    }

    /** CSS colorings */
    static class CSSTokenColoringInitializer
    extends SettingsUtil.TokenColoringInitializer {

        Font boldFont = SettingsDefaults.defaultFont.deriveFont(Font.BOLD);
        Font italicFont = SettingsDefaults.defaultFont.deriveFont(Font.ITALIC);
        Settings.Evaluator boldSubst = new SettingsUtil.FontStylePrintColoringEvaluator(Font.BOLD);
        Settings.Evaluator italicSubst = new SettingsUtil.FontStylePrintColoringEvaluator(Font.ITALIC);
        Settings.Evaluator lightGraySubst = new SettingsUtil.ForeColorPrintColoringEvaluator(Color.lightGray);

        Coloring commentColoring = new Coloring(italicFont, Coloring.FONT_MODE_APPLY_STYLE,
                            Color.gray, null);

        Coloring numbersColoring = new Coloring(null, Color.red, null);

        public CSSTokenColoringInitializer() {
            super(CSSTokenContext.context);
        }

        public Object getTokenColoring(TokenContextPath tokenContextPath,
        TokenCategory tokenIDOrCategory, boolean printingSet) {
            if (!printingSet) {
                switch (tokenIDOrCategory.getNumericID()) {
                    case CSSTokenContext.SELECTOR_ID:
                        return new Coloring (boldFont, Color.green.darker().darker(), null);

                    case CSSTokenContext.PROPERTY_ID:
                        return new Coloring (null, Color.blue, null);

                    case CSSTokenContext.COMMENT_ID:
                        return new Coloring(italicFont, Coloring.FONT_MODE_APPLY_STYLE,
                                          Color.lightGray, null);

                    case CSSTokenContext.ATKW_ID:
                        return new Coloring (boldFont, Color.blue, null);

                    case CSSTokenContext.ERROR_ID:
                        return new Coloring (null, Color.red, null);

                    case CSSTokenContext.PLAIN_ID:
                        return new Coloring (null, Color.black, null);

                }

            } else { // printing set
                switch (tokenIDOrCategory.getNumericID()) {

                    default:
                         return SettingsUtil.defaultPrintColoringEvaluator;
                }

            }

            return null;

        }

    }

}
... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.