Search in sources :

Example 1 with DefaultStyledDocument

use of javax.swing.text.DefaultStyledDocument in project android-classyshark by google.

the class DisplayArea method displayClass.

// TODO add here logic fo highlighter
// TODO by adding flag to Translator.ELEMENT
@Override
public void displayClass(List<Translator.ELEMENT> elements, String key) {
    displayDataState = DisplayDataState.INSIDE_CLASS;
    clearText();
    StyleConstants.setFontSize(style, 18);
    StyleConstants.setBackground(style, theme.getBackgroundColor());
    Document doc = new DefaultStyledDocument();
    fillTokensToDoc(elements, doc, false);
    StyleConstants.setForeground(style, theme.getIdentifiersColor());
    jTextPane.setDocument(doc);
    int i = calcScrollingPosition(key);
    jTextPane.setCaretPosition(i);
}
Also used : DefaultStyledDocument(javax.swing.text.DefaultStyledDocument) Document(javax.swing.text.Document) DefaultStyledDocument(javax.swing.text.DefaultStyledDocument)

Example 2 with DefaultStyledDocument

use of javax.swing.text.DefaultStyledDocument in project android-classyshark by google.

the class DisplayArea method displayClass.

@Override
public void displayClass(String classString) {
    displayDataState = DisplayDataState.INSIDE_CLASS;
    try {
        String currentText = jTextPane.getDocument().getText(0, jTextPane.getDocument().getLength());
        if (currentText.equals(getOneColorFormattedOutput(classString))) {
            return;
        }
    } catch (BadLocationException e) {
        e.printStackTrace();
    }
    clearText();
    StyleConstants.setFontSize(style, 18);
    Document doc = new DefaultStyledDocument();
    try {
        doc.insertString(doc.getLength(), getOneColorFormattedOutput(classString), style);
    } catch (BadLocationException e) {
        e.printStackTrace();
    }
    jTextPane.setDocument(doc);
    jTextPane.setCaretPosition(1);
}
Also used : DefaultStyledDocument(javax.swing.text.DefaultStyledDocument) Document(javax.swing.text.Document) DefaultStyledDocument(javax.swing.text.DefaultStyledDocument) BadLocationException(javax.swing.text.BadLocationException)

Example 3 with DefaultStyledDocument

use of javax.swing.text.DefaultStyledDocument in project intellij-community by JetBrains.

the class HtmlCopyPastePreProcessor method convertFromRtfStream.

private static String convertFromRtfStream(InputStream stream) {
    final DefaultStyledDocument document = new DefaultStyledDocument();
    try {
        new RTFEditorKit().read(stream, document, 0);
        final StringWriter writer = new StringWriter();
        new HTMLEditorKit().write(writer, document, 0, document.getLength());
        return writer.toString();
    } catch (IOException | BadLocationException e) {
        LOG.error(e);
    }
    return null;
}
Also used : StringWriter(java.io.StringWriter) RTFEditorKit(javax.swing.text.rtf.RTFEditorKit) HTMLEditorKit(javax.swing.text.html.HTMLEditorKit) IOException(java.io.IOException) DefaultStyledDocument(javax.swing.text.DefaultStyledDocument) BadLocationException(javax.swing.text.BadLocationException)

Example 4 with DefaultStyledDocument

use of javax.swing.text.DefaultStyledDocument in project Botnak by Gocnak.

the class ListenerURL method mouseReleased.

@Override
public void mouseReleased(MouseEvent e) {
    JTextPane editor = (JTextPane) e.getSource();
    Point pt = new Point(e.getX(), e.getY());
    int pos = editor.viewToModel(pt);
    if (pos >= 0) {
        Document doc = editor.getDocument();
        if (doc instanceof DefaultStyledDocument) {
            DefaultStyledDocument hdoc = (DefaultStyledDocument) doc;
            Element el = hdoc.getCharacterElement(pos);
            AttributeSet a = el.getAttributes();
            String href = (String) a.getAttribute(HTML.Attribute.HREF);
            if (href != null) {
                Utils.openWebPage(href);
            }
        }
    }
}
Also used : AttributeSet(javax.swing.text.AttributeSet) Element(javax.swing.text.Element) DefaultStyledDocument(javax.swing.text.DefaultStyledDocument) Document(javax.swing.text.Document) DefaultStyledDocument(javax.swing.text.DefaultStyledDocument)

Example 5 with DefaultStyledDocument

use of javax.swing.text.DefaultStyledDocument in project binnavi by google.

the class BaseTypeTableCellRenderer method renderType.

public static FormattedCharacterBuffer renderType(final TypeInstance instance, Font font, int desiredWidth, final boolean renderData) {
    DefaultStyledDocument document = new DefaultStyledDocument();
    generateDocument(instance, renderData, document);
    return convertDocumentToFormattedCharacterBuffer(document, font, desiredWidth);
}
Also used : DefaultStyledDocument(javax.swing.text.DefaultStyledDocument)

Aggregations

DefaultStyledDocument (javax.swing.text.DefaultStyledDocument)9 BadLocationException (javax.swing.text.BadLocationException)4 Document (javax.swing.text.Document)4 AttributeSet (javax.swing.text.AttributeSet)2 IOException (java.io.IOException)1 StringWriter (java.io.StringWriter)1 Element (javax.swing.text.Element)1 StyledDocument (javax.swing.text.StyledDocument)1 HTMLEditorKit (javax.swing.text.html.HTMLEditorKit)1 RTFEditorKit (javax.swing.text.rtf.RTFEditorKit)1