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;
}
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());
}
}
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();
}
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;
}
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();
}
Aggregations