【问题标题】:Custom color scheme for jEdit StandaloneTextArea?jEdit StandaloneTextArea的自定义配色方案?
【发布时间】:2014-05-20 10:20:02
【问题描述】:

我正在将StandaloneTextArea (STA) 组件用于具有语法高亮显示的编辑器。我知道如何通过xml文件定义函数和关键字,但我不知道如何自定义STA的字体和颜色。

这是我迄今为止尝试过的:

Mode mode = new Mode("asm");
mode.setProperty("file", assemblymodes[COMPILER_ACME]);
ModeProvider.instance.addMode(mode);
standaloneTextArea.getBuffer().setMode(mode);

我尝试使用paintersetStyle 设置颜色,但没有成功:

TextAreaPainter painter = standaloneTextArea.getPainter();
painter.setStyles(SyntaxUtilities.loadStyles(Font.MONOSPACED, 14));

我知道有像view.style.comment1 这样的颜色属性,但是如何分配这些属性以便将自定义配色方案应用于语法突出显示?

【问题讨论】:

    标签: java syntax-highlighting jedit


    【解决方案1】:

    好的,我找到了解决方案。我首先通过TextArea.createTextArea() 创建了 StandaloneTextArea,这在设置属性时似乎不起作用,所以我必须从 StandaloneTextArea 派生我自己的类:

    public class RL64TextArea extends StandaloneTextArea {
        final static Properties props;
        static IPropertyManager propertyManager;
    
        static {
            props = new Properties();
            props.putAll(loadProperties("jedit_keys.props"));
            props.putAll(loadProperties("jedit.props"));
            propertyManager = new IPropertyManager() {
                @Override
                public String getProperty(String name) {
                    return props.getProperty(name);
                }
            };
        }
    
        public void setProperty(String name, String val) {
            props.setProperty(name, val);
        }
    
        private static Properties loadProperties(String fileName) {
            Properties loadedProps = new Properties();
            InputStream in = StandaloneTextArea.class.getResourceAsStream(fileName);
            try {
                loadedProps.load(in);
            }
            catch (IOException e) {
                ConstantsR64.r64logger.log(Level.WARNING,e.getLocalizedMessage());
            }
            finally {
                IOUtilities.closeQuietly(in);
            }
            return loadedProps;
        }
    
        public RL64TextArea() {
            super(propertyManager);
    
            // set syntax rules
            Mode mode = new Mode("asm");
            mode.setProperty("file", "syntax-rules.xml");
            ModeProvider.instance.addMode(mode);
            // add mode to buffer
            getBuffer().setMode(mode);
    
            // set colors
            setProperty("view.style.function", "color:"+ColorSchemes.getColor(scheme, ColorSchemes.COLOR_SCRIPTKEYWORD));
            setProperty("view.style.keyword1", "color:"+ColorSchemes.getColor(scheme, ColorSchemes.COLOR_KEYWORD));
            // ... more colors
    
            // load styles
            getPainter().setStyles(SyntaxUtilities.loadStyles(Font.MONOSPACED, 12));
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-05-07
      • 2011-06-08
      • 1970-01-01
      • 2021-09-30
      • 1970-01-01
      • 2023-02-20
      • 1970-01-01
      • 2011-01-03
      相关资源
      最近更新 更多