Package org.w3c.dom.ranges

Examples of org.w3c.dom.ranges.Range


        if (ranges == null) {
            ranges = new Vector();
        }

        Range range = new RangeImpl(this);

        ranges.addElement(range);

        return range;
View Full Code Here


            for (int i = 0; i < tests.length; i++) {
                if (fStdOut) System.out.println("\n\nTest["+i+"]");
                if (fStdOut) System.out.println("\nBefore "+arg+": document="+tests[i]+":");
                parser.parse(new InputSource(new StringReader(tests[i])));
                DocumentImpl document = (DocumentImpl)parser.getDocument();
                Range range = document.createRange();
                Node root = document.getDocumentElement();
                boolean surround = false;
                Node surroundNode=document.createElement(SURROUND);
                if (arg.equals("surround")) {
                    surround = true;
                }
               
                if (i == 0) {
                    range.setStart(root.getFirstChild(), 1);
                    range.setEndBefore(root.getLastChild());
                    if (surround)
                        range.setEnd(root.getLastChild(),1);
                   
                }
                else if (i == 1) {
                    Node n1 = root.getFirstChild().getNextSibling().
                    getFirstChild();
                    range.setStart(n1, 1);
                    range.setEnd(root.getLastChild(), 1);
                    if (surround)
                        range.setEnd(n1,2);
                }
                else if (i == 2) {
                    range.setStart(root.getFirstChild(), 1);
                    Node n2 = root.getFirstChild().getNextSibling().getFirstChild();
                    range.setEnd(n2, 1);
                    if (surround)
                        range.setEndBefore(root.getLastChild());
                }
                else if (i == 3) {
                    Node n3 = root.getFirstChild().getFirstChild();
                    range.setStart(n3, 1);
                    range.setEnd(root.getLastChild().getFirstChild(), 1);
                    if (surround) {
                        range.selectNode(root.getFirstChild().getNextSibling());
                    }
                }
                else if (i == 4) {
                    Node n4 = root.getFirstChild().getFirstChild().getNextSibling().getFirstChild();
                    range.setStartAfter(n4);
                    range.setEndAfter(root.getLastChild().getFirstChild());
                    if (surround) {
                        range.selectNodeContents(root.getFirstChild().getNextSibling());
                    }
                }
               
                if (fStdOut) System.out.println("range.toString="+range.toString());
                DocumentFragment frag = null;
               
                if (arg.equals("surround")) {
                    try {
                        if (fStdOut) System.out.println("surroundNode="+surroundNode);
                        range.surroundContents(surroundNode);
                    } catch (org.w3c.dom.ranges.RangeException e) {
                        if (fStdOut) System.out.println(e);
                    }
                   String result = toString(document);
                   if (fStdOut) System.out.println("After surround: document="+result+":");
                   if (!result.equals(surroundResult[i])) {
                        if (fStdOut) System.out.println("Should be: document="+surroundResult[i]+":");
                        passed = false;
                        if (fStdOut) System.out.println("Test FAILED!");
                        if (fStdOut) System.out.println("*** Surround document Test["+i+"] FAILED!");
                   }
                }
               
                if (arg.equals("insert")) {
                    range.insertNode(document.createTextNode(INSERT));
                   String result = toString(document);
                   if (fStdOut) System.out.println("After  insert: document="+result+":");
                   if (!result.equals(insertResult[i])) {
                        if (fStdOut) System.out.println("Should be: document="+insertResult[i]+":");
                        passed = false;
                        if (fStdOut) System.out.println("Test FAILED!");
                        if (fStdOut) System.out.println("*** Insert document Test["+i+"] FAILED!");
                   }
                   
                } else
                if (arg.equals("delete")) {
                   range.deleteContents();
                   String result = toString(document);
                   if (fStdOut) System.out.println("After delete:"+result+":");
                   if (!result.equals(deleteResult[i])) {
                        if (fStdOut) System.out.println("Should be: document="+deleteResult[i]+":");
                        passed = false;
                        if (fStdOut) System.out.println("Test FAILED!");
                        if (fStdOut) System.out.println("*** Delete document Test["+i+"] FAILED!");
                   }
                }
                else
                if (arg.equals("extract")) {
                    frag = range.extractContents();
                    //range.insertNode(document.createTextNode("^"));
                   String result = toString(document);
                   if (fStdOut) System.out.println("After extract: document="+result+":");
                   if (!result.equals(deleteResult[i])) {
                        if (fStdOut) System.out.println("Should be: document="+deleteResult[i]+":");
                        passed = false;
                        if (fStdOut) System.out.println("*** Extract document Test["+i+"] FAILED!");
                   }
                   String fragResult = toString(frag);
                   if (fStdOut) System.out.println("After extract: fragment="+fragResult+":");
                   if (!fragResult.equals(extractResult[i])) {
                        if (fStdOut) System.out.println("Should be: fragment="+extractResult[i]+":");
                        passed = false;
                        if (fStdOut) System.out.println("*** Extract Fragment Test["+i+"] FAILED!");
                   }
                }
                  
                else
                if (arg.equals("clone")) {
                    frag = range.cloneContents();
                   String fragResult = toString(frag);
                   if (fStdOut) System.out.println("After clone: fragment="+fragResult);
                   if (!fragResult.equals(extractResult[i])) {
                        if (fStdOut) System.out.println("Should be: fragment="+extractResult[i]+":");
                        passed = false;
                        if (fStdOut) System.out.println("*** Clone Fragment Test["+i+"] FAILED!");
                   }
                }
               
            }
           
            } else
            if (arg.equals("insert2")) {
            if (fStdOut) System.out.println("\n*************** Test == "+arg+" ***************");
            for (int i = 0; i < 4; i++) {

                if (fStdOut) System.out.println("\n\nTest["+i+"]");
                if (fStdOut) System.out.println("\nBefore "+arg+": document="+INSERT2+":");
                parser.parse(new InputSource(new StringReader(INSERT2)));
                DocumentImpl document = (DocumentImpl)parser.getDocument();
                Node root = document.getDocumentElement();
                Range range = document.createRange();
                range.setStart(root.getFirstChild(),11);
                range.setEnd(root.getFirstChild(),18);
                Range rangei = document.createRange();
                if (i == 0) {
                    rangei.setStart(root.getFirstChild(), 10);
                    rangei.setEnd(root.getFirstChild(), 10);
                }
                if (i == 1) {
                    rangei.setStart(root.getFirstChild(), 11);
                    rangei.setEnd(root.getFirstChild(), 11);
                }
                if (i == 2) {
                    rangei.setStart(root.getFirstChild(), 12);
                    rangei.setEnd(root.getFirstChild(), 12);
                }
                if (i == 3) {
                    rangei.setStart(root.getFirstChild(), 17);
                    rangei.setEnd(root.getFirstChild(), 17);
                }
                //if (fStdOut) System.out.println("range: start1=="+range.getStartContainer());
                //root.insertBefore(document.createTextNode("YES!"), root.getFirstChild());
                //if (fStdOut) System.out.println("range: start2=="+range.getStartContainer());
  
                if (DEBUG) if (fStdOut) System.out.println("before insert start="+range.getStartOffset());
                if (DEBUG) if (fStdOut) System.out.println("before insert end="+range.getEndOffset());
                rangei.insertNode(document.createTextNode(INSERTED_TEXT));
                if (DEBUG) if (fStdOut) System.out.println("after insert start="+range.getStartOffset());
                if (DEBUG) if (fStdOut) System.out.println("after insert end="+range.getEndOffset());
               
                String result = toString(document);
                if (fStdOut) System.out.println("After insert2: document="+result+":");
                if (!result.equals(rangeInsertResult[i])) {
                    if (fStdOut) System.out.println("Should be: document="+rangeInsertResult[i]+":");
                    passed = false;
                    if (fStdOut) System.out.println("Test FAILED!");
                    if (fStdOut) System.out.println("*** Delete Ranges document Test["+i+"] FAILED!");
                }
            }
            } else
            if (arg.equals("delete2")) {
            //
            // Range Deletion, acting upon another range.
            //
      
            if (fStdOut) System.out.println("\n*************** Test == "+arg+" ***************");
            for (int i = 0; i < rangeDelete.length; i++) {
                if (fStdOut) System.out.println("\n\nTest["+i+"]");
                if (fStdOut) System.out.println("\nBefore "+arg+": document="+rangeDelete[i]+":");
                parser.parse(new InputSource(new StringReader(rangeDelete[i])));
                DocumentImpl document = (DocumentImpl)parser.getDocument();
                Range range = document.createRange();
                Range ranged = document.createRange();
                Node root = document.getDocumentElement();
                boolean surround = false;
                Node surroundNode=document.createElement(SURROUND);
                if (arg.equals("surround")) {
                    surround = true;
                }
               
                if (i == 0) {
                    ranged.setStart(root.getFirstChild(), 5);
                    ranged.setEnd(root.getFirstChild(), 14);
                   
                    range.setStart(root.getFirstChild(), 11);
                    range.setEnd(root.getFirstChild(), 19);
                }
                else if (i == 1) {
                    ranged.setStart(root.getFirstChild(), 5);
                    ranged.setEnd(root.getFirstChild(), 22);
                   
                    range.setStart(root.getFirstChild(), 11);
                    range.setEnd(root.getFirstChild(), 21);
                }
                else if (i == 2) {
                    ranged.setStart(root.getFirstChild(), 5);
                    ranged.setEnd(root.getFirstChild().getNextSibling()
                        .getFirstChild(), 1);
                       
                    range.setStart(root.getFirstChild(), 11);
                   
                    range.setEndAfter(root.getFirstChild().getNextSibling()
                        .getFirstChild());
                }
                else if (i == 3) {
                    ranged.setStart(root.getFirstChild(), 5);
                    ranged.setEnd(root.getFirstChild(), 11);
                   
                    range.setStart(root.getFirstChild(), 11);
                    range.setEnd(root.getFirstChild(), 21);
                }
                else if (i == 4) {
                    ranged.selectNode(root.getFirstChild().getNextSibling());
                   
                    range.setStart(root.getFirstChild().getNextSibling()
                        .getFirstChild(), 6);
                    range.setEnd(root.getFirstChild().getNextSibling()
                        .getFirstChild(), 15);
                }
               
                DocumentFragment frag = null;
               
                if (arg.equals("delete2")) {
                    if (DEBUG) {
                   if (fStdOut) System.out.println("BEFORE deleteContents()");
                   if (fStdOut) System.out.println("ranged: startc="+ranged.getStartContainer());
                   if (fStdOut) System.out.println("ranged: starto="+ranged.getStartOffset());
                   if (fStdOut) System.out.println("ranged:   endc="+ranged.getEndContainer());
                   if (fStdOut) System.out.println("ranged:   endo="+ranged.getEndOffset());
            
                   if (fStdOut) System.out.println("range: startc="+range.getStartContainer());
                   if (fStdOut) System.out.println("range: starto="+range.getStartOffset());
                   if (fStdOut) System.out.println("range:   endc="+range.getEndContainer());
                   if (fStdOut) System.out.println("range:   endo="+range.getEndOffset());
                    }
                   ranged.deleteContents();
                   String result = null;
                   if (DEBUG) {
                   if (fStdOut) System.out.println("AFTER deleteContents()");
                   result = toString(document);
                   if (fStdOut) System.out.println("ranged: startc="+ranged.getStartContainer());
                   if (fStdOut) System.out.println("ranged: starto="+ranged.getStartOffset());
                   if (fStdOut) System.out.println("ranged:   endc="+ranged.getEndContainer());
                   if (fStdOut) System.out.println("ranged:   endo="+ranged.getEndOffset());
            
                   if (fStdOut) System.out.println("range: startc="+range.getStartContainer());
                   if (fStdOut) System.out.println("range: starto="+range.getStartOffset());
                   if (fStdOut) System.out.println("range:   endc="+range.getEndContainer());
                   if (fStdOut) System.out.println("range:   endo="+range.getEndOffset());
                   }
                  
                   ranged.insertNode(document.createTextNode("^"));
                  
                   result = toString(document);
                   if (fStdOut) System.out.println("After delete2: document="+result+":");
                   if (!result.equals(rangeDeleteResult[i])) {
                        if (fStdOut) System.out.println("Should be: document="+rangeDeleteResult[i]+":");
View Full Code Here

        if (ranges == null) {
            ranges = new Vector();
        }

        Range range = new RangeImpl(this);

        ranges.addElement(range);

        return range;
View Full Code Here

        throw new DOMException(
        DOMException.INVALID_STATE_ERR,
                DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "INVALID_STATE_ERR", null));
      }
       
        Range range = fDocument.createRange();
        range.setStart(fStartContainer, fStartOffset);
        range.setEnd(fEndContainer, fEndOffset);
        return range;
    }
View Full Code Here

            }
        }
        if (firstText == null) {
            return;
        }
        Range r = docRange.createRange();
        r.setStart(firstText, 0);
        ViewModelInfo firstPoint = new ViewModelInfo(r, (InlineText) ((List) textInlineMap
                .get(firstText)).get(0));
        r = docRange.createRange();
        try {
            // possibly some dom impls don't handle this?
            r.setStart(lastText, lastText.getLength());
        } catch (Exception e) {
            r.setStart(lastText, Math.max(0, lastText.getLength() - 1));
        }
        List l = (List) textInlineMap.get(firstText);

        ViewModelInfo lastPoint = new ViewModelInfo(r, (InlineText) l.get(l.size() - 1));
        setDot(firstPoint);
View Full Code Here

            getComponent().getRootBox().clearSelection(modified);
            getComponent().repaint();
            lastHighlightedString = "";
            return;
        }
        Range range = getSelectionRange();

        if (lastSelectionRange != null
                && range.compareBoundaryPoints(Range.START_TO_START, lastSelectionRange) == 0
                && range.compareBoundaryPoints(Range.END_TO_END, lastSelectionRange) == 0) {
            return;
        }
        lastHighlightedString = "";
        lastSelectionRange = range.cloneRange();

        if (range.compareBoundaryPoints(Range.START_TO_END, range) == 0) {
            getComponent().getRootBox().clearSelection(modified);
        } else {
            boolean endBeforeStart = (this.markInfo.range.compareBoundaryPoints(
                    Range.START_TO_START, this.dotInfo.range) >= 0);
            // TODO: track modifications
            getComponent().getRootBox().clearSelection(modified);
            InlineText t1 = (endBeforeStart) ? this.dotInfo.text : this.markInfo.text;
            InlineText t2 = (!endBeforeStart) ? this.dotInfo.text : this.markInfo.text;
            if (t1 == null || t2 == null) {
                // TODO: need general debug here (never print to system.err; use XRLog instead)
                // TODO: is this just a warning, or should we bail out
                XRLog.general(Level.FINE, "null text node");
            }

            final Range acceptRange = docRange.createRange();
            final Range tr = range;
            final Node selectionEndNode = range.getEndContainer();
            NodeFilter f = new NodeFilter() {
                public short acceptNode(Node n) {
                    acceptRange.setStart(n, 0);
                    if (tr.getStartContainer() == n) {
                        return FILTER_ACCEPT;
                    }
                    if ((acceptRange.compareBoundaryPoints(Range.START_TO_START, tr) < 0 || acceptRange
                            .compareBoundaryPoints(Range.END_TO_START, tr) > 0)
                            && n != tr.getStartContainer() && n != tr.getEndContainer()) {
                        return NodeFilter.FILTER_SKIP;
                    }

                    return NodeFilter.FILTER_ACCEPT;
                }
View Full Code Here

        return ilbs;
    }

    ViewModelInfo infoFromPoint(MouseEvent e) {
        checkDocument();
        Range r = docRange.createRange();
        InlineText fndTxt = null;
        Box box = panel.getRootLayer().find(panel.getLayoutContext(), e.getX(), e.getY(), true);
        if (box == null) {
            return null;
        }
        Element elt = null;
        int offset = 0;
        InlineLayoutBox ilb = null;
        boolean containsWholeIlb = false;
        if (box instanceof InlineLayoutBox) {
            ilb = (InlineLayoutBox) box;
        } else {
            for (; ilb == null;) {
                List ilbs = getInlineLayoutBoxes(box, false);
                for (int i = ilbs.size() - 1; i >= 0; i--) {
                    InlineLayoutBox ilbt = (InlineLayoutBox) ilbs.get(i);
                    if (ilbt.getAbsY() <= e.getY() && ilbt.getAbsX() <= e.getX()) {
                        if (ilb == null || (ilbt.getAbsY() > ilb.getAbsY())
                                || (ilbt.getAbsY() == ilb.getAbsY() && ilbt.getX() > ilb.getX())) {

                            if (ilbt.isContainsVisibleContent()) {
                                boolean hasDecentTextNode = false;
                                int x = ilbt.getAbsX();

                                for (Iterator it = ilbt.getInlineChildren().iterator(); it
                                        .hasNext();) {
                                    Object o = it.next();
                                    if (o instanceof InlineText) {
                                        InlineText txt = (InlineText) o;
                                        if (txt.getTextNode() != null) {
                                            hasDecentTextNode = true;
                                            break;
                                        }
                                    }
                                }
                                if (hasDecentTextNode) {
                                    ilb = ilbt;
                                }
                            }
                        }
                        containsWholeIlb = true;
                    }
                }
                if (ilb == null) {
                    if (box.getParent() == null) {
                        return null;
                    }
                    box = box.getParent();
                }
            }
        }
        int x = ilb.getAbsX();
        InlineText lastItxt = null;
        for (Iterator it = ilb.getInlineChildren().iterator(); it.hasNext();) {
            Object o = it.next();
            if (o instanceof InlineText) {
                InlineText txt = (InlineText) o;
                if (txt.getTextNode() != null) {
                    if ((e.getX() >= x + txt.getX() && e.getX() < x + txt.getX() + txt.getWidth())
                            || containsWholeIlb) {
                        fndTxt = txt;
                        break;
                    } else {
                        if (e.getX() < x + txt.getX()) {
                            // assume inline image or somesuch
                            if (lastItxt != null) {
                                fndTxt = lastItxt;
                                break;
                            }
                        }
                    }
                }
                lastItxt = txt;
            }
        }

        LayoutContext lc = panel.getLayoutContext();
        if (fndTxt == null) {
            // TODO: need general debug flag here; not sure if this is an error condition and if the logging is necessary
            if (false) {
                XRLog.general(Level.FINE, ilb.dump(lc, "", Box.DUMP_RENDER));
                XRLog.general(Level.FINE, ilb.getParent().dump(lc, "", Box.DUMP_RENDER));
                XRLog.general(Level.FINE, ilb.getParent().getParent().dump(lc, "", Box.DUMP_RENDER));
            }
            return null;
        }

        String txt = fndTxt.getMasterText();

        CalculatedStyle style = ilb.getStyle();
        if (containsWholeIlb) {
            offset = fndTxt.getEnd();
        } else {
            for (offset = fndTxt.getStart(); offset < fndTxt.getEnd(); offset++) {
                int w = getTextWidth(lc, style, txt.substring(fndTxt.getStart(), offset + 1));
                if (w + x + fndTxt.getX() > e.getX()) {
                    break;
                }

            }
        }

        Node node = fndTxt.getTextNode();
        try {
            r.setStart(node, offset);
        } catch (Exception ex) {
            // maybe differs for dom impl? anyway, fix for issue 216
            r.setStart(node, ((Text) node).getLength() - 1);
        }
        return new ViewModelInfo(r, fndTxt);

    }
View Full Code Here

    public Range getSelectionRange() {
        if (this.dotInfo == null || this.dotInfo.range == null) {
            return null;
        }
        Range r = docRange.createRange();
        // some xml parsers don't allow end<start in the same text node. So,
        // handle dot<mark here

        if (this.markInfo.range.compareBoundaryPoints(Range.START_TO_START, this.dotInfo.range) <= 0) {
            r.setStart(this.markInfo.range.getStartContainer(), this.markInfo.range
                    .getStartOffset());
            r.setEnd(this.dotInfo.range.getStartContainer(), this.dotInfo.range.getStartOffset());
        } else {
            r.setStart(this.dotInfo.range.getStartContainer(), this.dotInfo.range.getStartOffset());
            r.setEnd(this.markInfo.range.getStartContainer(), this.markInfo.range.getStartOffset());
        }
        return r;
    }
View Full Code Here

        if (ranges == null) {
            ranges = new Vector();
        }

        Range range = new RangeImpl(this);

        ranges.addElement(range);

        return range;
View Full Code Here

        if (ranges == null) {
            ranges = new Vector();
        }

        Range range = new RangeImpl(this);

        ranges.addElement(range);

        return range;
View Full Code Here

TOP

Related Classes of org.w3c.dom.ranges.Range

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.