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

📄 css.java

📁 java jdk 1.4的源码
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
	styleConstantToCssMap.put(StyleConstants.Superscript, 				  CSS.Attribute.VERTICAL_ALIGN);	styleConstantToCssMap.put(StyleConstants.Subscript, 				  CSS.Attribute.VERTICAL_ALIGN);	styleConstantToCssMap.put(StyleConstants.Foreground, 				  CSS.Attribute.COLOR);	styleConstantToCssMap.put(StyleConstants.Background, 				  CSS.Attribute.BACKGROUND_COLOR);	styleConstantToCssMap.put(StyleConstants.FirstLineIndent, 				  CSS.Attribute.TEXT_INDENT);	styleConstantToCssMap.put(StyleConstants.LeftIndent, 				  CSS.Attribute.MARGIN_LEFT);	styleConstantToCssMap.put(StyleConstants.RightIndent, 				  CSS.Attribute.MARGIN_RIGHT);	styleConstantToCssMap.put(StyleConstants.SpaceAbove, 				  CSS.Attribute.MARGIN_TOP);	styleConstantToCssMap.put(StyleConstants.SpaceBelow, 				  CSS.Attribute.MARGIN_BOTTOM);	styleConstantToCssMap.put(StyleConstants.Alignment, 				  CSS.Attribute.TEXT_ALIGN);	// HTML->CSS	htmlValueToCssValueMap.put("disc", CSS.Value.DISC);	htmlValueToCssValueMap.put("square", CSS.Value.SQUARE);	htmlValueToCssValueMap.put("circle", CSS.Value.CIRCLE);	htmlValueToCssValueMap.put("1", CSS.Value.DECIMAL);	htmlValueToCssValueMap.put("a", CSS.Value.LOWER_ALPHA);	htmlValueToCssValueMap.put("A", CSS.Value.UPPER_ALPHA);	htmlValueToCssValueMap.put("i", CSS.Value.LOWER_ROMAN);	htmlValueToCssValueMap.put("I", CSS.Value.UPPER_ROMAN);	// CSS-> internal CSS	cssValueToInternalValueMap.put("disc", CSS.Value.DISC);	cssValueToInternalValueMap.put("square", CSS.Value.SQUARE);	cssValueToInternalValueMap.put("circle", CSS.Value.CIRCLE);	cssValueToInternalValueMap.put("decimal", CSS.Value.DECIMAL);	cssValueToInternalValueMap.put("lower-roman", CSS.Value.LOWER_ROMAN);	cssValueToInternalValueMap.put("upper-roman", CSS.Value.UPPER_ROMAN);	cssValueToInternalValueMap.put("lower-alpha", CSS.Value.LOWER_ALPHA);	cssValueToInternalValueMap.put("upper-alpha", CSS.Value.UPPER_ALPHA);	cssValueToInternalValueMap.put("repeat", CSS.Value.BACKGROUND_REPEAT);	cssValueToInternalValueMap.put("no-repeat",				       CSS.Value.BACKGROUND_NO_REPEAT);	cssValueToInternalValueMap.put("repeat-x",				       CSS.Value.BACKGROUND_REPEAT_X);	cssValueToInternalValueMap.put("repeat-y",				       CSS.Value.BACKGROUND_REPEAT_Y);	cssValueToInternalValueMap.put("scroll",				       CSS.Value.BACKGROUND_SCROLL);	cssValueToInternalValueMap.put("fixed",				       CSS.Value.BACKGROUND_FIXED);        // Register all the CSS attribute keys for archival/unarchival	Object[] keys = CSS.Attribute.allAttributes;	try {	    for (int i = 0; i < keys.length; i++) {		StyleContext.registerStaticAttributeKey(keys[i]);	    }	} catch (Throwable e) {	    e.printStackTrace();	}        // Register all the CSS Values for archival/unarchival	keys = CSS.Value.allValues;	try {	    for (int i = 0; i < keys.length; i++) {		StyleContext.registerStaticAttributeKey(keys[i]);	    }	} catch (Throwable e) {	    e.printStackTrace();	}    }    /**     * Returns a hashtable whose contents are used to indicate the valid     * fonts.     */    static Hashtable getValidFontNameMapping() {	if (fontMapping == null) {	    // This can get called from multiple threads, lock before setting	    synchronized(fontMappingLock) {		if (fontMapping == null) {		    String[]      names = null;                    GraphicsEnvironment ge = GraphicsEnvironment.                                               getLocalGraphicsEnvironment();                    if (ge != null) {                        names = ge.getAvailableFontFamilyNames();                    }		    if (names == null) {			names = Toolkit.getDefaultToolkit().getFontList();		    }		    if (names != null) {			fontMapping = new Hashtable(names.length * 2);			for (int counter = names.length - 1; counter >= 0;			     counter--) {			    // Put both lowercase and case value in table.			    fontMapping.put(names[counter].toLowerCase(),					    names[counter]);			    fontMapping.put(names[counter], names[counter]);			}		    }		    else {			fontMapping = new Hashtable(1);		    }		}	    }	}	return fontMapping;    }    /**     * Return the set of all possible CSS attribute keys.     */    public static Attribute[] getAllAttributeKeys() {	Attribute[] keys = new Attribute[Attribute.allAttributes.length];	System.arraycopy(Attribute.allAttributes, 0, keys, 0, Attribute.allAttributes.length);	return keys;    }    /**     * Translates a string to a <code>CSS.Attribute</code> object.     * This will return <code>null</code> if there is no attribute     * by the given name.     *     * @param name the name of the CSS attribute to fetch the     *  typesafe enumeration for     * @return the <code>CSS.Attribute</code> object,     *  or <code>null</code> if the string     *  doesn't represent a valid attribute key     */    public static final Attribute getAttribute(String name) {	return (Attribute) attributeMap.get(name);    }    /**     * Translates a string to a <code>CSS.Value</code> object.     * This will return <code>null</code> if there is no value     * by the given name.     *     * @param name the name of the CSS value to fetch the     *  typesafe enumeration for     * @return the <code>CSS.Value</code> object,      *  or <code>null</code> if the string     *  doesn't represent a valid CSS value name; this does     *  not mean that it doesn't represent a valid CSS value     */    static final Value getValue(String name) {	return (Value) valueMap.get(name);    }    //    // Conversion related methods/classes    //    /**     * Returns a URL for the given CSS url string. If relative,     * <code>base</code> is used as the parent. If a valid URL can not     * be found, this will not throw a MalformedURLException, instead      * null will be returned.     */    static URL getURL(URL base, String cssString) {	if (cssString == null) {	    return null;	}	if (cssString.startsWith("url(") &&	    cssString.endsWith(")")) {	    cssString = cssString.substring(4, cssString.length() - 1);	}	// Absolute first	try {	    URL url = new URL(cssString);	    if (url != null) {		return url;	    }	} catch (MalformedURLException mue) {	}	// Then relative	if (base != null) {	    // Relative URL, try from base	    try {		URL url = new URL(base, cssString);		return url;	    }	    catch (MalformedURLException muee) {	    }	}	return null;    }    /**     * Converts a type Color to a hex string     * in the format "#RRGGBB"     */    static String colorToHex(Color color) {      String colorstr = new String("#");      // Red      String str = Integer.toHexString(color.getRed());      if (str.length() > 2)	str = str.substring(0, 2);      else if (str.length() < 2)	colorstr += "0" + str;      else	colorstr += str;      // Green      str = Integer.toHexString(color.getGreen());      if (str.length() > 2)	str = str.substring(0, 2);      else if (str.length() < 2)	colorstr += "0" + str;      else	colorstr += str;      // Blue      str = Integer.toHexString(color.getBlue());      if (str.length() > 2)	str = str.substring(0, 2);      else if (str.length() < 2)	colorstr += "0" + str;      else	colorstr += str;      return colorstr;    }     /**      * Convert a "#FFFFFF" hex string to a Color.      * If the color specification is bad, an attempt      * will be made to fix it up.      */    static final Color hexToColor(String value) {	String digits;	int n = value.length();	if (value.startsWith("#")) {	    digits = value.substring(1, Math.min(value.length(), 7));	} else {	    digits = value;	}	String hstr = "0x" + digits;	Color c;	try {	    c = Color.decode(hstr);	} catch (NumberFormatException nfe) {	    c = null;	}	 return c;     }    /**     * Convert a color string such as "RED" or "#NNNNNN" or "rgb(r, g, b)"     * to a Color.     */    static Color stringToColor(String str) {      Color color = null;      if (str.length() == 0)        color = Color.black;      else if (str.startsWith("rgb(")) {          color = parseRGB(str);      }      else if (str.charAt(0) == '#')        color = hexToColor(str);      else if (str.equalsIgnoreCase("Black"))        color = hexToColor("#000000");      else if(str.equalsIgnoreCase("Silver"))        color = hexToColor("#C0C0C0");      else if(str.equalsIgnoreCase("Gray"))        color = hexToColor("#808080");      else if(str.equalsIgnoreCase("White"))        color = hexToColor("#FFFFFF");      else if(str.equalsIgnoreCase("Maroon"))        color = hexToColor("#800000");      else if(str.equalsIgnoreCase("Red"))        color = hexToColor("#FF0000");      else if(str.equalsIgnoreCase("Purple"))        color = hexToColor("#800080");      else if(str.equalsIgnoreCase("Fuchsia"))        color = hexToColor("#FF00FF");      else if(str.equalsIgnoreCase("Green"))        color = hexToColor("#008000");      else if(str.equalsIgnoreCase("Lime"))        color = hexToColor("#00FF00");      else if(str.equalsIgnoreCase("Olive"))        color = hexToColor("#808000");      else if(str.equalsIgnoreCase("Yellow"))        color = hexToColor("#FFFF00");      else if(str.equalsIgnoreCase("Navy"))        color = hexToColor("#000080");      else if(str.equalsIgnoreCase("Blue"))        color = hexToColor("#0000FF");      else if(str.equalsIgnoreCase("Teal"))        color = hexToColor("#008080");      else if(str.equalsIgnoreCase("Aqua"))        color = hexToColor("#00FFFF");      else	  color = hexToColor(str); // sometimes get specified without leading #      return color;    }    /**     * Parses a String in the format <code>rgb(r, g, b)</code> where     * each of the Color components is either an integer, or a floating number     * with a % after indicating a percentage value of 255. Values are     * constrained to fit with 0-255. The resulting Color is returned.     */    private static Color parseRGB(String string) {        // Find the next numeric char        int[] index = new int[1];        index[0] = 4;        int red = getColorComponent(string, index);        int green = getColorComponent(string, index);        int blue = getColorComponent(string, index);        return new Color(red, green, blue);    }    /**     * Returns the next integer value from <code>string</code> starting     * at <code>index[0]</code>. The value can either can an integer, or     * a percentage (floating number ending with %), in which case it is     * multiplied by 255.     */    private static int getColorComponent(String string, int[] index) {        int length = string.length();        char aChar;        // Skip non-decimal chars        while(index[0] < length && (aChar = string.charAt(index[0])) != '-' &&              !Character.isDigit(aChar) && aChar != '.') {            index[0]++;        }        int start = index[0];        if (start < length && string.charAt(index[0]) == '-') {            index[0]++;        }        while(index[0] < length &&                         Character.isDigit(string.charAt(index[0]))) {            index[0]++;        }        if (index[0] < length && string.charAt(index[0]) == '.') {            // Decimal value            index[0]++;            while(index[0] < length &&                  Character.isDigit(string.charAt(index[0]))) {                index[0]++;            }        }        if (start != index[0]) {            try {                float value = Float.parseFloat(string.substring                                               (start, index[0]));                if (index[0] < length && string.charAt(index[0]) == '%') {                    index[0]++;                    value = value * 255f / 100f;                }                return Math.min(255, Math.max(0, (int)value));            } catch (NumberFormatException nfe) {                // Treat as 0            }        }        return 0;    }    static int getIndexOfSize(float pt) {        for (int i = 0; i < sizeMap.length; i ++ )                if (pt <= sizeMap[i])                        return i + 1;        return sizeMap.length;    }    /**     * @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

⌨️ 快捷键说明

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