javax.swing.text.DefaultStyledDocument#putProperty ( )源码实例Demo

下面列出了javax.swing.text.DefaultStyledDocument#putProperty ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: netbeans   文件: HighlightingTest.java
private Document createDocument(String text) {
    try {
        DefaultStyledDocument doc = new DefaultStyledDocument();
        doc.putProperty(Language.class, JavaTokenId.language());
        doc.insertString(0, text, SimpleAttributeSet.EMPTY);
        return doc;
    } catch (BadLocationException e) {
        fail(e.getMessage());
    }
    return null;
}
 
源代码2 项目: netbeans   文件: SyntaxHighlightingTest.java
private Document createDocument(Language lang, String text) {
    try {
        DefaultStyledDocument doc = new DefaultStyledDocument();
        doc.putProperty(Language.class, lang);
        doc.insertString(0, text, SimpleAttributeSet.EMPTY);
        return doc;
    } catch (BadLocationException e) {
        fail(e.getMessage());
        return null;
    }
}
 
源代码3 项目: spotbugs   文件: JavaSourceDocument.java
public JavaSourceDocument(String title, Reader in, SourceFile theSource) throws IOException {
    doc = new DefaultStyledDocument();
    this.title = title;
    this.sourceFile = theSource;
    Debug.println("Created JavaSourceDocument for " + title);
    try {
        dek.read(in, doc, 0);
    } catch (BadLocationException e) {
        throw new RuntimeException(e);
    }
    in.close();
    doc.putProperty(Document.TitleProperty, title);
    //        root = doc.getDefaultRootElement();
    Toolkit toolkit = Toolkit.getDefaultToolkit();
    FontMetrics fontMetrics = toolkit.getFontMetrics(sourceFont);
    TabStop[] tabs = new TabStop[50];
    float width = fontMetrics.stringWidth(" ");

    int tabSize = GUISaveState.getInstance().getTabSize();
    for (int i = 0; i < tabs.length; i++) {
        tabs[i] = new TabStop(width * (tabSize + tabSize * i));
    }
    TAB_SET = new TabSet(tabs);
    StyleConstants.setTabSet(commentAttributes, TAB_SET);
    StyleConstants.setTabSet(javadocAttributes, TAB_SET);

    StyleConstants.setTabSet(quotesAttributes, TAB_SET);

    StyleConstants.setTabSet(keywordsAttributes, TAB_SET);

    StyleConstants.setTabSet(commentAttributes, TAB_SET);

    StyleConstants.setTabSet(whiteAttributes, TAB_SET);
    StyleConstants.setFontFamily(whiteAttributes, sourceFont.getFamily());
    StyleConstants.setFontSize(whiteAttributes, sourceFont.getSize());
    StyleConstants.setLeftIndent(whiteAttributes, NumberedParagraphView.NUMBERS_WIDTH);

    doc.setParagraphAttributes(0, doc.getLength(), whiteAttributes, true);
    JavaScanner parser = new JavaScanner(new DocumentCharacterIterator(doc));
    while (parser.next() != JavaScanner.EOF) {
        int kind = parser.getKind();
        switch (kind) {
        case JavaScanner.COMMENT:
            doc.setCharacterAttributes(parser.getStartPosition(), parser.getLength(), commentAttributes, true);
            break;

        case JavaScanner.KEYWORD:
            doc.setCharacterAttributes(parser.getStartPosition(), parser.getLength(), keywordsAttributes, true);
            break;

        case JavaScanner.JAVADOC:
            doc.setCharacterAttributes(parser.getStartPosition(), parser.getLength(), javadocAttributes, true);
            break;

        case JavaScanner.QUOTE:
            doc.setCharacterAttributes(parser.getStartPosition(), parser.getLength(), quotesAttributes, true);
            break;

        default:
            break;
        }

    }

}
 
 同类方法