Skip to content

Commit

Permalink
Fixed #1 supporting bold characters.
Browse files Browse the repository at this point in the history
  • Loading branch information
hiohiohio committed Oct 2, 2015
1 parent 5688a67 commit b6a1766
Showing 1 changed file with 14 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ private static class RefreshRunnable implements Runnable {
private final Pattern URLmather;
private final MutableAttributeSet URLAttribute;
private final AttributeSet defAttribute;
private final AttributeSet boldAttribute;

public RefreshRunnable(final StyledDocument doc, final ILogger logger) {
this.doc = doc;
Expand All @@ -259,6 +260,10 @@ public RefreshRunnable(final StyledDocument doc, final ILogger logger) {
StyleConstants.setForeground(this.URLAttribute, Color.blue);

this.defAttribute = new SimpleAttributeSet().copyAttributes();

final MutableAttributeSet tmp = new SimpleAttributeSet();
StyleConstants.setBold(tmp, true);
this.boldAttribute = tmp.copyAttributes();
}

public void run() {
Expand All @@ -282,8 +287,15 @@ public void run() {
while (matcher.find()) {
final int offset = matcher.start();
final int targetLength = matcher.end() - offset;
// transforming into Clickable text
applyStyle(URLAttribute, doc, offset, targetLength, matcher.group());

if (!doc.getCharacterElement(offset).getAttributes().containsAttributes(boldAttribute)) {
// transforming into Clickable text
applyStyle(URLAttribute, doc, offset, targetLength, matcher.group());
} else {
// transforming into Clickable text
applyStyle(URLAttribute, doc, offset, targetLength, matcher.group());
doc.setCharacterAttributes(offset, targetLength, boldAttribute.copyAttributes(), false);
}
}

} catch (BadLocationException ex) {
Expand Down

0 comments on commit b6a1766

Please sign in to comment.