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

📄 css.java

📁 Mobile 应用程序使用 Java Micro Edition (Java ME) 平台
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
     * @return an array of all the strings in <code>value</code>     *         that are separated by whitespace.     */    static String[] parseStrings(String value) {	int         current, last;	int         length = (value == null) ? 0 : value.length();	Vector      temp = new Vector(4);	current = 0;	while (current < length) {	    // Skip ws	    while (current < length && Character.isWhitespace		   (value.charAt(current))) {		current++;	    }	    last = current;	    while (current < length && !Character.isWhitespace		   (value.charAt(current))) {		current++;	    }	    if (last != current) {		temp.addElement(value.substring(last, current));	    }	    current++;	}	String[] retValue = new String[temp.size()];	temp.copyInto(retValue);	return retValue;    }    /**     * Return the point size, given a size index. Legal HTML index sizes     * are 1-7.     */    float getPointSize(int index, StyleSheet ss) {        ss = getStyleSheet(ss);        int[] sizeMap = (ss != null) ? ss.getSizeMap() :             StyleSheet.sizeMapDefault;        --index;	if (index < 0)	  return sizeMap[0];	else if (index > sizeMap.length - 1)	  return sizeMap[sizeMap.length - 1];	else	  return sizeMap[index];    }    private void translateEmbeddedAttributes(AttributeSet htmlAttrSet,					     MutableAttributeSet cssAttrSet) {	Enumeration keys = htmlAttrSet.getAttributeNames();	if (htmlAttrSet.getAttribute(StyleConstants.NameAttribute) ==	    HTML.Tag.HR) {	    // HR needs special handling due to us treating it as a leaf.	    translateAttributes(HTML.Tag.HR, htmlAttrSet, cssAttrSet);	}	while (keys.hasMoreElements()) {	    Object key = keys.nextElement();	    if (key instanceof HTML.Tag) {		HTML.Tag tag = (HTML.Tag)key;		Object o = htmlAttrSet.getAttribute(tag);		if (o != null && o instanceof AttributeSet) {		    translateAttributes(tag, (AttributeSet)o, cssAttrSet);		}	    } else if (key instanceof CSS.Attribute) {		cssAttrSet.addAttribute(key, htmlAttrSet.getAttribute(key));	    }	}    }    private void translateAttributes(HTML.Tag tag,					    AttributeSet htmlAttrSet,					    MutableAttributeSet cssAttrSet) {	Enumeration names = htmlAttrSet.getAttributeNames();	while (names.hasMoreElements()) {	    Object name = names.nextElement();	    if (name instanceof HTML.Attribute) {		HTML.Attribute key = (HTML.Attribute)name;		/*		 * HTML.Attribute.ALIGN needs special processing.		 * It can map to to 1 of many(3) possible CSS attributes		 * depending on the nature of the tag the attribute is		 * part off and depending on the value of the attribute.		 */		if (key == HTML.Attribute.ALIGN) {		    String htmlAttrValue = (String)htmlAttrSet.getAttribute(HTML.Attribute.ALIGN);		    if (htmlAttrValue != null) {			CSS.Attribute cssAttr = getCssAlignAttribute(tag, htmlAttrSet);			if (cssAttr != null) {			    Object o = getCssValue(cssAttr, htmlAttrValue);			    if (o != null) {				cssAttrSet.addAttribute(cssAttr, o);			    }			}		    }		} else {		    /*		     * The html size attribute has a mapping in the CSS world only		     * if it is par of a font or base font tag.		     */		    if (key == HTML.Attribute.SIZE && !isHTMLFontTag(tag)) {			continue;		    }		    translateAttribute(key, htmlAttrSet, cssAttrSet);		}	    } else if (name instanceof CSS.Attribute) {		cssAttrSet.addAttribute(name, htmlAttrSet.getAttribute(name));	    }	}    }    private void translateAttribute(HTML.Attribute key,					   AttributeSet htmlAttrSet,					   MutableAttributeSet cssAttrSet) {	/*	 * In the case of all remaining HTML.Attribute's they	 * map to 1 or more CCS.Attribute.	 */	CSS.Attribute[] cssAttrList = getCssAttribute(key);		String htmlAttrValue = (String)htmlAttrSet.getAttribute(key);		if (cssAttrList == null || htmlAttrValue == null) {	    return;	}	for (int i = 0; i < cssAttrList.length; i++) {	    Object o = getCssValue(cssAttrList[i], htmlAttrValue);	    if (o != null) {		cssAttrSet.addAttribute(cssAttrList[i], o);	    }	}    }    /**     * Given a CSS.Attribute object and its corresponding HTML.Attribute's     * value, this method returns a CssValue object to associate with the     * CSS attribute.     *     * @param the CSS.Attribute     * @param a String containing the value associated HTML.Attribtue.     */    Object getCssValue(CSS.Attribute cssAttr, String htmlAttrValue) {	CssValue value = (CssValue)valueConvertor.get(cssAttr);	Object o = value.parseHtmlValue(htmlAttrValue);	return o;    }    /**     * Maps an HTML.Attribute object to its appropriate CSS.Attributes.     *     * @param HTML.Attribute     * @return CSS.Attribute[]     */    private CSS.Attribute[] getCssAttribute(HTML.Attribute hAttr) {	return (CSS.Attribute[])htmlAttrToCssAttrMap.get(hAttr);    }    /**     * Maps HTML.Attribute.ALIGN to either:     *     CSS.Attribute.TEXT_ALIGN     *     CSS.Attribute.FLOAT     *     CSS.Attribute.VERTICAL_ALIGN     * based on the tag associated with the attribute and the     * value of the attribute.     *     * @param AttributeSet containing HTML attributes.     * @return CSS.Attribute mapping for HTML.Attribute.ALIGN.     */    private CSS.Attribute getCssAlignAttribute(HTML.Tag tag,						   AttributeSet htmlAttrSet) {	return CSS.Attribute.TEXT_ALIGN;/*	String htmlAttrValue = (String)htmlAttrSet.getAttribute(HTML.Attribute.ALIGN);	CSS.Attribute cssAttr = CSS.Attribute.TEXT_ALIGN;	if (htmlAttrValue != null && htmlAttrSet instanceof Element) {	    Element elem = (Element)htmlAttrSet;	    if (!elem.isLeaf() && tag.isBlock() && validTextAlignValue(htmlAttrValue)) {		return CSS.Attribute.TEXT_ALIGN;	    } else if (isFloater(htmlAttrValue)) {		return CSS.Attribute.FLOAT;	    } else if (elem.isLeaf()) {		return CSS.Attribute.VERTICAL_ALIGN;	    } 	}	return null;	*/    }    /**     * Fetches the tag associated with the HTML AttributeSet.     *     * @param  AttributeSet containing the HTML attributes.     * @return HTML.Tag     */    private HTML.Tag getHTMLTag(AttributeSet htmlAttrSet) {	Object o = htmlAttrSet.getAttribute(StyleConstants.NameAttribute);	if (o instanceof HTML.Tag) {	    HTML.Tag tag = (HTML.Tag) o;	    return tag;	}	return null;    }    private boolean isHTMLFontTag(HTML.Tag tag) {	return (tag != null && ((tag == HTML.Tag.FONT) || (tag == HTML.Tag.BASEFONT)));    }    private boolean isFloater(String alignValue) {	return (alignValue.equals("left") || alignValue.equals("right"));    }    private boolean validTextAlignValue(String alignValue) {	return (isFloater(alignValue) || alignValue.equals("center"));    }    /**     * Base class to CSS values in the attribute sets.  This     * is intended to act as a convertor to/from other attribute     * formats.     * <p>     * The CSS parser uses the parseCssValue method to convert     * a string to whatever format is appropriate a given key     * (i.e. these convertors are stored in a map using the     * CSS.Attribute as a key and the CssValue as the value).     * <p>     * The HTML to CSS conversion process first converts the     * HTML.Attribute to a CSS.Attribute, and then calls     * the parseHtmlValue method on the value of the HTML     * attribute to produce the corresponding CSS value.     * <p>     * The StyleConstants to CSS conversion process first      * converts the StyleConstants attribute to a      * CSS.Attribute, and then calls the fromStyleConstants     * method to convert the StyleConstants value to a      * CSS value.     * <p>     * The CSS to StyleConstants conversion process first     * converts the StyleConstants attribute to a      * CSS.Attribute, and then calls the toStyleConstants     * method to convert the CSS value to a StyleConstants     * value.     */    static class CssValue implements Serializable {	/**	 * Convert a CSS value string to the internal format	 * (for fast processing) used in the attribute sets.	 * The fallback storage for any value that we don't	 * have a special binary format for is a String. 	 */	Object parseCssValue(String value) {	    return value;	}	/**	 * Convert an HTML attribute value to a CSS attribute	 * value.  If there is no conversion, return null.	 * This is implemented to simply forward to the CSS	 * parsing by default (since some of the attribute	 * values are the same).  If the attribute value	 * isn't recognized as a CSS value it is generally	 * returned as null.	 */	Object parseHtmlValue(String value) {	    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 null;	}	/**	 * 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	 * @param v the view containing <code>AttributeSet</code>	 * @return the <code>StyleConstants</code> attribute value that 	 *   represents the CSS attribute value	 */	Object toStyleConstants(StyleConstants key, View v) {	    return null;	}	/**	 * Return the CSS format of the value	 */        public String toString() {	    return svalue;	}	/**	 * The value as a string... before conversion to a	 * binary format.	 */	String svalue;    }    /**     * By default CSS attributes are represented as simple     * strings.  They also have no conversion to/from     * StyleConstants by default. This class represents the      * value as a string (via the superclass), but      * provides StyleConstants conversion support for the      * CSS attributes that are held as strings.     */    static class StringValue extends CssValue {	/**	 * Convert a CSS value string to the internal format	 * (for fast processing) used in the attribute sets.	 * This produces a StringValue, so that it can be	 * used to convert from CSS to StyleConstants values.	 */	Object parseCssValue(String value) {	    StringValue sv = new StringValue();	    sv.svalue = value;	    return sv;	}	/**	 * Converts a <code>StyleConstants</code> attribute value to	 * a CSS attribute value.  If there is no conversion	 * returns <code>null</code>. 	 * 	 * @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 (key == StyleConstants.Italic) {		if (value.equals(Boolean.TRUE)) {		    return parseCssValue("italic");		}		return parseCssValue("");	    } else if (key == StyleConstants.Underline) {		if (value.equals(Boolean.TRUE)) {		    return parseCssValue("underline");		} 		return parseCssValue("");	    } else if (key == StyleConstants.Alignment) {		int align = ((Integer)value).intValue();		String ta;		switch(align) {		case StyleConstants.ALIGN_LEFT:		    ta = "left";		    break;		case StyleConstants.ALIGN_RIGHT:		    ta = "right";		    break;		case StyleConstants.ALIGN_CENTER:		    ta = "center";		    break;		case StyleConstants.ALIGN_JUSTIFIED:		    ta = "justify";		    break;		default:		    ta = "left";		}		return parseCssValue(ta);	    } else if (key == StyleConstants.StrikeThrough) {		if (value.equals(Boolean.TRUE)) {		    return parseCssValue("line-through");		} 		return parseCssValue("");	    } else if (key == StyleConstants.Superscript) {		if (value.equals(Boolean.TRUE)) {		    return parseCssValue("super");		}		return parseCssValue("");	    } else if (key == StyleConstants.Subscript) {		if (value.equals(Boolean.TRUE)) {		    return parseCssValue("sub");		}		return parseCssValue("");	    }	    return null;	}	/**

⌨️ 快捷键说明

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