use of javax.swing.text.Element in project pcgen by PCGen.
the class ExtendedHTMLEditorKit method getListItemParent.
/**
* Get the parent of the list item
* @param eleSearch
* @return the parent of the list item
*/
public static Element getListItemParent(Element eleSearch) {
String listItemTag = HTML.Tag.LI.toString();
Element workingElement = eleSearch;
do {
if (listItemTag.equals(workingElement.getName())) {
return workingElement;
}
workingElement = workingElement.getParentElement();
} while (!workingElement.getName().equals(HTML.Tag.HTML.toString()));
return null;
}
use of javax.swing.text.Element in project jdk8u_jdk by JetBrains.
the class ElementTreePanel method caretUpdate.
// CaretListener
/**
* Messaged when the selection in the editor has changed. Will update
* the selection in the tree.
*/
public void caretUpdate(CaretEvent e) {
if (!updatingSelection) {
int selBegin = Math.min(e.getDot(), e.getMark());
int end = Math.max(e.getDot(), e.getMark());
List<TreePath> paths = new ArrayList<TreePath>();
TreeModel model = getTreeModel();
Object root = model.getRoot();
int rootCount = model.getChildCount(root);
// in the selection.
for (int counter = 0; counter < rootCount; counter++) {
int start = selBegin;
while (start <= end) {
TreePath path = getPathForIndex(start, root, (Element) model.getChild(root, counter));
Element charElement = (Element) path.getLastPathComponent();
paths.add(path);
if (start >= charElement.getEndOffset()) {
start++;
} else {
start = charElement.getEndOffset();
}
}
}
// If a path was found, select it (them).
int numPaths = paths.size();
if (numPaths > 0) {
TreePath[] pathArray = new TreePath[numPaths];
paths.toArray(pathArray);
updatingSelection = true;
try {
getTree().setSelectionPaths(pathArray);
getTree().scrollPathToVisible(pathArray[0]);
} finally {
updatingSelection = false;
}
}
}
}
use of javax.swing.text.Element in project jdk8u_jdk by JetBrains.
the class ElementTreePanel method getPathForIndex.
/**
* Returns a TreePath to the element at <code>position</code>.
*/
protected TreePath getPathForIndex(int position, Object root, Element rootElement) {
TreePath path = new TreePath(root);
Element child = rootElement.getElement(rootElement.getElementIndex(position));
path = path.pathByAddingChild(rootElement);
path = path.pathByAddingChild(child);
while (!child.isLeaf()) {
child = child.getElement(child.getElementIndex(position));
path = path.pathByAddingChild(child);
}
return path;
}
use of javax.swing.text.Element in project jdk8u_jdk by JetBrains.
the class ElementTreePanel method valueChanged.
// TreeSelectionListener
/**
* Called whenever the value of the selection changes.
* @param e the event that characterizes the change.
*/
public void valueChanged(TreeSelectionEvent e) {
if (!updatingSelection && tree.getSelectionCount() == 1) {
TreePath selPath = tree.getSelectionPath();
Object lastPathComponent = selPath.getLastPathComponent();
if (!(lastPathComponent instanceof DefaultMutableTreeNode)) {
Element selElement = (Element) lastPathComponent;
updatingSelection = true;
try {
getEditor().select(selElement.getStartOffset(), selElement.getEndOffset());
} finally {
updatingSelection = false;
}
}
}
}
use of javax.swing.text.Element in project pcgen by PCGen.
the class NotesView method handleBackspace.
//methods dealing with Key Events
private void handleBackspace() {
// TODO: This sucks, clean it up
Element elem;
int pos = editor.getCaretPosition();
StyledDocument htmlDoc = (ExtendedHTMLDocument) editor.getStyledDocument();
try {
if (pos > 0) {
if ((editor.getSelectedText()) != null) {
ExtendedHTMLEditorKit.delete(editor);
return;
}
int sOffset = htmlDoc.getParagraphElement(pos).getStartOffset();
if (sOffset == editor.getSelectionStart()) {
if (ExtendedHTMLEditorKit.checkParentsTag(htmlDoc.getParagraphElement(editor.getCaretPosition()), HTML.Tag.LI)) {
elem = ExtendedHTMLEditorKit.getListItemParent(htmlDoc.getCharacterElement(editor.getCaretPosition()));
boolean content = false;
int so = elem.getStartOffset();
int eo = elem.getEndOffset();
if ((so + 1) < eo) {
char[] temp = editor.getText(so, eo - so).toCharArray();
for (char aTemp : temp) {
if (!Character.isWhitespace(aTemp)) {
content = true;
}
}
}
if (!content) {
elem.getParentElement();
ExtendedHTMLEditorKit.removeTag(editor, elem, true);
editor.setCaretPosition(sOffset - 1);
return;
}
editor.setCaretPosition(editor.getCaretPosition() - 1);
editor.moveCaretPosition(editor.getCaretPosition() - 2);
editor.replaceSelection("");
return;
}
}
editor.replaceSelection("");
}
} catch (BadLocationException ble) {
Logging.errorPrint(ble.getMessage(), ble);
}
}
Aggregations