TokenStyles.java

1
/*
2
 * This file is part of the programmer editor demo
3
 * Copyright (C) 2005 Stephen Ostermiller
4
 * http://ostermiller.org/contact.pl?regarding=Syntax+Highlighting
5
 * 
6
 * This program is free software; you can redistribute it and/or modify
7
 * it under the terms of the GNU General Public License as published by
8
 * the Free Software Foundation; either version 2 of the License, or
9
 * (at your option) any later version.
10
 * 
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 * 
16
 * See COPYING.TXT for details.
17
 */
18
package com.jsql.view.swing.sql.lexer;
19
20
import com.jsql.view.swing.util.UiUtil;
21
22
import javax.swing.text.AttributeSet;
23
import javax.swing.text.SimpleAttributeSet;
24
import javax.swing.text.StyleConstants;
25
import java.awt.*;
26
import java.util.HashMap;
27
28
class TokenStyles {
29
    
30
    /**
31
     * A hash table containing the text styles. Simple attribute sets are hashed
32
     * by name (String)
33
     */
34
    private static final HashMap<String, SimpleAttributeSet> styles = new HashMap<>();
35
    
36
    private TokenStyles() { } // disable constructor
37
38
    /**
39
     * Create the styles and place them in the hash table.
40
     */
41
    static {
42
        
43
        Color maroon = new Color(0xB03060);
44
        Color darkBlue = new Color(0x000080);
45
        Color darkGreen = Color.GREEN.darker();
46
        Color darkPurple = new Color(0xA020F0).darker();
47
48
        TokenStyles.addStyle("body", Color.WHITE, Color.BLACK, false, false);
49
        TokenStyles.addStyle("tag", Color.WHITE, Color.BLUE, true, false);
50
        TokenStyles.addStyle("endtag", Color.WHITE, Color.BLUE, false, false);
51
        TokenStyles.addStyle("reference", Color.WHITE, Color.BLACK, false, false);
52
        TokenStyles.addStyle("name", Color.WHITE, maroon, true, false);
53
        TokenStyles.addStyle("value", Color.WHITE, maroon, false, true);
54
        TokenStyles.addStyle("text", Color.WHITE, Color.BLACK, true, false);
55
        TokenStyles.addStyle("reservedWord", Color.WHITE, Color.BLUE, false, false);
56
        TokenStyles.addStyle("identifier", Color.WHITE, Color.BLACK, false, false);
57
        TokenStyles.addStyle("literal", Color.WHITE, maroon, false, false);
58
        TokenStyles.addStyle("separator", Color.WHITE, darkBlue, false, false);
59
        TokenStyles.addStyle("operator", Color.WHITE, Color.BLACK, true, false);
60
        TokenStyles.addStyle("comment", Color.WHITE, darkGreen, false, false);
61
        TokenStyles.addStyle("preprocessor", Color.WHITE, darkPurple, false, false);
62
        TokenStyles.addStyle("whitespace", Color.WHITE, Color.BLACK, false, false);
63
        TokenStyles.addStyle("error", Color.WHITE, Color.RED, false, false);
64
        TokenStyles.addStyle("unknown", Color.WHITE, Color.ORANGE, false, false);
65
        TokenStyles.addStyle("grayedOut", Color.WHITE, Color.GRAY, false, false);
66
    }
67
    
68
    private static void addStyle(String name, Color bg, Color fg, boolean bold, boolean italic) {
69
        
70
        SimpleAttributeSet style = new SimpleAttributeSet();
71
        StyleConstants.setFontFamily(style, UiUtil.FONT_MONO_NON_ASIAN.getFontName());
72
        StyleConstants.setFontSize(style, UiUtil.FONT_MONO_NON_ASIAN.getSize());
73
        StyleConstants.setBackground(style, bg);
74
        StyleConstants.setForeground(style, fg);
75
        StyleConstants.setBold(style, bold);
76
        StyleConstants.setItalic(style, italic);
77
        styles.put(name, style);
78
    }
79
80
    /**
81
     * Retrieve the style for the given type of token.
82
     * 
83
     * @param styleName
84
     *            the label for the type of text ("tag" for example) or null if
85
     *            the styleName is not known.
86
     * @return the style
87
     */
88
    public static AttributeSet getStyle(String styleName) {
89 1 1. getStyle : replaced return value with null for com/jsql/view/swing/sql/lexer/TokenStyles::getStyle → NO_COVERAGE
        return TokenStyles.styles.get(styleName);
90
    }
91
}

Mutations

89

1.1
Location : getStyle
Killed by : none
replaced return value with null for com/jsql/view/swing/sql/lexer/TokenStyles::getStyle → NO_COVERAGE

Active mutators

Tests examined


Report generated by PIT 1.16.1