Newer
Older
KisoJikkenNWP / src / main / java / istlab / KisoJikken / MyRSJTextArea.java
@motoki miura motoki miura on 22 Nov 2022 4 KB add comment
package istlab.KisoJikken;

import java.awt.Color;
import java.awt.Font;

import javax.swing.JPopupMenu;
import javax.swing.plaf.FontUIResource;

import org.fife.ui.rsyntaxtextarea.AbstractTokenMakerFactory;
import org.fife.ui.rsyntaxtextarea.RSyntaxTextArea;
import org.fife.ui.rsyntaxtextarea.Style;
import org.fife.ui.rsyntaxtextarea.SyntaxScheme;
import org.fife.ui.rsyntaxtextarea.Token;
import org.fife.ui.rsyntaxtextarea.TokenMakerFactory;

public class MyRSJTextArea extends RSyntaxTextArea {
    AbstractTokenMakerFactory atmf;

    public MyRSJTextArea() {
        String syn = "TokenMaker4MyRSJTextArea";
        atmf = (AbstractTokenMakerFactory) TokenMakerFactory.getDefaultInstance();
        atmf.putMapping(syn, "istlab.KisoJikken.Test." + syn); //独自のTokenMakerを登録
        setSyntaxEditingStyle(syn);
        setFont(new FontUIResource("sansserif", Font.PLAIN, 14));

        SyntaxScheme scheme = getSyntaxScheme();
        // SyntaxScheme scheme = new SyntaxScheme(false);
        // for(Style s : scheme.getStyles()){
        // System.out.println(s);

        Style baseStyle = new Style(Color.black);
        for (int i = 0; i < 39; i++)
            scheme.setStyle(i, baseStyle);
        Style commentStyle = new Style(new Color(0, 128, 0), new Color(255, 255, 0x66), //緑文字、黄色背景
                new Font("SansSerif", Font.ITALIC, 14));
        Style commentStyle2 = new Style(new Color(0, 128, 0), new Color(0xcc, 255, 255),// 緑文字、水色背景
                new Font("SansSerif", Font.ITALIC, 14));
        Style commentStyle3 = new Style(new Color(0xcc, 0x00, 0xcc), new Color(0xff, 0xcc, 0xff),//マゼンタむらさき文字、ピンク背景
                new Font("SansSerif", Font.ITALIC, 14));
        Style commentStyle4 = new Style(new Color(0x33, 0x88, 0xcc), new Color(0xee, 0xee, 0xee),
                new Font("SansSerif", Font.PLAIN, 14));
        int[] comlist = new int[] { Token.COMMENT_EOL, Token.COMMENT_KEYWORD, Token.COMMENT_MARKUP };
        for (int c : comlist) {
            scheme.setStyle(c, commentStyle);
        }
        int[] comlist2 = new int[] { Token.COMMENT_MULTILINE };
        for (int c : comlist2) {
            scheme.setStyle(c, commentStyle2);
        }
        int[] comlist3 = new int[] { Token.COMMENT_DOCUMENTATION };
        for (int c : comlist3) {
            scheme.setStyle(c, commentStyle3);
        }
        int[] comlist4 = new int[] { Token.ANNOTATION };
        for (int c : comlist4) {
            scheme.setStyle(c, commentStyle4);
        }
        setSyntaxScheme(scheme);

        // scheme.getStyle(Token.COMMENT_EOL).background = Color.cyan;
        // scheme.getStyle(Token.COMMENT_DOCUMENTATION).background =
        // Color.cyan.brighter();
        // scheme.getStyle(Token.COMMENT_KEYWORD).background = Color.green;
        // scheme.getStyle(Token.COMMENT_MARKUP).background = Color.gray;
        // scheme.getStyle(Token.COMMENT_MULTILINE).background = Color.yellow;

        // scheme.getStyle(Token.FUNCTION).foreground = Color.black;
        // scheme.getStyle(Token.IDENTIFIER).foreground = Color.black;
        // scheme.getStyle(Token.LITERAL_NUMBER_DECIMAL_INT).foreground = Color.black;
        // scheme.getStyle(Token.LITERAL_NUMBER_FLOAT).foreground = Color.black;
        // scheme.getStyle(Token.LITERAL_NUMBER_HEXADECIMAL).foreground = Color.black;
        // scheme.getStyle(Token.OPERATOR).foreground = Color.black;
        // scheme.getStyle(Token.VARIABLE).foreground = Color.black;
        // scheme.getStyle(Token.ANNOTATION).foreground = Color.black;
        // scheme.getStyle(Token.DATA_TYPE).foreground = Color.black;
        // scheme.getStyle(Token.ERROR_CHAR).foreground = Color.black;
        // scheme.getStyle(Token.LITERAL_CHAR).foreground = Color.black;

        setHighlightCurrentLine(false); // カーソル行のハイライトを消す
        setCodeFoldingEnabled(true);

    }

    @Override
    protected void configurePopupMenu(JPopupMenu popupMenu) {
    }

    @Override
    protected JPopupMenu createPopupMenu() {
        return null;
    }

}