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);
}
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);
}
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;
}
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);
}
}
}
}
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);
}
Aggregations