Java 类javax.swing.text.html.CSS.Attribute 实例源码

项目:cn1    文件:StyleSheet_ConvertAttr_ColorTest.java   
public void testColorRed01() throws Exception {
    ss.addCSSAttribute(simple, Attribute.COLOR, "red");
    attr = ss.createSmallAttributeSet(simple);

    cssValue = attr.getAttribute(Attribute.COLOR);
    scValue = attr.getAttribute(StyleConstants.Foreground);
    assertSame(Color.class, scValue.getClass());
    assertNotSame(String.class, cssValue.getClass());
    assertNotSame(Color.class, cssValue.getClass());
    assertEquals("red", cssValue.toString());
    if (isHarmony()) {
        assertSame(Color.RED, scValue);
    } else {
        assertEquals(Color.RED, scValue);
    }
}
项目:cn1    文件:StyleSheet.java   
private void updateProperties() {
    updateMargin();

    borderStyle =
        (BorderStyle)attr.getAttribute(CSS.Attribute.BORDER_STYLE);
    if (borderStyle != null) {
        borderColor =
            (BorderColor)attr.getAttribute(CSS.Attribute.BORDER_COLOR);
        updateBorderWidth();
    }

    backgroundImage =
        (CSS.ImageValue)attr.getAttribute(CSS.Attribute
                                               .BACKGROUND_IMAGE);
    backgroundRepeat =
        backgroundImage == null
        ? null
        : (CSS.BackgroundRepeat)attr.getAttribute(CSS.Attribute
                                                  .BACKGROUND_REPEAT);
    backgroundColor =
        (CSS.ColorProperty)attr.getAttribute(CSS.Attribute
                                             .BACKGROUND_COLOR);
}
项目:cn1    文件:StyleSheet.java   
public Object getAttribute(final Object key) {
    Object cssKey = CSS.mapToCSS(key);
    Object result = super.getAttribute(cssKey != null ? cssKey : key);
    if (!(cssKey instanceof Attribute)) {
        if (key == StyleConstants.Underline
            || key == StyleConstants.StrikeThrough) {

            return getTextDecoration(this, key);
        }
        return result;
    }
    if (result == null) {
        return super.getAttribute(key);
    }

    return ((PropertyValueConverter)result).fromCSS();
}
项目:cn1    文件:StyleSheet_ConvertAttr_FontTest.java   
private void assertAttributes(final String style,
                              final String variant,
                              final String weight,
                              final String size,
                              final String lineHeight,
                              final String family) {
    assertEquals("Attribute count", 6, simple.getAttributeCount());

    assertEquals("font-style",
                 style, getCSSAttribute(Attribute.FONT_STYLE));
    assertEquals("font-variant",
                 variant, getCSSAttribute(Attribute.FONT_VARIANT));
    assertEquals("font-weight",
                 weight, getCSSAttribute(Attribute.FONT_WEIGHT));
    assertEquals("font-size",
                 size, getCSSAttribute(Attribute.FONT_SIZE));
    assertEquals("line-height",
                 lineHeight, getCSSAttribute(Attribute.LINE_HEIGHT));
    assertEquals("font-family",
                 family, getCSSAttribute(Attribute.FONT_FAMILY));
}
项目:cn1    文件:StyleSheet_ConvertAttr_TextDecorationTest.java   
public void testAddAttributesUnderlineStrikeThrough() throws Exception {
    attr = ss.addAttribute(empty, StyleConstants.Underline, Boolean.TRUE);
    simple.addAttribute(StyleConstants.StrikeThrough, Boolean.TRUE);
    attr = ss.addAttributes(attr, simple);

    cssValue = attr.getAttribute(Attribute.TEXT_DECORATION);
    if (isHarmony()) {
        assertEquals("underline line-through", cssValue.toString());
        scValue = attr.getAttribute(StyleConstants.Underline);
        assertTrue(((Boolean)scValue).booleanValue());
        scValue = attr.getAttribute(StyleConstants.StrikeThrough);
        assertTrue(((Boolean)scValue).booleanValue());
    } else {
        assertTrue("underline".equals(cssValue.toString())
                   ^ "line-through".equals(cssValue.toString()));
    }
}
项目:cn1    文件:StyleSheet_ConvertAttr_TextDecorationTest.java   
public void testAddAttributesStrikeThroughUnderline() throws Exception {
    simple.addAttribute(StyleConstants.StrikeThrough, Boolean.TRUE);
    simple.addAttribute(StyleConstants.Underline, Boolean.TRUE);
    assertEquals(2, simple.getAttributeCount());

    attr = ss.addAttributes(empty, simple);
    assertEquals(1, attr.getAttributeCount());

    cssValue = attr.getAttribute(Attribute.TEXT_DECORATION);
    if (isHarmony()) {
        assertEquals("underline line-through", cssValue.toString());
        scValue = attr.getAttribute(StyleConstants.Underline);
        assertTrue(((Boolean)scValue).booleanValue());
        scValue = attr.getAttribute(StyleConstants.StrikeThrough);
        assertTrue(((Boolean)scValue).booleanValue());
    } else {
        assertTrue("underline".equals(cssValue.toString())
                   ^ "line-through".equals(cssValue.toString()));
    }
}
项目:cn1    文件:StyleSheetTest.java   
public void testRemoveAttributesAttributeSetAttributeSet_StyleConstants() {
    initAttributes();

    simple.addAttribute(StyleConstants.Bold, Boolean.TRUE);
    simple.addAttribute(StyleConstants.Italic, Boolean.TRUE);

    assertTrue(attr.isEqual(simple));

    attr = ss.removeAttributes(attr, simple);
    if (isHarmony()) {
        assertEquals(0, attr.getAttributeCount());
        assertNull(attr.getAttribute(Attribute.FONT_WEIGHT));
        assertNull(attr.getAttribute(StyleConstants.Bold));
        assertNull(attr.getAttribute(Attribute.FONT_STYLE));
        assertNull(attr.getAttribute(StyleConstants.Italic));
    } else {
        assertEquals(2, attr.getAttributeCount());
        assertNotNull(attr.getAttribute(Attribute.FONT_WEIGHT));
        assertNotNull(attr.getAttribute(StyleConstants.Bold));
        assertNotNull(attr.getAttribute(Attribute.FONT_STYLE));
        assertNotNull(attr.getAttribute(StyleConstants.Italic));
    }
}
项目:cn1    文件:StyleSheet_ConvertAttr_FontFamilyTest.java   
/**
 * Contains a known font on Windows.
 */
public void testFontFamilyW() {
    attr = ss.addAttribute(empty, StyleConstants.FontFamily, "Arial");
    Enumeration names = attr.getAttributeNames();
    Object name = names.nextElement();
    assertSame(Attribute.class, name.getClass());
    assertFalse(names.hasMoreElements());

    cssValue = attr.getAttribute(name);
    scValue = attr.getAttribute(StyleConstants.FontFamily);
    assertSame(String.class, scValue.getClass());
    assertNotSame(String.class, cssValue.getClass());
    assertNotSame(scValue, cssValue);
    assertFalse(scValue.equals(cssValue));
    if (fontList.contains("Arial")) {
        assertEquals("Arial", scValue.toString());
    } else {
        assertEquals("SansSerif", scValue.toString());
    }
}
项目:cn1    文件:StyleSheet_ConvertAttr_ListStyleTest.java   
public void testListStyle07() throws Exception {
    ss.addCSSAttribute(simple, Attribute.LIST_STYLE, "square inside");
    if (!BasicSwingTestCase.isHarmony()) {
        assertEquals(1, simple.getAttributeCount());
        cssValue = simple.getAttribute(Attribute.LIST_STYLE);
        assertEquals("square inside", cssValue.toString());
        return;
    }

    assertEquals(3, simple.getAttributeCount());

    cssValue = simple.getAttribute(Attribute.LIST_STYLE_TYPE);
    assertEquals("square", cssValue.toString());
    cssValue = simple.getAttribute(Attribute.LIST_STYLE_POSITION);
    assertEquals("inside", cssValue.toString());
    cssValue = simple.getAttribute(Attribute.LIST_STYLE_IMAGE);
    assertEquals("none", cssValue.toString());
}
项目:cn1    文件:StyleSheet_ConvertAttr_TextDecorationTest.java   
public void testTextDecorationStrikeThrough() throws Exception {
    ss.addCSSAttribute(simple, Attribute.TEXT_DECORATION, "strike-through");
    if (isHarmony()) {
        assertEquals(0, simple.getAttributeCount());
        return;
    }

    attr = ss.createSmallAttributeSet(simple);

    cssValue = attr.getAttribute(Attribute.TEXT_DECORATION);
    assertEquals("strike-through", cssValue.toString());

    scValue = attr.getAttribute(StyleConstants.Underline);
    assertFalse(((Boolean)scValue).booleanValue());

    scValue = attr.getAttribute(StyleConstants.StrikeThrough);
    assertFalse(((Boolean)scValue).booleanValue());
}
项目:cn1    文件:StyleSheet_RulesTest.java   
/**
     * Tests that <code>addRule</code> uses <code>addCSSAttribute</code>
     * to fill the attribute set.
     */
    public void testAddRule03() throws Exception {
        final Marker marker = new Marker();
        ss = new StyleSheet() {
            public void addCSSAttribute(final MutableAttributeSet attr,
                                        final Attribute key,
                                        final String value) {
                marker.setOccurred();
//                assertFalse(attr instanceof Style);
                assertSame(Attribute.FONT_SIZE, key);
                assertEquals("21pt", value);
                super.addCSSAttribute(attr, key, value);
            }
        };
        ss.addRule("   p    {  font-size   :   21pt   }    ");

        assertTrue(marker.isOccurred());
    }
项目:cn1    文件:StyleSheetTest.java   
/**
 * Adding an invalid value for SC-attribute.
 */
public void testAddAttributeInvalidValue02() throws Exception {
    if (isHarmony()) {
        testExceptionalCase(new NullPointerCase() {
            public void exceptionalAction() throws Exception {
                ss.addAttribute(empty, StyleConstants.FontSize,
                                "not-numeral");
            }
        });
        return;
    }
    attr = ss.addAttribute(empty, StyleConstants.FontSize, "not-numeral");
    assertEquals(1, attr.getAttributeCount());
    Object css = attr.getAttribute(Attribute.FONT_SIZE);
    assertEquals("not-numeral", css.toString());
    assertNotSame(String.class, css.getClass());

    Object sc = attr.getAttribute(StyleConstants.FontSize);
    assertSame(Integer.class, sc.getClass());
    assertEquals(12, ((Integer)sc).intValue());
}
项目:cn1    文件:StyleSheet_ConvertAttr_ListStyleTest.java   
public void testListStyle03() throws Exception {
    ss.addCSSAttribute(simple, Attribute.LIST_STYLE, "decimal");
    if (!BasicSwingTestCase.isHarmony()) {
        assertEquals(1, simple.getAttributeCount());
        cssValue = simple.getAttribute(Attribute.LIST_STYLE);
        assertEquals("decimal", cssValue.toString());
        return;
    }

    assertEquals(3, simple.getAttributeCount());

    cssValue = simple.getAttribute(Attribute.LIST_STYLE_TYPE);
    assertEquals("decimal", cssValue.toString());
    cssValue = simple.getAttribute(Attribute.LIST_STYLE_POSITION);
    assertEquals("outside", cssValue.toString());
    cssValue = simple.getAttribute(Attribute.LIST_STYLE_IMAGE);
    assertEquals("none", cssValue.toString());
}
项目:cn1    文件:StyleSheet_ConvertAttr_ListStyleTest.java   
public void testListStyle02() throws Exception {
    ss.addCSSAttribute(simple, Attribute.LIST_STYLE, "disc");
    if (!BasicSwingTestCase.isHarmony()) {
        assertEquals(1, simple.getAttributeCount());
        cssValue = simple.getAttribute(Attribute.LIST_STYLE);
        assertEquals("disc", cssValue.toString());
        return;
    }

    assertEquals(3, simple.getAttributeCount());

    cssValue = simple.getAttribute(Attribute.LIST_STYLE_TYPE);
    assertEquals("disc", cssValue.toString());
    cssValue = simple.getAttribute(Attribute.LIST_STYLE_POSITION);
    assertEquals("outside", cssValue.toString());
    cssValue = simple.getAttribute(Attribute.LIST_STYLE_IMAGE);
    assertEquals("none", cssValue.toString());
}
项目:cn1    文件:StyleSheetTest.java   
/**
 * Adding an attribute with CSS-key but with invalid value for that key.
 */
public void testAddAttributeInvalidValue01() throws Exception {
    if (isHarmony()) {
        testExceptionalCase(new NullPointerCase() {
            public void exceptionalAction() throws Exception {
                ss.addAttribute(empty, Attribute.FONT_SIZE,
                                "not-numeral");
            }
        });
        return;
    }
    attr = ss.addAttribute(empty, Attribute.FONT_SIZE, "not-numeral");
    assertEquals(1, attr.getAttributeCount());
    Object css = attr.getAttribute(Attribute.FONT_SIZE);
    assertEquals("not-numeral", css.toString());
    assertSame(String.class, css.getClass());
    Object sc = attr.getAttribute(StyleConstants.FontSize);
    assertNull(sc);
}
项目:cn1    文件:StyleSheet_ConvertAttr_BorderPartTestCase.java   
public void testSolidThin() throws Exception {
    ss.addCSSAttribute(simple, cssKey, "solid thin");
    cssValue = simple.getAttribute(cssKey);
    if (!isHarmony()) {
        assertSame(String.class, cssValue.getClass());
        assertEquals("solid thin", cssValue.toString());
        return;
    }

    assertNull(cssValue);
    assertEquals(2, simple.getAttributeCount());

    assertEquals(getStyleDeclaration("solid"),
                 simple.getAttribute(Attribute.BORDER_STYLE).toString());
    assertEquals("thin",
                 simple.getAttribute(cssWidthKey).toString());
}
项目:cn1    文件:StyleSheetTest.java   
/**
 * Shows that <code>StyleConstants</code> attributes are converted to
 * corresponding <code>CSS.Attribute</code> ones.
 */
public void testAddAttributes() {
    simple.addAttribute(StyleConstants.FontSize, new Integer(10));
    simple.addAttribute(StyleConstants.Alignment,
                        new Integer(StyleConstants.ALIGN_CENTER));

    attr = ss.addAttributes(empty, simple);
    assertEquals(2, attr.getAttributeCount());

    Enumeration names = attr.getAttributeNames();
    boolean hasSize = false;
    boolean hasAlign = false;
    while (names.hasMoreElements()) {
        Object name = names.nextElement();
        hasSize |= name == Attribute.FONT_SIZE;
        hasAlign |= name == Attribute.TEXT_ALIGN;
    }
    assertTrue(hasSize);
    assertTrue(hasAlign);

    assertTrue(attr instanceof SmallAttributeSet);
    assertSame(SmallAttributeSet.class, attr.getClass().getSuperclass());
}
项目:cn1    文件:StyleSheet_ConvertAttr_BorderPartTestCase.java   
public void testInsetRGBLength() throws Exception {
    ss.addCSSAttribute(simple, cssKey, "inset rgb(50%, 100%, 30%) 1px");
    cssValue = simple.getAttribute(cssKey);
    if (!isHarmony()) {
        assertSame(String.class, cssValue.getClass());
        assertEquals("inset rgb(50%, 100%, 30%) 1px", cssValue.toString());
        return;
    }

    assertNull(cssValue);
    assertEquals(3, simple.getAttributeCount());

    assertEquals(getColorDeclaration("rgb(50%, 100%, 30%)"),
                 simple.getAttribute(Attribute.BORDER_COLOR).toString());
    assertEquals(getStyleDeclaration("inset"),
                 simple.getAttribute(Attribute.BORDER_STYLE).toString());
    assertEquals("1px",
                 simple.getAttribute(cssWidthKey).toString());
}
项目:cn1    文件:StyleSheetTest.java   
public void testImportStyleSheetAddStyles() throws Exception {
    final File cssFile = File.createTempFile(getName(), ".css");
    cssFile.deleteOnExit();
    final FileWriter writer = new FileWriter(cssFile);
    writer.write("body {\n" +
                 "    background-color: white;\n" +
                 "}\n" +
                 "body {\n" +
                 "    color: black;\n" +
                 "}");
    writer.close();

    assertNull(ss.getStyle("body"));

    ss.importStyleSheet(cssFile.toURL());

    final Style body = ss.getStyle("body");
    assertEquals(2, body.getAttributeCount());
    final AttributeSet bodyAttr = body.getResolveParent();
    assertEquals(2, bodyAttr.getAttributeCount());
    assertEquals("white", bodyAttr.getAttribute(Attribute.BACKGROUND_COLOR)
                          .toString());
    assertEquals("black", bodyAttr.getAttribute(Attribute.COLOR).toString());
}
项目:incubator-netbeans    文件:SwingBrowserImpl.java   
/**
 * CSS with e.g. 'font-size: 75%' makes the HTML unreadable in the default JEditorPane
 * @param key
 * @param value
 * @return 
 */
private static String fixFontSize( Attribute key, String value ) {
    if( "font-size".equals( key.toString() ) && null != value && value.endsWith( "%" ) ) {
        String strPercentage = value.replace( "%", "");
        int percentage = Integer.parseInt( strPercentage );
        if( percentage < 100 ) {
            value = "100%";
        }
    }
    return value;
}
项目:InuktitutComputing    文件:NRC_HTMLDocument.java   
public Object trouverProprieteCSSHeritage(Attribute attr, Element element) {
    Object attrValue = trouverProprieteCSS(attr, element);
    if (attrValue == null) {
        // Si ce n'est pas le cas, vérifier le parent.
        Element parent = element.getParentElement();
        if (parent != null)
            attrValue = trouverProprieteCSSHeritage(attr, parent);
    }
    return attrValue;
}
项目:InuktitutComputing    文件:NRC_HTMLDocument.java   
private void decouperTexteEnLignes_String(Element element) {
    if (!element.isLeaf()) {
        Object display = trouverProprieteCSSHeritage(CSS.Attribute.DISPLAY,
                element);
        if (display != null)
            display = display.toString().toLowerCase();
        else {
            HTML.Tag tag = HTML.getTag(element.getName());
            if (tag == null)
                display = "";
            else if (tag.isBlock())
                display = "block";
            else
                display = "inline";
        }
        if (display.equals("block")) {
            decoupe += "<<" + element.getName() + ">>";
        }

        int elementCount = element.getElementCount();
        for (int i = 0; i < elementCount; i++) {
            Element elem = element.getElement(i);
            decouperTexteEnLignes_String(elem);
        }

        if (display.equals("block")) {
            decoupe += "<<" + element.getName() + ">>";
        }
    } else {
        int beg = element.getStartOffset();
        int end = element.getEndOffset();
        String text = null;
        try {
            text = getText(beg, end - beg);
            text = text.replaceAll("\\s+", " ");
            decoupe += text;
        } catch (BadLocationException e) {
        }
    }
}
项目:InuktitutComputing    文件:NRC_HTMLDocument.java   
public String[] trouverFontFamily(Element element) {
    AttributeSet as;
    String family = null;
    as = element.getAttributes();

    // Vérifier si l'élément de texte contient directement un
    // attribut "font-family". NOTE: Normalement, il ne devrait pas
    // le contenir car notre lecteur HTML a été modifié par rapport
    // au HTMLDocument.HTMLReader original qui, lui, convertit certains
    // éléments HTML affectant le texte en attributs qu'il ajoute à
    // l'élément de texte (par exemple, <FONT face=verdana> devient
    // un attribut font-family=verdana ajouté au texte qui suit.)
    // if (as.isDefined(CSS.Attribute.FONT_FAMILY))

    // Essayer l'attribut css font-family
    Object familyObject = as.getAttribute(CSS.Attribute.FONT_FAMILY);
    if (familyObject == null)
        family = null;
    else
        family = familyObject.toString();

    // Sinon, essay l'attribut css font
    // if (family == null) {
    // String font = (String)as.getAttribute(CSS.Attribute.FONT);
    // family = parseFontForFamily(font);
    // }
    if (family == null) {
        Element parent = element.getParentElement();
        // fontFamily =
        // transInuk.trouverFontFamilyHerit(parent,doc);
        if (parent != null) {
            String[] families = trouverFontFamilyHerit(parent);
            return families;
        } else
            return null;
    } else {
        return (String[]) new String[] { family };
    }
}
项目:cn1    文件:StyleSheet.java   
private float getBorderSideWidth(final int side, final View view) {
    final AttributeSet viewAttr = view.getAttributes();
    CSS.BorderStyle borderStyle =
        (BorderStyle)viewAttr.getAttribute(CSS.Attribute.BORDER_STYLE);
    if (borderStyle == null
        || borderStyle.getSideStyle(side).getIndex()
           == CSS.BorderStyleValue.NONE) {

        return 0;
    }

    return getBorderSideWidth(side, view, viewAttr);
}
项目:cn1    文件:StyleSheet_ConvertAttr_TextAlignTest.java   
public void testTextAlign() {
    attr = ss.addAttribute(empty, StyleConstants.Alignment,
                           new Integer(StyleConstants.ALIGN_RIGHT));

    Enumeration names = attr.getAttributeNames();
    Object name = names.nextElement();
    assertSame(Attribute.TEXT_ALIGN, name);
    assertFalse(names.hasMoreElements());

    cssValue = attr.getAttribute(Attribute.TEXT_ALIGN);
    scValue = attr.getAttribute(StyleConstants.Alignment);
    assertSame(Integer.class, scValue.getClass());
    assertNotSame(Integer.class, cssValue.getClass());
    assertNotSame(String.class, cssValue.getClass());
}
项目:cn1    文件:StyleSheet_ConvertAttr_ListStyleTest.java   
public void testListStyle14() throws Exception {
    ss.addCSSAttribute(simple, Attribute.LIST_STYLE, "none none");
    if (!BasicSwingTestCase.isHarmony()) {
        return;
    }

    assertEquals(3, simple.getAttributeCount());

    cssValue = simple.getAttribute(Attribute.LIST_STYLE_TYPE);
    assertEquals("none", cssValue.toString());
    cssValue = simple.getAttribute(Attribute.LIST_STYLE_POSITION);
    assertEquals("outside", cssValue.toString());
    cssValue = simple.getAttribute(Attribute.LIST_STYLE_IMAGE);
    assertEquals("none", cssValue.toString());
}
项目:cn1    文件:StyleSheet.java   
public AttributeSet addAttributes(final AttributeSet old,
                                  final AttributeSet attr) {
    MutableAttributeSet converted = new SimpleAttributeSet(old);
    Enumeration attrKeys = attr.getAttributeNames();
    while (attrKeys.hasMoreElements()) {
        Object key = attrKeys.nextElement();
        Object value = attr.getAttribute(key);
        Attribute cssKey = (Attribute)CSS.mapToCSSForced(key);
        if (cssKey == null) {
            if (key == StyleConstants.Underline
                || key == StyleConstants.StrikeThrough) {

                value = createTextDecoration(converted, key, value);
                key = CSS.Attribute.TEXT_DECORATION;
            }
            converted.addAttribute(key, value);
        } else {
            if (!(value instanceof CSS.PropertyValueConverter)) {
                value = cssKey.getConverter().toCSS(value);
            }
            if (value != null) {
                converted.addAttribute(cssKey, value);
            }
        }
    }
    return super.addAttributes(getEmptySet(), converted);
}
项目:cn1    文件:StyleSheet_ConvertAttr_BoldTest.java   
public void testBold900() throws Exception {
    ss.addCSSAttribute(simple, Attribute.FONT_WEIGHT, "900");
    assertEquals(1, simple.getAttributeCount());
    cssValue = simple.getAttribute(Attribute.FONT_WEIGHT);
    assertEquals("900", cssValue.toString());

    attr = ss.createSmallAttributeSet(simple);
    scValue = attr.getAttribute(StyleConstants.Bold);
    assertNotNull(scValue);
    assertTrue(((Boolean)scValue).booleanValue());
}
项目:cn1    文件:StyleSheet_ConvertAttr_ColorTest.java   
public void testColorRGBMinus25_127_0() throws Exception {
    ss.addCSSAttribute(simple, Attribute.COLOR, "rgb(-25, 127, 0)");
    attr = ss.createSmallAttributeSet(simple);

    cssValue = attr.getAttribute(Attribute.COLOR);
    scValue = attr.getAttribute(StyleConstants.Foreground);
    assertEquals("rgb(-25, 127, 0)", cssValue.toString());
    assertEquals(new Color(0, 127, 0), scValue);
}
项目:cn1    文件:StyleSheet.java   
public boolean addCSSAttributeFromHTML(final MutableAttributeSet attr,
                                       final CSS.Attribute key,
                                       final String value) {

    final int count = attr.getAttributeCount();
    final Object attrValue = attr.getAttribute(key);
    if (key == CSS.Attribute.BACKGROUND_IMAGE) {
        addCSSAttribute(attr, key, "url(" + value + ")");
    } else {
        addCSSAttribute(attr, key, value);
    }
    return count != attr.getAttributeCount()
           || attrValue != attr.getAttribute(key);
}
项目:cn1    文件:StyleSheetTest.java   
public void testAddCSSAttributeFromHTML_AddCSS() {
    final Marker marker = new Marker();
    ss = new StyleSheet() {
        public void addCSSAttribute(final MutableAttributeSet attr,
                                    final Attribute key,
                                    final String value) {
            marker.setOccurred();
            super.addCSSAttribute(attr, key, value);
        }
    };
    assertTrue(ss.addCSSAttributeFromHTML(simple, Attribute.TEXT_ALIGN,
                                          "left"));
    assertEquals(isHarmony(), marker.isOccurred());
}
项目:cn1    文件:StyleSheet.java   
public AttributeSet translateHTMLToCSS(final AttributeSet htmlAttrSet) {
        final Style result = addStyle(null, null);
//        if (((Element)htmlAttrSet).isLeaf()) {
//            return result;
//        }

        final Enumeration keys = htmlAttrSet.getAttributeNames();
        while (keys.hasMoreElements()) {
            Object key = keys.nextElement();
            Object value = htmlAttrSet.getAttribute(key);
            if (key instanceof CSS.Attribute) {
                result.addAttribute(key, value);
            } else {
                Object cssKey = HTML_ATTRIBUTE_TO_CSS.get(key);
                if (cssKey != null
                    && ((Attribute)cssKey).getConverter() != null) {

                    if ((key == HTML.Attribute.HEIGHT
                         || key == HTML.Attribute.WIDTH)
                        && value instanceof String
                        && !((String)value).endsWith("%")) {

                        value = ((Attribute)cssKey).getConverter()
                                .toCSS((String)value + /*"px"*/ "pt");
                    } else if (key == HTML.Attribute.BACKGROUND) {
                        value = ((Attribute)cssKey).getConverter()
                                .toCSS("url(" + value + ")");
                    } else {
                        value = ((Attribute)cssKey).getConverter().toCSS(value);
                    }

                    if (value != null) {
                        result.addAttribute(cssKey, value);
                    }
                }
            }
        }
        return result;
    }
项目:cn1    文件:StyleSheet_ConvertAttr_ColorTest.java   
public void testColorRGBFloatPercent1p2_0_100() throws Exception {
    ss.addCSSAttribute(simple, Attribute.COLOR, "rgb(1.1%, 0%, 100.00%)");
    attr = ss.createSmallAttributeSet(simple);

    cssValue = attr.getAttribute(Attribute.COLOR);
    scValue = attr.getAttribute(StyleConstants.Foreground);
    assertEquals("rgb(1.1%, 0%, 100.00%)", cssValue.toString());
    assertEquals((int)(255 * 0.01), (int)(255 * 0.011));
    assertEquals(new Color((int)(255 * 0.011), 0, 255), scValue);
}
项目:cn1    文件:StyleSheet.java   
private Object getCSSProperty(final AttributeSet attr,
                              final CSS.Attribute key) {
    Object value = attr.getAttribute(key);
    if (value != null) {
        return ((PropertyValueConverter)value).fromCSS();
    }
    return null;
}
项目:cn1    文件:StyleSheet_ConvertAttr_ItalicTest.java   
public void testItalicNormal() throws Exception {
    ss.addCSSAttribute(simple, Attribute.FONT_STYLE, "normal");
    assertEquals(1, simple.getAttributeCount());
    cssValue = simple.getAttribute(Attribute.FONT_STYLE);
    assertEquals("normal", cssValue.toString());

    attr = ss.createSmallAttributeSet(simple);
    scValue = attr.getAttribute(StyleConstants.Italic);
    assertNotNull(scValue);
    assertFalse(((Boolean)scValue).booleanValue());
}
项目:cn1    文件:StyleSheet_ConvertAttr_FontSizeTest.java   
public void testFontSizeLargerParented() {
    AttributeSet parent = ss.addAttribute(empty, StyleConstants.FontSize,
                                          "x-small");
    assertEquals(10, ((Integer)parent.getAttribute(StyleConstants.FontSize))
                     .intValue());
    attr = ss.addAttribute(empty, StyleConstants.ResolveAttribute, parent);
    attr = ss.addAttribute(attr, StyleConstants.FontSize, "larger");

    cssValue = attr.getAttribute(Attribute.FONT_SIZE);
    scValue = attr.getAttribute(StyleConstants.FontSize);
    assertSame(Integer.class, scValue.getClass());
    assertEquals("larger", cssValue.toString());
    assertEquals(12, ((Integer)scValue).intValue());
}
项目:cn1    文件:StyleSheet_ConvertAttr_TextAlignTest.java   
public void testTextAlignStringRight() {
    ss.addCSSAttribute(simple, Attribute.TEXT_ALIGN, "right");
    attr = ss.createSmallAttributeSet(simple);

    cssValue = attr.getAttribute(Attribute.TEXT_ALIGN);
    scValue = attr.getAttribute(StyleConstants.Alignment);
    assertEquals("right", cssValue.toString());
    assertEquals(StyleConstants.ALIGN_RIGHT, ((Integer)scValue).intValue());
}
项目:cn1    文件:StyleSheet_ConvertAttr_FontSizeTest.java   
public void testFontSizeXXLarge() {
    attr = ss.addAttribute(empty, StyleConstants.FontSize, "xx-large");

    cssValue = attr.getAttribute(Attribute.FONT_SIZE);
    scValue = attr.getAttribute(StyleConstants.FontSize);
    assertSame(Integer.class, scValue.getClass());
    assertEquals("xx-large", cssValue.toString());
    assertEquals(36, ((Integer)scValue).intValue());
}
项目:cn1    文件:StyleSheet_ConvertAttr_BoldTest.java   
public void testBoldNormal() throws Exception {
    ss.addCSSAttribute(simple, Attribute.FONT_WEIGHT, "normal");
    assertEquals(1, simple.getAttributeCount());
    cssValue = simple.getAttribute(Attribute.FONT_WEIGHT);
    assertEquals("normal", cssValue.toString());

    attr = ss.createSmallAttributeSet(simple);
    scValue = attr.getAttribute(StyleConstants.Bold);
    assertNotNull(scValue);
    assertFalse(((Boolean)scValue).booleanValue());
}
项目:cn1    文件:StyleSheet_ConvertAttr_ItalicTest.java   
public void testItalicOblique() throws Exception {
    ss.addCSSAttribute(simple, Attribute.FONT_STYLE, "oblique");
    assertEquals(1, simple.getAttributeCount());
    cssValue = simple.getAttribute(Attribute.FONT_STYLE);
    assertEquals("oblique", cssValue.toString());

    attr = ss.createSmallAttributeSet(simple);
    scValue = attr.getAttribute(StyleConstants.Italic);
    assertNotNull(scValue);
    assertFalse(((Boolean)scValue).booleanValue());
}