use of javax.swing.text.AttributeSet in project intellij-community by JetBrains.
the class EditableNotificationMessageElement method updateStyle.
protected void updateStyle(@NotNull JEditorPane editorPane, @Nullable JTree tree, Object value, boolean selected, boolean hasFocus) {
super.updateStyle(editorPane, tree, value, selected, hasFocus);
final HTMLDocument htmlDocument = (HTMLDocument) editorPane.getDocument();
final Style linkStyle = htmlDocument.getStyleSheet().getStyle(LINK_STYLE);
StyleConstants.setForeground(linkStyle, IdeTooltipManager.getInstance().getLinkForeground(false));
StyleConstants.setItalic(linkStyle, true);
HTMLDocument.Iterator iterator = htmlDocument.getIterator(HTML.Tag.A);
while (iterator.isValid()) {
boolean disabledLink = false;
final AttributeSet attributes = iterator.getAttributes();
if (attributes instanceof SimpleAttributeSet) {
final Object attribute = attributes.getAttribute(HTML.Attribute.HREF);
if (attribute instanceof String && disabledLinks.containsKey(attribute)) {
disabledLink = true;
//TODO [Vlad] add support for disabled link text update
////final String linkText = disabledLinks.get(attribute);
//if (linkText != null) {
//}
((SimpleAttributeSet) attributes).removeAttribute(HTML.Attribute.HREF);
}
if (attribute == null) {
disabledLink = true;
}
}
if (!disabledLink) {
htmlDocument.setCharacterAttributes(iterator.getStartOffset(), iterator.getEndOffset() - iterator.getStartOffset(), linkStyle, false);
}
iterator.next();
}
}
use of javax.swing.text.AttributeSet in project intellij-community by JetBrains.
the class SwingHelper method scrollToReference.
public static boolean scrollToReference(JEditorPane view, String reference) {
reference = StringUtil.trimStart(reference, "#");
List<String> toCheck = Arrays.asList("a", "h1", "h2", "h3", "h4");
Document document = view.getDocument();
if (document instanceof HTMLDocument) {
List<Element> list = new ArrayList<>();
for (Element root : document.getRootElements()) {
getAllElements(root, list, toCheck);
}
for (Element element : list) {
AttributeSet attributes = element.getAttributes();
String nm = (String) attributes.getAttribute(HTML.Attribute.NAME);
if (nm == null)
nm = (String) attributes.getAttribute(HTML.Attribute.ID);
if ((nm != null) && nm.equals(reference)) {
try {
int pos = element.getStartOffset();
Rectangle r = view.modelToView(pos);
if (r != null) {
Rectangle vis = view.getVisibleRect();
r.y -= 5;
r.height = vis.height;
view.scrollRectToVisible(r);
return true;
}
} catch (BadLocationException ex) {
//ignore
}
}
}
}
return false;
}
use of javax.swing.text.AttributeSet in project pcgen by PCGen.
the class NotesView method colorButtonActionPerformed.
//GEN-LAST:event_leftJustifyButtonActionPerformed
private void colorButtonActionPerformed() {
//GEN-FIRST:event_colorButtonActionPerformed
AttributeSet as = editor.getCharacterAttributes();
SimpleAttributeSet sas = new SimpleAttributeSet(as);
Color newColor = JColorChooser.showDialog(GMGenSystem.inst, "Choose Text Color", editor.getStyledDocument().getForeground(as));
if (newColor != null) {
StyleConstants.setForeground(sas, newColor);
editor.setCharacterAttributes(sas, true);
}
editor.repaint();
}
use of javax.swing.text.AttributeSet in project adempiere by adempiere.
the class Worker method dumpTags.
// run
/**
* Diagnostics
* @param doc html document
* @param tag html tag
*/
private void dumpTags(HTMLDocument doc, HTML.Tag tag) {
System.out.println("Doc=" + doc.getBase() + ", Tag=" + tag);
HTMLDocument.Iterator it = doc.getIterator(tag);
while (it != null && it.isValid()) {
AttributeSet as = it.getAttributes();
System.out.println("~ " + as);
it.next();
}
}
Aggregations