Search in sources :

Example 51 with Element

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

the class XHTMLWriter method balance.

private int balance(final Element elem, final boolean isEndtag) {
    final Element parentElement = elem.getParentElement();
    final int elementCount = parentElement.getElementCount();
    int balance = 0;
    final String elemName = elem.getName();
    for (int i = 0; i < elementCount; i++) {
        final Element childElement = parentElement.getElement(i);
        if (isEndtag) {
            if (childElement.equals(elem)) {
                balance--;
                break;
            }
        } else {
            if (childElement.equals(elem)) {
                balance = 1;
                continue;
            }
            if (balance == 0) {
                continue;
            }
        }
        if (!elemName.equals(childElement.getName())) {
            continue;
        }
        if (isEndtag(childElement)) {
            if (balance > 0) {
                balance--;
                continue;
            }
        } else {
            balance++;
        }
    }
    return balance;
}
Also used : Element(javax.swing.text.Element)

Example 52 with Element

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

the class RunFromHere method actionPerformed.

@Override
public void actionPerformed(ActionEvent ev) {
    Element root = EditorRegistry.lastFocusedComponent().getDocument().getDefaultRootElement();
    int caretPosition = EditorRegistry.lastFocusedComponent().getCaretPosition();
    int line = root.getElementIndex(caretPosition) - 1;
    try {
        runFromService.runFromLine(line);
    } catch (Exception e) {
        GUIHelpers.displayErrorDialog(e.getLocalizedMessage());
    }
}
Also used : Element(javax.swing.text.Element)

Example 53 with Element

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

the class RunFromHereHighlightContainer method runFromLineChanged.

@Override
public void runFromLineChanged(int lineNumber) {
    DataObject dataObject = NbEditorUtilities.getDataObject(weakDoc.get());
    if (dataObject == null) {
        clearHighlights();
        return;
    }
    EditorCookie pane = dataObject.getLookup().lookup(EditorCookie.class);
    JEditorPane[] panes = pane.getOpenedPanes();
    if (panes == null || panes.length == 0) {
        clearHighlights();
        return;
    }
    JEditorPane comp = panes[0];
    Element root = comp.getDocument().getDefaultRootElement();
    Element element = root.getElement(lineNumber + 1);
    bag.clear();
    if (element != null) {
        bag.addHighlight(0, element.getStartOffset(), highlightAttributes);
    }
    notifyHighlightsChanged();
}
Also used : DataObject(org.openide.loaders.DataObject) EditorCookie(org.openide.cookies.EditorCookie) Element(javax.swing.text.Element)

Example 54 with Element

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

the class SplitNode method getParentElement.

private Element getParentElement(final HTMLDocument doc) {
    final Element htmlRoot = doc.getDefaultRootElement();
    Element parentCandidate = htmlRoot.getElement(htmlRoot.getElementCount() - 1);
    do {
        if (parentCandidate.getElementCount() > 1) {
            return parentCandidate;
        }
        parentCandidate = parentCandidate.getElement(0);
    } while (!(parentCandidate.isLeaf() || parentCandidate.getName().equalsIgnoreCase("p-implied")));
    return null;
}
Also used : Element(javax.swing.text.Element)

Example 55 with Element

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

the class SHTMLEditLinkAction method actionPerformed.

public void actionPerformed(final ActionEvent ae) {
    SHTMLEditorPane editorPane = panel.getSHTMLEditorPane();
    final Element linkElement = editorPane.getCurrentLinkElement();
    final boolean foundLink = (linkElement != null);
    final String linkAsString;
    if (foundLink) {
        final AttributeSet elemAttrs = linkElement.getAttributes();
        final Object linkAttr = elemAttrs.getAttribute(HTML.Tag.A);
        final Object href = ((AttributeSet) linkAttr).getAttribute(HTML.Attribute.HREF);
        if (href != null) {
            linkAsString = href.toString();
        } else
            linkAsString = "http://";
    } else {
        linkAsString = "http://";
    }
    final String inputValue = UITools.showInputDialog(Controller.getCurrentController().getSelection().getSelected(), TextUtils.getText("edit_link_manually"), linkAsString);
    if (inputValue != null && !inputValue.matches("\\w+://")) {
        SHTMLEditorPane editor = panel.getSHTMLEditorPane();
        if (inputValue.equals("")) {
            editor.setLink(null, null, null);
            return;
        }
        try {
            final URI link = LinkController.createURI(inputValue.trim());
            editor.setLink(null, link.toString(), null);
        } catch (final URISyntaxException e1) {
            LogUtils.warn(e1);
            UITools.errorMessage(TextUtils.format("invalid_uri", inputValue));
            return;
        }
    }
    panel.updateActions();
}
Also used : SHTMLEditorPane(com.lightdev.app.shtm.SHTMLEditorPane) AttributeSet(javax.swing.text.AttributeSet) Element(javax.swing.text.Element) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI)

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