< prev index next >

src/java.desktop/share/classes/javax/swing/text/html/StyleSheet.java

Print this page

        

*** 44,54 **** * multiple views over the same model can be rendered * differently, etc. This can be thought of as a CSS * rule repository. The key for CSS attributes is an * object of type CSS.Attribute. The type of the value * is up to the StyleSheet implementation, but the ! * <code>toString</code> method is required * to return a string representation of CSS value. * <p> * The primary entry point for HTML View implementations * to get their attributes is the * {@link #getViewAttributes getViewAttributes} --- 44,54 ---- * multiple views over the same model can be rendered * differently, etc. This can be thought of as a CSS * rule repository. The key for CSS attributes is an * object of type CSS.Attribute. The type of the value * is up to the StyleSheet implementation, but the ! * {@code toString} method is required * to return a string representation of CSS value. * <p> * The primary entry point for HTML View implementations * to get their attributes is the * {@link #getViewAttributes getViewAttributes}
*** 99,123 **** * &nbsp; * </code></pre> * <p> * The semantics for when a CSS style should overide visual attributes * defined by an element are not well defined. For example, the html ! * <code>&lt;body bgcolor=red&gt;</code> makes the body have a red * background. But if the html file also contains the CSS rule ! * <code>body { background: blue }</code> it becomes less clear as to * what color the background of the body should be. The current * implementation gives visual attributes defined in the element the * highest precedence, that is they are always checked before any styles. * Therefore, in the previous example the background would have a * red color as the body element defines the background color to be red. * <p> * As already mentioned this supports CSS. We don't support the full CSS * spec. Refer to the javadoc of the CSS class to see what properties * we support. The two major CSS parsing related * concepts we do not currently ! * support are pseudo selectors, such as <code>A:link { color: red }</code>, ! * and the <code>important</code> modifier. * * @implNote This implementation is currently * incomplete. It can be replaced with alternative implementations * that are complete. Future versions of this class will provide * better CSS support. --- 99,123 ---- * &nbsp; * </code></pre> * <p> * The semantics for when a CSS style should overide visual attributes * defined by an element are not well defined. For example, the html ! * {@code <body bgcolor=red>} makes the body have a red * background. But if the html file also contains the CSS rule ! * {@code body { background: blue }} it becomes less clear as to * what color the background of the body should be. The current * implementation gives visual attributes defined in the element the * highest precedence, that is they are always checked before any styles. * Therefore, in the previous example the background would have a * red color as the body element defines the background color to be red. * <p> * As already mentioned this supports CSS. We don't support the full CSS * spec. Refer to the javadoc of the CSS class to see what properties * we support. The two major CSS parsing related * concepts we do not currently ! * support are pseudo selectors, such as {@code A:link { color: red }}, ! * and the {@code important} modifier. * * @implNote This implementation is currently * incomplete. It can be replaced with alternative implementations * that are complete. Future versions of this class will provide * better CSS support.
*** 261,272 **** } } /** * Fetches the rule that best matches the selector given ! * in string form. Where <code>selector</code> is a space separated ! * String of the element names. For example, <code>selector</code> * might be 'html body tr td''<p> * The attributes of the returned Style will change * as rules are added and removed. That is if you to ask for a rule * with a selector "table p" and a new rule was added with a selector * of "p" the returned Style would include the new attributes from --- 261,272 ---- } } /** * Fetches the rule that best matches the selector given ! * in string form. Where {@code selector} is a space separated ! * String of the element names. For example, {@code selector} * might be 'html body tr td''<p> * The attributes of the returned Style will change * as rules are added and removed. That is if you to ask for a rule * with a selector "table p" and a new rule was added with a selector * of "p" the returned Style would include the new attributes from
*** 394,405 **** } super.removeStyle(nm); } /** ! * Adds the rules from the StyleSheet <code>ss</code> to those of ! * the receiver. <code>ss's</code> rules will override the rules of * any previously added style sheets. An added StyleSheet will never * override the rules of the receiving style sheet. * * @param ss a StyleSheet * @since 1.3 --- 394,405 ---- } super.removeStyle(nm); } /** ! * Adds the rules from the StyleSheet {@code ss} to those of ! * the receiver. {@code ss's} rules will override the rules of * any previously added style sheets. An added StyleSheet will never * override the rules of the receiving style sheet. * * @param ss a StyleSheet * @since 1.3
*** 420,430 **** } } } /** ! * Removes the StyleSheet <code>ss</code> from those of the receiver. * * @param ss a StyleSheet * @since 1.3 */ public void removeStyleSheet(StyleSheet ss) { --- 420,430 ---- } } } /** ! * Removes the StyleSheet {@code ss} from those of the receiver. * * @param ss a StyleSheet * @since 1.3 */ public void removeStyleSheet(StyleSheet ss) {
*** 467,477 **** } return retValue; } /** ! * Imports a style sheet from <code>url</code>. The resulting rules * are directly added to the receiver. If you do not want the rules * to become part of the receiver, create a new StyleSheet and use * addStyleSheet to link it in. * * @param url an url --- 467,477 ---- } return retValue; } /** ! * Imports a style sheet from {@code url}. The resulting rules * are directly added to the receiver. If you do not want the rules * to become part of the receiver, create a new StyleSheet and use * addStyleSheet to link it in. * * @param url an url
*** 493,503 **** } } /** * Sets the base. All import statements that are relative, will be ! * relative to <code>base</code>. * * @param base a base. * @since 1.3 */ public void setBase(URL base) { --- 493,503 ---- } } /** * Sets the base. All import statements that are relative, will be ! * relative to {@code base}. * * @param base a base. * @since 1.3 */ public void setBase(URL base) {
*** 1029,1039 **** 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) { --- 1029,1039 ---- return CSS.stringToColor(string); } /** * Returns the ImageIcon to draw in the background for ! * {@code attr}. */ ImageIcon getBackgroundImage(AttributeSet attr) { Object value = attr.getAttribute(CSS.Attribute.BACKGROUND_IMAGE); if (value != null) {
*** 1095,1105 **** // 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<ResolvedStyle> values = resolvedStyles.elements(); while (values.hasMoreElements()) { --- 1095,1105 ---- // the sheet. // /** * Updates the attributes of the rules to reference any related ! * rules in {@code ss}. */ private synchronized void linkStyleSheetAt(StyleSheet ss, int index) { if (resolvedStyles.size() > 0) { Enumeration<ResolvedStyle> values = resolvedStyles.elements(); while (values.hasMoreElements()) {
*** 1109,1120 **** } } } /** ! * 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<ResolvedStyle> values = resolvedStyles.elements(); --- 1109,1120 ---- } } } /** ! * Removes references to the rules in {@code ss}. ! * {@code index} 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<ResolvedStyle> values = resolvedStyles.elements();
*** 1305,1315 **** } return retStyle; } /** ! * Returns the resolved style for <code>selector</code>. This will * create the resolved style, if necessary. */ private synchronized Style getResolvedStyle(String selector, Vector<Element> elements, HTML.Tag t) { --- 1305,1315 ---- } return retStyle; } /** ! * Returns the resolved style for {@code selector}. This will * create the resolved style, if necessary. */ private synchronized Style getResolvedStyle(String selector, Vector<Element> elements, HTML.Tag t) {
*** 1319,1329 **** } return retStyle; } /** ! * Returns the resolved style for <code>selector</code>. This will * create the resolved style, if necessary. */ private synchronized Style getResolvedStyle(String selector) { Style retStyle = resolvedStyles.get(selector); if (retStyle == null) { --- 1319,1329 ---- } return retStyle; } /** ! * Returns the resolved style for {@code selector}. This will * create the resolved style, if necessary. */ private synchronized Style getResolvedStyle(String selector) { Style retStyle = resolvedStyles.get(selector); if (retStyle == null) {
*** 1331,1342 **** } return retStyle; } /** ! * Adds <code>mapping</code> to <code>elements</code>. It is added ! * such that <code>elements</code> will remain ordered by * specificity. */ private void addSortedStyle(SelectorMapping mapping, Vector<SelectorMapping> elements) { int size = elements.size(); --- 1331,1342 ---- } return retStyle; } /** ! * Adds {@code mapping} to {@code elements}. It is added ! * such that {@code elements} will remain ordered by * specificity. */ private void addSortedStyle(SelectorMapping mapping, Vector<SelectorMapping> elements) { int size = elements.size();
*** 1352,1364 **** } elements.addElement(mapping); } /** ! * Adds <code>parentMapping</code> to <code>styles</code>, and ! * recursively calls this method if <code>parentMapping</code> has ! * any child mappings for any of the Elements in <code>elements</code>. */ private synchronized void getStyles(SelectorMapping parentMapping, Vector<SelectorMapping> styles, String[] tags, String[] ids, String[] classes, int index, int numElements, --- 1352,1364 ---- } elements.addElement(mapping); } /** ! * Adds {@code parentMapping} to {@code styles}, and ! * recursively calls this method if {@code parentMapping} has ! * any child mappings for any of the Elements in {@code elements}. */ private synchronized void getStyles(SelectorMapping parentMapping, Vector<SelectorMapping> styles, String[] tags, String[] ids, String[] classes, int index, int numElements,
*** 1415,1425 **** } } /** * Creates and returns a Style containing all the rules that match ! * <code>selector</code>. */ private synchronized Style createResolvedStyle(String selector, String[] tags, String[] ids, String[] classes) { SearchBuffer sb = SearchBuffer.obtainSearchBuffer(); --- 1415,1425 ---- } } /** * Creates and returns a Style containing all the rules that match ! * {@code selector}. */ private synchronized Style createResolvedStyle(String selector, String[] tags, String[] ids, String[] classes) { SearchBuffer sb = SearchBuffer.obtainSearchBuffer();
*** 1498,1515 **** } } /** * Creates and returns a Style containing all the rules that ! * matches <code>selector</code>. * * @param elements a Vector of all the Elements * the style is being asked for. The * first Element is the deepest Element, with the last Element * representing the root. * @param t the Tag to use for ! * the first Element in <code>elements</code> */ private Style createResolvedStyle(String selector, Vector<Element> elements, HTML.Tag t) { int numElements = elements.size(); // Build three arrays, one for tags, one for class's, and one for --- 1498,1515 ---- } } /** * Creates and returns a Style containing all the rules that ! * matches {@code selector}. * * @param elements a Vector of all the Elements * the style is being asked for. The * first Element is the deepest Element, with the last Element * representing the root. * @param t the Tag to use for ! * the first Element in {@code elements} */ private Style createResolvedStyle(String selector, Vector<Element> elements, HTML.Tag t) { int numElements = elements.size(); // Build three arrays, one for tags, one for class's, and one for
*** 1562,1573 **** return createResolvedStyle(selector, tags, ids, classes); } /** * Creates and returns a Style containing all the rules that match ! * <code>selector</code>. It is assumed that each simple selector ! * in <code>selector</code> is separated by a space. */ private Style createResolvedStyle(String selector) { SearchBuffer sb = SearchBuffer.obtainSearchBuffer(); // Will contain the tags, ids, and classes, in that order. @SuppressWarnings("unchecked") --- 1562,1573 ---- return createResolvedStyle(selector, tags, ids, classes); } /** * Creates and returns a Style containing all the rules that match ! * {@code selector}. It is assumed that each simple selector ! * in {@code selector} is separated by a space. */ private Style createResolvedStyle(String selector) { SearchBuffer sb = SearchBuffer.obtainSearchBuffer(); // Will contain the tags, ids, and classes, in that order. @SuppressWarnings("unchecked")
*** 1763,1773 **** } return sb; } /** ! * Adds <code>sb</code> to the stack of SearchBuffers that can * be used. */ static void releaseSearchBuffer(SearchBuffer sb) { sb.empty(); searchBuffers.push(sb); --- 1763,1773 ---- } return sb; } /** ! * Adds {@code sb} to the stack of SearchBuffers that can * be used. */ static void releaseSearchBuffer(SearchBuffer sb) { sb.empty(); searchBuffers.push(sb);
*** 2155,2165 **** } return childtype; } /** ! * Obtains the starting index from <code>parent</code>. */ private void getStart(View parent) { checkedForStart = true; Element element = parent.getElement(); if (element != null) { --- 2155,2165 ---- } return childtype; } /** ! * Obtains the starting index from {@code parent}. */ private void getStart(View parent) { checkedForStart = true; Element element = parent.getElement(); if (element != null) {
*** 2178,2189 **** } } /** * Returns an integer that should be used to render the child at ! * <code>childIndex</code> with. The retValue will usually be ! * <code>childIndex</code> + 1, unless <code>parentView</code> * has some Views that do not represent LI's, or one of the views * has a HTML.Attribute.START specified. */ private int getRenderIndex(View parentView, int childIndex) { if (!checkedForStart) { --- 2178,2189 ---- } } /** * Returns an integer that should be used to render the child at ! * {@code childIndex} with. The retValue will usually be ! * {@code childIndex} + 1, unless {@code parentView} * has some Views that do not represent LI's, or one of the views * has a HTML.Attribute.START specified. */ private int getRenderIndex(View parentView, int childIndex) { if (!checkedForStart) {
*** 2858,2868 **** } /** * Inserts a Style into the receiver so that the styles the * receiver represents are still ordered by specificity. ! * <code>style</code> will be added before any extended styles, that * is before extendedIndex. */ synchronized void insertStyle(Style style, int specificity) { AttributeSet[] attrs = getAttributes(); int maxCounter = attrs.length; --- 2858,2868 ---- } /** * Inserts a Style into the receiver so that the styles the * receiver represents are still ordered by specificity. ! * {@code style} will be added before any extended styles, that * is before extendedIndex. */ synchronized void insertStyle(Style style, int specificity) { AttributeSet[] attrs = getAttributes(); int maxCounter = attrs.length;
*** 2877,2887 **** extendedIndex++; } /** * Removes a previously added style. This will do nothing if ! * <code>style</code> is not referenced by the receiver. */ synchronized void removeStyle(Style style) { AttributeSet[] attrs = getAttributes(); for (int counter = attrs.length - 1; counter >= 0; counter--) { --- 2877,2887 ---- extendedIndex++; } /** * Removes a previously added style. This will do nothing if ! * {@code style} is not referenced by the receiver. */ synchronized void removeStyle(Style style) { AttributeSet[] attrs = getAttributes(); for (int counter = attrs.length - 1; counter >= 0; counter--) {
*** 2894,2928 **** } } } /** ! * Adds <code>s</code> as one of the Attributesets to look up * attributes in. */ synchronized void insertExtendedStyleAt(Style attr, int index) { insertAttributeSetAt(attr, extendedIndex + index); } /** ! * Adds <code>s</code> as one of the AttributeSets to look up * attributes in. It will be the AttributeSet last checked. */ synchronized void addExtendedStyle(Style attr) { insertAttributeSetAt(attr, getAttributes().length); } /** ! * Removes the style at <code>index</code> + ! * <code>extendedIndex</code>. */ synchronized void removeExtendedStyleAt(int index) { removeAttributeSetAt(extendedIndex + index); } /** ! * Returns true if the receiver matches <code>selector</code>, where * a match is defined by the CSS rule matching. * Each simple selector must be separated by a single space. */ protected boolean matches(String selector) { int sLast = selector.length(); --- 2894,2928 ---- } } } /** ! * Adds {@code s} as one of the Attributesets to look up * attributes in. */ synchronized void insertExtendedStyleAt(Style attr, int index) { insertAttributeSetAt(attr, extendedIndex + index); } /** ! * Adds {@code s} as one of the AttributeSets to look up * attributes in. It will be the AttributeSet last checked. */ synchronized void addExtendedStyle(Style attr) { insertAttributeSetAt(attr, getAttributes().length); } /** ! * Removes the style at {@code index} + ! * {@code extendedIndex}. */ synchronized void removeExtendedStyleAt(int index) { removeAttributeSetAt(extendedIndex + index); } /** ! * Returns true if the receiver matches {@code selector}, where * a match is defined by the CSS rule matching. * Each simple selector must be separated by a single space. */ protected boolean matches(String selector) { int sLast = selector.length();
*** 3082,3092 **** } /** * SelectorMapping contains a specifitiy, as an integer, and an associated ! * Style. It can also reference children <code>SelectorMapping</code>s, * so that it behaves like a tree. * <p> * This is not thread safe, it is assumed the caller will take the * necessary precations if this is to be used in a threaded environment. */ --- 3082,3092 ---- } /** * SelectorMapping contains a specifitiy, as an integer, and an associated ! * Style. It can also reference children {@code SelectorMapping}s, * so that it behaves like a tree. * <p> * This is not thread safe, it is assumed the caller will take the * necessary precations if this is to be used in a threaded environment. */
*** 3117,3128 **** return style; } /** * Returns the child mapping identified by the simple selector ! * <code>selector</code>. If a child mapping does not exist for ! *<code>selector</code>, and <code>create</code> is true, a new * one will be created. */ public SelectorMapping getChildSelectorMapping(String selector, boolean create) { SelectorMapping retValue = null; --- 3117,3128 ---- return style; } /** * Returns the child mapping identified by the simple selector ! * {@code selector}. If a child mapping does not exist for ! *{@code selector}, and {@code create} is true, a new * one will be created. */ public SelectorMapping getChildSelectorMapping(String selector, boolean create) { SelectorMapping retValue = null;
*** 3141,3160 **** } return retValue; } /** ! * Creates a child <code>SelectorMapping</code> with the specified ! * <code>specificity</code>. */ protected SelectorMapping createChildSelectorMapping(int specificity) { return new SelectorMapping(specificity); } /** * Returns the specificity for the child selector ! * <code>selector</code>. */ protected int getChildSpecificity(String selector) { // class (.) 100 // id (#) 10000 char firstChar = selector.charAt(0); --- 3141,3160 ---- } return retValue; } /** ! * Creates a child {@code SelectorMapping} with the specified ! * {@code specificity}. */ protected SelectorMapping createChildSelectorMapping(int specificity) { return new SelectorMapping(specificity); } /** * Returns the specificity for the child selector ! * {@code selector}. */ protected int getChildSpecificity(String selector) { // class (.) 100 // id (#) 10000 char firstChar = selector.charAt(0);
*** 3262,3273 **** // CSSParserCallback methods, public to implement the interface. // /** * Invoked when a valid @import is encountered, will call ! * <code>importStyleSheet</code> if a ! * <code>MalformedURLException</code> is not thrown in creating * the URL. */ public void handleImport(String importString) { URL url = CSS.getURL(base, importString); if (url != null) { --- 3262,3273 ---- // CSSParserCallback methods, public to implement the interface. // /** * Invoked when a valid @import is encountered, will call ! * {@code importStyleSheet} if a ! * {@code MalformedURLException} is not thrown in creating * the URL. */ public void handleImport(String importString) { URL url = CSS.getURL(base, importString); if (url != null) {
< prev index next >