Search in sources :

Example 16 with AttributeSet

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();
    }
}
Also used : SimpleAttributeSet(javax.swing.text.SimpleAttributeSet) SimpleAttributeSet(javax.swing.text.SimpleAttributeSet) AttributeSet(javax.swing.text.AttributeSet) HTMLDocument(javax.swing.text.html.HTMLDocument) Style(javax.swing.text.Style)

Example 17 with AttributeSet

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;
}
Also used : AttributeSet(javax.swing.text.AttributeSet) HTMLDocument(javax.swing.text.html.HTMLDocument) Element(javax.swing.text.Element) HTMLDocument(javax.swing.text.html.HTMLDocument) Document(javax.swing.text.Document) BadLocationException(javax.swing.text.BadLocationException)

Example 18 with AttributeSet

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();
}
Also used : SimpleAttributeSet(javax.swing.text.SimpleAttributeSet) AttributeSet(javax.swing.text.AttributeSet) SimpleAttributeSet(javax.swing.text.SimpleAttributeSet) Color(java.awt.Color)

Example 19 with AttributeSet

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();
    }
}
Also used : AttributeSet(javax.swing.text.AttributeSet) HTMLDocument(javax.swing.text.html.HTMLDocument)

Aggregations

AttributeSet (javax.swing.text.AttributeSet)19 Element (javax.swing.text.Element)6 SimpleAttributeSet (javax.swing.text.SimpleAttributeSet)6 HTMLDocument (javax.swing.text.html.HTMLDocument)5 BadLocationException (javax.swing.text.BadLocationException)4 Point (java.awt.Point)3 Color (java.awt.Color)2 Font (java.awt.Font)2 FontMetrics (java.awt.FontMetrics)2 Rectangle (java.awt.Rectangle)2 URL (java.net.URL)2 DefaultStyledDocument (javax.swing.text.DefaultStyledDocument)2 Document (javax.swing.text.Document)2 HTMLEditorKit (javax.swing.text.html.HTMLEditorKit)2 FormattedCharacterBuffer (com.google.security.zynamics.zylib.gui.CodeDisplay.FormattedCharacterBuffer)1 OpenFileDescriptor (com.intellij.openapi.fileEditor.OpenFileDescriptor)1 Project (com.intellij.openapi.project.Project)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 HyperlinkAdapter (com.intellij.ui.HyperlinkAdapter)1 Dimension (java.awt.Dimension)1