Java 类javax.swing.text.html.HTMLDocument.RunElement 实例源码

项目:cn1    文件:HTMLDocumentTest.java   
public void testCreateLeafElement() throws BadLocationException {
    Element leaf = htmlDoc.createLeafElement(null, null, 0, 1);
    assertTrue(leaf instanceof HTMLDocument.RunElement);
    assertNull(leaf.getParentElement());
    assertEquals(0, leaf.getStartOffset());
    assertEquals(1, leaf.getEndOffset());
    assertNotSame(htmlDoc.createLeafElement(null, null, 0, 1),
                  htmlDoc.createLeafElement(null, null, 0, 1));

    htmlDoc.insertString(0, "01234", null);

    Element leaf2 = htmlDoc.createLeafElement(leaf, null, 1, 3);
    assertTrue(leaf2 instanceof HTMLDocument.RunElement);
    assertSame(leaf, leaf2.getParentElement());
    assertEquals(1, leaf2.getStartOffset());
    assertEquals(3, leaf2.getEndOffset());

    htmlDoc.remove(0, 5);
    assertEquals(0, leaf2.getStartOffset());
    assertEquals(0, leaf2.getEndOffset());
}
项目:freeVM    文件:HTMLDocumentTest.java   
public void testCreateLeafElement() throws BadLocationException {
    Element leaf = htmlDoc.createLeafElement(null, null, 0, 1);
    assertTrue(leaf instanceof HTMLDocument.RunElement);
    assertNull(leaf.getParentElement());
    assertEquals(0, leaf.getStartOffset());
    assertEquals(1, leaf.getEndOffset());
    assertNotSame(htmlDoc.createLeafElement(null, null, 0, 1),
                  htmlDoc.createLeafElement(null, null, 0, 1));

    htmlDoc.insertString(0, "01234", null);

    Element leaf2 = htmlDoc.createLeafElement(leaf, null, 1, 3);
    assertTrue(leaf2 instanceof HTMLDocument.RunElement);
    assertSame(leaf, leaf2.getParentElement());
    assertEquals(1, leaf2.getStartOffset());
    assertEquals(3, leaf2.getEndOffset());

    htmlDoc.remove(0, 5);
    assertEquals(0, leaf2.getStartOffset());
    assertEquals(0, leaf2.getEndOffset());
}
项目:freeVM    文件:HTMLDocumentTest.java   
public void testCreateLeafElement() throws BadLocationException {
    Element leaf = htmlDoc.createLeafElement(null, null, 0, 1);
    assertTrue(leaf instanceof HTMLDocument.RunElement);
    assertNull(leaf.getParentElement());
    assertEquals(0, leaf.getStartOffset());
    assertEquals(1, leaf.getEndOffset());
    assertNotSame(htmlDoc.createLeafElement(null, null, 0, 1),
                  htmlDoc.createLeafElement(null, null, 0, 1));

    htmlDoc.insertString(0, "01234", null);

    Element leaf2 = htmlDoc.createLeafElement(leaf, null, 1, 3);
    assertTrue(leaf2 instanceof HTMLDocument.RunElement);
    assertSame(leaf, leaf2.getParentElement());
    assertEquals(1, leaf2.getStartOffset());
    assertEquals(3, leaf2.getEndOffset());

    htmlDoc.remove(0, 5);
    assertEquals(0, leaf2.getStartOffset());
    assertEquals(0, leaf2.getEndOffset());
}
项目:cn1    文件:StyleSheet_TranslateHTMLToCSS.java   
public void testTranslateHTMLToCSSPContent() throws Exception {
    AbstractElement content =
        (AbstractElement)doc.getDefaultRootElement()
                         .getElement(0).getElement(0).getElement(0);
    assertEquals("content", content.getName());
    assertTrue(content instanceof RunElement);

    content.addAttribute(HTML.Attribute.BGCOLOR, "#ffffff");
    content.addAttribute(HTML.Attribute.BACKGROUND, "bg.jpg");
    content.addAttribute(HTML.Attribute.TEXT, "black");
    content.addAttribute(HTML.Attribute.LINK, "blue");
    content.addAttribute(HTML.Attribute.ALINK, "red");
    content.addAttribute(HTML.Attribute.VLINK, "purple");

    attr = ss.translateHTMLToCSS(content);
    assertSame(NamedStyle.class, attr.getClass());
    assertNull(((NamedStyle)attr).getName());
    if (isHarmony()) {
        assertEquals("url(bg.jpg)",
                     attr.getAttribute(CSS.Attribute.BACKGROUND_IMAGE)
                     .toString());
        assertEquals("#ffffff",
                     attr.getAttribute(CSS.Attribute.BACKGROUND_COLOR)
                     .toString());
        assertEquals("black",
                     attr.getAttribute(CSS.Attribute.COLOR).toString());
    } else {
        assertEquals(0, attr.getAttributeCount());
    }
}
项目:freeVM    文件:StyleSheet_TranslateHTMLToCSS.java   
public void testTranslateHTMLToCSSPContent() throws Exception {
    AbstractElement content =
        (AbstractElement)doc.getDefaultRootElement()
                         .getElement(0).getElement(0).getElement(0);
    assertEquals("content", content.getName());
    assertTrue(content instanceof RunElement);

    content.addAttribute(HTML.Attribute.BGCOLOR, "#ffffff");
    content.addAttribute(HTML.Attribute.BACKGROUND, "bg.jpg");
    content.addAttribute(HTML.Attribute.TEXT, "black");
    content.addAttribute(HTML.Attribute.LINK, "blue");
    content.addAttribute(HTML.Attribute.ALINK, "red");
    content.addAttribute(HTML.Attribute.VLINK, "purple");

    attr = ss.translateHTMLToCSS(content);
    assertSame(NamedStyle.class, attr.getClass());
    assertNull(((NamedStyle)attr).getName());
    if (isHarmony()) {
        assertEquals("url(bg.jpg)",
                     attr.getAttribute(CSS.Attribute.BACKGROUND_IMAGE)
                     .toString());
        assertEquals("#ffffff",
                     attr.getAttribute(CSS.Attribute.BACKGROUND_COLOR)
                     .toString());
        assertEquals("black",
                     attr.getAttribute(CSS.Attribute.COLOR).toString());
    } else {
        assertEquals(0, attr.getAttributeCount());
    }
}
项目:freeVM    文件:StyleSheet_TranslateHTMLToCSS.java   
public void testTranslateHTMLToCSSPContent() throws Exception {
    AbstractElement content =
        (AbstractElement)doc.getDefaultRootElement()
                         .getElement(0).getElement(0).getElement(0);
    assertEquals("content", content.getName());
    assertTrue(content instanceof RunElement);

    content.addAttribute(HTML.Attribute.BGCOLOR, "#ffffff");
    content.addAttribute(HTML.Attribute.BACKGROUND, "bg.jpg");
    content.addAttribute(HTML.Attribute.TEXT, "black");
    content.addAttribute(HTML.Attribute.LINK, "blue");
    content.addAttribute(HTML.Attribute.ALINK, "red");
    content.addAttribute(HTML.Attribute.VLINK, "purple");

    attr = ss.translateHTMLToCSS(content);
    assertSame(NamedStyle.class, attr.getClass());
    assertNull(((NamedStyle)attr).getName());
    if (isHarmony()) {
        assertEquals("url(bg.jpg)",
                     attr.getAttribute(CSS.Attribute.BACKGROUND_IMAGE)
                     .toString());
        assertEquals("#ffffff",
                     attr.getAttribute(CSS.Attribute.BACKGROUND_COLOR)
                     .toString());
        assertEquals("black",
                     attr.getAttribute(CSS.Attribute.COLOR).toString());
    } else {
        assertEquals(0, attr.getAttributeCount());
    }
}
项目:cn1    文件:HTMLDocumentTest.java   
public void testCreateDefaultRoot() {
    try {
        htmlDoc.insertString(0, "123", null);
    } catch (BadLocationException e) {}

    final Element root = htmlDoc.createDefaultRoot();
    assertSame(htmlDoc, root.getDocument());
    assertTrue(root instanceof BlockElement);
    AttributeSet attributes = root.getAttributes();
    assertNotNull(attributes);
    assertEquals(1, attributes.getAttributeCount());
    assertEquals(StyleConstants.NameAttribute, attributes.getAttributeNames().nextElement());
    assertEquals(Tag.HTML, attributes.getAttribute(StyleConstants.NameAttribute));
    assertEquals("html", root.getName());
    assertNull(root.getParentElement());
    assertNull(((BlockElement)root).getResolveParent());

    assertEquals(1, root.getElementCount());
    assertTrue(root.getElement(0) instanceof BlockElement);
    assertSame(root, root.getElement(0).getParentElement());
    Element child = root.getElement(0);
    attributes = child.getAttributes();
    assertNotNull(attributes);
    assertEquals(1, attributes.getAttributeCount());
    assertEquals(StyleConstants.NameAttribute, child.getAttributes().getAttributeNames().nextElement());
    assertEquals(Tag.BODY, attributes.getAttribute(StyleConstants.NameAttribute));
    assertEquals("body", child.getName());
    assertNull(((BlockElement)child).getResolveParent());

    assertEquals(1, child.getElementCount());
    assertTrue(child.getElement(0) instanceof BlockElement);
    assertSame(child, child.getElement(0).getParentElement());
    child = child.getElement(0);
    attributes = child.getAttributes();
    assertNotNull(attributes);
    assertEquals(2, attributes.getAttributeCount());
    checkAttributes(attributes, StyleConstants.NameAttribute, Tag.P);
    checkAttributes(attributes, CSS.Attribute.MARGIN_TOP, "0");
    assertEquals("p", child.getName());
    assertNull(((BlockElement)child).getResolveParent());

    assertEquals(1, child.getElementCount());
    assertTrue(child.getElement(0) instanceof RunElement);
    assertSame(child, child.getElement(0).getParentElement());
    child = child.getElement(0);
    attributes = child.getAttributes();
    assertNotNull(attributes);
    assertEquals(1, attributes.getAttributeCount());
    assertEquals(StyleConstants.NameAttribute, child.getAttributes().getAttributeNames().nextElement());
    assertEquals(Tag.CONTENT, attributes.getAttribute(StyleConstants.NameAttribute));
    assertEquals("content", child.getName());
    assertNull(((RunElement)child).getResolveParent());
    if (!isHarmony()) {
        assertEquals(0, child.getStartOffset());
        assertEquals(1, child.getEndOffset());
    } else {
        assertEquals(0, child.getStartOffset());
        assertEquals(4, child.getEndOffset());
    }
}
项目:cn1    文件:HTMLDocument_RunElementTest.java   
public void testGetResolveParent() {
    AbstractElement parent = htmlDoc.new RunElement(null, null, 0, 0);
    AbstractElement block = htmlDoc.new RunElement(parent, null, 0, 0);
    assertNull(parent.getResolveParent());
    assertNull(block.getResolveParent());
}
项目:freeVM    文件:HTMLDocumentTest.java   
public void testCreateDefaultRoot() {
    try {
        htmlDoc.insertString(0, "123", null);
    } catch (BadLocationException e) {}

    final Element root = htmlDoc.createDefaultRoot();
    assertSame(htmlDoc, root.getDocument());
    assertTrue(root instanceof BlockElement);
    AttributeSet attributes = root.getAttributes();
    assertNotNull(attributes);
    assertEquals(1, attributes.getAttributeCount());
    assertEquals(StyleConstants.NameAttribute, attributes.getAttributeNames().nextElement());
    assertEquals(Tag.HTML, attributes.getAttribute(StyleConstants.NameAttribute));
    assertEquals("html", root.getName());
    assertNull(root.getParentElement());
    assertNull(((BlockElement)root).getResolveParent());

    assertEquals(1, root.getElementCount());
    assertTrue(root.getElement(0) instanceof BlockElement);
    assertSame(root, root.getElement(0).getParentElement());
    Element child = root.getElement(0);
    attributes = child.getAttributes();
    assertNotNull(attributes);
    assertEquals(1, attributes.getAttributeCount());
    assertEquals(StyleConstants.NameAttribute, child.getAttributes().getAttributeNames().nextElement());
    assertEquals(Tag.BODY, attributes.getAttribute(StyleConstants.NameAttribute));
    assertEquals("body", child.getName());
    assertNull(((BlockElement)child).getResolveParent());

    assertEquals(1, child.getElementCount());
    assertTrue(child.getElement(0) instanceof BlockElement);
    assertSame(child, child.getElement(0).getParentElement());
    child = child.getElement(0);
    attributes = child.getAttributes();
    assertNotNull(attributes);
    assertEquals(2, attributes.getAttributeCount());
    checkAttributes(attributes, StyleConstants.NameAttribute, Tag.P);
    checkAttributes(attributes, CSS.Attribute.MARGIN_TOP, "0");
    assertEquals("p", child.getName());
    assertNull(((BlockElement)child).getResolveParent());

    assertEquals(1, child.getElementCount());
    assertTrue(child.getElement(0) instanceof RunElement);
    assertSame(child, child.getElement(0).getParentElement());
    child = child.getElement(0);
    attributes = child.getAttributes();
    assertNotNull(attributes);
    assertEquals(1, attributes.getAttributeCount());
    assertEquals(StyleConstants.NameAttribute, child.getAttributes().getAttributeNames().nextElement());
    assertEquals(Tag.CONTENT, attributes.getAttribute(StyleConstants.NameAttribute));
    assertEquals("content", child.getName());
    assertNull(((RunElement)child).getResolveParent());
    if (!isHarmony()) {
        assertEquals(0, child.getStartOffset());
        assertEquals(1, child.getEndOffset());
    } else {
        assertEquals(0, child.getStartOffset());
        assertEquals(4, child.getEndOffset());
    }
}
项目:freeVM    文件:HTMLDocument_RunElementTest.java   
public void testGetResolveParent() {
    AbstractElement parent = htmlDoc.new RunElement(null, null, 0, 0);
    AbstractElement block = htmlDoc.new RunElement(parent, null, 0, 0);
    assertNull(parent.getResolveParent());
    assertNull(block.getResolveParent());
}
项目:freeVM    文件:HTMLDocumentTest.java   
public void testCreateDefaultRoot() {
    try {
        htmlDoc.insertString(0, "123", null);
    } catch (BadLocationException e) {}

    final Element root = htmlDoc.createDefaultRoot();
    assertSame(htmlDoc, root.getDocument());
    assertTrue(root instanceof BlockElement);
    AttributeSet attributes = root.getAttributes();
    assertNotNull(attributes);
    assertEquals(1, attributes.getAttributeCount());
    assertEquals(StyleConstants.NameAttribute, attributes.getAttributeNames().nextElement());
    assertEquals(Tag.HTML, attributes.getAttribute(StyleConstants.NameAttribute));
    assertEquals("html", root.getName());
    assertNull(root.getParentElement());
    assertNull(((BlockElement)root).getResolveParent());

    assertEquals(1, root.getElementCount());
    assertTrue(root.getElement(0) instanceof BlockElement);
    assertSame(root, root.getElement(0).getParentElement());
    Element child = root.getElement(0);
    attributes = child.getAttributes();
    assertNotNull(attributes);
    assertEquals(1, attributes.getAttributeCount());
    assertEquals(StyleConstants.NameAttribute, child.getAttributes().getAttributeNames().nextElement());
    assertEquals(Tag.BODY, attributes.getAttribute(StyleConstants.NameAttribute));
    assertEquals("body", child.getName());
    assertNull(((BlockElement)child).getResolveParent());

    assertEquals(1, child.getElementCount());
    assertTrue(child.getElement(0) instanceof BlockElement);
    assertSame(child, child.getElement(0).getParentElement());
    child = child.getElement(0);
    attributes = child.getAttributes();
    assertNotNull(attributes);
    assertEquals(2, attributes.getAttributeCount());
    checkAttributes(attributes, StyleConstants.NameAttribute, Tag.P);
    checkAttributes(attributes, CSS.Attribute.MARGIN_TOP, "0");
    assertEquals("p", child.getName());
    assertNull(((BlockElement)child).getResolveParent());

    assertEquals(1, child.getElementCount());
    assertTrue(child.getElement(0) instanceof RunElement);
    assertSame(child, child.getElement(0).getParentElement());
    child = child.getElement(0);
    attributes = child.getAttributes();
    assertNotNull(attributes);
    assertEquals(1, attributes.getAttributeCount());
    assertEquals(StyleConstants.NameAttribute, child.getAttributes().getAttributeNames().nextElement());
    assertEquals(Tag.CONTENT, attributes.getAttribute(StyleConstants.NameAttribute));
    assertEquals("content", child.getName());
    assertNull(((RunElement)child).getResolveParent());
    if (!isHarmony()) {
        assertEquals(0, child.getStartOffset());
        assertEquals(1, child.getEndOffset());
    } else {
        assertEquals(0, child.getStartOffset());
        assertEquals(4, child.getEndOffset());
    }
}
项目:freeVM    文件:HTMLDocument_RunElementTest.java   
public void testGetResolveParent() {
    AbstractElement parent = htmlDoc.new RunElement(null, null, 0, 0);
    AbstractElement block = htmlDoc.new RunElement(parent, null, 0, 0);
    assertNull(parent.getResolveParent());
    assertNull(block.getResolveParent());
}