use of javax.swing.text.MutableAttributeSet in project languagetool by languagetool-org.
the class RetainLineBreakTransferHandler method extractText.
private String extractText(Reader reader) {
StringBuilder result = new StringBuilder();
HTMLEditorKit.ParserCallback parserCallback = new HTMLEditorKit.ParserCallback() {
@Override
public void handleText(char[] data, int pos) {
result.append(data);
}
@Override
public void handleStartTag(HTML.Tag tag, MutableAttributeSet attribute, int pos) {
}
@Override
public void handleEndTag(HTML.Tag tag, int pos) {
}
@Override
public void handleSimpleTag(HTML.Tag tag, MutableAttributeSet a, int pos) {
if (tag.equals(HTML.Tag.BR)) {
result.append('\n');
}
}
@Override
public void handleComment(char[] data, int pos) {
}
@Override
public void handleError(String errMsg, int pos) {
}
};
try {
new ParserDelegator().parse(reader, parserCallback, true);
} catch (IOException e) {
throw new RuntimeException(e);
}
return result.toString();
}
use of javax.swing.text.MutableAttributeSet in project intellij-community by JetBrains.
the class PyPIPackageUtil method parsePackageVersionsFromArchives.
@NotNull
private static List<String> parsePackageVersionsFromArchives(@NotNull String archivesUrl) throws IOException {
return HttpRequests.request(archivesUrl).userAgent(getUserAgent()).connect(request -> {
final List<String> versions = new ArrayList<>();
final Reader reader = request.getReader();
new ParserDelegator().parse(reader, new HTMLEditorKit.ParserCallback() {
HTML.Tag myTag;
@Override
public void handleStartTag(HTML.Tag tag, MutableAttributeSet set, int i) {
myTag = tag;
}
@Override
public void handleText(@NotNull char[] data, int pos) {
if (myTag != null && "a".equals(myTag.toString())) {
String packageVersion = String.valueOf(data);
final String suffix = ".tar.gz";
if (!packageVersion.endsWith(suffix))
return;
packageVersion = StringUtil.trimEnd(packageVersion, suffix);
versions.add(splitNameVersion(packageVersion).second);
}
}
}, true);
versions.sort(PackageVersionComparator.VERSION_COMPARATOR.reversed());
return versions;
});
}
use of javax.swing.text.MutableAttributeSet in project intellij-community by JetBrains.
the class HyperlinkLabel method setHtmlText.
public void setHtmlText(String text) {
HTMLEditorKit.Parser parse = new ParserDelegator();
final HighlightedText highlightedText = new HighlightedText();
try {
parse.parse(new StringReader(text), new HTMLEditorKit.ParserCallback() {
private TextAttributes currentAttributes = null;
@Override
public void handleText(char[] data, int pos) {
highlightedText.appendText(data, currentAttributes);
}
@Override
public void handleStartTag(HTML.Tag t, MutableAttributeSet a, int pos) {
if (t == HTML.Tag.B) {
currentAttributes = BOLD_ATTRIBUTES;
} else if (t == HTML.Tag.A) {
currentAttributes = myAnchorAttributes;
}
}
@Override
public void handleEndTag(HTML.Tag t, int pos) {
currentAttributes = null;
}
}, false);
} catch (IOException e) {
LOG.error(e);
}
highlightedText.applyToComponent(this);
final JComponent parent = (JComponent) getParent();
parent.revalidate();
parent.repaint();
adjustSize();
}
use of javax.swing.text.MutableAttributeSet in project JMRI by JMRI.
the class JTextPaneAppender method createAttributes.
private void createAttributes() {
String[] prio = new String[6];
prio[0] = Level.FATAL.toString();
prio[1] = Level.ERROR.toString();
prio[2] = Level.WARN.toString();
prio[3] = Level.INFO.toString();
prio[4] = Level.DEBUG.toString();
prio[5] = Level.TRACE.toString();
myAttributeSet = new Hashtable<String, MutableAttributeSet>();
for (int i = 0; i < prio.length; i++) {
MutableAttributeSet att = new SimpleAttributeSet();
myAttributeSet.put(prio[i], att);
StyleConstants.setFontSize(att, 14);
}
StyleConstants.setForeground(myAttributeSet.get(Level.FATAL.toString()), Color.red);
StyleConstants.setForeground(myAttributeSet.get(Level.ERROR.toString()), Color.red);
StyleConstants.setForeground(myAttributeSet.get(Level.WARN.toString()), Color.orange);
StyleConstants.setForeground(myAttributeSet.get(Level.INFO.toString()), Color.black);
StyleConstants.setForeground(myAttributeSet.get(Level.DEBUG.toString()), Color.black);
StyleConstants.setForeground(myAttributeSet.get(Level.TRACE.toString()), Color.black);
}
use of javax.swing.text.MutableAttributeSet in project opennars by opennars.
the class SwingText method printColorBlock.
public void printColorBlock(final Color color, final String s) {
// StyleContext sc = StyleContext.getDefaultStyleContext();
MutableAttributeSet aset = getInputAttributes();
StyleConstants.setBackground(aset, color);
try {
int l = doc.getLength();
doc.insertString(l, s, aset);
} catch (BadLocationException ex) {
Logger.getLogger(SwingLogText.class.getName()).log(Level.SEVERE, null, ex);
}
}
Aggregations