如何从GutterIconInfo获取行号-RSyntaxTextArea

时间:2018-10-13 16:48:26

标签: code-editor rsyntaxtextarea

我正在使用RSyntaxTextArea进行代码编辑,并且我需要知道在中有一个断点

使用以下代码,我可以将文本区域的偏移量移至找到断点的位置,但是我不能仅计算每个断点

版本:rsyntaxtextarea-3.0.0

View

输出:

GUTTERS
断点标记偏移:15
断点标记偏移:41
文字区域属性
当前行的端点偏移:15
当前行的末端偏移:18
行数:11

有什么想法吗?

public class Tab extends javax.swing.JPanel {

    RSyntaxTextArea textArea;
    RTextScrollPane sp;
    Gutter gutter;

    public Tab(){
        initComponents();
        this.setLayout(new BorderLayout());
        AtextArea = new RSyntaxTextArea();
        textArea.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_JAVASCRIPT);
        textArea.setCodeFoldingEnabled(true);
        textArea.setCurrentLineHighlightColor(new Color(227, 242, 253, 200));
        textArea.setFadeCurrentLineHighlight(true);
        textArea.setBorder(BorderFactory.createEmptyBorder());
        sp = new RTextScrollPane(textArea);
        gutter = sp.getGutter();
        ImageIcon breakPoint = new ImageIcon(System.getProperty("user.dir") + "/src/olc2/dew/sources/icons/024-break-point.png");
        gutter.setBookmarkIcon(breakPoint);
        gutter.setFoldIndicatorEnabled(true);
        gutter.setBookmarkingEnabled(true);
        this.add(sp);    
    }

    public void showGutters() {
        GutterIconInfo[] breakPoints = gutter.getBookmarks();
        System.out.println("GUTTERS");
        for (GutterIconInfo breakPoint : breakPoints) {
            System.out.println("Break Point Marked Offset: " + breakPoint.getMarkedOffset());//Show the offset until to find a break point
        }
        //I need only the break point number line, don't the offset
        System.out.println("TEXT AREA PROPERTIES");
        System.out.println("End Offset of Current Line: " + textArea.getLineStartOffsetOfCurrentLine());
        System.out.println("End Offset of Current Line: " + textArea.getLineEndOffsetOfCurrentLine());
        System.out.println("Line Count: " + textArea.getLineCount());
        System.out.println("Line Height: " + textArea.getLineHeight());
    }
}

0 个答案:

没有答案