jdk/src/share/classes/javax/swing/text/html/CSS.java
changeset 23697 e556a715949f
parent 23010 6dadb192ad81
child 24269 325ea76ea0e9
equal deleted inserted replaced
23696:7deff68428ef 23697:e556a715949f
     1 /*
     1 /*
     2  * Copyright (c) 1998, 2013, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 1998, 2014, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.  Oracle designates this
     7  * published by the Free Software Foundation.  Oracle designates this
   121  *
   121  *
   122  * @author  Timothy Prinzing
   122  * @author  Timothy Prinzing
   123  * @author  Scott Violet
   123  * @author  Scott Violet
   124  * @see StyleSheet
   124  * @see StyleSheet
   125  */
   125  */
       
   126 @SuppressWarnings("serial") // Same-version serialization only
   126 public class CSS implements Serializable {
   127 public class CSS implements Serializable {
   127 
   128 
   128     /**
   129     /**
   129      * Definitions to be used as a key on AttributeSet's
   130      * Definitions to be used as a key on AttributeSet's
   130      * that might hold CSS attributes.  Since this is a
   131      * that might hold CSS attributes.  Since this is a
  1561      * converts the StyleConstants attribute to a
  1562      * converts the StyleConstants attribute to a
  1562      * CSS.Attribute, and then calls the toStyleConstants
  1563      * CSS.Attribute, and then calls the toStyleConstants
  1563      * method to convert the CSS value to a StyleConstants
  1564      * method to convert the CSS value to a StyleConstants
  1564      * value.
  1565      * value.
  1565      */
  1566      */
       
  1567     @SuppressWarnings("serial") // Same-version serialization only
  1566     static class CssValue implements Serializable {
  1568     static class CssValue implements Serializable {
  1567 
  1569 
  1568         /**
  1570         /**
  1569          * Convert a CSS value string to the internal format
  1571          * Convert a CSS value string to the internal format
  1570          * (for fast processing) used in the attribute sets.
  1572          * (for fast processing) used in the attribute sets.
  1639      * StyleConstants by default. This class represents the
  1641      * StyleConstants by default. This class represents the
  1640      * value as a string (via the superclass), but
  1642      * value as a string (via the superclass), but
  1641      * provides StyleConstants conversion support for the
  1643      * provides StyleConstants conversion support for the
  1642      * CSS attributes that are held as strings.
  1644      * CSS attributes that are held as strings.
  1643      */
  1645      */
       
  1646     @SuppressWarnings("serial") // Same-version serialization only
  1644     static class StringValue extends CssValue {
  1647     static class StringValue extends CssValue {
  1645 
  1648 
  1646         /**
  1649         /**
  1647          * Convert a CSS value string to the internal format
  1650          * Convert a CSS value string to the internal format
  1648          * (for fast processing) used in the attribute sets.
  1651          * (for fast processing) used in the attribute sets.
  1795      * percentage, depending upon the ending of the
  1798      * percentage, depending upon the ending of the
  1796      * associated string.
  1799      * associated string.
  1797      * If the type is Integer, the value is specified
  1800      * If the type is Integer, the value is specified
  1798      * in terms of a size index.
  1801      * in terms of a size index.
  1799      */
  1802      */
       
  1803     @SuppressWarnings("serial") // Same-version serialization only
  1800     class FontSize extends CssValue {
  1804     class FontSize extends CssValue {
  1801 
  1805 
  1802         /**
  1806         /**
  1803          * Returns the size in points.  This is ultimately
  1807          * Returns the size in points.  This is ultimately
  1804          * what we need for the purpose of creating/fetching
  1808          * what we need for the purpose of creating/fetching
  1964         float value;
  1968         float value;
  1965         boolean index;
  1969         boolean index;
  1966         LengthUnit lu;
  1970         LengthUnit lu;
  1967     }
  1971     }
  1968 
  1972 
       
  1973     @SuppressWarnings("serial") // Same-version serialization only
  1969     static class FontFamily extends CssValue {
  1974     static class FontFamily extends CssValue {
  1970 
  1975 
  1971         /**
  1976         /**
  1972          * Returns the font family to use.
  1977          * Returns the font family to use.
  1973          */
  1978          */
  2061         }
  2066         }
  2062 
  2067 
  2063         String family;
  2068         String family;
  2064     }
  2069     }
  2065 
  2070 
       
  2071     @SuppressWarnings("serial") // Same-version serialization only
  2066     static class FontWeight extends CssValue {
  2072     static class FontWeight extends CssValue {
  2067 
  2073 
  2068         int getValue() {
  2074         int getValue() {
  2069             return weight;
  2075             return weight;
  2070         }
  2076         }
  2123         }
  2129         }
  2124 
  2130 
  2125         int weight;
  2131         int weight;
  2126     }
  2132     }
  2127 
  2133 
       
  2134     @SuppressWarnings("serial") // Same-version serialization only
  2128     static class ColorValue extends CssValue {
  2135     static class ColorValue extends CssValue {
  2129 
  2136 
  2130         /**
  2137         /**
  2131          * Returns the color to use.
  2138          * Returns the color to use.
  2132          */
  2139          */
  2182         }
  2189         }
  2183 
  2190 
  2184         Color c;
  2191         Color c;
  2185     }
  2192     }
  2186 
  2193 
       
  2194     @SuppressWarnings("serial") // Same-version serialization only
  2187     static class BorderStyle extends CssValue {
  2195     static class BorderStyle extends CssValue {
  2188 
  2196 
  2189         CSS.Value getValue() {
  2197         CSS.Value getValue() {
  2190             return style;
  2198             return style;
  2191         }
  2199         }
  2234 
  2242 
  2235         // CSS.Values are static, don't archive it.
  2243         // CSS.Values are static, don't archive it.
  2236         transient private CSS.Value style;
  2244         transient private CSS.Value style;
  2237     }
  2245     }
  2238 
  2246 
       
  2247     @SuppressWarnings("serial") // Same-version serialization only
  2239     static class LengthValue extends CssValue {
  2248     static class LengthValue extends CssValue {
  2240 
  2249 
  2241         /**
  2250         /**
  2242          * if this length value may be negative.
  2251          * if this length value may be negative.
  2243          */
  2252          */
  2371 
  2380 
  2372     /**
  2381     /**
  2373      * BorderWidthValue is used to model BORDER_XXX_WIDTH and adds support
  2382      * BorderWidthValue is used to model BORDER_XXX_WIDTH and adds support
  2374      * for the thin/medium/thick values.
  2383      * for the thin/medium/thick values.
  2375      */
  2384      */
       
  2385     @SuppressWarnings("serial") // Same-version serialization only
  2376     static class BorderWidthValue extends LengthValue {
  2386     static class BorderWidthValue extends LengthValue {
  2377         BorderWidthValue(String svalue, int index) {
  2387         BorderWidthValue(String svalue, int index) {
  2378             this.svalue = svalue;
  2388             this.svalue = svalue;
  2379             span = values[index];
  2389             span = values[index];
  2380             percentage = false;
  2390             percentage = false;
  2410 
  2420 
  2411     /**
  2421     /**
  2412      * Handles uniquing of CSS values, like lists, and background image
  2422      * Handles uniquing of CSS values, like lists, and background image
  2413      * repeating.
  2423      * repeating.
  2414      */
  2424      */
       
  2425     @SuppressWarnings("serial") // Same-version serialization only
  2415     static class CssValueMapper extends CssValue {
  2426     static class CssValueMapper extends CssValue {
  2416         Object parseCssValue(String value) {
  2427         Object parseCssValue(String value) {
  2417             Object retValue = cssValueToInternalValueMap.get(value);
  2428             Object retValue = cssValueToInternalValueMap.get(value);
  2418             if (retValue == null) {
  2429             if (retValue == null) {
  2419                 retValue = cssValueToInternalValueMap.get(value.toLowerCase());
  2430                 retValue = cssValueToInternalValueMap.get(value.toLowerCase());
  2433 
  2444 
  2434 
  2445 
  2435     /**
  2446     /**
  2436      * Used for background images, to represent the position.
  2447      * Used for background images, to represent the position.
  2437      */
  2448      */
       
  2449     @SuppressWarnings("serial") // Same-version serialization only
  2438     static class BackgroundPosition extends CssValue {
  2450     static class BackgroundPosition extends CssValue {
  2439         float horizontalPosition;
  2451         float horizontalPosition;
  2440         float verticalPosition;
  2452         float verticalPosition;
  2441         // bitmask: bit 0, horizontal relative, bit 1 horizontal relative to
  2453         // bitmask: bit 0, horizontal relative, bit 1 horizontal relative to
  2442         // font size, 2 vertical relative to size, 3 vertical relative to
  2454         // font size, 2 vertical relative to size, 3 vertical relative to
  2578 
  2590 
  2579 
  2591 
  2580     /**
  2592     /**
  2581      * Used for BackgroundImages.
  2593      * Used for BackgroundImages.
  2582      */
  2594      */
       
  2595     @SuppressWarnings("serial") // Same-version serialization only
  2583     static class BackgroundImage extends CssValue {
  2596     static class BackgroundImage extends CssValue {
  2584         private boolean    loadedImage;
  2597         private boolean    loadedImage;
  2585         private ImageIcon  image;
  2598         private ImageIcon  image;
  2586 
  2599 
  2587         Object parseCssValue(String value) {
  2600         Object parseCssValue(String value) {
  2617 
  2630 
  2618     /**
  2631     /**
  2619      * Parses a length value, this is used internally, and never added
  2632      * Parses a length value, this is used internally, and never added
  2620      * to an AttributeSet or returned to the developer.
  2633      * to an AttributeSet or returned to the developer.
  2621      */
  2634      */
       
  2635     @SuppressWarnings("serial") // Same-version serialization only
  2622     static class LengthUnit implements Serializable {
  2636     static class LengthUnit implements Serializable {
  2623         static Hashtable<String, Float> lengthMapping = new Hashtable<String, Float>(6);
  2637         static Hashtable<String, Float> lengthMapping = new Hashtable<String, Float>(6);
  2624         static Hashtable<String, Float> w3cLengthMapping = new Hashtable<String, Float>(6);
  2638         static Hashtable<String, Float> w3cLengthMapping = new Hashtable<String, Float>(6);
  2625         static {
  2639         static {
  2626             lengthMapping.put("pt", new Float(1f));
  2640             lengthMapping.put("pt", new Float(1f));