⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 css.java

📁 java jdk 1.4的源码
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
	Object bv = new BorderWidthValue(null, 0);	valueConvertor.put(CSS.Attribute.BORDER_WIDTH, lv);	valueConvertor.put(CSS.Attribute.BORDER_TOP_WIDTH, bv);	valueConvertor.put(CSS.Attribute.BORDER_BOTTOM_WIDTH, bv);	valueConvertor.put(CSS.Attribute.BORDER_LEFT_WIDTH, bv);	valueConvertor.put(CSS.Attribute.BORDER_RIGHT_WIDTH, bv);	valueConvertor.put(CSS.Attribute.TEXT_INDENT, lv);	valueConvertor.put(CSS.Attribute.WIDTH, lv);	valueConvertor.put(CSS.Attribute.HEIGHT, lv);	valueConvertor.put(CSS.Attribute.BORDER_SPACING, lv);	Object sv = new StringValue();	valueConvertor.put(CSS.Attribute.FONT_STYLE, sv);	valueConvertor.put(CSS.Attribute.TEXT_DECORATION, sv);	valueConvertor.put(CSS.Attribute.TEXT_ALIGN, sv);	valueConvertor.put(CSS.Attribute.VERTICAL_ALIGN, sv);	Object valueMapper = new CssValueMapper();	valueConvertor.put(CSS.Attribute.LIST_STYLE_TYPE,			   valueMapper);	valueConvertor.put(CSS.Attribute.BACKGROUND_IMAGE,			   new BackgroundImage());	valueConvertor.put(CSS.Attribute.BACKGROUND_POSITION,			   new BackgroundPosition());	valueConvertor.put(CSS.Attribute.BACKGROUND_REPEAT,			   valueMapper);	valueConvertor.put(CSS.Attribute.BACKGROUND_ATTACHMENT,			   valueMapper);	Object generic = new CssValue();	int n = CSS.Attribute.allAttributes.length;	for (int i = 0; i < n; i++) {	    CSS.Attribute key = CSS.Attribute.allAttributes[i];	    if (valueConvertor.get(key) == null) {		valueConvertor.put(key, generic);	    }	}    }    /**     * Sets the base font size. <code>sz</code> is a CSS value, and is     * not necessarily the point size. Use getPointSize to determine the     * point size corresponding to <code>sz</code>.     */    void setBaseFontSize(int sz) {	if (sz < 1)	  baseFontSize = 0;	else if (sz > 7)	  baseFontSize = 7;	else	  baseFontSize = sz;    }    /**     * Sets the base font size from the passed in string.     */    void setBaseFontSize(String size) {	int relSize, absSize, diff;	if (size != null) {	    if (size.startsWith("+")) {		relSize = Integer.valueOf(size.substring(1)).intValue();		setBaseFontSize(baseFontSize + relSize);	    } else if (size.startsWith("-")) {		relSize = -Integer.valueOf(size.substring(1)).intValue();		setBaseFontSize(baseFontSize + relSize);	    } else {		setBaseFontSize(Integer.valueOf(size).intValue());	    }	}    }    /**     * Returns the base font size.     */    int getBaseFontSize() {	return baseFontSize;    }    /**     * Parses the CSS property <code>key</code> with value     * <code>value</code> placing the result in <code>att</code>.     */    void addInternalCSSValue(MutableAttributeSet attr,			     CSS.Attribute key, String value) {	if (key == CSS.Attribute.FONT) {	    ShorthandFontParser.parseShorthandFont(this, value, attr);	}	else if (key == CSS.Attribute.BACKGROUND) {	    ShorthandBackgroundParser.parseShorthandBackground		               (this, value, attr);	}	else if (key == CSS.Attribute.MARGIN) {	    ShorthandMarginParser.parseShorthandMargin(this, value, attr,					   CSS.Attribute.ALL_MARGINS);	}	else if (key == CSS.Attribute.PADDING) {	    ShorthandMarginParser.parseShorthandMargin(this, value, attr,					   CSS.Attribute.ALL_PADDING);	}	else if (key == CSS.Attribute.BORDER_WIDTH) {	    ShorthandMarginParser.parseShorthandMargin(this, value, attr,					   CSS.Attribute.ALL_BORDER_WIDTHS);	}	else {	    Object iValue = getInternalCSSValue(key, value);	    if (iValue != null) {		attr.addAttribute(key, iValue);	    }	}    }    /**     * Gets the internal CSS representation of <code>value</code> which is     * a CSS value of the CSS attribute named <code>key</code>. The receiver     * should not modify <code>value</code>, and the first <code>count</code>     * strings are valid.     */    Object getInternalCSSValue(CSS.Attribute key, String value) {	CssValue conv = (CssValue) valueConvertor.get(key);	return conv.parseCssValue(value);    }    /**     * Maps from a StyleConstants to a CSS Attribute.     */    Attribute styleConstantsKeyToCSSKey(StyleConstants sc) {	return (Attribute)styleConstantToCssMap.get(sc);    }    /**     * Maps from a StyleConstants value to a CSS value.     */    Object styleConstantsValueToCSSValue(StyleConstants sc,					 Object styleValue) {	Object cssKey = styleConstantsKeyToCSSKey(sc);	if (cssKey != null) {	    CssValue conv = (CssValue)valueConvertor.get(cssKey);	    return conv.fromStyleConstants(sc, styleValue);	}	return null;    }    /**     * Converts the passed in CSS value to a StyleConstants value.     * <code>key</code> identifies the CSS attribute being mapped.     */    Object cssValueToStyleConstantsValue(StyleConstants key, Object value) {	if (value instanceof CssValue) {	    return ((CssValue)value).toStyleConstants((StyleConstants)key,						      null);	}	return null;    }    /**     * Returns the font for the values in the passed in AttributeSet.     * It is assumed the keys will be CSS.Attribute keys.     * <code>sc</code> is the StyleContext that will be messaged to get     * the font once the size, name and style have been determined.     */    Font getFont(StyleContext sc, AttributeSet a, int defaultSize) {	int size = getFontSize(a, defaultSize);	/*	 * If the vertical alignment is set to either superscirpt or	 * subscript we reduce the font size by 2 points.	 */	StringValue vAlignV = (StringValue)a.getAttribute	                      (CSS.Attribute.VERTICAL_ALIGN);	if ((vAlignV != null)) {	    String vAlign = vAlignV.toString();	    if ((vAlign.indexOf("sup") >= 0) ||		(vAlign.indexOf("sub") >= 0)) {		size -= 2;	    }	}		FontFamily familyValue = (FontFamily)a.getAttribute	                                    (CSS.Attribute.FONT_FAMILY);	String family = (familyValue != null) ? familyValue.getValue() :	                          "SansSerif";	int style = Font.PLAIN;	FontWeight weightValue = (FontWeight) a.getAttribute	                          (CSS.Attribute.FONT_WEIGHT);	if ((weightValue != null) && (weightValue.getValue() > 400)) {	    style |= Font.BOLD;	}	Object fs = a.getAttribute(CSS.Attribute.FONT_STYLE);	if ((fs != null) && (fs.toString().indexOf("italic") >= 0)) {	    style |= Font.ITALIC;	}	Font f = sc.getFont(family, style, size);	return f;    }    static int getFontSize(AttributeSet attr, int defaultSize) {	// PENDING(prinz) this is a 1.1 based implementation, need to also	// have a 1.2 version.	FontSize sizeValue = (FontSize)attr.getAttribute(CSS.Attribute.							 FONT_SIZE);	return (sizeValue != null) ? (int)sizeValue.getValue(attr) :	                             defaultSize;    }    /**     * Takes a set of attributes and turn it into a color     * specification.  This might be used to specify things     * like brighter, more hue, etc.     * This will return null if there is no value for <code>key</code>.     *     * @param key CSS.Attribute identifying where color is stored.     * @param a the set of attributes     * @return the color     */    Color getColor(AttributeSet a, CSS.Attribute key) {	ColorValue cv = (ColorValue) a.getAttribute(key);	if (cv != null) {	    return cv.getValue();	}	return null;    }    /**     * Returns the size of a font from the passed in string.     *     * @param size CSS string describing font size     * @param baseFontSize size to use for relative units.     */    float getPointSize(String size) {	int relSize, absSize, diff, index;	if (size != null) {	    if (size.startsWith("+")) {		relSize = Integer.valueOf(size.substring(1)).intValue();		return getPointSize(baseFontSize + relSize);	    } else if (size.startsWith("-")) {		relSize = -Integer.valueOf(size.substring(1)).intValue();		return getPointSize(baseFontSize + relSize);	    } else {		absSize = Integer.valueOf(size).intValue();		return getPointSize(absSize);	    }	}	return 0;    }    /**     * Returns the length of the attribute in <code>a</code> with     * key <code>key</code>.     */    float getLength(AttributeSet a, CSS.Attribute key) {	LengthValue lv = (LengthValue) a.getAttribute(key);	float len = (lv != null) ? lv.getValue() : 0;	return len;    }    /**     * Convert a set of HTML attributes to an equivalent     * set of CSS attributes.     *     * @param AttributeSet containing the HTML attributes.     * @return AttributeSet containing the corresponding CSS attributes.     *        The AttributeSet will be empty if there are no mapping     *        CSS attributes.     */    AttributeSet translateHTMLToCSS(AttributeSet htmlAttrSet) {	MutableAttributeSet cssAttrSet = new SimpleAttributeSet();	Element elem = (Element)htmlAttrSet;	HTML.Tag tag = getHTMLTag(htmlAttrSet);	if ((tag == HTML.Tag.TD) || (tag == HTML.Tag.TH)) {	    // translate border width into the cells	    AttributeSet tableAttr = elem.getParentElement().		                     getParentElement().getAttributes();	    translateAttribute(HTML.Attribute.BORDER, tableAttr, cssAttrSet);	    String pad = (String)tableAttr.getAttribute(HTML.Attribute.CELLPADDING);	    if (pad != null) {		Object v = getInternalCSSValue(CSS.Attribute.PADDING_TOP, pad);		cssAttrSet.addAttribute(CSS.Attribute.PADDING_TOP, v);		cssAttrSet.addAttribute(CSS.Attribute.PADDING_BOTTOM, v);		cssAttrSet.addAttribute(CSS.Attribute.PADDING_LEFT, v);		cssAttrSet.addAttribute(CSS.Attribute.PADDING_RIGHT, v);	    }	}	if (elem.isLeaf()) {	    translateEmbeddedAttributes(htmlAttrSet, cssAttrSet);	} else {	    translateAttributes(tag, htmlAttrSet, cssAttrSet);	}	if (tag == HTML.Tag.CAPTION) {	    /* 	     * Navigator uses ALIGN for caption placement and IE uses VALIGN.	     */	    Object v = htmlAttrSet.getAttribute(HTML.Attribute.ALIGN);	    if ((v != null) && (v.equals("top") || v.equals("bottom"))) {		cssAttrSet.addAttribute(CSS.Attribute.CAPTION_SIDE, v);		cssAttrSet.removeAttribute(CSS.Attribute.TEXT_ALIGN);	    } else {		v = htmlAttrSet.getAttribute(HTML.Attribute.VALIGN);		if (v != null) {		    cssAttrSet.addAttribute(CSS.Attribute.CAPTION_SIDE, v);		}	    }	}	return cssAttrSet;    }    private static final Hashtable attributeMap = new Hashtable();    private static final Hashtable valueMap = new Hashtable();    /**     * The HTML/CSS size model has seven slots     * that one can assign sizes to.     */    static int sizeMap[] = { 8, 10, 12, 14, 18, 24, 36 };    /**     * The hashtable and the static initalization block below,     * set up a mapping from well-known HTML attributes to     * CSS attributes.  For the most part, there is a 1-1 mapping     * between the two.  However in the case of certain HTML     * attributes for example HTML.Attribute.VSPACE or     * HTML.Attribute.HSPACE, end up mapping to two CSS.Attribute's.     * Therefore, the value associated with each HTML.Attribute.     * key ends up being an array of CSS.Attribute.* objects.     */    private static final Hashtable htmlAttrToCssAttrMap = new Hashtable(20);    /**     * The hashtable and static initialization that follows sets     * up a translation from StyleConstants (i.e. the <em>well known</em>     * attributes) to the associated CSS attributes.     */    private static final Hashtable styleConstantToCssMap = new Hashtable(17);    /** Maps from HTML value to a CSS value. Used in internal mapping. */    private static final Hashtable htmlValueToCssValueMap = new Hashtable(8);    /** Maps from CSS value (string) to internal value. */    private static final Hashtable cssValueToInternalValueMap = new Hashtable(13);    /** Used to indicate if a font family name is valid. */    private static Hashtable fontMapping;    private static final Object fontMappingLock = new Object();    static {	// load the attribute map	for (int i = 0; i < Attribute.allAttributes.length; i++ ) {	    attributeMap.put(Attribute.allAttributes[i].toString(),			     Attribute.allAttributes[i]);	}	// load the value map	for (int i = 0; i < Value.allValues.length; i++ ) {	    valueMap.put(Value.allValues[i].toString(), 			     Value.allValues[i]);	}	htmlAttrToCssAttrMap.put(HTML.Attribute.COLOR,				 new CSS.Attribute[]{CSS.Attribute.COLOR});	htmlAttrToCssAttrMap.put(HTML.Attribute.TEXT,				 new CSS.Attribute[]{CSS.Attribute.COLOR});	htmlAttrToCssAttrMap.put(HTML.Attribute.CLEAR,				 new CSS.Attribute[]{CSS.Attribute.CLEAR});	htmlAttrToCssAttrMap.put(HTML.Attribute.BACKGROUND,				 new CSS.Attribute[]{CSS.Attribute.BACKGROUND_IMAGE});	htmlAttrToCssAttrMap.put(HTML.Attribute.BGCOLOR,				 new CSS.Attribute[]{CSS.Attribute.BACKGROUND_COLOR});	htmlAttrToCssAttrMap.put(HTML.Attribute.WIDTH,				 new CSS.Attribute[]{CSS.Attribute.WIDTH});	htmlAttrToCssAttrMap.put(HTML.Attribute.HEIGHT,				 new CSS.Attribute[]{CSS.Attribute.HEIGHT});	htmlAttrToCssAttrMap.put(HTML.Attribute.BORDER,				 new CSS.Attribute[]{CSS.Attribute.BORDER_TOP_WIDTH, CSS.Attribute.BORDER_RIGHT_WIDTH, CSS.Attribute.BORDER_BOTTOM_WIDTH, CSS.Attribute.BORDER_LEFT_WIDTH});	htmlAttrToCssAttrMap.put(HTML.Attribute.CELLPADDING,				 new CSS.Attribute[]{CSS.Attribute.PADDING});	htmlAttrToCssAttrMap.put(HTML.Attribute.CELLSPACING,				 new CSS.Attribute[]{CSS.Attribute.BORDER_SPACING});	htmlAttrToCssAttrMap.put(HTML.Attribute.MARGINWIDTH,				 new CSS.Attribute[]{CSS.Attribute.MARGIN_LEFT,						     CSS.Attribute.MARGIN_RIGHT});	htmlAttrToCssAttrMap.put(HTML.Attribute.MARGINHEIGHT,				 new CSS.Attribute[]{CSS.Attribute.MARGIN_TOP,						     CSS.Attribute.MARGIN_BOTTOM});	htmlAttrToCssAttrMap.put(HTML.Attribute.HSPACE,				 new CSS.Attribute[]{CSS.Attribute.PADDING_LEFT,						     CSS.Attribute.PADDING_RIGHT});	htmlAttrToCssAttrMap.put(HTML.Attribute.VSPACE,				 new CSS.Attribute[]{CSS.Attribute.PADDING_BOTTOM,						     CSS.Attribute.PADDING_TOP});	htmlAttrToCssAttrMap.put(HTML.Attribute.FACE,				 new CSS.Attribute[]{CSS.Attribute.FONT_FAMILY});	htmlAttrToCssAttrMap.put(HTML.Attribute.SIZE,				 new CSS.Attribute[]{CSS.Attribute.FONT_SIZE});	htmlAttrToCssAttrMap.put(HTML.Attribute.VALIGN,				 new CSS.Attribute[]{CSS.Attribute.VERTICAL_ALIGN});	htmlAttrToCssAttrMap.put(HTML.Attribute.ALIGN,				 new CSS.Attribute[]{CSS.Attribute.VERTICAL_ALIGN,						     CSS.Attribute.TEXT_ALIGN,						     CSS.Attribute.FLOAT});	htmlAttrToCssAttrMap.put(HTML.Attribute.TYPE,				 new CSS.Attribute[]{CSS.Attribute.LIST_STYLE_TYPE});	htmlAttrToCssAttrMap.put(HTML.Attribute.NOWRAP,				 new CSS.Attribute[]{CSS.Attribute.WHITE_SPACE});	// initialize StyleConstants mapping 	styleConstantToCssMap.put(StyleConstants.FontFamily, 				  CSS.Attribute.FONT_FAMILY);	styleConstantToCssMap.put(StyleConstants.FontSize, 				  CSS.Attribute.FONT_SIZE);	styleConstantToCssMap.put(StyleConstants.Bold, 				  CSS.Attribute.FONT_WEIGHT);	styleConstantToCssMap.put(StyleConstants.Italic, 				  CSS.Attribute.FONT_STYLE);	styleConstantToCssMap.put(StyleConstants.Underline, 				  CSS.Attribute.TEXT_DECORATION);	styleConstantToCssMap.put(StyleConstants.StrikeThrough, 				  CSS.Attribute.TEXT_DECORATION);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -