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

📄 stylesheet.java

📁 JAVA 所有包
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
		Object cssKey = css.styleConstantsKeyToCSSKey		                    ((StyleConstants)key);		if (cssKey != null) {		    Object value = super.getAttribute(cssKey);		    if (value != null) {			return css.cssValueToStyleConstantsValue			                   ((StyleConstants)key, value);		    }		}	    }	    return super.getAttribute(key);	}    }    /**     * Small set of attributes that does conversion of requests     * for attributes of type StyleConstants.     */    class SmallConversionSet extends SmallAttributeSet {	/**	 * Creates a new attribute set based on a supplied set of attributes.	 *	 * @param source the set of attributes	 */        public SmallConversionSet(AttributeSet attrs) {	    super(attrs);	} 	        /**         * Checks whether a given attribute is defined.         *         * @param key the attribute key         * @return true if the attribute is defined         * @see AttributeSet#isDefined         */        public boolean isDefined(Object key) {	    if (key instanceof StyleConstants) {		Object cssKey = css.styleConstantsKeyToCSSKey		                    ((StyleConstants)key);		if (cssKey != null) {		    return super.isDefined(cssKey);		}	    }	    return super.isDefined(key);	}        /**         * Gets the value of an attribute.         *         * @param key the attribute name         * @return the attribute value         * @see AttributeSet#getAttribute         */        public Object getAttribute(Object key) {	    if (key instanceof StyleConstants) {		Object cssKey = css.styleConstantsKeyToCSSKey		                    ((StyleConstants)key);		if (cssKey != null) {		    Object value = super.getAttribute(cssKey);		    if (value != null) {			return css.cssValueToStyleConstantsValue			                   ((StyleConstants)key, value);		    }		}	    }	    return super.getAttribute(key);	}    }    // ---- Resource handling ----------------------------------------    /**     * Fetches the font to use for the given set of attributes.     */    public Font getFont(AttributeSet a) {	return css.getFont(this, a, 12, this);    }    /**     * Takes a set of attributes and turn it into a foreground color     * specification.  This might be used to specify things     * like brighter, more hue, etc.     *     * @param a the set of attributes     * @return the color     */    public Color getForeground(AttributeSet a) {	Color c = css.getColor(a, CSS.Attribute.COLOR);	if (c == null) {	    return Color.black;	}	return c;    }    /**     * Takes a set of attributes and turn it into a background color     * specification.  This might be used to specify things     * like brighter, more hue, etc.     *     * @param a the set of attributes     * @return the color     */    public Color getBackground(AttributeSet a) {	return css.getColor(a, CSS.Attribute.BACKGROUND_COLOR);    }    /**     * Fetches the box formatter to use for the given set     * of CSS attributes.     */    public BoxPainter getBoxPainter(AttributeSet a) {	return new BoxPainter(a, css, this);    }    /**     * Fetches the list formatter to use for the given set     * of CSS attributes.     */    public ListPainter getListPainter(AttributeSet a) {	return new ListPainter(a, this);    }    /**     * Sets the base font size, with valid values between 1 and 7.     */    public void setBaseFontSize(int sz) {	css.setBaseFontSize(sz);    }    /**     * Sets the base font size from the passed in String. The string     * can either identify a specific font size, with legal values between     * 1 and 7, or identifiy a relative font size such as +1 or -2.     */    public void setBaseFontSize(String size) {	css.setBaseFontSize(size);    }    public static int getIndexOfSize(float pt) {	return CSS.getIndexOfSize(pt, sizeMapDefault);    }    /**     * Returns the point size, given a size index.     */    public float getPointSize(int index) {	return css.getPointSize(index, this);    }    /**     *  Given a string such as "+2", "-2", or "2",     *  returns a point size value.     */    public float getPointSize(String size) {	return css.getPointSize(size, this);    }    /**     * Converts a color string such as "RED" or "#NNNNNN" to a Color.     * Note: This will only convert the HTML3.2 color strings     *       or a string of length 7;     *       otherwise, it will return null.     */    public Color stringToColor(String string) {	return CSS.stringToColor(string);    }    /**     * Returns the ImageIcon to draw in the background for     * <code>attr</code>.     */    ImageIcon getBackgroundImage(AttributeSet attr) {	Object value = attr.getAttribute(CSS.Attribute.BACKGROUND_IMAGE);	if (value != null) {	    return ((CSS.BackgroundImage)value).getImage(getBase());	}	return null;    }    /**     * Adds a rule into the StyleSheet.     *     * @param selector the selector to use for the rule.     *  This will be a set of simple selectors, and must     *  be a length of 1 or greater.     * @param declaration the set of CSS attributes that     *  make up the rule.     */    void addRule(String[] selector, AttributeSet declaration,		 boolean isLinked) {	int n = selector.length;	StringBuffer sb = new StringBuffer();	sb.append(selector[0]);	for (int counter = 1; counter < n; counter++) {	    sb.append(' ');	    sb.append(selector[counter]);	}	String selectorName = sb.toString();	Style rule = getStyle(selectorName);	if (rule == null) {	    // Notice how the rule is first created, and it not part of	    // the synchronized block. It is done like this as creating	    // a new rule will fire a ChangeEvent. We do not want to be	    // holding the lock when calling to other objects, it can	    // result in deadlock.	    Style altRule = addStyle(selectorName, null);	    synchronized(this) {		SelectorMapping mapping = getRootSelectorMapping();		for (int i = n - 1; i >= 0; i--) {		    mapping = mapping.getChildSelectorMapping                                      (selector[i], true);		}		rule = mapping.getStyle();		if (rule == null) {                    rule = altRule;                    mapping.setStyle(rule);		    refreshResolvedRules(selectorName, selector, rule,					 mapping.getSpecificity());		}	    }	}	if (isLinked) {	    rule = getLinkedStyle(rule);	}	rule.addAttributes(declaration);    }    //    // The following gaggle of methods is used in maintaing the rules from    // the sheet.    //    /**     * Updates the attributes of the rules to reference any related     * rules in <code>ss</code>.     */    private synchronized void linkStyleSheetAt(StyleSheet ss, int index) {	if (resolvedStyles.size() > 0) {	    Enumeration values = resolvedStyles.elements();	    while (values.hasMoreElements()) {		ResolvedStyle rule = (ResolvedStyle)values.nextElement();		rule.insertExtendedStyleAt(ss.getRule(rule.getName()),					   index);	    }	}    }    /**     * Removes references to the rules in <code>ss</code>.     * <code>index</code> gives the index the StyleSheet was at, that is     * how many StyleSheets had been added before it.     */    private synchronized void unlinkStyleSheet(StyleSheet ss, int index) {	if (resolvedStyles.size() > 0) {	    Enumeration values = resolvedStyles.elements();	    while (values.hasMoreElements()) {		ResolvedStyle rule = (ResolvedStyle)values.nextElement();		rule.removeExtendedStyleAt(index);	    }	}    }    /**     * Returns the simple selectors that comprise selector.     */    /* protected */    String[] getSimpleSelectors(String selector) {	selector = cleanSelectorString(selector);	SearchBuffer sb = SearchBuffer.obtainSearchBuffer();	Vector selectors = sb.getVector();	int lastIndex = 0;	int length = selector.length();	while (lastIndex != -1) {	    int newIndex = selector.indexOf(' ', lastIndex);	    if (newIndex != -1) {		selectors.addElement(selector.substring(lastIndex, newIndex));		if (++newIndex == length) {		    lastIndex = -1;		}		else {		    lastIndex = newIndex;		}	    }	    else {		selectors.addElement(selector.substring(lastIndex));		lastIndex = -1;	    }	}	String[] retValue = new String[selectors.size()];	selectors.copyInto(retValue);	SearchBuffer.releaseSearchBuffer(sb);	return retValue;    }    /**     * Returns a string that only has one space between simple selectors,     * which may be the passed in String.     */    /*protected*/ String cleanSelectorString(String selector) {	boolean lastWasSpace = true;	for (int counter = 0, maxCounter = selector.length();	     counter < maxCounter; counter++) {	    switch(selector.charAt(counter)) {	    case ' ':		if (lastWasSpace) {		    return _cleanSelectorString(selector);		}		lastWasSpace = true;		break;	    case '\n':	    case '\r':	    case '\t':		return _cleanSelectorString(selector);	    default:		lastWasSpace = false;	    }	}	if (lastWasSpace) {	    return _cleanSelectorString(selector);	}	// It was fine.	return selector;    }    /**     * Returns a new String that contains only one space between non     * white space characters.     */    private String _cleanSelectorString(String selector) {	SearchBuffer sb = SearchBuffer.obtainSearchBuffer();	StringBuffer buff = sb.getStringBuffer();	boolean lastWasSpace = true;	int lastIndex = 0;	char[] chars = selector.toCharArray();	int numChars = chars.length;	String retValue = null;	try {	    for (int counter = 0; counter < numChars; counter++) {		switch(chars[counter]) {		case ' ':		    if (!lastWasSpace) {			lastWasSpace = true;			if (lastIndex < counter) {			    buff.append(chars, lastIndex,					1 + counter - lastIndex);			}		    }		    lastIndex = counter + 1;		    break;		case '\n':		case '\r':		case '\t':		    if (!lastWasSpace) {			lastWasSpace = true;			if (lastIndex < counter) {			    buff.append(chars, lastIndex,					counter - lastIndex);			    buff.append(' ');			}		    }		    lastIndex = counter + 1;		    break;		default:		    lastWasSpace = false;		    break;		}	    }	    if (lastWasSpace && buff.length() > 0) {		// Remove last space.		buff.setLength(buff.length() - 1);	    }	    else if (lastIndex < numChars) {		buff.append(chars, lastIndex, numChars - lastIndex);	    }	    retValue = buff.toString();	}	finally {	    SearchBuffer.releaseSearchBuffer(sb);	}	return retValue;    }    /**     * Returns the root selector mapping that all selectors are relative     * to. This is an inverted graph of the selectors.     */    private SelectorMapping getRootSelectorMapping() {	return selectorMapping;    }    /**     * Returns the specificity of the passed in String. It assumes the     * passed in string doesn't contain junk, that is each selector is

⌨️ 快捷键说明

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