Package javax.swing.text

Examples of javax.swing.text.Element


    public Element getElement(final Element e, final Object attribute,
                              final Object value) {
        final ElementIterator it = new ElementIterator(e);
        while (it.next() != null) {
            final Element current = it.current();
            if (current.getAttributes().containsAttribute(attribute, value)) {
                return current;
            }
        }
        return null;
    }
View Full Code Here


        if (TARGET_TOP.equals(target)){
            return;
        }

        final Element source = event.getSourceElement();
        final String src = event.getURL().toString();
        if (source != null && TARGET_SELF.equals(target)) {
            processTarget(source, src);
        } else if (source != null && TARGET_PARENT.equals(target)) {
            final Element parent = source.getParentElement();
            if (getParser() == null) {
                setParser(new ParserDelegator());
            }
            try {
                setOuterHTML(parent, "<frame src=\"" + src + "\">");
            } catch (BadLocationException e) {
            } catch (IOException e) {
            }
        } else {
            final ElementIterator frameIterator = new ElementIterator(getDefaultRootElement());
            if (frameIterator != null) {
                while (frameIterator.next() != null) {
                    final Element element = frameIterator.current();
                    if (Tag.FRAME.equals(element.getName())
                        && element.getAttributes().containsAttribute(HTML.Attribute.NAME, target)) {
                       
                        processTarget(element, src);
                    }
                }
            }
View Full Code Here

        fireRemoveUpdate(removeEvent);
    }

    private void insertHTMLText(final Element elem, final int offset,
                                final String htmlText) throws IOException {
        Element preceedBranch = getInsertionStartElement(offset - 1);
        int pop = -1;
        int push = -1;
        do {
            pop++;
            preceedBranch = preceedBranch.getParentElement();
            push = getAncestorDepth(preceedBranch, elem);
        } while (preceedBranch != null && push < 0);
        if (push == -1) {
            return;
        }
View Full Code Here

        }
        return -1;
    }
   
    private Element getInsertionStartElement(final int offset) {
        Element result = getDefaultRootElement();
        do {
            result = result.getElement(result.getElementIndex(offset));
        } while (!result.isLeaf());
       
        return result;
    }
View Full Code Here

        return result;
    }

    private int getAncestorDepth(final Element elem, final Element child) {
        int depth = 0;
        Element parent = child;
        while (parent != null) {
            if (elem == parent) {
                return depth;
            }
            depth++;
            parent = parent.getParentElement();
        }
        return -1;
    }
View Full Code Here

           
            parseBuffer.clear();
        }

        private void removeDefaultBody() {
            Element impliedLF = getCharacterElement(getLength() - 1);
            try {
                remove(getLength() - 1, 1);
            } catch (BadLocationException e) {
            }
            BranchElement root = (BranchElement)getDefaultRootElement();
            final int oddBodyIndex = root.getElementCount() - 1;
            Element oddBody = root.getElement(oddBodyIndex);
            final Element[] emptyArray = new Element[0];
            root.replace(oddBodyIndex, 1, emptyArray);
           
            Element lf = getCharacterElement(getLength());
            writeLock();
            try {
                ((MutableAttributeSet)lf).removeAttributes(lf.getAttributes().getAttributeNames());
                ((MutableAttributeSet)lf).addAttributes(impliedLF.getAttributes());
            } finally {
                writeUnlock();
            }
           
View Full Code Here

        }
       
        private String getStyleNameAt(int pos) {
            try {
                StyledDocument doc = (StyledDocument) getDocument();
                Element elem = doc.getCharacterElement(pos);
                AttributeSet attrs = elem.getAttributes();
                Object result = attrs.getAttribute(StyleConstants.NameAttribute);
                return (String) result;
            } catch (Exception e) {
                return null;
            }
View Full Code Here

  //..Return the Line no at caret
  public int getLineAtCaret(JTextComponent component)
  {
    int caretPosition = component.getCaretPosition();
    Element root = component.getDocument().getDefaultRootElement();
    return root.getElementIndex( caretPosition ) + 1;
  }
View Full Code Here

  //..Return the Column no at caret
  public int getColumnAtCaret(JTextComponent component)
  {
    int caretPosition = component.getCaretPosition();
    Element root = component.getDocument().getDefaultRootElement();
    int line = root.getElementIndex( caretPosition );
    int lineStart = root.getElement( line ).getStartOffset();
    return caretPosition - lineStart + 1;
  }
View Full Code Here

        }
    }

    private static Element getParagraphElement(final Document doc,
                                               final int offset) {
        Element root = doc.getDefaultRootElement();
        return root.getElement(root.getElementIndex(offset));
    }
View Full Code Here

TOP

Related Classes of javax.swing.text.Element

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.