?? css.java
字號:
* @param key the <code>StyleConstants</code> attribute * @return the <code>StyleConstants</code> attribute value that * represents the CSS attribute value */ Object toStyleConstants(StyleConstants key, View v) { if (key == StyleConstants.Italic) { if (svalue.indexOf("italic") >= 0) { return Boolean.TRUE; } return Boolean.FALSE; } else if (key == StyleConstants.Underline) { if (svalue.indexOf("underline") >= 0) { return Boolean.TRUE; } return Boolean.FALSE; } else if (key == StyleConstants.Alignment) { if (svalue.equals("right")) { return new Integer(StyleConstants.ALIGN_RIGHT); } else if (svalue.equals("center")) { return new Integer(StyleConstants.ALIGN_CENTER); } else if (svalue.equals("justify")) { return new Integer(StyleConstants.ALIGN_JUSTIFIED); } return new Integer(StyleConstants.ALIGN_LEFT); } else if (key == StyleConstants.StrikeThrough) { if (svalue.indexOf("line-through") >= 0) { return Boolean.TRUE; } return Boolean.FALSE; } else if (key == StyleConstants.Superscript) { if (svalue.indexOf("super") >= 0) { return Boolean.TRUE; } return Boolean.FALSE; } else if (key == StyleConstants.Subscript) { if (svalue.indexOf("sub") >= 0) { return Boolean.TRUE; } return Boolean.FALSE; } return null; } // Used by ViewAttributeSet boolean isItalic() { return (svalue.indexOf("italic") != -1); } boolean isStrike() { return (svalue.indexOf("line-through") != -1); } boolean isUnderline() { return (svalue.indexOf("underline") != -1); } boolean isSub() { return (svalue.indexOf("sub") != -1); } boolean isSup() { return (svalue.indexOf("sup") != -1); } } /** * Represents a value for the CSS.FONT_SIZE attribute. * The binary format of the value can be one of several * types. If the type is Float, * the value is specified in terms of point or * percentage, depending upon the ending of the * associated string. * If the type is Integer, the value is specified * in terms of a size index. */ class FontSize extends CssValue { /** * Returns the size in points. This is ultimately * what we need for the purpose of creating/fetching * a Font object. * * @param a the attribute set the value is being * requested from. We may need to walk up the * resolve hierarchy if it's relative. */ float getValue(AttributeSet a, StyleSheet ss) { ss = getStyleSheet(ss); if (index) { // it's an index, translate from size table return getPointSize((int) value, ss); } else if (lu == null) { return value; } else { if (lu.type == 0) { boolean isW3CLengthUnits = (ss == null) ? false : ss.isW3CLengthUnits(); return lu.getValue(isW3CLengthUnits); } if (a != null) { AttributeSet resolveParent = a.getResolveParent(); if (resolveParent != null) { int pValue = StyleConstants.getFontSize(resolveParent); float retValue; if (lu.type == 1 || lu.type == 3) { retValue = lu.value * (float)pValue; } else { retValue = lu.value + (float)pValue; } return retValue; } } // a is null, or no resolve parent. return 12; } } Object parseCssValue(String value) { FontSize fs = new FontSize(); fs.svalue = value; try { if (value.equals("xx-small")) { fs.value = 1; fs.index = true; } else if (value.equals("x-small")) { fs.value = 2; fs.index = true; } else if (value.equals("small")) { fs.value = 3; fs.index = true; } else if (value.equals("medium")) { fs.value = 4; fs.index = true; } else if (value.equals("large")) { fs.value = 5; fs.index = true; } else if (value.equals("x-large")) { fs.value = 6; fs.index = true; } else if (value.equals("xx-large")) { fs.value = 7; fs.index = true; } else { fs.lu = new LengthUnit(value, (short)1, 1f); } // relative sizes, larger | smaller (adjust from parent by // 1.5 pixels) // em, ex refer to parent sizes // lengths: pt, mm, cm, pc, in, px // em (font height 3em would be 3 times font height) // ex (height of X) // lengths are (+/-) followed by a number and two letter // unit identifier } catch (NumberFormatException nfe) { fs = null; } return fs; } Object parseHtmlValue(String value) { FontSize fs = new FontSize(); fs.svalue = value; try { /* * relative sizes in the size attribute are relative * to the <basefont>'s size. */ int baseFontSize = getBaseFontSize(); if ((value != null) && (value.charAt(0) == '+')) { int relSize = Integer.valueOf(value.substring(1)).intValue(); fs.value = baseFontSize + relSize; fs.index = true; } else if ((value != null) && (value.charAt(0) == '-')) { int relSize = -Integer.valueOf(value.substring(1)).intValue(); fs.value = baseFontSize + relSize; fs.index = true; } else { fs.value = Integer.parseInt(value); if (fs.value > 7) { fs.value = 7; } else if (fs.value < 0) { fs.value = 0; } fs.index = true; } } catch (NumberFormatException nfe) { fs = null; } return fs; } /** * Converts a <code>StyleConstants</code> attribute value to * a CSS attribute value. If there is no conversion * returns <code>null</code>. By default, there is no conversion. * * @param key the <code>StyleConstants</code> attribute * @param value the value of a <code>StyleConstants</code> * attribute to be converted * @return the CSS value that represents the * <code>StyleConstants</code> value */ Object fromStyleConstants(StyleConstants key, Object value) { if (value instanceof Number) { FontSize fs = new FontSize(); fs.value = getIndexOfSize(((Number)value).floatValue(), StyleSheet.sizeMapDefault); fs.svalue = Integer.toString((int)fs.value); fs.index = true; return fs; } return parseCssValue(value.toString()); } /** * Converts a CSS attribute value to a <code>StyleConstants</code> * value. If there is no conversion, returns <code>null</code>. * By default, there is no conversion. * * @param key the <code>StyleConstants</code> attribute * @return the <code>StyleConstants</code> attribute value that * represents the CSS attribute value */ Object toStyleConstants(StyleConstants key, View v) { if (v != null) { return new Integer((int) getValue(v.getAttributes(), null)); } return new Integer((int) getValue(null, null)); } float value; boolean index; LengthUnit lu; } static class FontFamily extends CssValue { /** * Returns the font family to use. */ String getValue() { return family; } Object parseCssValue(String value) { int cIndex = value.indexOf(','); FontFamily ff = new FontFamily(); ff.svalue = value; ff.family = null; if (cIndex == -1) { setFontName(ff, value); } else { boolean done = false; int lastIndex; int length = value.length(); cIndex = 0; while (!done) { // skip ws. while (cIndex < length && Character.isWhitespace(value.charAt(cIndex))) cIndex++; // Find next ',' lastIndex = cIndex; cIndex = value.indexOf(',', cIndex); if (cIndex == -1) { cIndex = length; } if (lastIndex < length) { if (lastIndex != cIndex) { int lastCharIndex = cIndex; if (cIndex > 0 && value.charAt(cIndex - 1) == ' '){ lastCharIndex--; } setFontName(ff, value.substring (lastIndex, lastCharIndex)); done = (ff.family != null); } cIndex++; } else { done = true; } } } if (ff.family == null) { ff.family = "SansSerif"; } return ff; } private void setFontName(FontFamily ff, String fontName) { ff.family = fontName; } Object parseHtmlValue(String value) { // TBD return parseCssValue(value); } /** * Converts a <code>StyleConstants</code> attribute value to * a CSS attribute value. If there is no conversion * returns <code>null</code>. By default, there is no conversion. * * @param key the <code>StyleConstants</code> attribute * @param value the value of a <code>StyleConstants</code> * attribute to be converted * @return the CSS value that represents the * <code>StyleConstants</code> value */ Object fromStyleConstants(StyleConstants key, Object value) { return parseCssValue(value.toString()); } /** * Converts a CSS attribute value to a <code>StyleConstants</code> * value. If there is no conversion, returns <code>null</code>. * By default, there is no conversion. * * @param key the <code>StyleConstants</code> attribute * @return the <code>StyleConstants</code> attribute value that * represents the CSS attribute value */ Object toStyleConstants(StyleConstants key, View v) { return family; } String family; } static class FontWeight extends CssValue { int getValue() { return weight; } Object parseCssValue(String value) { FontWeight fw = new FontWeight(); fw.svalue = value; if (value.equals("bold")) { fw.weight = 700; } else if (value.equals("normal")) { fw.weight = 400; } else { // PENDING(prinz) add support for relative values try { fw.weight = Integer.parseInt(value); } catch (NumberFormatException nfe) { fw = null; } } return fw; } /** * Converts a <code>StyleConstants</code> attribute value to * a CSS attribute value. If there is no conversion * returns <code>null</code>. By default, there is no conversion. * * @param key the <code>StyleConstants</code> attribute * @param value the value of a <code>StyleConstants</code> * attribute to be converted * @return the CSS value that represents the * <code>StyleConstants</code> value */ Object fromStyleConstants(StyleConstants key, Object value) { if (value.equals(Boolean.TRUE)) { return parseCssValue("bold"); } return parseCssValue("normal"); } /** * Converts a CSS attribute value to a <code>StyleConstants</code> * value. If there is no conversion, returns <code>null</code>. * By default, there is no conversion. * * @param key the <code>StyleConstants</code> attribute * @return the <code>StyleConstants</code> attribute value that * represents the CSS attribute value */ Object toStyleConstants(StyleConstants key, View v) { return (weight > 500) ? Boolean.TRUE : Boolean.FALSE; } boolean isBold() { return (weight > 500); } int weight; } static class Color
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -