Search in sources :

Example 36 with Element

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;
}
Also used : TreePath(javax.swing.tree.TreePath) Element(javax.swing.text.Element)

Example 37 with Element

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;
            }
        }
    }
}
Also used : TreePath(javax.swing.tree.TreePath) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) Element(javax.swing.text.Element)

Example 38 with Element

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

Example 39 with Element

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);
    }
}
Also used : ExtendedHTMLDocument(gmgen.gui.ExtendedHTMLDocument) Element(javax.swing.text.Element) StyledDocument(javax.swing.text.StyledDocument) Point(java.awt.Point) BadLocationException(javax.swing.text.BadLocationException)

Example 40 with Element

use of javax.swing.text.Element in project processdash by dtuma.

the class PersonLookupDialog method processUserInterfaceChanges.

private void processUserInterfaceChanges(HTMLDocument htmlDoc) {
    // if we find a title in the HTML doc, use it as the title of the dialog
    Object docTitle = htmlDoc.getProperty(HTMLDocument.TitleProperty);
    if (docTitle != null)
        dialog.setTitle(String.valueOf(docTitle));
    // enlarge the dialog if necessary to fit the contents.
    Dimension pref = html.getPreferredSize();
    Dimension curr = scrollPane.getViewport().getSize();
    Dimension d = dialog.getSize();
    // First, test to see if the dialog needs to be taller.  If so,
    // enlarge it.
    double yDelta = pref.getHeight() - curr.getHeight();
    if (yDelta > 0) {
        d.height = (int) Math.min(d.height + yDelta + 1, MAX_DIALOG_HEIGHT);
        dialog.setSize(d);
        dialog.validate();
        // changing the dialog height could have caused a vertical
        // scrollbar to appear or disappear.  Just in case, get the new
        // size of the viewport so the horizontal resizing logic can use it.
        curr = scrollPane.getViewport().getSize();
    }
    // Now test to see if the dialog needs to be wider.  If so, enlarge it.
    double xDelta = pref.getWidth() - curr.getWidth();
    if (xDelta > 0) {
        d.width = (int) (d.width + xDelta + 4);
        dialog.setSize(d);
        dialog.validate();
    }
    // stays in the same location as before
    if (yDelta > 0 || xDelta > 0) {
        Point location = dialog.getLocation();
        //
        location.setLocation(Math.max(0, location.x - Math.max(0, xDelta / 2)), Math.max(0, location.y - Math.max(0, yDelta / 2)));
        dialog.setLocation(location);
    }
    // scan the HTML document, and arrange for all text fields to perform
    // a "select all" when they receive the focus.  Also, arrange for all
    // buttons to accept Enter as an activation key.
    tweakInputFields(html);
    // if one of the elements on the form has the ID "grabFocus," arrange
    // for it to receive focus immediately.
    Element e = htmlDoc.getElement("grabFocus");
    JComponent c = findComponentForInputElement(e);
    if (c != null)
        new GrabFocus(c);
}
Also used : Element(javax.swing.text.Element) JComponent(javax.swing.JComponent) Dimension(java.awt.Dimension) Point(java.awt.Point)

Aggregations

Element (javax.swing.text.Element)40 BadLocationException (javax.swing.text.BadLocationException)15 Point (java.awt.Point)13 AttributeSet (javax.swing.text.AttributeSet)6 HTMLDocument (javax.swing.text.html.HTMLDocument)6 FontMetrics (java.awt.FontMetrics)4 Dimension (java.awt.Dimension)3 IOException (java.io.IOException)3 Document (javax.swing.text.Document)3 TreePath (javax.swing.tree.TreePath)3 ExtendedHTMLDocument (gmgen.gui.ExtendedHTMLDocument)2 Font (java.awt.Font)2 Insets (java.awt.Insets)2 Rectangle (java.awt.Rectangle)2 Accessible (javax.accessibility.Accessible)2 JTextComponent (javax.swing.text.JTextComponent)2 SimpleAttributeSet (javax.swing.text.SimpleAttributeSet)2 HTMLEditorKit (javax.swing.text.html.HTMLEditorKit)2 Reader (java.io.Reader)1 StringReader (java.io.StringReader)1