Search in sources :

Example 96 with Element

use of javax.swing.text.Element in project Universal-G-Code-Sender by winder.

the class EditorListener method caretUpdate.

@Override
public void caretUpdate(CaretEvent e) {
    if (e.getSource() instanceof JEditorPane) {
        JEditorPane jep = (JEditorPane) e.getSource();
        Element map = jep.getDocument().getDefaultRootElement();
        int startIndex = map.getElementIndex(jep.getSelectionStart());
        int endIndex = map.getElementIndex(jep.getSelectionEnd());
        if (highlight != null) {
            highlight.setHighlightedLines(startIndex, endIndex);
        }
    }
}
Also used : Element(javax.swing.text.Element)

Example 97 with Element

use of javax.swing.text.Element in project freeplane by freeplane.

the class AutoSpellChecker method checkElements.

/**
 * Check the Elements on the given position.
 */
private void checkElements(int offset, final int length) {
    final int end = offset + length;
    final Document document = jText.getDocument();
    Element element;
    do {
        try {
            // We need to use a ParagraphElement because a CharacterElement produce problems with formating in a word
            element = ((AbstractDocument) document).getParagraphElement(offset);
        } catch (final java.lang.Exception ex) {
            return;
        }
        removeHighlighters(element);
        checkElement(element);
        offset = element.getEndOffset();
    } while (offset <= end && offset < document.getLength());
}
Also used : Element(javax.swing.text.Element) AbstractDocument(javax.swing.text.AbstractDocument) Document(javax.swing.text.Document)

Example 98 with Element

use of javax.swing.text.Element in project freeplane by freeplane.

the class FixedHTMLWriter method writeAttributes.

/*
	 * (non-Javadoc)
	 * @seejavax.swing.text.html.HTMLWriter#writeAttributes(javax.swing.text.
	 * AttributeSet)
	 */
@Override
protected void writeAttributes(final AttributeSet attr) throws IOException {
    if (attr instanceof Element) {
        final Element elem = (Element) attr;
        if (elem.isLeaf() || elem.getName().equalsIgnoreCase("p-implied")) {
            super.writeAttributes(attr);
            return;
        }
    }
    convAttr.removeAttributes(convAttr);
    FixedHTMLWriter.convertToHTML(attr, convAttr);
    final Enumeration<?> names = convAttr.getAttributeNames();
    while (names.hasMoreElements()) {
        final Object name = names.nextElement();
        if (name instanceof HTML.Tag || name instanceof StyleConstants || name == HTML.Attribute.ENDTAG) {
            continue;
        }
        write(" " + name + "=\"" + convAttr.getAttribute(name) + "\"");
    }
}
Also used : StyleConstants(javax.swing.text.StyleConstants) Element(javax.swing.text.Element)

Example 99 with Element

use of javax.swing.text.Element in project freeplane by freeplane.

the class HtmlUtils method getCurrentLinkElement.

public static Element getCurrentLinkElement(HTMLDocument doc, int pos) {
    Element element2 = null;
    Element element = doc.getCharacterElement(pos);
    // elem.getAttributes().getAttribute(HTML.Tag.A);
    Object linkAttribute = null;
    Object href = null;
    while (element != null && linkAttribute == null) {
        element2 = element;
        linkAttribute = element.getAttributes().getAttribute(HTML.Tag.A);
        if (linkAttribute != null) {
            href = ((AttributeSet) linkAttribute).getAttribute(HTML.Attribute.HREF);
        }
        element = element.getParentElement();
    }
    if (linkAttribute != null && href != null) {
        return element2;
    } else {
        return null;
    }
}
Also used : Element(javax.swing.text.Element)

Example 100 with Element

use of javax.swing.text.Element in project freeplane by freeplane.

the class HtmlUtils method getURLOfExistingLink.

/**
 * Gets the string URL of an existing link, or null if none.
 */
public static String getURLOfExistingLink(HTMLDocument doc, int pos) {
    // setIgnoreActions(true);
    final Element linkElement = HtmlUtils.getCurrentLinkElement(doc, pos);
    final boolean foundLink = (linkElement != null);
    if (!foundLink) {
        return null;
    }
    final AttributeSet elemAttrs = linkElement.getAttributes();
    final Object linkAttr = elemAttrs.getAttribute(HTML.Tag.A);
    final Object href = ((AttributeSet) linkAttr).getAttribute(HTML.Attribute.HREF);
    return href != null ? href.toString() : null;
}
Also used : AttributeSet(javax.swing.text.AttributeSet) Element(javax.swing.text.Element)

Aggregations

Element (javax.swing.text.Element)100 BadLocationException (javax.swing.text.BadLocationException)35 Point (java.awt.Point)19 AttributeSet (javax.swing.text.AttributeSet)15 Document (javax.swing.text.Document)15 HTMLDocument (javax.swing.text.html.HTMLDocument)11 FontMetrics (java.awt.FontMetrics)6 Dimension (java.awt.Dimension)5 Rectangle (java.awt.Rectangle)5 View (javax.swing.text.View)5 Font (java.awt.Font)4 Insets (java.awt.Insets)4 IOException (java.io.IOException)4 AbstractDocument (javax.swing.text.AbstractDocument)4 StyledDocument (javax.swing.text.StyledDocument)4 java.awt (java.awt)3 Objects (java.util.Objects)3 javax.swing (javax.swing)3 AbstractElement (javax.swing.text.AbstractDocument.AbstractElement)3 HTML (javax.swing.text.html.HTML)3