Java 类javax.swing.text.AbstractDocument.BranchElement 实例源码

项目:cn1    文件:AbstractDocumentTest.java   
public void testGetBidiRootElement() {
    Element root = doc.getBidiRootElement();
    assertNotNull(root);
    assertTrue(root instanceof BranchElement);
    assertEquals("bidi root", root.getName());
    assertEquals(0, root.getStartOffset());
    assertEquals(1, root.getEndOffset());
    Enumeration<?> elements = ((BranchElement) root).children();
    Element element = null;
    int count = 0;
    while (elements.hasMoreElements()) {
        count++;
        element = (Element) elements.nextElement();
    }
    // if the document is empty there should be only one child
    assertEquals(1, count);
    assertTrue(element instanceof LeafElement);
    assertEquals("bidi level", element.getName());
    assertSame(AbstractDocument.BidiElementName, element.getName());
    assertEquals(0, element.getStartOffset());
    assertEquals(1, element.getEndOffset());
}
项目:cn1    文件:FlowView_FlowStrategyTest.java   
@Override
protected void setUp() throws Exception {
    super.setUp();
    doc = new DefaultStyledDocument();
    doc.insertString(0, "this is the test text with some long words in p2\n"
    //                   |              |
            //  0123456789012345678901234567890123456789012345678
            //  0         1         2         3         4
            + "Long words: internationalization, localization", null);
    root = doc.getDefaultRootElement();
    p1 = root.getElement(0);
    // Break the first paragraph into several
    doc.writeLock();
    Element[] leaves = new Element[] { doc.createLeafElement(p1, null, 0, 17),
            doc.createLeafElement(p1, null, 17, 32),
            doc.createLeafElement(p1, null, 32, 49) };
    ((BranchElement) p1).replace(0, p1.getElementCount(), leaves);
    doc.writeUnlock();
    p1L = p1.getElement(0);
    // Initialize the view
    view = new FlowViewImplWithFactory(p1, Y_AXIS, new PartFactory());
    strategy = view.strategy = new TestStrategy();
    view.loadChildren(null);
    row = view.createRow();
    view.append(row);
}
项目:cn1    文件:AbstractDocument_BranchElementTest.java   
/**
 * Test getElementIndex behavior if some elements are zero-length,
 * i.e. start and end offsets are the same.
 */
public void testGetElementIndex02() {
    BranchElement root = doc.new BranchElement(null, null);
    LeafElement[] leaves = { doc.new LeafElement(root, null, 0, 0), // [0]
            doc.new LeafElement(root, null, 0, 1), // [1]
            doc.new LeafElement(root, null, 0, 1), // [2]
            doc.new LeafElement(root, null, 1, 1), // [3]
            doc.new LeafElement(root, null, 1, 1), // [4]
            doc.new LeafElement(root, null, 1, 2), // [5]
            doc.new LeafElement(root, null, 2, 3) // [6]
    };
    root.replace(0, 0, leaves);
    assertEquals(0, root.getElementIndex(-1));
    assertEquals(1, root.getElementIndex(0));
    assertEquals(5 /*2*/, root.getElementIndex(1));
    assertEquals(6, root.getElementIndex(2));
    assertEquals(6, root.getElementIndex(3));
    assertEquals(6, root.getElementIndex(4));
}
项目:cn1    文件:AbstractDocument_BranchElementTest.java   
/**
 * Tests getElementIndex behavior when there are no child elements, but
 * <code>getStartOffset</code> and <code>getEndOffset</code> are overridden
 * to prevent <code>{@link NullPointerException}</code>.
 */
// Regression for HARMONY-2756
public void testGetElementIndex06() {
    par = doc.new BranchElement(null, null) {
        private static final long serialVersionUID = 1L;

        @Override
        public int getStartOffset() {
            return 10;
        }

        @Override
        public int getEndOffset() {
            return 20;
        }
    };
    assertEquals(0, par.getElementIndex(-1));
    assertEquals(0, par.getElementIndex(0));
    assertEquals(0, par.getElementIndex(10));
    assertEquals(0, par.getElementIndex(15));
    assertEquals(0, par.getElementIndex(20));
    assertEquals(0, par.getElementIndex(25));
}
项目:cn1    文件:PlainDocumentTest.java   
/**
 * Generic assertions upon element return by createDefaultRoot.
 */
public void testCreateDefaultRoot01() throws BadLocationException {
    Element root = doc.createDefaultRoot();
    assertTrue(root instanceof BranchElement);
    assertEquals(AbstractDocument.ParagraphElementName, root.getName());
    assertEquals(1, root.getElementCount());
    checkOffsets(root.getElement(0), 0, 1);
    doc.insertString(0, paragraphs, null);
    root = doc.createDefaultRoot();
    assertEquals(1, root.getElementCount());
    if (BasicSwingTestCase.isHarmony()) {
        checkOffsets(root.getElement(0), doc.getStartPosition().getOffset(), doc
                .getEndPosition().getOffset());
    } else {
        checkOffsets(root.getElement(0), 0, 1);
    }
}
项目:cn1    文件:GlyphView_BreakTest.java   
/**
 * Tests <code>breakView</code> uses <code>createFragment</code> to
 * produce the part.
 */
public void testBreakViewCreate() throws Exception {
    view = new GlyphView(root) {
        @Override
        public View createFragment(int startOffset, int endOffset) {
            final Element part = ((AbstractDocument) doc).new LeafElement(null, null,
                    startOffset, endOffset);
            return new LabelView(part);
        };
    };
    final float width = metrics.stringWidth(FULL_TEXT.substring(0, 2));
    final View fragment = view.breakView(X_AXIS, 0, 0, width);
    assertTrue(fragment instanceof LabelView);
    assertFalse(view instanceof LabelView);
    assertEquals(view.getStartOffset(), fragment.getStartOffset());
    assertEquals(view.getStartOffset() + 2, fragment.getEndOffset());
    assertTrue(fragment.getElement() instanceof LeafElement);
    assertTrue(view.getElement() instanceof BranchElement);
}
项目:freeVM    文件:AbstractDocumentTest.java   
public void testGetBidiRootElement() {
    Element root = doc.getBidiRootElement();
    assertNotNull(root);
    assertTrue(root instanceof BranchElement);
    assertEquals("bidi root", root.getName());
    assertEquals(0, root.getStartOffset());
    assertEquals(1, root.getEndOffset());
    Enumeration<?> elements = ((BranchElement) root).children();
    Element element = null;
    int count = 0;
    while (elements.hasMoreElements()) {
        count++;
        element = (Element) elements.nextElement();
    }
    // if the document is empty there should be only one child
    assertEquals(1, count);
    assertTrue(element instanceof LeafElement);
    assertEquals("bidi level", element.getName());
    assertSame(AbstractDocument.BidiElementName, element.getName());
    assertEquals(0, element.getStartOffset());
    assertEquals(1, element.getEndOffset());
}
项目:freeVM    文件:FlowView_FlowStrategyTest.java   
@Override
protected void setUp() throws Exception {
    super.setUp();
    doc = new DefaultStyledDocument();
    doc.insertString(0, "this is the test text with some long words in p2\n"
    //                   |              |
            //  0123456789012345678901234567890123456789012345678
            //  0         1         2         3         4
            + "Long words: internationalization, localization", null);
    root = doc.getDefaultRootElement();
    p1 = root.getElement(0);
    // Break the first paragraph into several
    doc.writeLock();
    Element[] leaves = new Element[] { doc.createLeafElement(p1, null, 0, 17),
            doc.createLeafElement(p1, null, 17, 32),
            doc.createLeafElement(p1, null, 32, 49) };
    ((BranchElement) p1).replace(0, p1.getElementCount(), leaves);
    doc.writeUnlock();
    p1L = p1.getElement(0);
    // Initialize the view
    view = new FlowViewImplWithFactory(p1, Y_AXIS, new PartFactory());
    strategy = view.strategy = new TestStrategy();
    view.loadChildren(null);
    row = view.createRow();
    view.append(row);
}
项目:freeVM    文件:AbstractDocument_BranchElementTest.java   
/**
 * Test getElementIndex behavior if some elements are zero-length,
 * i.e. start and end offsets are the same.
 */
public void testGetElementIndex02() {
    BranchElement root = doc.new BranchElement(null, null);
    LeafElement[] leaves = { doc.new LeafElement(root, null, 0, 0), // [0]
            doc.new LeafElement(root, null, 0, 1), // [1]
            doc.new LeafElement(root, null, 0, 1), // [2]
            doc.new LeafElement(root, null, 1, 1), // [3]
            doc.new LeafElement(root, null, 1, 1), // [4]
            doc.new LeafElement(root, null, 1, 2), // [5]
            doc.new LeafElement(root, null, 2, 3) // [6]
    };
    root.replace(0, 0, leaves);
    assertEquals(0, root.getElementIndex(-1));
    assertEquals(1, root.getElementIndex(0));
    assertEquals(5 /*2*/, root.getElementIndex(1));
    assertEquals(6, root.getElementIndex(2));
    assertEquals(6, root.getElementIndex(3));
    assertEquals(6, root.getElementIndex(4));
}
项目:freeVM    文件:AbstractDocument_BranchElementTest.java   
/**
 * Tests getElementIndex behavior when there are no child elements, but
 * <code>getStartOffset</code> and <code>getEndOffset</code> are overridden
 * to prevent <code>{@link NullPointerException}</code>.
 */
// Regression for HARMONY-2756
public void testGetElementIndex06() {
    par = doc.new BranchElement(null, null) {
        private static final long serialVersionUID = 1L;

        @Override
        public int getStartOffset() {
            return 10;
        }

        @Override
        public int getEndOffset() {
            return 20;
        }
    };
    assertEquals(0, par.getElementIndex(-1));
    assertEquals(0, par.getElementIndex(0));
    assertEquals(0, par.getElementIndex(10));
    assertEquals(0, par.getElementIndex(15));
    assertEquals(0, par.getElementIndex(20));
    assertEquals(0, par.getElementIndex(25));
}
项目:freeVM    文件:PlainDocumentTest.java   
/**
 * Generic assertions upon element return by createDefaultRoot.
 */
public void testCreateDefaultRoot01() throws BadLocationException {
    Element root = doc.createDefaultRoot();
    assertTrue(root instanceof BranchElement);
    assertEquals(AbstractDocument.ParagraphElementName, root.getName());
    assertEquals(1, root.getElementCount());
    checkOffsets(root.getElement(0), 0, 1);
    doc.insertString(0, paragraphs, null);
    root = doc.createDefaultRoot();
    assertEquals(1, root.getElementCount());
    if (BasicSwingTestCase.isHarmony()) {
        checkOffsets(root.getElement(0), doc.getStartPosition().getOffset(), doc
                .getEndPosition().getOffset());
    } else {
        checkOffsets(root.getElement(0), 0, 1);
    }
}
项目:freeVM    文件:GlyphView_BreakTest.java   
/**
 * Tests <code>breakView</code> uses <code>createFragment</code> to
 * produce the part.
 */
public void testBreakViewCreate() throws Exception {
    view = new GlyphView(root) {
        @Override
        public View createFragment(int startOffset, int endOffset) {
            final Element part = ((AbstractDocument) doc).new LeafElement(null, null,
                    startOffset, endOffset);
            return new LabelView(part);
        };
    };
    final float width = metrics.stringWidth(FULL_TEXT.substring(0, 2));
    final View fragment = view.breakView(X_AXIS, 0, 0, width);
    assertTrue(fragment instanceof LabelView);
    assertFalse(view instanceof LabelView);
    assertEquals(view.getStartOffset(), fragment.getStartOffset());
    assertEquals(view.getStartOffset() + 2, fragment.getEndOffset());
    assertTrue(fragment.getElement() instanceof LeafElement);
    assertTrue(view.getElement() instanceof BranchElement);
}
项目:freeVM    文件:AbstractDocumentTest.java   
public void testGetBidiRootElement() {
    Element root = doc.getBidiRootElement();
    assertNotNull(root);
    assertTrue(root instanceof BranchElement);
    assertEquals("bidi root", root.getName());
    assertEquals(0, root.getStartOffset());
    assertEquals(1, root.getEndOffset());
    Enumeration<?> elements = ((BranchElement) root).children();
    Element element = null;
    int count = 0;
    while (elements.hasMoreElements()) {
        count++;
        element = (Element) elements.nextElement();
    }
    // if the document is empty there should be only one child
    assertEquals(1, count);
    assertTrue(element instanceof LeafElement);
    assertEquals("bidi level", element.getName());
    assertSame(AbstractDocument.BidiElementName, element.getName());
    assertEquals(0, element.getStartOffset());
    assertEquals(1, element.getEndOffset());
}
项目:freeVM    文件:FlowView_FlowStrategyTest.java   
@Override
protected void setUp() throws Exception {
    super.setUp();
    doc = new DefaultStyledDocument();
    doc.insertString(0, "this is the test text with some long words in p2\n"
    //                   |              |
            //  0123456789012345678901234567890123456789012345678
            //  0         1         2         3         4
            + "Long words: internationalization, localization", null);
    root = doc.getDefaultRootElement();
    p1 = root.getElement(0);
    // Break the first paragraph into several
    doc.writeLock();
    Element[] leaves = new Element[] { doc.createLeafElement(p1, null, 0, 17),
            doc.createLeafElement(p1, null, 17, 32),
            doc.createLeafElement(p1, null, 32, 49) };
    ((BranchElement) p1).replace(0, p1.getElementCount(), leaves);
    doc.writeUnlock();
    p1L = p1.getElement(0);
    // Initialize the view
    view = new FlowViewImplWithFactory(p1, Y_AXIS, new PartFactory());
    strategy = view.strategy = new TestStrategy();
    view.loadChildren(null);
    row = view.createRow();
    view.append(row);
}
项目:freeVM    文件:AbstractDocument_BranchElementTest.java   
/**
 * Test getElementIndex behavior if some elements are zero-length,
 * i.e. start and end offsets are the same.
 */
public void testGetElementIndex02() {
    BranchElement root = doc.new BranchElement(null, null);
    LeafElement[] leaves = { doc.new LeafElement(root, null, 0, 0), // [0]
            doc.new LeafElement(root, null, 0, 1), // [1]
            doc.new LeafElement(root, null, 0, 1), // [2]
            doc.new LeafElement(root, null, 1, 1), // [3]
            doc.new LeafElement(root, null, 1, 1), // [4]
            doc.new LeafElement(root, null, 1, 2), // [5]
            doc.new LeafElement(root, null, 2, 3) // [6]
    };
    root.replace(0, 0, leaves);
    assertEquals(0, root.getElementIndex(-1));
    assertEquals(1, root.getElementIndex(0));
    assertEquals(5 /*2*/, root.getElementIndex(1));
    assertEquals(6, root.getElementIndex(2));
    assertEquals(6, root.getElementIndex(3));
    assertEquals(6, root.getElementIndex(4));
}
项目:freeVM    文件:AbstractDocument_BranchElementTest.java   
/**
 * Tests getElementIndex behavior when there are no child elements, but
 * <code>getStartOffset</code> and <code>getEndOffset</code> are overridden
 * to prevent <code>{@link NullPointerException}</code>.
 */
// Regression for HARMONY-2756
public void testGetElementIndex06() {
    par = doc.new BranchElement(null, null) {
        private static final long serialVersionUID = 1L;

        @Override
        public int getStartOffset() {
            return 10;
        }

        @Override
        public int getEndOffset() {
            return 20;
        }
    };
    assertEquals(0, par.getElementIndex(-1));
    assertEquals(0, par.getElementIndex(0));
    assertEquals(0, par.getElementIndex(10));
    assertEquals(0, par.getElementIndex(15));
    assertEquals(0, par.getElementIndex(20));
    assertEquals(0, par.getElementIndex(25));
}
项目:freeVM    文件:PlainDocumentTest.java   
/**
 * Generic assertions upon element return by createDefaultRoot.
 */
public void testCreateDefaultRoot01() throws BadLocationException {
    Element root = doc.createDefaultRoot();
    assertTrue(root instanceof BranchElement);
    assertEquals(AbstractDocument.ParagraphElementName, root.getName());
    assertEquals(1, root.getElementCount());
    checkOffsets(root.getElement(0), 0, 1);
    doc.insertString(0, paragraphs, null);
    root = doc.createDefaultRoot();
    assertEquals(1, root.getElementCount());
    if (BasicSwingTestCase.isHarmony()) {
        checkOffsets(root.getElement(0), doc.getStartPosition().getOffset(), doc
                .getEndPosition().getOffset());
    } else {
        checkOffsets(root.getElement(0), 0, 1);
    }
}
项目:freeVM    文件:GlyphView_BreakTest.java   
/**
 * Tests <code>breakView</code> uses <code>createFragment</code> to
 * produce the part.
 */
public void testBreakViewCreate() throws Exception {
    view = new GlyphView(root) {
        @Override
        public View createFragment(int startOffset, int endOffset) {
            final Element part = ((AbstractDocument) doc).new LeafElement(null, null,
                    startOffset, endOffset);
            return new LabelView(part);
        };
    };
    final float width = metrics.stringWidth(FULL_TEXT.substring(0, 2));
    final View fragment = view.breakView(X_AXIS, 0, 0, width);
    assertTrue(fragment instanceof LabelView);
    assertFalse(view instanceof LabelView);
    assertEquals(view.getStartOffset(), fragment.getStartOffset());
    assertEquals(view.getStartOffset() + 2, fragment.getEndOffset());
    assertTrue(fragment.getElement() instanceof LeafElement);
    assertTrue(view.getElement() instanceof BranchElement);
}
项目:trygve    文件:TextEditorGUI.java   
public void setBreakpointToEOLAt(int byteOffset, int lineNumber) {
    final StyledDocument doc = (StyledDocument)editPane.getDocument();
    final Element paragraphElement = doc.getParagraphElement(byteOffset);
    if (paragraphElement.getClass() == BranchElement.class) {
        final SimpleAttributeSet sas = new SimpleAttributeSet(); 
        StyleConstants.setBackground(sas, Color.cyan);

        // Look for ending delimiter
        int length = 1;
        try {
            for (int i = byteOffset; ; i++) {
                if (i >= doc.getLength()) {
                    length = i - byteOffset + 1;
                    break;
                } else if (doc.getText(i, 1).equals("\n")) {
                    length = i - byteOffset;
                    break;
                }
            }
        } catch (BadLocationException ble) {
            length = 0;
        }
        if (0 < length) {
            doc.setCharacterAttributes(byteOffset, length, sas, false);
        }
    }
}
项目:cn1    文件:DefaultStyledDocument_ElementBuffer_ChangeTest.java   
@Override
protected void setUp() throws Exception {
    super.setUp();
    doc = new DefaultStyledDocument();
    root = doc.getDefaultRootElement();
    buf = new DefStyledDoc_Helpers.ElementBufferWithLogging(doc, root);
    doc.buffer = buf;
    paragraph = root.getElement(0);
    content = doc.getContent();
    content.insertString(0, "plainbolditalic\ntext");
    // Create the structure equivalent to this sequence:
    //doc.insertString(doc.getLength(), "plain", null);    // 5 chars
    //doc.insertString(doc.getLength(), "bold", bold);     // 4 chars
    //doc.insertString(doc.getLength(), "italic", italic); // 6 chars
    //doc.insertString(doc.getLength(), "\ntext", null);   // 5 chars
    doc.writeLock(); // Write lock needed to modify document structure
    Element[] leaves = new Element[4];
    leaves[0] = doc.createLeafElement(paragraph, null, 0, 5);
    leaves[1] = doc.createLeafElement(paragraph, bold, 5, 9);
    leaves[2] = doc.createLeafElement(paragraph, italic, 9, 15);
    leaves[3] = doc.createLeafElement(paragraph, null, 15, 16);
    ((BranchElement) paragraph).replace(0, 1, leaves);
    BranchElement branch = (BranchElement) doc.createBranchElement(root, null);
    leaves = new Element[1];
    leaves[0] = doc.createLeafElement(branch, null, 16, 21);
    branch.replace(0, 0, leaves);
    ((BranchElement) root).replace(1, 0, new Element[] { branch });
}
项目:cn1    文件:DefaultStyledDocumentTest.java   
public void testDefaultStyledDocumentContentStyleContext() {
    StyleContext styles = new StyleContext();
    doc = new DefaultStyledDocument(new GapContent(10), styles);
    assertEquals(10, ((GapContent) doc.getContent()).getArrayLength());
    Element root = doc.getDefaultRootElement();
    assertTrue(root instanceof SectionElement);
    assertEquals(1, root.getElementCount());
    Element child = root.getElement(0);
    assertTrue(child instanceof BranchElement);
    assertEquals(1, child.getElementCount());
    assertTrue(child.getElement(0) instanceof LeafElement);
    assertSame(styles, doc.getAttributeContext());
    assertSame(styles.getStyle(StyleContext.DEFAULT_STYLE), child.getAttributes()
            .getResolveParent());
}
项目:cn1    文件:DefaultStyledDocumentTest.java   
public void testCreateDefaultRoot() {
    AbstractElement defRoot = doc.createDefaultRoot();
    assertTrue(defRoot instanceof SectionElement);
    assertEquals(0, defRoot.getAttributeCount());
    assertEquals(1, defRoot.getElementCount());
    assertTrue(defRoot.getElement(0) instanceof BranchElement);
}
项目:cn1    文件:AbstractDocument_AbstractElementRTest.java   
public void testGetNameBranch() throws Exception {
    final String name = "Ast";
    attrs.addAttribute(AbstractDocument.ElementNameAttribute, name);
    element = doc.new BranchElement(root, attrs);
    assertSame(name, element.getName());
    assertSame(root, element.getParentElement());
}
项目:cn1    文件:AbstractDocument_AbstractElementRTest.java   
public void testGetNameParent() throws Exception {
    final String parentName = "parentName";
    attrs.addAttribute(AbstractDocument.ElementNameAttribute, parentName);
    BranchElement parent = doc.new BranchElement(null, attrs);
    AbstractElement element = new AbstractElementImpl(doc, parent, null);
    assertTrue(parent.isDefined(AbstractDocument.ElementNameAttribute));
    assertEquals(parentName, parent.getName());
    assertFalse(element.isDefined(AbstractDocument.ElementNameAttribute));
    assertNull(element.getName());
}
项目:cn1    文件:DefaultStyledDocument_ElementBuffer_RemoveTest.java   
@Override
protected void setUp() throws Exception {
    super.setUp();
    doc = new DefaultStyledDocument();
    root = doc.getDefaultRootElement();
    buf = new DefStyledDoc_Helpers.ElementBufferWithLogging(doc, root);
    doc.buffer = buf;
    paragraph = root.getElement(0);
    content = doc.getContent();
    content.insertString(0, "plainbolditalic\ntext");
    // Create the structure equivalent to this sequence:
    //doc.insertString(doc.getLength(), "plain", null);    // 5 chars
    //doc.insertString(doc.getLength(), "bold", bold);     // 4 chars
    //doc.insertString(doc.getLength(), "italic", italic); // 6 chars
    //doc.insertString(doc.getLength(), "\ntext", null);   // 5 chars
    doc.writeLock(); // Write lock needed to modify document structure
    Element[] leaves = new Element[4];
    leaves[0] = doc.createLeafElement(paragraph, null, 0, 5);
    leaves[1] = doc.createLeafElement(paragraph, bold, 5, 9);
    leaves[2] = doc.createLeafElement(paragraph, italic, 9, 15);
    leaves[3] = doc.createLeafElement(paragraph, null, 15, 16);
    ((BranchElement) paragraph).replace(0, 1, leaves);
    BranchElement branch = (BranchElement) doc.createBranchElement(root, null);
    leaves = new Element[1];
    leaves[0] = doc.createLeafElement(branch, null, 16, 21);
    branch.replace(0, 0, leaves);
    branch.addAttributes(boldFalse);
    branch.addAttributes(italicFalse);
    // Add this branch to the root
    ((BranchElement) root).replace(1, 0, new Element[] { branch });
}
项目:cn1    文件:AbstractDocument_LeafElementTest.java   
@Override
protected void setUp() throws Exception {
    super.setUp();
    StyleContextTest.sc = StyleContext.getDefaultStyleContext();
    as = new AttributeSet[] { StyleContextTest.addAttribute(1),
            StyleContextTest.addAttribute(null, 2, 2),
            StyleContextTest.addAttribute(null, 5, 2) };
    doc = new DisAbstractedDocument(new GapContent());
    doc.insertString(0, "0123456789", as[0]);
    doc.writeLock();
    BranchElement branch = doc.new BranchElement(null, as[1]);
    leaf1 = doc.new LeafElement(null, as[2], 0, 3);
    leaf2 = doc.new LeafElement(branch, as[2], 5, 8);
    doc.writeUnlock();
}
项目:cn1    文件:DefaultStyledDocument_ElementBuffer_InsertSeveralNewLinesTest.java   
@Override
protected void setUp() throws Exception {
    super.setUp();
    doc = new DefaultStyledDocument();
    root = doc.getDefaultRootElement();
    buf = new DefStyledDoc_Helpers.ElementBufferWithLogging(doc, root);
    doc.buffer = buf;
    paragraph = root.getElement(0);
    content = doc.getContent();
    paragraph = root.getElement(0);
    content.insertString(0, "plainbolditalic\ntext");
    // Create the structure equivalent to this sequence:
    //doc.insertString(doc.getLength(), "plain", null);    // 5 chars
    //doc.insertString(doc.getLength(), "bold", bold);     // 4 chars
    //doc.insertString(doc.getLength(), "italic", italic); // 6 chars
    //doc.insertString(doc.getLength(), "\ntext", null);   // 5 chars
    doc.writeLock(); // Write lock needed to modify document structure
    Element[] leaves = new Element[4];
    leaves[0] = doc.createLeafElement(paragraph, null, 0, 5);
    leaves[1] = doc.createLeafElement(paragraph, bold, 5, 9);
    leaves[2] = doc.createLeafElement(paragraph, italic, 9, 15);
    leaves[3] = doc.createLeafElement(paragraph, null, 15, 16);
    ((BranchElement) paragraph).replace(0, 1, leaves);
    BranchElement branch = (BranchElement) doc.createBranchElement(root, null);
    leaves = new Element[1];
    leaves[0] = doc.createLeafElement(branch, null, 16, 21);
    branch.replace(0, 0, leaves);
    // Add this branch to the root
    ((BranchElement) root).replace(1, 0, new Element[] { branch });
    insertOffset = 5 + 2;
}
项目:cn1    文件:DefaultStyledDocument_ElementBuffer_InsertTextTest.java   
@Override
protected void setUp() throws Exception {
    super.setUp();
    doc = new DefaultStyledDocument();
    root = doc.getDefaultRootElement();
    buf = new DefStyledDoc_Helpers.ElementBufferWithLogging(doc, root);
    doc.buffer = buf;
    paragraph = root.getElement(0);
    content = doc.getContent();
    paragraph = root.getElement(0);
    content.insertString(0, "plainbolditalic\ntext");
    // Create the structure equivalent to this sequence:
    //doc.insertString(doc.getLength(), "plain", null);    // 5 chars
    //doc.insertString(doc.getLength(), "bold", bold);     // 4 chars
    //doc.insertString(doc.getLength(), "italic", italic); // 6 chars
    //doc.insertString(doc.getLength(), "\ntext", null);   // 5 chars
    doc.writeLock(); // Write lock needed to modify document structure
    Element[] leaves = new Element[4];
    leaves[0] = doc.createLeafElement(paragraph, null, 0, 5);
    leaves[1] = doc.createLeafElement(paragraph, bold, 5, 9);
    leaves[2] = doc.createLeafElement(paragraph, italic, 9, 15);
    leaves[3] = doc.createLeafElement(paragraph, null, 15, 16);
    ((BranchElement) paragraph).replace(0, 1, leaves);
    BranchElement branch = (BranchElement) doc.createBranchElement(root, null);
    leaves = new Element[1];
    leaves[0] = doc.createLeafElement(branch, null, 16, 21);
    branch.replace(0, 0, leaves);
    // Add this branch to the root
    ((BranchElement) root).replace(1, 0, new Element[] { branch });
    insertOffset = 5 + 2;
}
项目:cn1    文件:AbstractDocument_BranchElementTest.java   
@Override
protected void setUp() throws Exception {
    super.setUp();
    StyleContextTest.sc = StyleContext.getDefaultStyleContext();
    as = new AttributeSet[] { StyleContextTest.addAttribute(1),
            StyleContextTest.addAttribute(2), StyleContextTest.addAttribute(null, 3, 2) };
    doc = new PlainDocument();
    doc.insertString(0, LTR + RTL + LTR + RTL + "\n01234", as[0]);
    bidi = (BranchElement) doc.getBidiRootElement();
    leaf1 = bidi.getElement(0).getElement(0);
    par = (BranchElement) doc.getDefaultRootElement();
    leaf2 = par.getElement(0);
    leaf3 = par.getElement(1);
}
项目:cn1    文件:AbstractDocument_BranchElementTest.java   
public void testGetStartOffsetNoChildren() {
    par = doc.new BranchElement(null, null);
    try {
        par.getStartOffset();
        fail("NullPointerException is expected");
    } catch (NullPointerException e) {
        // expected
    }
}
项目:cn1    文件:AbstractDocument_BranchElementTest.java   
public void testGetEndOffsetNoChildren() {
    par = doc.new BranchElement(null, null);
    try {
        par.getEndOffset();
        fail("NullPointerException is expected");
    } catch (NullPointerException e) {
        // expected
    }
}
项目:cn1    文件:AbstractDocument_BranchElementTest.java   
public void testBranchElement() {
    doc.writeLock();
    bidi = doc.new BranchElement(par, as[2]);
    doc.writeUnlock();
    assertNotSame(as[2], bidi.getAttributes());
    assertEquals(as[2], bidi.getAttributes());
    assertSame(par, bidi.getParentElement());
    assertEquals(0, bidi.getElementCount());
    assertNull(bidi.getElement(0));
    Enumeration<?> elements = bidi.children();
    assertNull(elements);
}
项目:cn1    文件:AbstractDocument_BranchElementTest.java   
/**
 * Creates <code>BranchElement</code> which doesn't span over the whole document.
 * <code>DefaultStyledDocument</code> is used to prepare the structure.
 */
private BranchElement createBranchElement() throws BadLocationException {
    final DefaultStyledDocument styledDoc = new DefaultStyledDocument(); 
    doc = styledDoc;
    doc.insertString(doc.getLength(), "1 line\nonetwothree\n3 line", null);
    //                                 0123456 789012345678 901234
    //                                 0          1          2
    styledDoc.setCharacterAttributes(7, 3, SimpleAttributeSet.EMPTY, false);
    styledDoc.setCharacterAttributes(10, 3, SimpleAttributeSet.EMPTY, false);
    styledDoc.setCharacterAttributes(13, 5, SimpleAttributeSet.EMPTY, false);
    return (BranchElement)doc.getDefaultRootElement().getElement(1);
}
项目:cn1    文件:DefaultStyledDocumentRTest.java   
private void createEmptyHTMLStructure() {
    doc = new DefStyledDoc_Helpers.DefStyledDocWithLogging();
    root = doc.getDefaultRootElement();
    buf = new DefStyledDoc_Helpers.ElementBufferWithLogging(doc, root) {
        private static final long serialVersionUID = 1L;

        @Override
        public void insert(int offset, int length, ElementSpec[] spec,
                DefaultDocumentEvent event) {
            super.insert(offset, length, specs = spec, event);
        }
    };
    doc.buffer = buf;
    doc.writeLock();
    try {
        final BranchElement html = (BranchElement) root;
        html.addAttribute(ELEMENT_NAME, "html");
        final BranchElement body = createBranch(html);
        body.addAttribute(ELEMENT_NAME, "body");
        final BranchElement p = createBranch(body);
        p.addAttribute(ELEMENT_NAME, "p");
        final LeafElement content = createLeaf(p, 0, 1);
        content.addAttribute(ELEMENT_NAME, "leaf1");
        p.replace(0, 0, new Element[] { content });
        body.replace(0, 0, new Element[] { p });
        html.replace(0, 1, new Element[] { body });
    } finally {
        doc.writeUnlock();
    }
}
项目:cn1    文件:CompositeView_ModelViewTest.java   
/**
 * Tests viewToModel(float, float, Shape, Bias[]).
 * For isBefore, isAfter the Y is used only. In this test either
 * isBefore or isAfter is true.
 * <p>In this test modified <code>root</code> is used so that
 * <code>view.getStartOffset() != 0</code> and
 * <code>view.getEndOffset() != doc.getLength()</code>.
 */
public void testViewToModel04() {
    // Modify the root
    final int oldCount = root.getElementCount();
    BranchElement docRoot = (BranchElement) root;
    final Element[] empty = new Element[0];
    docRoot.replace(0, 1, empty);
    docRoot.replace(docRoot.getElementCount() - 1, 1, empty);
    final int newCount = root.getElementCount();
    assertEquals(oldCount - 2, newCount);
    // Re-load children
    view.removeAll();
    view.loadChildren(factory);
    CompositeViewTest.useBoth = false;
    CompositeViewTest.useX = false;
    int x, y;
    // Before the allocation
    x = bounds.x;
    y = bounds.y - 1;
    assertTrue(view.isBefore(x, y, bounds));
    int offset = view.viewToModel(x, y, shape, bias);
    assertEquals(view.getStartOffset(), offset);
    assertEquals(root.getElement(0).getStartOffset(), offset);
    // After the allocation
    y = bounds.y + bounds.height + 1;
    assertTrue(view.isAfter(x, y, bounds));
    bias[0] = null;
    offset = view.viewToModel(x, y, shape, bias);
    assertEquals(view.getEndOffset() - 1, offset);
    assertEquals(root.getElement(root.getElementCount() - 1).getEndOffset() - 1, offset);
    if (BasicSwingTestCase.isHarmony()) {
        assertSame(Bias.Backward, bias[0]);
    }
}
项目:cn1    文件:AbstractDocument_LeafElement_TreeNodeTest.java   
@Override
protected void setUp() throws Exception {
    doc = new DisAbstractedDocument(new GapContent());
    doc.writeLock();
    BranchElement branch = doc.new BranchElement(null, null);
    aElement = doc.new LeafElement(null, null, 0, 3);
    parented = doc.new LeafElement(parent = branch, null, 5, 8);
    doc.writeUnlock();
}
项目:cn1    文件:HTMLDocument_BlockElementTest.java   
protected void setUp() throws Exception {
    super.setUp();

    htmlDoc = new LockableHTMLDocument();
    doc = htmlDoc;

    doc.insertString(0, LTR + RTL + LTR + RTL + "\n01234", as[0]);

    bidi  = (BranchElement)doc.getBidiRootElement();
    leaf1 = (LeafElement)bidi.getElement(0).getElement(0);
    par   = (BranchElement)doc.getDefaultRootElement();
    leaf2 = par != null ? par.getElement(0) : null;
    leaf3 = leaf2;
}
项目:cn1    文件:HTMLDocument_RunElementTest.java   
protected void setUp() throws Exception {
    super.setUp();

    htmlDoc = new LockableHTMLDocument();
    doc = htmlDoc;

    doc.insertString(0, "0123456789", as[0]);

    htmlDoc.lockWrite();
    BranchElement branch = doc.new BranchElement(null, as[1]);
    leaf1 = doc.new LeafElement(null, as[2], 0, 3);
    leaf2 = doc.new LeafElement(branch, as[2], 5, 8);
    htmlDoc.unlockWrite();
}
项目:cn1    文件:StyleSheet_TranslateHTMLToCSS.java   
public void testTranslateHTMLToCSSStyledDocument() throws Exception {
    StyledDocument doc = new DefaultStyledDocument();
    doc.insertString(0, "line1\nline2", null);

    MutableAttributeSet mas = new SimpleAttributeSet();
    mas.addAttribute(HTML.Attribute.BGCOLOR, "#ffffff");
    mas.addAttribute(HTML.Attribute.TEXT, "black");
    doc.setParagraphAttributes(0, 1, mas, false);

    AbstractElement branch =
        (AbstractElement)doc.getDefaultRootElement().getElement(0);
    assertEquals("paragraph", branch.getName());
    assertTrue(branch instanceof BranchElement);
    assertSame(BranchElement.class, branch.getClass());


    attr = ss.translateHTMLToCSS(branch);
    assertSame(NamedStyle.class, attr.getClass());
    assertNull(((NamedStyle)attr).getName());

    assertEquals(2, attr.getAttributeCount());
    assertEquals("#ffffff",
                 attr.getAttribute(CSS.Attribute.BACKGROUND_COLOR)
                 .toString());
    assertEquals("black",
                 attr.getAttribute(CSS.Attribute.COLOR).toString());
}
项目:cn1    文件:DefaultStyledDocument_ElementBuffer_InsertNewLineTest.java   
@Override
protected void setUp() throws Exception {
    super.setUp();
    doc = new DefaultStyledDocument();
    root = doc.getDefaultRootElement();
    buf = new DefStyledDoc_Helpers.ElementBufferWithLogging(doc, root);
    doc.buffer = buf;
    paragraph = root.getElement(0);
    content = doc.getContent();
    content.insertString(0, "plainbolditalic\ntext");
    // Create the structure equivalent to this sequence:
    //doc.insertString(doc.getLength(), "plain", null);    // 5 chars
    //doc.insertString(doc.getLength(), "bold", bold);     // 4 chars
    //doc.insertString(doc.getLength(), "italic", italic); // 6 chars
    //doc.insertString(doc.getLength(), "\ntext", null);   // 5 chars
    doc.writeLock(); // Write lock needed to modify document structure
    Element[] leaves = new Element[4];
    leaves[0] = doc.createLeafElement(paragraph, null, 0, 5);
    leaves[1] = doc.createLeafElement(paragraph, bold, 5, 9);
    leaves[2] = doc.createLeafElement(paragraph, italic, 9, 15);
    leaves[3] = doc.createLeafElement(paragraph, null, 15, 16);
    ((BranchElement) paragraph).replace(0, 1, leaves);
    BranchElement branch = (BranchElement) doc.createBranchElement(root, null);
    leaves = new Element[1];
    leaves[0] = doc.createLeafElement(branch, null, 16, 21);
    branch.replace(0, 0, leaves);
    // Add this branch to the root
    ((BranchElement) root).replace(1, 0, new Element[] { branch });
    insertOffset = 5 + 2;
}