jdk/src/java.desktop/share/classes/javax/swing/text/html/CSS.java
author martin
Thu, 30 Oct 2014 07:31:41 -0700
changeset 28059 e576535359cc
parent 26749 b6598aa90114
child 32865 f9cb6e427f9e
permissions -rw-r--r--
8067377: My hobby: caning, then then canning, the the can-can Summary: Fix ALL the stutters! Reviewed-by: rriggs, mchung, lancea
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
23697
e556a715949f 8034169: Fix serial lint warnings in javax.swing
darcy
parents: 23010
diff changeset
     2
 * Copyright (c) 1998, 2014, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1299
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1299
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1299
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1299
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1299
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
package javax.swing.text.html;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
import java.awt.Color;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.awt.Font;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.awt.GraphicsEnvironment;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.awt.Toolkit;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.awt.HeadlessException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.awt.Image;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.io.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.lang.reflect.Method;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.net.URL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.net.MalformedURLException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.util.Enumeration;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import java.util.Hashtable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import java.util.Vector;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import java.util.Locale;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import javax.swing.ImageIcon;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import javax.swing.SizeRequirements;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
import javax.swing.text.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * Defines a set of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * <a href="http://www.w3.org/TR/REC-CSS1">CSS attributes</a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * as a typesafe enumeration.  The HTML View implementations use
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * CSS attributes to determine how they will render. This also defines
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * methods to map between CSS/HTML/StyleConstants. Any shorthand
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * properties, such as font, are mapped to the intrinsic properties.
21278
ef8a3a2a72f2 8022746: List of spelling errors in API doc
malenkov
parents: 20158
diff changeset
    52
 * <p>The following describes the CSS properties that are supported by the
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * rendering engine:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * <ul><li>font-family
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 *   <li>font-style
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 *   <li>font-size (supports relative units)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 *   <li>font-weight
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 *   <li>font
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 *   <li>color
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 *   <li>background-color (with the exception of transparent)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 *   <li>background-image
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 *   <li>background-repeat
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 *   <li>background-position
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 *   <li>background
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 *   <li>text-decoration (with the exception of blink and overline)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 *   <li>vertical-align (only sup and super)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 *   <li>text-align (justify is treated as center)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 *   <li>margin-top
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 *   <li>margin-right
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 *   <li>margin-bottom
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 *   <li>margin-left
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 *   <li>margin
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 *   <li>padding-top
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
 *   <li>padding-right
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
 *   <li>padding-bottom
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
 *   <li>padding-left
9219
607f3926b219 7025525: CSS property list in javax.swing.text.html.CSS is incomplete
rupashka
parents: 5506
diff changeset
    77
 *   <li>padding
607f3926b219 7025525: CSS property list in javax.swing.text.html.CSS is incomplete
rupashka
parents: 5506
diff changeset
    78
 *   <li>border-top-style
607f3926b219 7025525: CSS property list in javax.swing.text.html.CSS is incomplete
rupashka
parents: 5506
diff changeset
    79
 *   <li>border-right-style
607f3926b219 7025525: CSS property list in javax.swing.text.html.CSS is incomplete
rupashka
parents: 5506
diff changeset
    80
 *   <li>border-bottom-style
607f3926b219 7025525: CSS property list in javax.swing.text.html.CSS is incomplete
rupashka
parents: 5506
diff changeset
    81
 *   <li>border-left-style
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
 *   <li>border-style (only supports inset, outset and none)
9219
607f3926b219 7025525: CSS property list in javax.swing.text.html.CSS is incomplete
rupashka
parents: 5506
diff changeset
    83
 *   <li>border-top-color
607f3926b219 7025525: CSS property list in javax.swing.text.html.CSS is incomplete
rupashka
parents: 5506
diff changeset
    84
 *   <li>border-right-color
607f3926b219 7025525: CSS property list in javax.swing.text.html.CSS is incomplete
rupashka
parents: 5506
diff changeset
    85
 *   <li>border-bottom-color
607f3926b219 7025525: CSS property list in javax.swing.text.html.CSS is incomplete
rupashka
parents: 5506
diff changeset
    86
 *   <li>border-left-color
607f3926b219 7025525: CSS property list in javax.swing.text.html.CSS is incomplete
rupashka
parents: 5506
diff changeset
    87
 *   <li>border-color
607f3926b219 7025525: CSS property list in javax.swing.text.html.CSS is incomplete
rupashka
parents: 5506
diff changeset
    88
 *   <li>list-style-image
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
 *   <li>list-style-type
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
 *   <li>list-style-position
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
 * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
 * The following are modeled, but currently not rendered.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
 * <ul><li>font-variant
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
 *   <li>background-attachment (background always treated as scroll)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
 *   <li>word-spacing
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
 *   <li>letter-spacing
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
 *   <li>text-indent
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
 *   <li>text-transform
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
 *   <li>line-height
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
 *   <li>border-top-width (this is used to indicate if a border should be used)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
 *   <li>border-right-width
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
 *   <li>border-bottom-width
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
 *   <li>border-left-width
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
 *   <li>border-width
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
 *   <li>border-top
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
 *   <li>border-right
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
 *   <li>border-bottom
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
 *   <li>border-left
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
 *   <li>border
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
 *   <li>width
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
 *   <li>height
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
 *   <li>float
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
 *   <li>clear
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
 *   <li>display
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
 *   <li>white-space
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
 *   <li>list-style
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
 * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
 * <p><b>Note: for the time being we do not fully support relative units,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
 * unless noted, so that
20158
1c5d22e5b898 8025117: [cleanup] Eliminate doclint errors in javax/swing/text classes
yan
parents: 10320
diff changeset
   120
 * p { margin-top: 10% } will be treated as if no margin-top was specified.</b>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
 * @author  Timothy Prinzing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
 * @author  Scott Violet
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
 * @see StyleSheet
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
 */
23697
e556a715949f 8034169: Fix serial lint warnings in javax.swing
darcy
parents: 23010
diff changeset
   126
@SuppressWarnings("serial") // Same-version serialization only
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
public class CSS implements Serializable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     * Definitions to be used as a key on AttributeSet's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     * that might hold CSS attributes.  Since this is a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     * closed set (i.e. defined exactly by the specification),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     * it is final and cannot be extended.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    public static final class Attribute {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        private Attribute(String name, String defaultValue, boolean inherited) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
            this.name = name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
            this.defaultValue = defaultValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
            this.inherited = inherited;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
         * The string representation of the attribute.  This
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
         * should exactly match the string specified in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
         * CSS specification.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
            return name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
         * Fetch the default value for the attribute.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
         * If there is no default value (such as for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
         * composite attributes), null will be returned.
24269
325ea76ea0e9 8042105: Fix some more doclint issues in javax.swing.text.html classes
yan
parents: 23697
diff changeset
   156
         *
325ea76ea0e9 8042105: Fix some more doclint issues in javax.swing.text.html classes
yan
parents: 23697
diff changeset
   157
         * @return default value for the attribute
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        public String getDefaultValue() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
            return defaultValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
         * Indicates if the attribute should be inherited
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
         * from the parent or not.
24269
325ea76ea0e9 8042105: Fix some more doclint issues in javax.swing.text.html classes
yan
parents: 23697
diff changeset
   166
         *
325ea76ea0e9 8042105: Fix some more doclint issues in javax.swing.text.html classes
yan
parents: 23697
diff changeset
   167
         * @return true if the attribute should be inherited from the parent
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        public boolean isInherited() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
            return inherited;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        private String name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        private String defaultValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        private boolean inherited;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
25148
1026dc322690 8046446: Fix doclint warnings in javax.swing.text.html package
yan
parents: 24269
diff changeset
   178
        /**
1026dc322690 8046446: Fix doclint warnings in javax.swing.text.html package
yan
parents: 24269
diff changeset
   179
         * CSS attribute "background".
1026dc322690 8046446: Fix doclint warnings in javax.swing.text.html package
yan
parents: 24269
diff changeset
   180
         */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        public static final Attribute BACKGROUND =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
            new Attribute("background", null, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
25148
1026dc322690 8046446: Fix doclint warnings in javax.swing.text.html package
yan
parents: 24269
diff changeset
   184
        /**
1026dc322690 8046446: Fix doclint warnings in javax.swing.text.html package
yan
parents: 24269
diff changeset
   185
         * CSS attribute "background-attachment".
1026dc322690 8046446: Fix doclint warnings in javax.swing.text.html package
yan
parents: 24269
diff changeset
   186
         */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        public static final Attribute BACKGROUND_ATTACHMENT =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
            new Attribute("background-attachment", "scroll", false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
25148
1026dc322690 8046446: Fix doclint warnings in javax.swing.text.html package
yan
parents: 24269
diff changeset
   190
        /**
1026dc322690 8046446: Fix doclint warnings in javax.swing.text.html package
yan
parents: 24269
diff changeset
   191
         * CSS attribute "background-color".
1026dc322690 8046446: Fix doclint warnings in javax.swing.text.html package
yan
parents: 24269
diff changeset
   192
         */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        public static final Attribute BACKGROUND_COLOR =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
            new Attribute("background-color", "transparent", false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
25148
1026dc322690 8046446: Fix doclint warnings in javax.swing.text.html package
yan
parents: 24269
diff changeset
   196
        /**
1026dc322690 8046446: Fix doclint warnings in javax.swing.text.html package
yan
parents: 24269
diff changeset
   197
         * CSS attribute "background-image".
1026dc322690 8046446: Fix doclint warnings in javax.swing.text.html package
yan
parents: 24269
diff changeset
   198
         */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        public static final Attribute BACKGROUND_IMAGE =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
            new Attribute("background-image", "none", false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
25148
1026dc322690 8046446: Fix doclint warnings in javax.swing.text.html package
yan
parents: 24269
diff changeset
   202
        /**
1026dc322690 8046446: Fix doclint warnings in javax.swing.text.html package
yan
parents: 24269
diff changeset
   203
         * CSS attribute "background-position".
1026dc322690 8046446: Fix doclint warnings in javax.swing.text.html package
yan
parents: 24269
diff changeset
   204
         */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        public static final Attribute BACKGROUND_POSITION =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
            new Attribute("background-position", null, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
25148
1026dc322690 8046446: Fix doclint warnings in javax.swing.text.html package
yan
parents: 24269
diff changeset
   208
        /**
1026dc322690 8046446: Fix doclint warnings in javax.swing.text.html package
yan
parents: 24269
diff changeset
   209
         * CSS attribute "background-repeat".
1026dc322690 8046446: Fix doclint warnings in javax.swing.text.html package
yan
parents: 24269
diff changeset
   210
         */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
        public static final Attribute BACKGROUND_REPEAT =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
            new Attribute("background-repeat", "repeat", false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
25148
1026dc322690 8046446: Fix doclint warnings in javax.swing.text.html package
yan
parents: 24269
diff changeset
   214
        /**
1026dc322690 8046446: Fix doclint warnings in javax.swing.text.html package
yan
parents: 24269
diff changeset
   215
         * CSS attribute "border".
1026dc322690 8046446: Fix doclint warnings in javax.swing.text.html package
yan
parents: 24269
diff changeset
   216
         */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
        public static final Attribute BORDER =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
            new Attribute("border", null, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
25148
1026dc322690 8046446: Fix doclint warnings in javax.swing.text.html package
yan
parents: 24269
diff changeset
   220
        /**
1026dc322690 8046446: Fix doclint warnings in javax.swing.text.html package
yan
parents: 24269
diff changeset
   221
         * CSS attribute "border-bottom".
1026dc322690 8046446: Fix doclint warnings in javax.swing.text.html package
yan
parents: 24269
diff changeset
   222
         */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        public static final Attribute BORDER_BOTTOM =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
            new Attribute("border-bottom", null, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
25148
1026dc322690 8046446: Fix doclint warnings in javax.swing.text.html package
yan
parents: 24269
diff changeset
   226
        /**
1026dc322690 8046446: Fix doclint warnings in javax.swing.text.html package
yan
parents: 24269
diff changeset
   227
         * CSS attribute "border-bottom-color".
1026dc322690 8046446: Fix doclint warnings in javax.swing.text.html package
yan
parents: 24269
diff changeset
   228
         */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        public static final Attribute BORDER_BOTTOM_COLOR =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
            new Attribute("border-bottom-color", null, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
25148
1026dc322690 8046446: Fix doclint warnings in javax.swing.text.html package
yan
parents: 24269
diff changeset
   232
        /**
1026dc322690 8046446: Fix doclint warnings in javax.swing.text.html package
yan
parents: 24269
diff changeset
   233
         * CSS attribute "border-bottom-style".
1026dc322690 8046446: Fix doclint warnings in javax.swing.text.html package
yan
parents: 24269
diff changeset
   234
         */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
        public static final Attribute BORDER_BOTTOM_STYLE =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
            new Attribute("border-bottom-style", "none", false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
25148
1026dc322690 8046446: Fix doclint warnings in javax.swing.text.html package
yan
parents: 24269
diff changeset
   238
        /**
1026dc322690 8046446: Fix doclint warnings in javax.swing.text.html package
yan
parents: 24269
diff changeset
   239
         * CSS attribute "border-bottom-width".
1026dc322690 8046446: Fix doclint warnings in javax.swing.text.html package
yan
parents: 24269
diff changeset
   240
         */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
        public static final Attribute BORDER_BOTTOM_WIDTH =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
            new Attribute("border-bottom-width", "medium", false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
25148
1026dc322690 8046446: Fix doclint warnings in javax.swing.text.html package
yan
parents: 24269
diff changeset
   244
        /**
1026dc322690 8046446: Fix doclint warnings in javax.swing.text.html package
yan
parents: 24269
diff changeset
   245
         * CSS attribute "border-color".
1026dc322690 8046446: Fix doclint warnings in javax.swing.text.html package
yan
parents: 24269
diff changeset
   246
         */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
        public static final Attribute BORDER_COLOR =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
            new Attribute("border-color", null, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
25148
1026dc322690 8046446: Fix doclint warnings in javax.swing.text.html package
yan
parents: 24269
diff changeset
   250
        /**
1026dc322690 8046446: Fix doclint warnings in javax.swing.text.html package
yan
parents: 24269
diff changeset
   251
         * CSS attribute "border-left".
1026dc322690 8046446: Fix doclint warnings in javax.swing.text.html package
yan
parents: 24269
diff changeset
   252
         */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
        public static final Attribute BORDER_LEFT =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
            new Attribute("border-left", null, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
25148
1026dc322690 8046446: Fix doclint warnings in javax.swing.text.html package
yan
parents: 24269
diff changeset
   256
        /**
1026dc322690 8046446: Fix doclint warnings in javax.swing.text.html package
yan
parents: 24269
diff changeset
   257
         * CSS attribute "margin-right".
1026dc322690 8046446: Fix doclint warnings in javax.swing.text.html package
yan
parents: 24269
diff changeset
   258
         */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
        public static final Attribute BORDER_LEFT_COLOR =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
            new Attribute("border-left-color", null, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
25148
1026dc322690 8046446: Fix doclint warnings in javax.swing.text.html package
yan
parents: 24269
diff changeset
   262
        /**
1026dc322690 8046446: Fix doclint warnings in javax.swing.text.html package
yan
parents: 24269
diff changeset
   263
         * CSS attribute "border-left-style".
1026dc322690 8046446: Fix doclint warnings in javax.swing.text.html package
yan
parents: 24269
diff changeset
   264
         */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
        public static final Attribute BORDER_LEFT_STYLE =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
            new Attribute("border-left-style", "none", false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
25148
1026dc322690 8046446: Fix doclint warnings in javax.swing.text.html package
yan
parents: 24269
diff changeset
   268
        /**
1026dc322690 8046446: Fix doclint warnings in javax.swing.text.html package
yan
parents: 24269
diff changeset
   269
         * CSS attribute "border-left-width".
1026dc322690 8046446: Fix doclint warnings in javax.swing.text.html package
yan
parents: 24269
diff changeset
   270
         */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
        public static final Attribute BORDER_LEFT_WIDTH =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
            new Attribute("border-left-width", "medium", false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
25148
1026dc322690 8046446: Fix doclint warnings in javax.swing.text.html package
yan
parents: 24269
diff changeset
   274
        /**
1026dc322690 8046446: Fix doclint warnings in javax.swing.text.html package
yan
parents: 24269
diff changeset
   275
         * CSS attribute "border-right".
1026dc322690 8046446: Fix doclint warnings in javax.swing.text.html package
yan
parents: 24269
diff changeset
   276
         */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
        public static final Attribute BORDER_RIGHT =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
            new Attribute("border-right", null, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
25148
1026dc322690 8046446: Fix doclint warnings in javax.swing.text.html package
yan
parents: 24269
diff changeset
   280
        /**
1026dc322690 8046446: Fix doclint warnings in javax.swing.text.html package
yan
parents: 24269
diff changeset
   281
         * CSS attribute "border-right-color".
1026dc322690 8046446: Fix doclint warnings in javax.swing.text.html package
yan
parents: 24269
diff changeset
   282
         */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
        public static final Attribute BORDER_RIGHT_COLOR =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
            new Attribute("border-right-color", null, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
25148
1026dc322690 8046446: Fix doclint warnings in javax.swing.text.html package
yan
parents: 24269
diff changeset
   286
        /**
1026dc322690 8046446: Fix doclint warnings in javax.swing.text.html package
yan
parents: 24269
diff changeset
   287
         * CSS attribute "border-right-style".
1026dc322690 8046446: Fix doclint warnings in javax.swing.text.html package
yan
parents: 24269
diff changeset
   288
         */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
        public static final Attribute BORDER_RIGHT_STYLE =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
            new Attribute("border-right-style", "none", false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
25148
1026dc322690 8046446: Fix doclint warnings in javax.swing.text.html package
yan
parents: 24269
diff changeset
   292
        /**
1026dc322690 8046446: Fix doclint warnings in javax.swing.text.html package
yan
parents: 24269
diff changeset
   293
         * CSS attribute "border-right-width".
1026dc322690 8046446: Fix doclint warnings in javax.swing.text.html package
yan
parents: 24269
diff changeset
   294
         */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
        public static final Attribute BORDER_RIGHT_WIDTH =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
            new Attribute("border-right-width", "medium", false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
25148
1026dc322690 8046446: Fix doclint warnings in javax.swing.text.html package
yan
parents: 24269
diff changeset
   298
        /**
1026dc322690 8046446: Fix doclint warnings in javax.swing.text.html package
yan
parents: 24269
diff changeset
   299
         * CSS attribute "border-style".
1026dc322690 8046446: Fix doclint warnings in javax.swing.text.html package
yan
parents: 24269
diff changeset
   300
         */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
        public static final Attribute BORDER_STYLE =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
            new Attribute("border-style", "none", false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
25148
1026dc322690 8046446: Fix doclint warnings in javax.swing.text.html package
yan
parents: 24269
diff changeset
   304
        /**
1026dc322690 8046446: Fix doclint warnings in javax.swing.text.html package
yan
parents: 24269
diff changeset
   305
         * CSS attribute "border-top".
1026dc322690 8046446: Fix doclint warnings in javax.swing.text.html package
yan
parents: 24269
diff changeset
   306
         */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
        public static final Attribute BORDER_TOP =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
            new Attribute("border-top", null, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
25148
1026dc322690 8046446: Fix doclint warnings in javax.swing.text.html package
yan
parents: 24269
diff changeset
   310
        /**
1026dc322690 8046446: Fix doclint warnings in javax.swing.text.html package
yan
parents: 24269
diff changeset
   311
         * CSS attribute "border-top-color".
1026dc322690 8046446: Fix doclint warnings in javax.swing.text.html package
yan
parents: 24269
diff changeset
   312
         */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
        public static final Attribute BORDER_TOP_COLOR =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
            new Attribute("border-top-color", null, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
25148
1026dc322690 8046446: Fix doclint warnings in javax.swing.text.html package
yan
parents: 24269
diff changeset
   316
        /**
1026dc322690 8046446: Fix doclint warnings in javax.swing.text.html package
yan
parents: 24269
diff changeset
   317
         * CSS attribute "border-top-style".
1026dc322690 8046446: Fix doclint warnings in javax.swing.text.html package
yan
parents: 24269
diff changeset
   318
         */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
        public static final Attribute BORDER_TOP_STYLE =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
            new Attribute("border-top-style", "none", false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
25148
1026dc322690 8046446: Fix doclint warnings in javax.swing.text.html package
yan
parents: 24269
diff changeset
   322
        /**
1026dc322690 8046446: Fix doclint warnings in javax.swing.text.html package
yan
parents: 24269
diff changeset
   323
         * CSS attribute "border-top-width".
1026dc322690 8046446: Fix doclint warnings in javax.swing.text.html package
yan
parents: 24269
diff changeset
   324
         */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
        public static final Attribute BORDER_TOP_WIDTH =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
            new Attribute("border-top-width", "medium", false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
25148
1026dc322690 8046446: Fix doclint warnings in javax.swing.text.html package
yan
parents: 24269
diff changeset
   328
        /**
1026dc322690 8046446: Fix doclint warnings in javax.swing.text.html package
yan
parents: 24269
diff changeset
   329
         * CSS attribute "border-width".
1026dc322690 8046446: Fix doclint warnings in javax.swing.text.html package
yan
parents: 24269
diff changeset
   330
         */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
        public static final Attribute BORDER_WIDTH =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
            new Attribute("border-width", "medium", false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
25148
1026dc322690 8046446: Fix doclint warnings in javax.swing.text.html package
yan
parents: 24269
diff changeset
   334
        /**
1026dc322690 8046446: Fix doclint warnings in javax.swing.text.html package
yan
parents: 24269
diff changeset
   335
         * CSS attribute "clear".
1026dc322690 8046446: Fix doclint warnings in javax.swing.text.html package
yan
parents: 24269
diff changeset
   336
         */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
        public static final Attribute CLEAR =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
            new Attribute("clear", "none", false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
25148
1026dc322690 8046446: Fix doclint warnings in javax.swing.text.html package
yan
parents: 24269
diff changeset
   340
        /**
1026dc322690 8046446: Fix doclint warnings in javax.swing.text.html package
yan
parents: 24269
diff changeset
   341
         * CSS attribute "color".
1026dc322690 8046446: Fix doclint warnings in javax.swing.text.html package
yan
parents: 24269
diff changeset
   342
         */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
        public static final Attribute COLOR =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
            new Attribute("color", "black", true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
25148
1026dc322690 8046446: Fix doclint warnings in javax.swing.text.html package
yan
parents: 24269
diff changeset
   346
        /**
1026dc322690 8046446: Fix doclint warnings in javax.swing.text.html package
yan
parents: 24269
diff changeset
   347
         * CSS attribute "display".
1026dc322690 8046446: Fix doclint warnings in javax.swing.text.html package
yan
parents: 24269
diff changeset
   348
         */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
        public static final Attribute DISPLAY =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
            new Attribute("display", "block", false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
25148
1026dc322690 8046446: Fix doclint warnings in javax.swing.text.html package
yan
parents: 24269
diff changeset
   352
        /**
1026dc322690 8046446: Fix doclint warnings in javax.swing.text.html package
yan
parents: 24269
diff changeset
   353
         * CSS attribute "float".
1026dc322690 8046446: Fix doclint warnings in javax.swing.text.html package
yan
parents: 24269
diff changeset
   354
         */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
        public static final Attribute FLOAT =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
            new Attribute("float", "none", false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
25148
1026dc322690 8046446: Fix doclint warnings in javax.swing.text.html package
yan
parents: 24269
diff changeset
   358
        /**
1026dc322690 8046446: Fix doclint warnings in javax.swing.text.html package
yan
parents: 24269
diff changeset
   359
         * CSS attribute "font".
1026dc322690 8046446: Fix doclint warnings in javax.swing.text.html package
yan
parents: 24269
diff changeset
   360
         */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
        public static final Attribute FONT =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
            new Attribute("font", null, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
25148
1026dc322690 8046446: Fix doclint warnings in javax.swing.text.html package
yan
parents: 24269
diff changeset
   364
        /**
1026dc322690 8046446: Fix doclint warnings in javax.swing.text.html package
yan
parents: 24269
diff changeset
   365
         * CSS attribute "font-family".
1026dc322690 8046446: Fix doclint warnings in javax.swing.text.html package
yan
parents: 24269
diff changeset
   366
         */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
        public static final Attribute FONT_FAMILY =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
            new Attribute("font-family", null, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
25148
1026dc322690 8046446: Fix doclint warnings in javax.swing.text.html package
yan
parents: 24269
diff changeset
   370
        /**
1026dc322690 8046446: Fix doclint warnings in javax.swing.text.html package
yan
parents: 24269
diff changeset
   371
         * CSS attribute "font-size".
1026dc322690 8046446: Fix doclint warnings in javax.swing.text.html package
yan
parents: 24269
diff changeset
   372
         */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
        public static final Attribute FONT_SIZE =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
            new Attribute("font-size", "medium", true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
25148
1026dc322690 8046446: Fix doclint warnings in javax.swing.text.html package
yan
parents: 24269
diff changeset
   376
        /**
1026dc322690 8046446: Fix doclint warnings in javax.swing.text.html package
yan
parents: 24269
diff changeset
   377
         * CSS attribute "font-style".
1026dc322690 8046446: Fix doclint warnings in javax.swing.text.html package
yan
parents: 24269
diff changeset
   378
         */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
        public static final Attribute FONT_STYLE =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
            new Attribute("font-style", "normal", true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
25148
1026dc322690 8046446: Fix doclint warnings in javax.swing.text.html package
yan
parents: 24269
diff changeset
   382
        /**
1026dc322690 8046446: Fix doclint warnings in javax.swing.text.html package
yan
parents: 24269
diff changeset
   383
         * CSS attribute "font-variant".
1026dc322690 8046446: Fix doclint warnings in javax.swing.text.html package
yan
parents: 24269
diff changeset
   384
         */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
        public static final Attribute FONT_VARIANT =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
            new Attribute("font-variant", "normal", true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
25148
1026dc322690 8046446: Fix doclint warnings in javax.swing.text.html package
yan
parents: 24269
diff changeset
   388
        /**
1026dc322690 8046446: Fix doclint warnings in javax.swing.text.html package
yan
parents: 24269
diff changeset
   389
         * CSS attribute "font-weight".
1026dc322690 8046446: Fix doclint warnings in javax.swing.text.html package
yan
parents: 24269
diff changeset
   390
         */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
        public static final Attribute FONT_WEIGHT =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
            new Attribute("font-weight", "normal", true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
25148
1026dc322690 8046446: Fix doclint warnings in javax.swing.text.html package
yan
parents: 24269
diff changeset
   394
        /**
1026dc322690 8046446: Fix doclint warnings in javax.swing.text.html package
yan
parents: 24269
diff changeset
   395
         * CSS attribute "height".
1026dc322690 8046446: Fix doclint warnings in javax.swing.text.html package
yan
parents: 24269
diff changeset
   396
         */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
        public static final Attribute HEIGHT =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
            new Attribute("height", "auto", false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
25148
1026dc322690 8046446: Fix doclint warnings in javax.swing.text.html package
yan
parents: 24269
diff changeset
   400
        /**
1026dc322690 8046446: Fix doclint warnings in javax.swing.text.html package
yan
parents: 24269
diff changeset
   401
         * CSS attribute "letter-spacing".
1026dc322690 8046446: Fix doclint warnings in javax.swing.text.html package
yan
parents: 24269
diff changeset
   402
         */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
        public static final Attribute LETTER_SPACING =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
            new Attribute("letter-spacing", "normal", true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
25148
1026dc322690 8046446: Fix doclint warnings in javax.swing.text.html package
yan
parents: 24269
diff changeset
   406
        /**
1026dc322690 8046446: Fix doclint warnings in javax.swing.text.html package
yan
parents: 24269
diff changeset
   407
         * CSS attribute "line-height".
1026dc322690 8046446: Fix doclint warnings in javax.swing.text.html package
yan
parents: 24269
diff changeset
   408
         */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
        public static final Attribute LINE_HEIGHT =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
            new Attribute("line-height", "normal", true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
25148
1026dc322690 8046446: Fix doclint warnings in javax.swing.text.html package
yan
parents: 24269
diff changeset
   412
        /**
1026dc322690 8046446: Fix doclint warnings in javax.swing.text.html package
yan
parents: 24269
diff changeset
   413
         * CSS attribute "list-style".
1026dc322690 8046446: Fix doclint warnings in javax.swing.text.html package
yan
parents: 24269
diff changeset
   414
         */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
        public static final Attribute LIST_STYLE =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
            new Attribute("list-style", null, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
25148
1026dc322690 8046446: Fix doclint warnings in javax.swing.text.html package
yan
parents: 24269
diff changeset
   418
        /**
1026dc322690 8046446: Fix doclint warnings in javax.swing.text.html package
yan
parents: 24269
diff changeset
   419
         * CSS attribute "list-style-image".
1026dc322690 8046446: Fix doclint warnings in javax.swing.text.html package
yan
parents: 24269
diff changeset
   420
         */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
        public static final Attribute LIST_STYLE_IMAGE =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
            new Attribute("list-style-image", "none", true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
25148
1026dc322690 8046446: Fix doclint warnings in javax.swing.text.html package
yan
parents: 24269
diff changeset
   424
        /**
1026dc322690 8046446: Fix doclint warnings in javax.swing.text.html package
yan
parents: 24269
diff changeset
   425
         * CSS attribute "list-style-position".
1026dc322690 8046446: Fix doclint warnings in javax.swing.text.html package
yan
parents: 24269
diff changeset
   426
         */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
        public static final Attribute LIST_STYLE_POSITION =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
            new Attribute("list-style-position", "outside", true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
25148
1026dc322690 8046446: Fix doclint warnings in javax.swing.text.html package
yan
parents: 24269
diff changeset
   430
        /**
1026dc322690 8046446: Fix doclint warnings in javax.swing.text.html package
yan
parents: 24269
diff changeset
   431
         * CSS attribute "list-style-type".
1026dc322690 8046446: Fix doclint warnings in javax.swing.text.html package
yan
parents: 24269
diff changeset
   432
         */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
        public static final Attribute LIST_STYLE_TYPE =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
            new Attribute("list-style-type", "disc", true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
25148
1026dc322690 8046446: Fix doclint warnings in javax.swing.text.html package
yan
parents: 24269
diff changeset
   436
        /**
1026dc322690 8046446: Fix doclint warnings in javax.swing.text.html package
yan
parents: 24269
diff changeset
   437
         * CSS attribute "margin".
1026dc322690 8046446: Fix doclint warnings in javax.swing.text.html package
yan
parents: 24269
diff changeset
   438
         */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
        public static final Attribute MARGIN =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
            new Attribute("margin", null, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
25148
1026dc322690 8046446: Fix doclint warnings in javax.swing.text.html package
yan
parents: 24269
diff changeset
   442
        /**
1026dc322690 8046446: Fix doclint warnings in javax.swing.text.html package
yan
parents: 24269
diff changeset
   443
         * CSS attribute "margin-bottom".
1026dc322690 8046446: Fix doclint warnings in javax.swing.text.html package
yan
parents: 24269
diff changeset
   444
         */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
        public static final Attribute MARGIN_BOTTOM =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
            new Attribute("margin-bottom", "0", false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
25148
1026dc322690 8046446: Fix doclint warnings in javax.swing.text.html package
yan
parents: 24269
diff changeset
   448
        /**
1026dc322690 8046446: Fix doclint warnings in javax.swing.text.html package
yan
parents: 24269
diff changeset
   449
         * CSS attribute "margin-left".
1026dc322690 8046446: Fix doclint warnings in javax.swing.text.html package
yan
parents: 24269
diff changeset
   450
         */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
        public static final Attribute MARGIN_LEFT =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
            new Attribute("margin-left", "0", false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
25148
1026dc322690 8046446: Fix doclint warnings in javax.swing.text.html package
yan
parents: 24269
diff changeset
   454
        /**
1026dc322690 8046446: Fix doclint warnings in javax.swing.text.html package
yan
parents: 24269
diff changeset
   455
         * CSS attribute "margin-right".
1026dc322690 8046446: Fix doclint warnings in javax.swing.text.html package
yan
parents: 24269
diff changeset
   456
         */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
        public static final Attribute MARGIN_RIGHT =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
            new Attribute("margin-right", "0", false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
         * made up css attributes to describe orientation depended
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
         * margins. used for <dir>, <menu>, <ul> etc. see
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
         * 5088268 for more details
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
        static final Attribute MARGIN_LEFT_LTR =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
            new Attribute("margin-left-ltr",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
                          Integer.toString(Integer.MIN_VALUE), false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
        static final Attribute MARGIN_LEFT_RTL =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
            new Attribute("margin-left-rtl",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
                          Integer.toString(Integer.MIN_VALUE), false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
        static final Attribute MARGIN_RIGHT_LTR =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
            new Attribute("margin-right-ltr",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
                          Integer.toString(Integer.MIN_VALUE), false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
        static final Attribute MARGIN_RIGHT_RTL =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
            new Attribute("margin-right-rtl",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
                          Integer.toString(Integer.MIN_VALUE), false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
25148
1026dc322690 8046446: Fix doclint warnings in javax.swing.text.html package
yan
parents: 24269
diff changeset
   482
        /**
1026dc322690 8046446: Fix doclint warnings in javax.swing.text.html package
yan
parents: 24269
diff changeset
   483
         * CSS attribute "margin-top".
1026dc322690 8046446: Fix doclint warnings in javax.swing.text.html package
yan
parents: 24269
diff changeset
   484
         */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
        public static final Attribute MARGIN_TOP =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
            new Attribute("margin-top", "0", false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
25148
1026dc322690 8046446: Fix doclint warnings in javax.swing.text.html package
yan
parents: 24269
diff changeset
   488
        /**
1026dc322690 8046446: Fix doclint warnings in javax.swing.text.html package
yan
parents: 24269
diff changeset
   489
         * CSS attribute "padding".
1026dc322690 8046446: Fix doclint warnings in javax.swing.text.html package
yan
parents: 24269
diff changeset
   490
         */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
        public static final Attribute PADDING =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
            new Attribute("padding", null, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
25148
1026dc322690 8046446: Fix doclint warnings in javax.swing.text.html package
yan
parents: 24269
diff changeset
   494
        /**
1026dc322690 8046446: Fix doclint warnings in javax.swing.text.html package
yan
parents: 24269
diff changeset
   495
         * CSS attribute "padding-bottom".
1026dc322690 8046446: Fix doclint warnings in javax.swing.text.html package
yan
parents: 24269
diff changeset
   496
         */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
        public static final Attribute PADDING_BOTTOM =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
            new Attribute("padding-bottom", "0", false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
25148
1026dc322690 8046446: Fix doclint warnings in javax.swing.text.html package
yan
parents: 24269
diff changeset
   500
        /**
1026dc322690 8046446: Fix doclint warnings in javax.swing.text.html package
yan
parents: 24269
diff changeset
   501
         * CSS attribute "padding-left".
1026dc322690 8046446: Fix doclint warnings in javax.swing.text.html package
yan
parents: 24269
diff changeset
   502
         */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
        public static final Attribute PADDING_LEFT =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
            new Attribute("padding-left", "0", false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
25148
1026dc322690 8046446: Fix doclint warnings in javax.swing.text.html package
yan
parents: 24269
diff changeset
   506
        /**
1026dc322690 8046446: Fix doclint warnings in javax.swing.text.html package
yan
parents: 24269
diff changeset
   507
         * CSS attribute "padding-right".
1026dc322690 8046446: Fix doclint warnings in javax.swing.text.html package
yan
parents: 24269
diff changeset
   508
         */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
        public static final Attribute PADDING_RIGHT =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
            new Attribute("padding-right", "0", false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
25148
1026dc322690 8046446: Fix doclint warnings in javax.swing.text.html package
yan
parents: 24269
diff changeset
   512
        /**
1026dc322690 8046446: Fix doclint warnings in javax.swing.text.html package
yan
parents: 24269
diff changeset
   513
         * CSS attribute "padding-top".
1026dc322690 8046446: Fix doclint warnings in javax.swing.text.html package
yan
parents: 24269
diff changeset
   514
         */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
        public static final Attribute PADDING_TOP =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
            new Attribute("padding-top", "0", false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
25148
1026dc322690 8046446: Fix doclint warnings in javax.swing.text.html package
yan
parents: 24269
diff changeset
   518
        /**
1026dc322690 8046446: Fix doclint warnings in javax.swing.text.html package
yan
parents: 24269
diff changeset
   519
         * CSS attribute "text-align".
1026dc322690 8046446: Fix doclint warnings in javax.swing.text.html package
yan
parents: 24269
diff changeset
   520
         */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
        public static final Attribute TEXT_ALIGN =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
            new Attribute("text-align", null, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
25148
1026dc322690 8046446: Fix doclint warnings in javax.swing.text.html package
yan
parents: 24269
diff changeset
   524
        /**
1026dc322690 8046446: Fix doclint warnings in javax.swing.text.html package
yan
parents: 24269
diff changeset
   525
         * CSS attribute "text-decoration".
1026dc322690 8046446: Fix doclint warnings in javax.swing.text.html package
yan
parents: 24269
diff changeset
   526
         */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
        public static final Attribute TEXT_DECORATION =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
            new Attribute("text-decoration", "none", true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
25148
1026dc322690 8046446: Fix doclint warnings in javax.swing.text.html package
yan
parents: 24269
diff changeset
   530
        /**
1026dc322690 8046446: Fix doclint warnings in javax.swing.text.html package
yan
parents: 24269
diff changeset
   531
         * CSS attribute "text-indent".
1026dc322690 8046446: Fix doclint warnings in javax.swing.text.html package
yan
parents: 24269
diff changeset
   532
         */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
        public static final Attribute TEXT_INDENT =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
            new Attribute("text-indent", "0", true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
25148
1026dc322690 8046446: Fix doclint warnings in javax.swing.text.html package
yan
parents: 24269
diff changeset
   536
        /**
1026dc322690 8046446: Fix doclint warnings in javax.swing.text.html package
yan
parents: 24269
diff changeset
   537
         * CSS attribute "text-transform".
1026dc322690 8046446: Fix doclint warnings in javax.swing.text.html package
yan
parents: 24269
diff changeset
   538
         */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
        public static final Attribute TEXT_TRANSFORM =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
            new Attribute("text-transform", "none", true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
25148
1026dc322690 8046446: Fix doclint warnings in javax.swing.text.html package
yan
parents: 24269
diff changeset
   542
        /**
1026dc322690 8046446: Fix doclint warnings in javax.swing.text.html package
yan
parents: 24269
diff changeset
   543
         * CSS attribute "vertical-align".
1026dc322690 8046446: Fix doclint warnings in javax.swing.text.html package
yan
parents: 24269
diff changeset
   544
         */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
        public static final Attribute VERTICAL_ALIGN =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
            new Attribute("vertical-align", "baseline", false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
25148
1026dc322690 8046446: Fix doclint warnings in javax.swing.text.html package
yan
parents: 24269
diff changeset
   548
        /**
1026dc322690 8046446: Fix doclint warnings in javax.swing.text.html package
yan
parents: 24269
diff changeset
   549
         * CSS attribute "word-spacing".
1026dc322690 8046446: Fix doclint warnings in javax.swing.text.html package
yan
parents: 24269
diff changeset
   550
         */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
        public static final Attribute WORD_SPACING =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
            new Attribute("word-spacing", "normal", true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
25148
1026dc322690 8046446: Fix doclint warnings in javax.swing.text.html package
yan
parents: 24269
diff changeset
   554
        /**
1026dc322690 8046446: Fix doclint warnings in javax.swing.text.html package
yan
parents: 24269
diff changeset
   555
         * CSS attribute "white-space".
1026dc322690 8046446: Fix doclint warnings in javax.swing.text.html package
yan
parents: 24269
diff changeset
   556
         */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
        public static final Attribute WHITE_SPACE =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
            new Attribute("white-space", "normal", true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
25148
1026dc322690 8046446: Fix doclint warnings in javax.swing.text.html package
yan
parents: 24269
diff changeset
   560
        /**
1026dc322690 8046446: Fix doclint warnings in javax.swing.text.html package
yan
parents: 24269
diff changeset
   561
         * CSS attribute "width".
1026dc322690 8046446: Fix doclint warnings in javax.swing.text.html package
yan
parents: 24269
diff changeset
   562
         */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
        public static final Attribute WIDTH =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
            new Attribute("width", "auto", false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
        /*public*/ static final Attribute BORDER_SPACING =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
            new Attribute("border-spacing", "0", true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
        /*public*/ static final Attribute CAPTION_SIDE =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
            new Attribute("caption-side", "left", true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
        // All possible CSS attribute keys.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
        static final Attribute[] allAttributes = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
            BACKGROUND, BACKGROUND_ATTACHMENT, BACKGROUND_COLOR,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
            BACKGROUND_IMAGE, BACKGROUND_POSITION, BACKGROUND_REPEAT,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
            BORDER, BORDER_BOTTOM, BORDER_BOTTOM_WIDTH, BORDER_COLOR,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
            BORDER_LEFT, BORDER_LEFT_WIDTH, BORDER_RIGHT, BORDER_RIGHT_WIDTH,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
            BORDER_STYLE, BORDER_TOP, BORDER_TOP_WIDTH, BORDER_WIDTH,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
            BORDER_TOP_STYLE, BORDER_RIGHT_STYLE, BORDER_BOTTOM_STYLE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
            BORDER_LEFT_STYLE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
            BORDER_TOP_COLOR, BORDER_RIGHT_COLOR, BORDER_BOTTOM_COLOR,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
            BORDER_LEFT_COLOR,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
            CLEAR, COLOR, DISPLAY, FLOAT, FONT, FONT_FAMILY, FONT_SIZE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
            FONT_STYLE, FONT_VARIANT, FONT_WEIGHT, HEIGHT, LETTER_SPACING,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
            LINE_HEIGHT, LIST_STYLE, LIST_STYLE_IMAGE, LIST_STYLE_POSITION,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
            LIST_STYLE_TYPE, MARGIN, MARGIN_BOTTOM, MARGIN_LEFT, MARGIN_RIGHT,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
            MARGIN_TOP, PADDING, PADDING_BOTTOM, PADDING_LEFT, PADDING_RIGHT,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
            PADDING_TOP, TEXT_ALIGN, TEXT_DECORATION, TEXT_INDENT, TEXT_TRANSFORM,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
            VERTICAL_ALIGN, WORD_SPACING, WHITE_SPACE, WIDTH,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
            BORDER_SPACING, CAPTION_SIDE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
            MARGIN_LEFT_LTR, MARGIN_LEFT_RTL, MARGIN_RIGHT_LTR, MARGIN_RIGHT_RTL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
        };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
        private static final Attribute[] ALL_MARGINS =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
                { MARGIN_TOP, MARGIN_RIGHT, MARGIN_BOTTOM, MARGIN_LEFT };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
        private static final Attribute[] ALL_PADDING =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
                { PADDING_TOP, PADDING_RIGHT, PADDING_BOTTOM, PADDING_LEFT };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
        private static final Attribute[] ALL_BORDER_WIDTHS =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
                { BORDER_TOP_WIDTH, BORDER_RIGHT_WIDTH, BORDER_BOTTOM_WIDTH,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
                  BORDER_LEFT_WIDTH };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
        private static final Attribute[] ALL_BORDER_STYLES =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
                { BORDER_TOP_STYLE, BORDER_RIGHT_STYLE, BORDER_BOTTOM_STYLE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
                  BORDER_LEFT_STYLE };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
        private static final Attribute[] ALL_BORDER_COLORS =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
                { BORDER_TOP_COLOR, BORDER_RIGHT_COLOR, BORDER_BOTTOM_COLOR,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
                  BORDER_LEFT_COLOR };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
    static final class Value {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
        private Value(String name) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
            this.name = name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
         * The string representation of the attribute.  This
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
         * should exactly match the string specified in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
         * CSS specification.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
        public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
            return name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
        static final Value INHERITED = new Value("inherited");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
        static final Value NONE = new Value("none");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
        static final Value HIDDEN = new Value("hidden");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
        static final Value DOTTED = new Value("dotted");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
        static final Value DASHED = new Value("dashed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
        static final Value SOLID = new Value("solid");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
        static final Value DOUBLE = new Value("double");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
        static final Value GROOVE = new Value("groove");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
        static final Value RIDGE = new Value("ridge");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
        static final Value INSET = new Value("inset");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
        static final Value OUTSET = new Value("outset");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
        // Lists.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
        static final Value DISC = new Value("disc");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
        static final Value CIRCLE = new Value("circle");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
        static final Value SQUARE = new Value("square");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
        static final Value DECIMAL = new Value("decimal");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
        static final Value LOWER_ROMAN = new Value("lower-roman");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
        static final Value UPPER_ROMAN = new Value("upper-roman");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
        static final Value LOWER_ALPHA = new Value("lower-alpha");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
        static final Value UPPER_ALPHA = new Value("upper-alpha");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
        // background-repeat
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
        static final Value BACKGROUND_NO_REPEAT = new Value("no-repeat");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
        static final Value BACKGROUND_REPEAT = new Value("repeat");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
        static final Value BACKGROUND_REPEAT_X = new Value("repeat-x");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
        static final Value BACKGROUND_REPEAT_Y = new Value("repeat-y");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
        // background-attachment
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
        static final Value BACKGROUND_SCROLL = new Value("scroll");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
        static final Value BACKGROUND_FIXED = new Value("fixed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
        private String name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
        static final Value[] allValues = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
            INHERITED, NONE, DOTTED, DASHED, SOLID, DOUBLE, GROOVE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
            RIDGE, INSET, OUTSET, DISC, CIRCLE, SQUARE, DECIMAL,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
            LOWER_ROMAN, UPPER_ROMAN, LOWER_ALPHA, UPPER_ALPHA,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
            BACKGROUND_NO_REPEAT, BACKGROUND_REPEAT,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
            BACKGROUND_REPEAT_X, BACKGROUND_REPEAT_Y,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
            BACKGROUND_FIXED, BACKGROUND_FIXED
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
        };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
25148
1026dc322690 8046446: Fix doclint warnings in javax.swing.text.html package
yan
parents: 24269
diff changeset
   666
    /**
1026dc322690 8046446: Fix doclint warnings in javax.swing.text.html package
yan
parents: 24269
diff changeset
   667
     * Constructs a CSS object.
1026dc322690 8046446: Fix doclint warnings in javax.swing.text.html package
yan
parents: 24269
diff changeset
   668
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
    public CSS() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
        baseFontSize = baseFontSizeIndex + 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
        // setup the css conversion table
1287
a04aca99c77a 6722802: Code improvement and warnings removing from the javax.swing.text package
rupashka
parents: 438
diff changeset
   672
        valueConvertor = new Hashtable<Object, Object>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
        valueConvertor.put(CSS.Attribute.FONT_SIZE, new FontSize());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
        valueConvertor.put(CSS.Attribute.FONT_FAMILY, new FontFamily());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
        valueConvertor.put(CSS.Attribute.FONT_WEIGHT, new FontWeight());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
        Object bs = new BorderStyle();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
        valueConvertor.put(CSS.Attribute.BORDER_TOP_STYLE, bs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
        valueConvertor.put(CSS.Attribute.BORDER_RIGHT_STYLE, bs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
        valueConvertor.put(CSS.Attribute.BORDER_BOTTOM_STYLE, bs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
        valueConvertor.put(CSS.Attribute.BORDER_LEFT_STYLE, bs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
        Object cv = new ColorValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
        valueConvertor.put(CSS.Attribute.COLOR, cv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
        valueConvertor.put(CSS.Attribute.BACKGROUND_COLOR, cv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
        valueConvertor.put(CSS.Attribute.BORDER_TOP_COLOR, cv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
        valueConvertor.put(CSS.Attribute.BORDER_RIGHT_COLOR, cv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
        valueConvertor.put(CSS.Attribute.BORDER_BOTTOM_COLOR, cv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
        valueConvertor.put(CSS.Attribute.BORDER_LEFT_COLOR, cv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
        Object lv = new LengthValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
        valueConvertor.put(CSS.Attribute.MARGIN_TOP, lv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
        valueConvertor.put(CSS.Attribute.MARGIN_BOTTOM, lv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
        valueConvertor.put(CSS.Attribute.MARGIN_LEFT, lv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
        valueConvertor.put(CSS.Attribute.MARGIN_LEFT_LTR, lv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
        valueConvertor.put(CSS.Attribute.MARGIN_LEFT_RTL, lv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
        valueConvertor.put(CSS.Attribute.MARGIN_RIGHT, lv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
        valueConvertor.put(CSS.Attribute.MARGIN_RIGHT_LTR, lv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
        valueConvertor.put(CSS.Attribute.MARGIN_RIGHT_RTL, lv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
        valueConvertor.put(CSS.Attribute.PADDING_TOP, lv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
        valueConvertor.put(CSS.Attribute.PADDING_BOTTOM, lv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
        valueConvertor.put(CSS.Attribute.PADDING_LEFT, lv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
        valueConvertor.put(CSS.Attribute.PADDING_RIGHT, lv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
        Object bv = new BorderWidthValue(null, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
        valueConvertor.put(CSS.Attribute.BORDER_TOP_WIDTH, bv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
        valueConvertor.put(CSS.Attribute.BORDER_BOTTOM_WIDTH, bv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
        valueConvertor.put(CSS.Attribute.BORDER_LEFT_WIDTH, bv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
        valueConvertor.put(CSS.Attribute.BORDER_RIGHT_WIDTH, bv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
        Object nlv = new LengthValue(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
        valueConvertor.put(CSS.Attribute.TEXT_INDENT, nlv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
        valueConvertor.put(CSS.Attribute.WIDTH, lv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
        valueConvertor.put(CSS.Attribute.HEIGHT, lv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
        valueConvertor.put(CSS.Attribute.BORDER_SPACING, lv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
        Object sv = new StringValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
        valueConvertor.put(CSS.Attribute.FONT_STYLE, sv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
        valueConvertor.put(CSS.Attribute.TEXT_DECORATION, sv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
        valueConvertor.put(CSS.Attribute.TEXT_ALIGN, sv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
        valueConvertor.put(CSS.Attribute.VERTICAL_ALIGN, sv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
        Object valueMapper = new CssValueMapper();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
        valueConvertor.put(CSS.Attribute.LIST_STYLE_TYPE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
                           valueMapper);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
        valueConvertor.put(CSS.Attribute.BACKGROUND_IMAGE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
                           new BackgroundImage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
        valueConvertor.put(CSS.Attribute.BACKGROUND_POSITION,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
                           new BackgroundPosition());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
        valueConvertor.put(CSS.Attribute.BACKGROUND_REPEAT,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
                           valueMapper);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
        valueConvertor.put(CSS.Attribute.BACKGROUND_ATTACHMENT,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
                           valueMapper);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
        Object generic = new CssValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
        int n = CSS.Attribute.allAttributes.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
        for (int i = 0; i < n; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
            CSS.Attribute key = CSS.Attribute.allAttributes[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
            if (valueConvertor.get(key) == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
                valueConvertor.put(key, generic);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
     * Sets the base font size. <code>sz</code> is a CSS value, and is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
     * not necessarily the point size. Use getPointSize to determine the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
     * point size corresponding to <code>sz</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
    void setBaseFontSize(int sz) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
        if (sz < 1)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
          baseFontSize = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
        else if (sz > 7)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
          baseFontSize = 7;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
        else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
          baseFontSize = sz;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
     * Sets the base font size from the passed in string.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
    void setBaseFontSize(String size) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
        int relSize, absSize, diff;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
        if (size != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
            if (size.startsWith("+")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
                relSize = Integer.valueOf(size.substring(1)).intValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
                setBaseFontSize(baseFontSize + relSize);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
            } else if (size.startsWith("-")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
                relSize = -Integer.valueOf(size.substring(1)).intValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
                setBaseFontSize(baseFontSize + relSize);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
                setBaseFontSize(Integer.valueOf(size).intValue());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
     * Returns the base font size.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
    int getBaseFontSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
        return baseFontSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
     * Parses the CSS property <code>key</code> with value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
     * <code>value</code> placing the result in <code>att</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
    void addInternalCSSValue(MutableAttributeSet attr,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
                             CSS.Attribute key, String value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
        if (key == CSS.Attribute.FONT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
            ShorthandFontParser.parseShorthandFont(this, value, attr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
        else if (key == CSS.Attribute.BACKGROUND) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
            ShorthandBackgroundParser.parseShorthandBackground
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
                               (this, value, attr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
        else if (key == CSS.Attribute.MARGIN) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
            ShorthandMarginParser.parseShorthandMargin(this, value, attr,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
                                           CSS.Attribute.ALL_MARGINS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
        else if (key == CSS.Attribute.PADDING) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
            ShorthandMarginParser.parseShorthandMargin(this, value, attr,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
                                           CSS.Attribute.ALL_PADDING);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
        else if (key == CSS.Attribute.BORDER_WIDTH) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
            ShorthandMarginParser.parseShorthandMargin(this, value, attr,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
                                           CSS.Attribute.ALL_BORDER_WIDTHS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
        else if (key == CSS.Attribute.BORDER_COLOR) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
            ShorthandMarginParser.parseShorthandMargin(this, value, attr,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
                                            CSS.Attribute.ALL_BORDER_COLORS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
        else if (key == CSS.Attribute.BORDER_STYLE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
            ShorthandMarginParser.parseShorthandMargin(this, value, attr,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
                                            CSS.Attribute.ALL_BORDER_STYLES);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
        else if ((key == CSS.Attribute.BORDER) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
                   (key == CSS.Attribute.BORDER_TOP) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
                   (key == CSS.Attribute.BORDER_RIGHT) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
                   (key == CSS.Attribute.BORDER_BOTTOM) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
                   (key == CSS.Attribute.BORDER_LEFT)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
            ShorthandBorderParser.parseShorthandBorder(attr, key, value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
            Object iValue = getInternalCSSValue(key, value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
            if (iValue != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
                attr.addAttribute(key, iValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
     * Gets the internal CSS representation of <code>value</code> which is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
     * a CSS value of the CSS attribute named <code>key</code>. The receiver
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
     * should not modify <code>value</code>, and the first <code>count</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
     * strings are valid.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
    Object getInternalCSSValue(CSS.Attribute key, String value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
        CssValue conv = (CssValue) valueConvertor.get(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
        Object r = conv.parseCssValue(value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
        return r != null ? r : conv.parseCssValue(key.getDefaultValue());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
     * Maps from a StyleConstants to a CSS Attribute.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
    Attribute styleConstantsKeyToCSSKey(StyleConstants sc) {
1287
a04aca99c77a 6722802: Code improvement and warnings removing from the javax.swing.text package
rupashka
parents: 438
diff changeset
   841
        return styleConstantToCssMap.get(sc);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
     * Maps from a StyleConstants value to a CSS value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
    Object styleConstantsValueToCSSValue(StyleConstants sc,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
                                         Object styleValue) {
1287
a04aca99c77a 6722802: Code improvement and warnings removing from the javax.swing.text package
rupashka
parents: 438
diff changeset
   849
        Attribute cssKey = styleConstantsKeyToCSSKey(sc);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
        if (cssKey != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
            CssValue conv = (CssValue)valueConvertor.get(cssKey);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
            return conv.fromStyleConstants(sc, styleValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
     * Converts the passed in CSS value to a StyleConstants value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
     * <code>key</code> identifies the CSS attribute being mapped.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
    Object cssValueToStyleConstantsValue(StyleConstants key, Object value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
        if (value instanceof CssValue) {
1287
a04aca99c77a 6722802: Code improvement and warnings removing from the javax.swing.text package
rupashka
parents: 438
diff changeset
   863
            return ((CssValue)value).toStyleConstants(key, null);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
     * Returns the font for the values in the passed in AttributeSet.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
     * It is assumed the keys will be CSS.Attribute keys.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
     * <code>sc</code> is the StyleContext that will be messaged to get
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
     * the font once the size, name and style have been determined.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
    Font getFont(StyleContext sc, AttributeSet a, int defaultSize, StyleSheet ss) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
        ss = getStyleSheet(ss);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
        int size = getFontSize(a, defaultSize, ss);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
        /*
26749
b6598aa90114 8055326: Fix typos in client-related packages
serb
parents: 26037
diff changeset
   879
         * If the vertical alignment is set to either superscript or
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
         * subscript we reduce the font size by 2 points.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
        StringValue vAlignV = (StringValue)a.getAttribute
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
                              (CSS.Attribute.VERTICAL_ALIGN);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
        if ((vAlignV != null)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
            String vAlign = vAlignV.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
            if ((vAlign.indexOf("sup") >= 0) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
                (vAlign.indexOf("sub") >= 0)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
                size -= 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
        FontFamily familyValue = (FontFamily)a.getAttribute
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
                                            (CSS.Attribute.FONT_FAMILY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
        String family = (familyValue != null) ? familyValue.getValue() :
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
                                  Font.SANS_SERIF;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
        int style = Font.PLAIN;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
        FontWeight weightValue = (FontWeight) a.getAttribute
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
                                  (CSS.Attribute.FONT_WEIGHT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
        if ((weightValue != null) && (weightValue.getValue() > 400)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
            style |= Font.BOLD;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
        Object fs = a.getAttribute(CSS.Attribute.FONT_STYLE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
        if ((fs != null) && (fs.toString().indexOf("italic") >= 0)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
            style |= Font.ITALIC;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
        if (family.equalsIgnoreCase("monospace")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
            family = Font.MONOSPACED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
        Font f = sc.getFont(family, style, size);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
        if (f == null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
            || (f.getFamily().equals(Font.DIALOG)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
                && ! family.equalsIgnoreCase(Font.DIALOG))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
            family = Font.SANS_SERIF;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
            f = sc.getFont(family, style, size);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
        return f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
    static int getFontSize(AttributeSet attr, int defaultSize, StyleSheet ss) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
        // PENDING(prinz) this is a 1.1 based implementation, need to also
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
        // have a 1.2 version.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
        FontSize sizeValue = (FontSize)attr.getAttribute(CSS.Attribute.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
                                                         FONT_SIZE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
        return (sizeValue != null) ? sizeValue.getValue(attr, ss)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
                                   : defaultSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
     * Takes a set of attributes and turn it into a color
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
     * specification.  This might be used to specify things
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
     * like brighter, more hue, etc.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
     * This will return null if there is no value for <code>key</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
     * @param key CSS.Attribute identifying where color is stored.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
     * @param a the set of attributes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
     * @return the color
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
    Color getColor(AttributeSet a, CSS.Attribute key) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
        ColorValue cv = (ColorValue) a.getAttribute(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   941
        if (cv != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   942
            return cv.getValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   944
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
     * Returns the size of a font from the passed in string.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
     * @param size CSS string describing font size
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
     * @param baseFontSize size to use for relative units.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   953
    float getPointSize(String size, StyleSheet ss) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   954
        int relSize, absSize, diff, index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   955
        ss = getStyleSheet(ss);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   956
        if (size != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   957
            if (size.startsWith("+")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   958
                relSize = Integer.valueOf(size.substring(1)).intValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
                return getPointSize(baseFontSize + relSize, ss);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
            } else if (size.startsWith("-")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   961
                relSize = -Integer.valueOf(size.substring(1)).intValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   962
                return getPointSize(baseFontSize + relSize, ss);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   963
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   964
                absSize = Integer.valueOf(size).intValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   965
                return getPointSize(absSize, ss);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   966
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   967
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   968
        return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   969
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   970
90ce3da70b43 Initial load
duke
parents:
diff changeset
   971
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   972
     * Returns the length of the attribute in <code>a</code> with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   973
     * key <code>key</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   974
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   975
    float getLength(AttributeSet a, CSS.Attribute key, StyleSheet ss) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   976
        ss = getStyleSheet(ss);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   977
        LengthValue lv = (LengthValue) a.getAttribute(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   978
        boolean isW3CLengthUnits = (ss == null) ? false : ss.isW3CLengthUnits();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   979
        float len = (lv != null) ? lv.getValue(isW3CLengthUnits) : 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   980
        return len;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   981
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   982
90ce3da70b43 Initial load
duke
parents:
diff changeset
   983
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   984
     * Convert a set of HTML attributes to an equivalent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   985
     * set of CSS attributes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   986
     *
1287
a04aca99c77a 6722802: Code improvement and warnings removing from the javax.swing.text package
rupashka
parents: 438
diff changeset
   987
     * @param htmlAttrSet AttributeSet containing the HTML attributes.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   988
     * @return AttributeSet containing the corresponding CSS attributes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   989
     *        The AttributeSet will be empty if there are no mapping
90ce3da70b43 Initial load
duke
parents:
diff changeset
   990
     *        CSS attributes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   991
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   992
    AttributeSet translateHTMLToCSS(AttributeSet htmlAttrSet) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   993
        MutableAttributeSet cssAttrSet = new SimpleAttributeSet();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   994
        Element elem = (Element)htmlAttrSet;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   995
        HTML.Tag tag = getHTMLTag(htmlAttrSet);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   996
        if ((tag == HTML.Tag.TD) || (tag == HTML.Tag.TH)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   997
            // translate border width into the cells, if it has non-zero value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   998
            AttributeSet tableAttr = elem.getParentElement().
90ce3da70b43 Initial load
duke
parents:
diff changeset
   999
                                     getParentElement().getAttributes();
10320
fb28887eb9f2 7030332: Default borders in tables looks incorrect JEditorPane
rupashka
parents: 9219
diff changeset
  1000
fb28887eb9f2 7030332: Default borders in tables looks incorrect JEditorPane
rupashka
parents: 9219
diff changeset
  1001
            int borderWidth = getTableBorder(tableAttr);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1002
            if (borderWidth > 0) {
10320
fb28887eb9f2 7030332: Default borders in tables looks incorrect JEditorPane
rupashka
parents: 9219
diff changeset
  1003
                // If table contains the BORDER attribute cells should have border width equals 1
fb28887eb9f2 7030332: Default borders in tables looks incorrect JEditorPane
rupashka
parents: 9219
diff changeset
  1004
                translateAttribute(HTML.Attribute.BORDER, "1", cssAttrSet);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1005
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1006
            String pad = (String)tableAttr.getAttribute(HTML.Attribute.CELLPADDING);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1007
            if (pad != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1008
                LengthValue v =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1009
                    (LengthValue)getInternalCSSValue(CSS.Attribute.PADDING_TOP, pad);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1010
                v.span = (v.span < 0) ? 0 : v.span;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1011
                cssAttrSet.addAttribute(CSS.Attribute.PADDING_TOP, v);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1012
                cssAttrSet.addAttribute(CSS.Attribute.PADDING_BOTTOM, v);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1013
                cssAttrSet.addAttribute(CSS.Attribute.PADDING_LEFT, v);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1014
                cssAttrSet.addAttribute(CSS.Attribute.PADDING_RIGHT, v);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1015
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1016
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1017
        if (elem.isLeaf()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1018
            translateEmbeddedAttributes(htmlAttrSet, cssAttrSet);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1019
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1020
            translateAttributes(tag, htmlAttrSet, cssAttrSet);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1021
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1022
        if (tag == HTML.Tag.CAPTION) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1023
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1024
             * Navigator uses ALIGN for caption placement and IE uses VALIGN.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1025
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1026
            Object v = htmlAttrSet.getAttribute(HTML.Attribute.ALIGN);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1027
            if ((v != null) && (v.equals("top") || v.equals("bottom"))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1028
                cssAttrSet.addAttribute(CSS.Attribute.CAPTION_SIDE, v);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1029
                cssAttrSet.removeAttribute(CSS.Attribute.TEXT_ALIGN);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1030
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1031
                v = htmlAttrSet.getAttribute(HTML.Attribute.VALIGN);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1032
                if (v != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1033
                    cssAttrSet.addAttribute(CSS.Attribute.CAPTION_SIDE, v);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1034
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1035
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1036
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1037
        return cssAttrSet;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1038
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1039
10320
fb28887eb9f2 7030332: Default borders in tables looks incorrect JEditorPane
rupashka
parents: 9219
diff changeset
  1040
    private static int getTableBorder(AttributeSet tableAttr) {
fb28887eb9f2 7030332: Default borders in tables looks incorrect JEditorPane
rupashka
parents: 9219
diff changeset
  1041
        String borderValue = (String) tableAttr.getAttribute(HTML.Attribute.BORDER);
fb28887eb9f2 7030332: Default borders in tables looks incorrect JEditorPane
rupashka
parents: 9219
diff changeset
  1042
fb28887eb9f2 7030332: Default borders in tables looks incorrect JEditorPane
rupashka
parents: 9219
diff changeset
  1043
        if (borderValue == HTML.NULL_ATTRIBUTE_VALUE || "".equals(borderValue)) {
fb28887eb9f2 7030332: Default borders in tables looks incorrect JEditorPane
rupashka
parents: 9219
diff changeset
  1044
            // Some browsers accept <TABLE BORDER> and <TABLE BORDER=""> with the same semantics as BORDER=1
fb28887eb9f2 7030332: Default borders in tables looks incorrect JEditorPane
rupashka
parents: 9219
diff changeset
  1045
            return 1;
fb28887eb9f2 7030332: Default borders in tables looks incorrect JEditorPane
rupashka
parents: 9219
diff changeset
  1046
        }
fb28887eb9f2 7030332: Default borders in tables looks incorrect JEditorPane
rupashka
parents: 9219
diff changeset
  1047
fb28887eb9f2 7030332: Default borders in tables looks incorrect JEditorPane
rupashka
parents: 9219
diff changeset
  1048
        try {
fb28887eb9f2 7030332: Default borders in tables looks incorrect JEditorPane
rupashka
parents: 9219
diff changeset
  1049
            return Integer.parseInt(borderValue);
fb28887eb9f2 7030332: Default borders in tables looks incorrect JEditorPane
rupashka
parents: 9219
diff changeset
  1050
        } catch (NumberFormatException e) {
fb28887eb9f2 7030332: Default borders in tables looks incorrect JEditorPane
rupashka
parents: 9219
diff changeset
  1051
            return 0;
fb28887eb9f2 7030332: Default borders in tables looks incorrect JEditorPane
rupashka
parents: 9219
diff changeset
  1052
        }
fb28887eb9f2 7030332: Default borders in tables looks incorrect JEditorPane
rupashka
parents: 9219
diff changeset
  1053
    }
fb28887eb9f2 7030332: Default borders in tables looks incorrect JEditorPane
rupashka
parents: 9219
diff changeset
  1054
1287
a04aca99c77a 6722802: Code improvement and warnings removing from the javax.swing.text package
rupashka
parents: 438
diff changeset
  1055
    private static final Hashtable<String, Attribute> attributeMap = new Hashtable<String, Attribute>();
a04aca99c77a 6722802: Code improvement and warnings removing from the javax.swing.text package
rupashka
parents: 438
diff changeset
  1056
    private static final Hashtable<String, Value> valueMap = new Hashtable<String, Value>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1057
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1058
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1059
     * The hashtable and the static initalization block below,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1060
     * set up a mapping from well-known HTML attributes to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1061
     * CSS attributes.  For the most part, there is a 1-1 mapping
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1062
     * between the two.  However in the case of certain HTML
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1063
     * attributes for example HTML.Attribute.VSPACE or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1064
     * HTML.Attribute.HSPACE, end up mapping to two CSS.Attribute's.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1065
     * Therefore, the value associated with each HTML.Attribute.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1066
     * key ends up being an array of CSS.Attribute.* objects.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1067
     */
1287
a04aca99c77a 6722802: Code improvement and warnings removing from the javax.swing.text package
rupashka
parents: 438
diff changeset
  1068
    private static final Hashtable<HTML.Attribute, CSS.Attribute[]> htmlAttrToCssAttrMap = new Hashtable<HTML.Attribute, CSS.Attribute[]>(20);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1069
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1070
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1071
     * The hashtable and static initialization that follows sets
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1072
     * up a translation from StyleConstants (i.e. the <em>well known</em>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1073
     * attributes) to the associated CSS attributes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1074
     */
1287
a04aca99c77a 6722802: Code improvement and warnings removing from the javax.swing.text package
rupashka
parents: 438
diff changeset
  1075
    private static final Hashtable<Object, Attribute> styleConstantToCssMap = new Hashtable<Object, Attribute>(17);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1076
    /** Maps from HTML value to a CSS value. Used in internal mapping. */
1287
a04aca99c77a 6722802: Code improvement and warnings removing from the javax.swing.text package
rupashka
parents: 438
diff changeset
  1077
    private static final Hashtable<String, CSS.Value> htmlValueToCssValueMap = new Hashtable<String, CSS.Value>(8);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1078
    /** Maps from CSS value (string) to internal value. */
1287
a04aca99c77a 6722802: Code improvement and warnings removing from the javax.swing.text package
rupashka
parents: 438
diff changeset
  1079
    private static final Hashtable<String, CSS.Value> cssValueToInternalValueMap = new Hashtable<String, CSS.Value>(13);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1080
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1081
    static {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1082
        // load the attribute map
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1083
        for (int i = 0; i < Attribute.allAttributes.length; i++ ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1084
            attributeMap.put(Attribute.allAttributes[i].toString(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1085
                             Attribute.allAttributes[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1086
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1087
        // load the value map
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1088
        for (int i = 0; i < Value.allValues.length; i++ ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1089
            valueMap.put(Value.allValues[i].toString(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1090
                             Value.allValues[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1091
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1092
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1093
        htmlAttrToCssAttrMap.put(HTML.Attribute.COLOR,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1094
                                 new CSS.Attribute[]{CSS.Attribute.COLOR});
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1095
        htmlAttrToCssAttrMap.put(HTML.Attribute.TEXT,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1096
                                 new CSS.Attribute[]{CSS.Attribute.COLOR});
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1097
        htmlAttrToCssAttrMap.put(HTML.Attribute.CLEAR,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1098
                                 new CSS.Attribute[]{CSS.Attribute.CLEAR});
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1099
        htmlAttrToCssAttrMap.put(HTML.Attribute.BACKGROUND,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1100
                                 new CSS.Attribute[]{CSS.Attribute.BACKGROUND_IMAGE});
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1101
        htmlAttrToCssAttrMap.put(HTML.Attribute.BGCOLOR,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1102
                                 new CSS.Attribute[]{CSS.Attribute.BACKGROUND_COLOR});
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1103
        htmlAttrToCssAttrMap.put(HTML.Attribute.WIDTH,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1104
                                 new CSS.Attribute[]{CSS.Attribute.WIDTH});
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1105
        htmlAttrToCssAttrMap.put(HTML.Attribute.HEIGHT,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1106
                                 new CSS.Attribute[]{CSS.Attribute.HEIGHT});
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1107
        htmlAttrToCssAttrMap.put(HTML.Attribute.BORDER,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1108
                                 new CSS.Attribute[]{CSS.Attribute.BORDER_TOP_WIDTH, CSS.Attribute.BORDER_RIGHT_WIDTH, CSS.Attribute.BORDER_BOTTOM_WIDTH, CSS.Attribute.BORDER_LEFT_WIDTH});
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1109
        htmlAttrToCssAttrMap.put(HTML.Attribute.CELLPADDING,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1110
                                 new CSS.Attribute[]{CSS.Attribute.PADDING});
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1111
        htmlAttrToCssAttrMap.put(HTML.Attribute.CELLSPACING,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1112
                                 new CSS.Attribute[]{CSS.Attribute.BORDER_SPACING});
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1113
        htmlAttrToCssAttrMap.put(HTML.Attribute.MARGINWIDTH,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1114
                                 new CSS.Attribute[]{CSS.Attribute.MARGIN_LEFT,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1115
                                                     CSS.Attribute.MARGIN_RIGHT});
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1116
        htmlAttrToCssAttrMap.put(HTML.Attribute.MARGINHEIGHT,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1117
                                 new CSS.Attribute[]{CSS.Attribute.MARGIN_TOP,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1118
                                                     CSS.Attribute.MARGIN_BOTTOM});
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1119
        htmlAttrToCssAttrMap.put(HTML.Attribute.HSPACE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1120
                                 new CSS.Attribute[]{CSS.Attribute.PADDING_LEFT,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1121
                                                     CSS.Attribute.PADDING_RIGHT});
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1122
        htmlAttrToCssAttrMap.put(HTML.Attribute.VSPACE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1123
                                 new CSS.Attribute[]{CSS.Attribute.PADDING_BOTTOM,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1124
                                                     CSS.Attribute.PADDING_TOP});
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1125
        htmlAttrToCssAttrMap.put(HTML.Attribute.FACE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1126
                                 new CSS.Attribute[]{CSS.Attribute.FONT_FAMILY});
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1127
        htmlAttrToCssAttrMap.put(HTML.Attribute.SIZE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1128
                                 new CSS.Attribute[]{CSS.Attribute.FONT_SIZE});
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1129
        htmlAttrToCssAttrMap.put(HTML.Attribute.VALIGN,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1130
                                 new CSS.Attribute[]{CSS.Attribute.VERTICAL_ALIGN});
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1131
        htmlAttrToCssAttrMap.put(HTML.Attribute.ALIGN,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1132
                                 new CSS.Attribute[]{CSS.Attribute.VERTICAL_ALIGN,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1133
                                                     CSS.Attribute.TEXT_ALIGN,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1134
                                                     CSS.Attribute.FLOAT});
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1135
        htmlAttrToCssAttrMap.put(HTML.Attribute.TYPE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1136
                                 new CSS.Attribute[]{CSS.Attribute.LIST_STYLE_TYPE});
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1137
        htmlAttrToCssAttrMap.put(HTML.Attribute.NOWRAP,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1138
                                 new CSS.Attribute[]{CSS.Attribute.WHITE_SPACE});
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1139
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1140
        // initialize StyleConstants mapping
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1141
        styleConstantToCssMap.put(StyleConstants.FontFamily,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1142
                                  CSS.Attribute.FONT_FAMILY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1143
        styleConstantToCssMap.put(StyleConstants.FontSize,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1144
                                  CSS.Attribute.FONT_SIZE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1145
        styleConstantToCssMap.put(StyleConstants.Bold,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1146
                                  CSS.Attribute.FONT_WEIGHT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1147
        styleConstantToCssMap.put(StyleConstants.Italic,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1148
                                  CSS.Attribute.FONT_STYLE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1149
        styleConstantToCssMap.put(StyleConstants.Underline,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1150
                                  CSS.Attribute.TEXT_DECORATION);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1151
        styleConstantToCssMap.put(StyleConstants.StrikeThrough,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1152
                                  CSS.Attribute.TEXT_DECORATION);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1153
        styleConstantToCssMap.put(StyleConstants.Superscript,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1154
                                  CSS.Attribute.VERTICAL_ALIGN);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1155
        styleConstantToCssMap.put(StyleConstants.Subscript,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1156
                                  CSS.Attribute.VERTICAL_ALIGN);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1157
        styleConstantToCssMap.put(StyleConstants.Foreground,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1158
                                  CSS.Attribute.COLOR);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1159
        styleConstantToCssMap.put(StyleConstants.Background,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1160
                                  CSS.Attribute.BACKGROUND_COLOR);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1161
        styleConstantToCssMap.put(StyleConstants.FirstLineIndent,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1162
                                  CSS.Attribute.TEXT_INDENT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1163
        styleConstantToCssMap.put(StyleConstants.LeftIndent,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1164
                                  CSS.Attribute.MARGIN_LEFT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1165
        styleConstantToCssMap.put(StyleConstants.RightIndent,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1166
                                  CSS.Attribute.MARGIN_RIGHT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1167
        styleConstantToCssMap.put(StyleConstants.SpaceAbove,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1168
                                  CSS.Attribute.MARGIN_TOP);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1169
        styleConstantToCssMap.put(StyleConstants.SpaceBelow,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1170
                                  CSS.Attribute.MARGIN_BOTTOM);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1171
        styleConstantToCssMap.put(StyleConstants.Alignment,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1172
                                  CSS.Attribute.TEXT_ALIGN);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1173
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1174
        // HTML->CSS
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1175
        htmlValueToCssValueMap.put("disc", CSS.Value.DISC);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1176
        htmlValueToCssValueMap.put("square", CSS.Value.SQUARE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1177
        htmlValueToCssValueMap.put("circle", CSS.Value.CIRCLE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1178
        htmlValueToCssValueMap.put("1", CSS.Value.DECIMAL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1179
        htmlValueToCssValueMap.put("a", CSS.Value.LOWER_ALPHA);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1180
        htmlValueToCssValueMap.put("A", CSS.Value.UPPER_ALPHA);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1181
        htmlValueToCssValueMap.put("i", CSS.Value.LOWER_ROMAN);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1182
        htmlValueToCssValueMap.put("I", CSS.Value.UPPER_ROMAN);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1183
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1184
        // CSS-> internal CSS
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1185
        cssValueToInternalValueMap.put("none", CSS.Value.NONE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1186
        cssValueToInternalValueMap.put("disc", CSS.Value.DISC);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1187
        cssValueToInternalValueMap.put("square", CSS.Value.SQUARE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1188
        cssValueToInternalValueMap.put("circle", CSS.Value.CIRCLE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1189
        cssValueToInternalValueMap.put("decimal", CSS.Value.DECIMAL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1190
        cssValueToInternalValueMap.put("lower-roman", CSS.Value.LOWER_ROMAN);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1191
        cssValueToInternalValueMap.put("upper-roman", CSS.Value.UPPER_ROMAN);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1192
        cssValueToInternalValueMap.put("lower-alpha", CSS.Value.LOWER_ALPHA);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1193
        cssValueToInternalValueMap.put("upper-alpha", CSS.Value.UPPER_ALPHA);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1194
        cssValueToInternalValueMap.put("repeat", CSS.Value.BACKGROUND_REPEAT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1195
        cssValueToInternalValueMap.put("no-repeat",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1196
                                       CSS.Value.BACKGROUND_NO_REPEAT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1197
        cssValueToInternalValueMap.put("repeat-x",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1198
                                       CSS.Value.BACKGROUND_REPEAT_X);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1199
        cssValueToInternalValueMap.put("repeat-y",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1200
                                       CSS.Value.BACKGROUND_REPEAT_Y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1201
        cssValueToInternalValueMap.put("scroll",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1202
                                       CSS.Value.BACKGROUND_SCROLL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1203
        cssValueToInternalValueMap.put("fixed",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1204
                                       CSS.Value.BACKGROUND_FIXED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1205
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1206
        // Register all the CSS attribute keys for archival/unarchival
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1207
        Object[] keys = CSS.Attribute.allAttributes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1208
        try {
1287
a04aca99c77a 6722802: Code improvement and warnings removing from the javax.swing.text package
rupashka
parents: 438
diff changeset
  1209
            for (Object key : keys) {
a04aca99c77a 6722802: Code improvement and warnings removing from the javax.swing.text package
rupashka
parents: 438
diff changeset
  1210
                StyleContext.registerStaticAttributeKey(key);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1211
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1212
        } catch (Throwable e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1213
            e.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1214
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1215
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1216
        // Register all the CSS Values for archival/unarchival
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1217
        keys = CSS.Value.allValues;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1218
        try {
1287
a04aca99c77a 6722802: Code improvement and warnings removing from the javax.swing.text package
rupashka
parents: 438
diff changeset
  1219
            for (Object key : keys) {
a04aca99c77a 6722802: Code improvement and warnings removing from the javax.swing.text package
rupashka
parents: 438
diff changeset
  1220
                StyleContext.registerStaticAttributeKey(key);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1221
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1222
        } catch (Throwable e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1223
            e.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1224
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1225
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1226
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1227
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1228
     * Return the set of all possible CSS attribute keys.
24269
325ea76ea0e9 8042105: Fix some more doclint issues in javax.swing.text.html classes
yan
parents: 23697
diff changeset
  1229
     *
325ea76ea0e9 8042105: Fix some more doclint issues in javax.swing.text.html classes
yan
parents: 23697
diff changeset
  1230
     * @return the set of all possible CSS attribute keys
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1231
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1232
    public static Attribute[] getAllAttributeKeys() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1233
        Attribute[] keys = new Attribute[Attribute.allAttributes.length];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1234
        System.arraycopy(Attribute.allAttributes, 0, keys, 0, Attribute.allAttributes.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1235
        return keys;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1236
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1237
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1238
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1239
     * Translates a string to a <code>CSS.Attribute</code> object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1240
     * This will return <code>null</code> if there is no attribute
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1241
     * by the given name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1242
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1243
     * @param name the name of the CSS attribute to fetch the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1244
     *  typesafe enumeration for
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1245
     * @return the <code>CSS.Attribute</code> object,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1246
     *  or <code>null</code> if the string
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1247
     *  doesn't represent a valid attribute key
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1248
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1249
    public static final Attribute getAttribute(String name) {
1287
a04aca99c77a 6722802: Code improvement and warnings removing from the javax.swing.text package
rupashka
parents: 438
diff changeset
  1250
        return attributeMap.get(name);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1251
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1252
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1253
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1254
     * Translates a string to a <code>CSS.Value</code> object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1255
     * This will return <code>null</code> if there is no value
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1256
     * by the given name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1257
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1258
     * @param name the name of the CSS value to fetch the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1259
     *  typesafe enumeration for
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1260
     * @return the <code>CSS.Value</code> object,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1261
     *  or <code>null</code> if the string
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1262
     *  doesn't represent a valid CSS value name; this does
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1263
     *  not mean that it doesn't represent a valid CSS value
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1264
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1265
    static final Value getValue(String name) {
1287
a04aca99c77a 6722802: Code improvement and warnings removing from the javax.swing.text package
rupashka
parents: 438
diff changeset
  1266
        return valueMap.get(name);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1267
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1268
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1269
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1270
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1271
    // Conversion related methods/classes
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1272
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1273
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1274
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1275
     * Returns a URL for the given CSS url string. If relative,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1276
     * <code>base</code> is used as the parent. If a valid URL can not
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1277
     * be found, this will not throw a MalformedURLException, instead
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1278
     * null will be returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1279
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1280
    static URL getURL(URL base, String cssString) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1281
        if (cssString == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1282
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1283
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1284
        if (cssString.startsWith("url(") &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1285
            cssString.endsWith(")")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1286
            cssString = cssString.substring(4, cssString.length() - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1287
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1288
        // Absolute first
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1289
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1290
            URL url = new URL(cssString);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1291
            if (url != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1292
                return url;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1293
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1294
        } catch (MalformedURLException mue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1295
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1296
        // Then relative
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1297
        if (base != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1298
            // Relative URL, try from base
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1299
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1300
                URL url = new URL(base, cssString);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1301
                return url;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1302
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1303
            catch (MalformedURLException muee) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1304
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1305
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1306
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1307
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1308
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1309
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1310
     * Converts a type Color to a hex string
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1311
     * in the format "#RRGGBB"
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1312
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1313
    static String colorToHex(Color color) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1314
438
2ae294e4518c 6613529: Avoid duplicate object creation within JDK packages
dav
parents: 2
diff changeset
  1315
      String colorstr = "#";
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1316
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1317
      // Red
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1318
      String str = Integer.toHexString(color.getRed());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1319
      if (str.length() > 2)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1320
        str = str.substring(0, 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1321
      else if (str.length() < 2)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1322
        colorstr += "0" + str;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1323
      else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1324
        colorstr += str;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1325
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1326
      // Green
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1327
      str = Integer.toHexString(color.getGreen());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1328
      if (str.length() > 2)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1329
        str = str.substring(0, 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1330
      else if (str.length() < 2)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1331
        colorstr += "0" + str;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1332
      else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1333
        colorstr += str;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1334
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1335
      // Blue
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1336
      str = Integer.toHexString(color.getBlue());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1337
      if (str.length() > 2)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1338
        str = str.substring(0, 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1339
      else if (str.length() < 2)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1340
        colorstr += "0" + str;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1341
      else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1342
        colorstr += str;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1343
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1344
      return colorstr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1345
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1346
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1347
     /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1348
      * Convert a "#FFFFFF" hex string to a Color.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1349
      * If the color specification is bad, an attempt
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1350
      * will be made to fix it up.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1351
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1352
    static final Color hexToColor(String value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1353
        String digits;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1354
        int n = value.length();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1355
        if (value.startsWith("#")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1356
            digits = value.substring(1, Math.min(value.length(), 7));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1357
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1358
            digits = value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1359
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1360
        String hstr = "0x" + digits;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1361
        Color c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1362
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1363
            c = Color.decode(hstr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1364
        } catch (NumberFormatException nfe) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1365
            c = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1366
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1367
         return c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1368
     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1369
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1370
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1371
     * Convert a color string such as "RED" or "#NNNNNN" or "rgb(r, g, b)"
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1372
     * to a Color.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1373
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1374
    static Color stringToColor(String str) {
1287
a04aca99c77a 6722802: Code improvement and warnings removing from the javax.swing.text package
rupashka
parents: 438
diff changeset
  1375
      Color color;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1376
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1377
      if (str == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1378
          return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1379
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1380
      if (str.length() == 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1381
        color = Color.black;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1382
      else if (str.startsWith("rgb(")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1383
          color = parseRGB(str);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1384
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1385
      else if (str.charAt(0) == '#')
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1386
        color = hexToColor(str);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1387
      else if (str.equalsIgnoreCase("Black"))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1388
        color = hexToColor("#000000");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1389
      else if(str.equalsIgnoreCase("Silver"))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1390
        color = hexToColor("#C0C0C0");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1391
      else if(str.equalsIgnoreCase("Gray"))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1392
        color = hexToColor("#808080");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1393
      else if(str.equalsIgnoreCase("White"))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1394
        color = hexToColor("#FFFFFF");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1395
      else if(str.equalsIgnoreCase("Maroon"))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1396
        color = hexToColor("#800000");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1397
      else if(str.equalsIgnoreCase("Red"))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1398
        color = hexToColor("#FF0000");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1399
      else if(str.equalsIgnoreCase("Purple"))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1400
        color = hexToColor("#800080");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1401
      else if(str.equalsIgnoreCase("Fuchsia"))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1402
        color = hexToColor("#FF00FF");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1403
      else if(str.equalsIgnoreCase("Green"))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1404
        color = hexToColor("#008000");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1405
      else if(str.equalsIgnoreCase("Lime"))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1406
        color = hexToColor("#00FF00");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1407
      else if(str.equalsIgnoreCase("Olive"))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1408
        color = hexToColor("#808000");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1409
      else if(str.equalsIgnoreCase("Yellow"))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1410
        color = hexToColor("#FFFF00");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1411
      else if(str.equalsIgnoreCase("Navy"))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1412
        color = hexToColor("#000080");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1413
      else if(str.equalsIgnoreCase("Blue"))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1414
        color = hexToColor("#0000FF");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1415
      else if(str.equalsIgnoreCase("Teal"))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1416
        color = hexToColor("#008080");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1417
      else if(str.equalsIgnoreCase("Aqua"))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1418
        color = hexToColor("#00FFFF");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1419
      else if(str.equalsIgnoreCase("Orange"))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1420
        color = hexToColor("#FF8000");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1421
      else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1422
          color = hexToColor(str); // sometimes get specified without leading #
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1423
      return color;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1424
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1425
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1426
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1427
     * Parses a String in the format <code>rgb(r, g, b)</code> where
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1428
     * each of the Color components is either an integer, or a floating number
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1429
     * with a % after indicating a percentage value of 255. Values are
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1430
     * constrained to fit with 0-255. The resulting Color is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1431
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1432
    private static Color parseRGB(String string) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1433
        // Find the next numeric char
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1434
        int[] index = new int[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1435
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1436
        index[0] = 4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1437
        int red = getColorComponent(string, index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1438
        int green = getColorComponent(string, index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1439
        int blue = getColorComponent(string, index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1440
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1441
        return new Color(red, green, blue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1442
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1443
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1444
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1445
     * Returns the next integer value from <code>string</code> starting
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1446
     * at <code>index[0]</code>. The value can either can an integer, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1447
     * a percentage (floating number ending with %), in which case it is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1448
     * multiplied by 255.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1449
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1450
    private static int getColorComponent(String string, int[] index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1451
        int length = string.length();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1452
        char aChar;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1453
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1454
        // Skip non-decimal chars
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1455
        while(index[0] < length && (aChar = string.charAt(index[0])) != '-' &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1456
              !Character.isDigit(aChar) && aChar != '.') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1457
            index[0]++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1458
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1459
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1460
        int start = index[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1461
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1462
        if (start < length && string.charAt(index[0]) == '-') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1463
            index[0]++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1464
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1465
        while(index[0] < length &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1466
                         Character.isDigit(string.charAt(index[0]))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1467
            index[0]++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1468
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1469
        if (index[0] < length && string.charAt(index[0]) == '.') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1470
            // Decimal value
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1471
            index[0]++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1472
            while(index[0] < length &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1473
                  Character.isDigit(string.charAt(index[0]))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1474
                index[0]++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1475
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1476
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1477
        if (start != index[0]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1478
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1479
                float value = Float.parseFloat(string.substring
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1480
                                               (start, index[0]));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1481
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1482
                if (index[0] < length && string.charAt(index[0]) == '%') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1483
                    index[0]++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1484
                    value = value * 255f / 100f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1485
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1486
                return Math.min(255, Math.max(0, (int)value));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1487
            } catch (NumberFormatException nfe) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1488
                // Treat as 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1489
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1490
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1491
        return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1492
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1493
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1494
    static int getIndexOfSize(float pt, int[] sizeMap) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1495
        for (int i = 0; i < sizeMap.length; i ++ )
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1496
                if (pt <= sizeMap[i])
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1497
                        return i + 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1498
        return sizeMap.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1499
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1500
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1501
    static int getIndexOfSize(float pt, StyleSheet ss) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1502
        int[] sizeMap = (ss != null) ? ss.getSizeMap() :
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1503
            StyleSheet.sizeMapDefault;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1504
        return getIndexOfSize(pt, sizeMap);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1505
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1506
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1507
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1508
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1509
     * @return an array of all the strings in <code>value</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1510
     *         that are separated by whitespace.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1511
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1512
    static String[] parseStrings(String value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1513
        int         current, last;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1514
        int         length = (value == null) ? 0 : value.length();
1287
a04aca99c77a 6722802: Code improvement and warnings removing from the javax.swing.text package
rupashka
parents: 438
diff changeset
  1515
        Vector<String> temp = new Vector<String>(4);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1516
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1517
        current = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1518
        while (current < length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1519
            // Skip ws
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1520
            while (current < length && Character.isWhitespace
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1521
                   (value.charAt(current))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1522
                current++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1523
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1524
            last = current;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1525
            while (current < length && !Character.isWhitespace
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1526
                   (value.charAt(current))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1527
                current++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1528
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1529
            if (last != current) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1530
                temp.addElement(value.substring(last, current));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1531
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1532
            current++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1533
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1534
        String[] retValue = new String[temp.size()];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1535
        temp.copyInto(retValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1536
        return retValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1537
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1538
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1539
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1540
     * Return the point size, given a size index. Legal HTML index sizes
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1541
     * are 1-7.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1542
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1543
    float getPointSize(int index, StyleSheet ss) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1544
        ss = getStyleSheet(ss);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1545
        int[] sizeMap = (ss != null) ? ss.getSizeMap() :
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1546
            StyleSheet.sizeMapDefault;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1547
        --index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1548
        if (index < 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1549
          return sizeMap[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1550
        else if (index > sizeMap.length - 1)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1551
          return sizeMap[sizeMap.length - 1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1552
        else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1553
          return sizeMap[index];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1554
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1555
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1556
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1557
    private void translateEmbeddedAttributes(AttributeSet htmlAttrSet,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1558
                                             MutableAttributeSet cssAttrSet) {
25193
187a455af8f8 8043549: Fix raw and unchecked lint warnings in javax.swing.text.*
darcy
parents: 24269
diff changeset
  1559
        Enumeration<?> keys = htmlAttrSet.getAttributeNames();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1560
        if (htmlAttrSet.getAttribute(StyleConstants.NameAttribute) ==
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1561
            HTML.Tag.HR) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1562
            // HR needs special handling due to us treating it as a leaf.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1563
            translateAttributes(HTML.Tag.HR, htmlAttrSet, cssAttrSet);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1564
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1565
        while (keys.hasMoreElements()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1566
            Object key = keys.nextElement();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1567
            if (key instanceof HTML.Tag) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1568
                HTML.Tag tag = (HTML.Tag)key;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1569
                Object o = htmlAttrSet.getAttribute(tag);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1570
                if (o != null && o instanceof AttributeSet) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1571
                    translateAttributes(tag, (AttributeSet)o, cssAttrSet);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1572
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1573
            } else if (key instanceof CSS.Attribute) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1574
                cssAttrSet.addAttribute(key, htmlAttrSet.getAttribute(key));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1575
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1576
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1577
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1578
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1579
    private void translateAttributes(HTML.Tag tag,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1580
                                            AttributeSet htmlAttrSet,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1581
                                            MutableAttributeSet cssAttrSet) {
25193
187a455af8f8 8043549: Fix raw and unchecked lint warnings in javax.swing.text.*
darcy
parents: 24269
diff changeset
  1582
        Enumeration<?> names = htmlAttrSet.getAttributeNames();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1583
        while (names.hasMoreElements()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1584
            Object name = names.nextElement();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1585
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1586
            if (name instanceof HTML.Attribute) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1587
                HTML.Attribute key = (HTML.Attribute)name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1588
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1589
                /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1590
                 * HTML.Attribute.ALIGN needs special processing.
28059
e576535359cc 8067377: My hobby: caning, then then canning, the the can-can
martin
parents: 26749
diff changeset
  1591
                 * It can map to 1 of many(3) possible CSS attributes
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1592
                 * depending on the nature of the tag the attribute is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1593
                 * part off and depending on the value of the attribute.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1594
                 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1595
                if (key == HTML.Attribute.ALIGN) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1596
                    String htmlAttrValue = (String)htmlAttrSet.getAttribute(HTML.Attribute.ALIGN);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1597
                    if (htmlAttrValue != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1598
                        CSS.Attribute cssAttr = getCssAlignAttribute(tag, htmlAttrSet);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1599
                        if (cssAttr != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1600
                            Object o = getCssValue(cssAttr, htmlAttrValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1601
                            if (o != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1602
                                cssAttrSet.addAttribute(cssAttr, o);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1603
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1604
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1605
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1606
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1607
                    if (key == HTML.Attribute.SIZE && !isHTMLFontTag(tag)) {
10320
fb28887eb9f2 7030332: Default borders in tables looks incorrect JEditorPane
rupashka
parents: 9219
diff changeset
  1608
                        /*
fb28887eb9f2 7030332: Default borders in tables looks incorrect JEditorPane
rupashka
parents: 9219
diff changeset
  1609
                         * The html size attribute has a mapping in the CSS world only
fb28887eb9f2 7030332: Default borders in tables looks incorrect JEditorPane
rupashka
parents: 9219
diff changeset
  1610
                         * if it is par of a font or base font tag.
fb28887eb9f2 7030332: Default borders in tables looks incorrect JEditorPane
rupashka
parents: 9219
diff changeset
  1611
                         */
fb28887eb9f2 7030332: Default borders in tables looks incorrect JEditorPane
rupashka
parents: 9219
diff changeset
  1612
                    } else if (tag == HTML.Tag.TABLE && key == HTML.Attribute.BORDER) {
fb28887eb9f2 7030332: Default borders in tables looks incorrect JEditorPane
rupashka
parents: 9219
diff changeset
  1613
                        int borderWidth = getTableBorder(htmlAttrSet);
fb28887eb9f2 7030332: Default borders in tables looks incorrect JEditorPane
rupashka
parents: 9219
diff changeset
  1614
fb28887eb9f2 7030332: Default borders in tables looks incorrect JEditorPane
rupashka
parents: 9219
diff changeset
  1615
                        if (borderWidth > 0) {
fb28887eb9f2 7030332: Default borders in tables looks incorrect JEditorPane
rupashka
parents: 9219
diff changeset
  1616
                            translateAttribute(HTML.Attribute.BORDER, Integer.toString(borderWidth), cssAttrSet);
fb28887eb9f2 7030332: Default borders in tables looks incorrect JEditorPane
rupashka
parents: 9219
diff changeset
  1617
                        }
fb28887eb9f2 7030332: Default borders in tables looks incorrect JEditorPane
rupashka
parents: 9219
diff changeset
  1618
                    } else {
fb28887eb9f2 7030332: Default borders in tables looks incorrect JEditorPane
rupashka
parents: 9219
diff changeset
  1619
                        translateAttribute(key, (String) htmlAttrSet.getAttribute(key), cssAttrSet);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1620
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1621
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1622
            } else if (name instanceof CSS.Attribute) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1623
                cssAttrSet.addAttribute(name, htmlAttrSet.getAttribute(name));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1624
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1625
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1626
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1627
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1628
    private void translateAttribute(HTML.Attribute key,
10320
fb28887eb9f2 7030332: Default borders in tables looks incorrect JEditorPane
rupashka
parents: 9219
diff changeset
  1629
                                           String htmlAttrValue,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1630
                                           MutableAttributeSet cssAttrSet) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1631
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1632
         * In the case of all remaining HTML.Attribute's they
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1633
         * map to 1 or more CCS.Attribute.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1634
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1635
        CSS.Attribute[] cssAttrList = getCssAttribute(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1636
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1637
        if (cssAttrList == null || htmlAttrValue == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1638
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1639
        }
1287
a04aca99c77a 6722802: Code improvement and warnings removing from the javax.swing.text package
rupashka
parents: 438
diff changeset
  1640
        for (Attribute cssAttr : cssAttrList) {
a04aca99c77a 6722802: Code improvement and warnings removing from the javax.swing.text package
rupashka
parents: 438
diff changeset
  1641
            Object o = getCssValue(cssAttr, htmlAttrValue);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1642
            if (o != null) {
1287
a04aca99c77a 6722802: Code improvement and warnings removing from the javax.swing.text package
rupashka
parents: 438
diff changeset
  1643
                cssAttrSet.addAttribute(cssAttr , o);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1644
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1645
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1646
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1647
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1648
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1649
     * Given a CSS.Attribute object and its corresponding HTML.Attribute's
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1650
     * value, this method returns a CssValue object to associate with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1651
     * CSS attribute.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1652
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1653
     * @param the CSS.Attribute
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1654
     * @param a String containing the value associated HTML.Attribtue.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1655
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1656
    Object getCssValue(CSS.Attribute cssAttr, String htmlAttrValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1657
        CssValue value = (CssValue)valueConvertor.get(cssAttr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1658
        Object o = value.parseHtmlValue(htmlAttrValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1659
        return o;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1660
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1661
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1662
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1663
     * Maps an HTML.Attribute object to its appropriate CSS.Attributes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1664
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1665
     * @param HTML.Attribute
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1666
     * @return CSS.Attribute[]
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1667
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1668
    private CSS.Attribute[] getCssAttribute(HTML.Attribute hAttr) {
1287
a04aca99c77a 6722802: Code improvement and warnings removing from the javax.swing.text package
rupashka
parents: 438
diff changeset
  1669
        return htmlAttrToCssAttrMap.get(hAttr);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1670
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1671
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1672
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1673
     * Maps HTML.Attribute.ALIGN to either:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1674
     *     CSS.Attribute.TEXT_ALIGN
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1675
     *     CSS.Attribute.FLOAT
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1676
     *     CSS.Attribute.VERTICAL_ALIGN
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1677
     * based on the tag associated with the attribute and the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1678
     * value of the attribute.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1679
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1680
     * @param AttributeSet containing HTML attributes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1681
     * @return CSS.Attribute mapping for HTML.Attribute.ALIGN.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1682
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1683
    private CSS.Attribute getCssAlignAttribute(HTML.Tag tag,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1684
                                                   AttributeSet htmlAttrSet) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1685
        return CSS.Attribute.TEXT_ALIGN;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1686
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1687
        String htmlAttrValue = (String)htmlAttrSet.getAttribute(HTML.Attribute.ALIGN);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1688
        CSS.Attribute cssAttr = CSS.Attribute.TEXT_ALIGN;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1689
        if (htmlAttrValue != null && htmlAttrSet instanceof Element) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1690
            Element elem = (Element)htmlAttrSet;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1691
            if (!elem.isLeaf() && tag.isBlock() && validTextAlignValue(htmlAttrValue)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1692
                return CSS.Attribute.TEXT_ALIGN;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1693
            } else if (isFloater(htmlAttrValue)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1694
                return CSS.Attribute.FLOAT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1695
            } else if (elem.isLeaf()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1696
                return CSS.Attribute.VERTICAL_ALIGN;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1697
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1698
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1699
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1700
        */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1701
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1702
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1703
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1704
     * Fetches the tag associated with the HTML AttributeSet.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1705
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1706
     * @param  AttributeSet containing the HTML attributes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1707
     * @return HTML.Tag
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1708
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1709
    private HTML.Tag getHTMLTag(AttributeSet htmlAttrSet) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1710
        Object o = htmlAttrSet.getAttribute(StyleConstants.NameAttribute);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1711
        if (o instanceof HTML.Tag) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1712
            HTML.Tag tag = (HTML.Tag) o;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1713
            return tag;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1714
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1715
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1716
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1717
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1718
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1719
    private boolean isHTMLFontTag(HTML.Tag tag) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1720
        return (tag != null && ((tag == HTML.Tag.FONT) || (tag == HTML.Tag.BASEFONT)));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1721
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1722
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1723
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1724
    private boolean isFloater(String alignValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1725
        return (alignValue.equals("left") || alignValue.equals("right"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1726
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1727
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1728
    private boolean validTextAlignValue(String alignValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1729
        return (isFloater(alignValue) || alignValue.equals("center"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1730
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1731
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1732
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1733
     * Base class to CSS values in the attribute sets.  This
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1734
     * is intended to act as a convertor to/from other attribute
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1735
     * formats.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1736
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1737
     * The CSS parser uses the parseCssValue method to convert
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1738
     * a string to whatever format is appropriate a given key
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1739
     * (i.e. these convertors are stored in a map using the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1740
     * CSS.Attribute as a key and the CssValue as the value).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1741
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1742
     * The HTML to CSS conversion process first converts the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1743
     * HTML.Attribute to a CSS.Attribute, and then calls
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1744
     * the parseHtmlValue method on the value of the HTML
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1745
     * attribute to produce the corresponding CSS value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1746
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1747
     * The StyleConstants to CSS conversion process first
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1748
     * converts the StyleConstants attribute to a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1749
     * CSS.Attribute, and then calls the fromStyleConstants
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1750
     * method to convert the StyleConstants value to a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1751
     * CSS value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1752
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1753
     * The CSS to StyleConstants conversion process first
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1754
     * converts the StyleConstants attribute to a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1755
     * CSS.Attribute, and then calls the toStyleConstants
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1756
     * method to convert the CSS value to a StyleConstants
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1757
     * value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1758
     */
23697
e556a715949f 8034169: Fix serial lint warnings in javax.swing
darcy
parents: 23010
diff changeset
  1759
    @SuppressWarnings("serial") // Same-version serialization only
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1760
    static class CssValue implements Serializable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1761
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1762
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1763
         * Convert a CSS value string to the internal format
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1764
         * (for fast processing) used in the attribute sets.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1765
         * The fallback storage for any value that we don't
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1766
         * have a special binary format for is a String.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1767
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1768
        Object parseCssValue(String value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1769
            return value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1770
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1771
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1772
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1773
         * Convert an HTML attribute value to a CSS attribute
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1774
         * value.  If there is no conversion, return null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1775
         * This is implemented to simply forward to the CSS
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1776
         * parsing by default (since some of the attribute
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1777
         * values are the same).  If the attribute value
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1778
         * isn't recognized as a CSS value it is generally
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1779
         * returned as null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1780
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1781
        Object parseHtmlValue(String value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1782
            return parseCssValue(value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1783
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1784
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1785
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1786
         * Converts a <code>StyleConstants</code> attribute value to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1787
         * a CSS attribute value.  If there is no conversion,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1788
         * returns <code>null</code>.  By default, there is no conversion.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1789
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1790
         * @param key the <code>StyleConstants</code> attribute
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1791
         * @param value the value of a <code>StyleConstants</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1792
         *   attribute to be converted
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1793
         * @return the CSS value that represents the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1794
         *   <code>StyleConstants</code> value
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1795
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1796
        Object fromStyleConstants(StyleConstants key, Object value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1797
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1798
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1799
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1800
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1801
         * Converts a CSS attribute value to a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1802
         * <code>StyleConstants</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1803
         * value.  If there is no conversion, returns
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1804
         * <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1805
         * By default, there is no conversion.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1806
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1807
         * @param key the <code>StyleConstants</code> attribute
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1808
         * @param v the view containing <code>AttributeSet</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1809
         * @return the <code>StyleConstants</code> attribute value that
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1810
         *   represents the CSS attribute value
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1811
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1812
        Object toStyleConstants(StyleConstants key, View v) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1813
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1814
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1815
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1816
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1817
         * Return the CSS format of the value
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1818
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1819
        public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1820
            return svalue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1821
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1822
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1823
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1824
         * The value as a string... before conversion to a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1825
         * binary format.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1826
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1827
        String svalue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1828
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1829
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1830
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1831
     * By default CSS attributes are represented as simple
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1832
     * strings.  They also have no conversion to/from
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1833
     * StyleConstants by default. This class represents the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1834
     * value as a string (via the superclass), but
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1835
     * provides StyleConstants conversion support for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1836
     * CSS attributes that are held as strings.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1837
     */
23697
e556a715949f 8034169: Fix serial lint warnings in javax.swing
darcy
parents: 23010
diff changeset
  1838
    @SuppressWarnings("serial") // Same-version serialization only
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1839
    static class StringValue extends CssValue {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1840
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1841
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1842
         * Convert a CSS value string to the internal format
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1843
         * (for fast processing) used in the attribute sets.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1844
         * This produces a StringValue, so that it can be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1845
         * used to convert from CSS to StyleConstants values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1846
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1847
        Object parseCssValue(String value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1848
            StringValue sv = new StringValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1849
            sv.svalue = value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1850
            return sv;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1851
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1852
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1853
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1854
         * Converts a <code>StyleConstants</code> attribute value to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1855
         * a CSS attribute value.  If there is no conversion
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1856
         * returns <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1857
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1858
         * @param key the <code>StyleConstants</code> attribute
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1859
         * @param value the value of a <code>StyleConstants</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1860
         *   attribute to be converted
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1861
         * @return the CSS value that represents the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1862
         *   <code>StyleConstants</code> value
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1863
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1864
        Object fromStyleConstants(StyleConstants key, Object value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1865
            if (key == StyleConstants.Italic) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1866
                if (value.equals(Boolean.TRUE)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1867
                    return parseCssValue("italic");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1868
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1869
                return parseCssValue("");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1870
            } else if (key == StyleConstants.Underline) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1871
                if (value.equals(Boolean.TRUE)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1872
                    return parseCssValue("underline");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1873
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1874
                return parseCssValue("");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1875
            } else if (key == StyleConstants.Alignment) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1876
                int align = ((Integer)value).intValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1877
                String ta;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1878
                switch(align) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1879
                case StyleConstants.ALIGN_LEFT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1880
                    ta = "left";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1881
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1882
                case StyleConstants.ALIGN_RIGHT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1883
                    ta = "right";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1884
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1885
                case StyleConstants.ALIGN_CENTER:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1886
                    ta = "center";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1887
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1888
                case StyleConstants.ALIGN_JUSTIFIED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1889
                    ta = "justify";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1890
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1891
                default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1892
                    ta = "left";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1893
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1894
                return parseCssValue(ta);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1895
            } else if (key == StyleConstants.StrikeThrough) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1896
                if (value.equals(Boolean.TRUE)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1897
                    return parseCssValue("line-through");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1898
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1899
                return parseCssValue("");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1900
            } else if (key == StyleConstants.Superscript) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1901
                if (value.equals(Boolean.TRUE)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1902
                    return parseCssValue("super");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1903
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1904
                return parseCssValue("");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1905
            } else if (key == StyleConstants.Subscript) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1906
                if (value.equals(Boolean.TRUE)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1907
                    return parseCssValue("sub");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1908
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1909
                return parseCssValue("");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1910
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1911
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1912
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1913
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1914
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1915
         * Converts a CSS attribute value to a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1916
         * <code>StyleConstants</code> value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1917
         * If there is no conversion, returns <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1918
         * By default, there is no conversion.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1919
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1920
         * @param key the <code>StyleConstants</code> attribute
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1921
         * @return the <code>StyleConstants</code> attribute value that
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1922
         *   represents the CSS attribute value
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1923
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1924
        Object toStyleConstants(StyleConstants key, View v) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1925
            if (key == StyleConstants.Italic) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1926
                if (svalue.indexOf("italic") >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1927
                    return Boolean.TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1928
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1929
                return Boolean.FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1930
            } else if (key == StyleConstants.Underline) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1931
                if (svalue.indexOf("underline") >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1932
                    return Boolean.TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1933
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1934
                return Boolean.FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1935
            } else if (key == StyleConstants.Alignment) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1936
                if (svalue.equals("right")) {
25777
bb88947b6766 8049893: Replace uses of 'new Integer()' with appropriate alternative across client classes
prr
parents: 25208
diff changeset
  1937
                    return StyleConstants.ALIGN_RIGHT;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1938
                } else if (svalue.equals("center")) {
25777
bb88947b6766 8049893: Replace uses of 'new Integer()' with appropriate alternative across client classes
prr
parents: 25208
diff changeset
  1939
                    return StyleConstants.ALIGN_CENTER;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1940
                } else if  (svalue.equals("justify")) {
25777
bb88947b6766 8049893: Replace uses of 'new Integer()' with appropriate alternative across client classes
prr
parents: 25208
diff changeset
  1941
                    return StyleConstants.ALIGN_JUSTIFIED;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1942
                }
25777
bb88947b6766 8049893: Replace uses of 'new Integer()' with appropriate alternative across client classes
prr
parents: 25208
diff changeset
  1943
                return StyleConstants.ALIGN_LEFT;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1944
            } else if (key == StyleConstants.StrikeThrough) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1945
                if (svalue.indexOf("line-through") >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1946
                    return Boolean.TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1947
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1948
                return Boolean.FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1949
            } else if (key == StyleConstants.Superscript) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1950
                if (svalue.indexOf("super") >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1951
                    return Boolean.TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1952
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1953
                return Boolean.FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1954
            } else if (key == StyleConstants.Subscript) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1955
                if (svalue.indexOf("sub") >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1956
                    return Boolean.TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1957
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1958
                return Boolean.FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1959
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1960
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1961
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1962
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1963
        // Used by ViewAttributeSet
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1964
        boolean isItalic() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1965
            return (svalue.indexOf("italic") != -1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1966
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1967
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1968
        boolean isStrike() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1969
            return (svalue.indexOf("line-through") != -1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1970
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1971
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1972
        boolean isUnderline() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1973
            return (svalue.indexOf("underline") != -1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1974
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1975
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1976
        boolean isSub() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1977
            return (svalue.indexOf("sub") != -1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1978
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1979
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1980
        boolean isSup() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1981
            return (svalue.indexOf("sup") != -1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1982
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1983
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1984
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1985
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1986
     * Represents a value for the CSS.FONT_SIZE attribute.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1987
     * The binary format of the value can be one of several
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1988
     * types.  If the type is Float,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1989
     * the value is specified in terms of point or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1990
     * percentage, depending upon the ending of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1991
     * associated string.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1992
     * If the type is Integer, the value is specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1993
     * in terms of a size index.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1994
     */
23697
e556a715949f 8034169: Fix serial lint warnings in javax.swing
darcy
parents: 23010
diff changeset
  1995
    @SuppressWarnings("serial") // Same-version serialization only
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1996
    class FontSize extends CssValue {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1997
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1998
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1999
         * Returns the size in points.  This is ultimately
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2000
         * what we need for the purpose of creating/fetching
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2001
         * a Font object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2002
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2003
         * @param a the attribute set the value is being
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2004
         *  requested from.  We may need to walk up the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2005
         *  resolve hierarchy if it's relative.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2006
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2007
        int getValue(AttributeSet a, StyleSheet ss) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2008
            ss = getStyleSheet(ss);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2009
            if (index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2010
                // it's an index, translate from size table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2011
                return Math.round(getPointSize((int) value, ss));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2012
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2013
            else if (lu == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2014
                return Math.round(value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2015
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2016
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2017
                if (lu.type == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2018
                    boolean isW3CLengthUnits = (ss == null) ? false : ss.isW3CLengthUnits();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2019
                    return Math.round(lu.getValue(isW3CLengthUnits));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2020
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2021
                if (a != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2022
                    AttributeSet resolveParent = a.getResolveParent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2023
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2024
                    if (resolveParent != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2025
                        int pValue = StyleConstants.getFontSize(resolveParent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2026
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2027
                        float retValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2028
                        if (lu.type == 1 || lu.type == 3) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2029
                            retValue = lu.value * (float)pValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2030
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2031
                        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2032
                            retValue = lu.value + (float)pValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2033
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2034
                        return Math.round(retValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2035
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2036
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2037
                // a is null, or no resolve parent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2038
                return 12;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2039
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2040
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2041
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2042
        Object parseCssValue(String value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2043
            FontSize fs = new FontSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2044
            fs.svalue = value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2045
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2046
                if (value.equals("xx-small")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2047
                    fs.value = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2048
                    fs.index = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2049
                } else if (value.equals("x-small")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2050
                    fs.value = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2051
                    fs.index = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2052
                } else if (value.equals("small")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2053
                    fs.value = 3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2054
                    fs.index = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2055
                } else if (value.equals("medium")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2056
                    fs.value = 4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2057
                    fs.index = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2058
                } else if (value.equals("large")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2059
                    fs.value = 5;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2060
                    fs.index = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2061
                } else if (value.equals("x-large")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2062
                    fs.value = 6;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2063
                    fs.index = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2064
                } else if (value.equals("xx-large")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2065
                    fs.value = 7;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2066
                    fs.index = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2067
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2068
                    fs.lu = new LengthUnit(value, (short)1, 1f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2069
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2070
                // relative sizes, larger | smaller (adjust from parent by
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2071
                // 1.5 pixels)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2072
                // em, ex refer to parent sizes
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2073
                // lengths: pt, mm, cm, pc, in, px
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2074
                //          em (font height 3em would be 3 times font height)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2075
                //          ex (height of X)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2076
                // lengths are (+/-) followed by a number and two letter
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2077
                // unit identifier
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2078
            } catch (NumberFormatException nfe) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2079
                fs = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2080
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2081
            return fs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2082
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2083
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2084
        Object parseHtmlValue(String value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2085
            if ((value == null) || (value.length() == 0)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2086
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2087
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2088
            FontSize fs = new FontSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2089
            fs.svalue = value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2090
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2091
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2092
                /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2093
                 * relative sizes in the size attribute are relative
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2094
                 * to the <basefont>'s size.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2095
                 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2096
                int baseFontSize = getBaseFontSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2097
                if (value.charAt(0) == '+') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2098
                    int relSize = Integer.valueOf(value.substring(1)).intValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2099
                    fs.value = baseFontSize + relSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2100
                    fs.index = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2101
                } else if (value.charAt(0) == '-') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2102
                    int relSize = -Integer.valueOf(value.substring(1)).intValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2103
                    fs.value = baseFontSize + relSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2104
                    fs.index = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2105
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2106
                    fs.value = Integer.parseInt(value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2107
                    if (fs.value > 7) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2108
                        fs.value = 7;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2109
                    } else if (fs.value < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2110
                        fs.value = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2111
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2112
                    fs.index = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2113
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2114
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2115
            } catch (NumberFormatException nfe) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2116
                fs = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2117
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2118
            return fs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2119
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2120
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2121
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2122
         * Converts a <code>StyleConstants</code> attribute value to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2123
         * a CSS attribute value.  If there is no conversion
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2124
         * returns <code>null</code>.  By default, there is no conversion.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2125
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2126
         * @param key the <code>StyleConstants</code> attribute
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2127
         * @param value the value of a <code>StyleConstants</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2128
         *   attribute to be converted
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2129
         * @return the CSS value that represents the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2130
         *   <code>StyleConstants</code> value
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2131
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2132
        Object fromStyleConstants(StyleConstants key, Object value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2133
            if (value instanceof Number) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2134
                FontSize fs = new FontSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2135
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2136
                fs.value = getIndexOfSize(((Number)value).floatValue(), StyleSheet.sizeMapDefault);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2137
                fs.svalue = Integer.toString((int)fs.value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2138
                fs.index = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2139
                return fs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2140
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2141
            return parseCssValue(value.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2142
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2143
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2144
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2145
         * Converts a CSS attribute value to a <code>StyleConstants</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2146
         * value.  If there is no conversion, returns <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2147
         * By default, there is no conversion.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2148
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2149
         * @param key the <code>StyleConstants</code> attribute
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2150
         * @return the <code>StyleConstants</code> attribute value that
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2151
         *   represents the CSS attribute value
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2152
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2153
        Object toStyleConstants(StyleConstants key, View v) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2154
            if (v != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2155
                return Integer.valueOf(getValue(v.getAttributes(), null));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2156
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2157
            return Integer.valueOf(getValue(null, null));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2158
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2159
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2160
        float value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2161
        boolean index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2162
        LengthUnit lu;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2163
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2164
23697
e556a715949f 8034169: Fix serial lint warnings in javax.swing
darcy
parents: 23010
diff changeset
  2165
    @SuppressWarnings("serial") // Same-version serialization only
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2166
    static class FontFamily extends CssValue {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2167
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2168
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2169
         * Returns the font family to use.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2170
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2171
        String getValue() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2172
            return family;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2173
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2174
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2175
        Object parseCssValue(String value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2176
            int cIndex = value.indexOf(',');
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2177
            FontFamily ff = new FontFamily();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2178
            ff.svalue = value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2179
            ff.family = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2180
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2181
            if (cIndex == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2182
                setFontName(ff, value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2183
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2184
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2185
                boolean done = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2186
                int lastIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2187
                int length = value.length();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2188
                cIndex = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2189
                while (!done) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2190
                    // skip ws.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2191
                    while (cIndex < length &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2192
                           Character.isWhitespace(value.charAt(cIndex)))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2193
                        cIndex++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2194
                    // Find next ','
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2195
                    lastIndex = cIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2196
                    cIndex = value.indexOf(',', cIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2197
                    if (cIndex == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2198
                        cIndex = length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2199
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2200
                    if (lastIndex < length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2201
                        if (lastIndex != cIndex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2202
                            int lastCharIndex = cIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2203
                            if (cIndex > 0 && value.charAt(cIndex - 1) == ' '){
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2204
                                lastCharIndex--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2205
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2206
                            setFontName(ff, value.substring
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2207
                                        (lastIndex, lastCharIndex));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2208
                            done = (ff.family != null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2209
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2210
                        cIndex++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2211
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2212
                    else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2213
                        done = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2214
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2215
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2216
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2217
            if (ff.family == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2218
                ff.family = Font.SANS_SERIF;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2219
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2220
            return ff;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2221
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2222
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2223
        private void setFontName(FontFamily ff, String fontName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2224
            ff.family = fontName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2225
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2226
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2227
        Object parseHtmlValue(String value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2228
            // TBD
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2229
            return parseCssValue(value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2230
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2231
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2232
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2233
         * Converts a <code>StyleConstants</code> attribute value to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2234
         * a CSS attribute value.  If there is no conversion
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2235
         * returns <code>null</code>.  By default, there is no conversion.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2236
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2237
         * @param key the <code>StyleConstants</code> attribute
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2238
         * @param value the value of a <code>StyleConstants</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2239
         *   attribute to be converted
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2240
         * @return the CSS value that represents the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2241
         *   <code>StyleConstants</code> value
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2242
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2243
        Object fromStyleConstants(StyleConstants key, Object value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2244
            return parseCssValue(value.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2245
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2246
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2247
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2248
         * Converts a CSS attribute value to a <code>StyleConstants</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2249
         * value.  If there is no conversion, returns <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2250
         * By default, there is no conversion.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2251
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2252
         * @param key the <code>StyleConstants</code> attribute
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2253
         * @return the <code>StyleConstants</code> attribute value that
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2254
         *   represents the CSS attribute value
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2255
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2256
        Object toStyleConstants(StyleConstants key, View v) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2257
            return family;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2258
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2259
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2260
        String family;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2261
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2262
23697
e556a715949f 8034169: Fix serial lint warnings in javax.swing
darcy
parents: 23010
diff changeset
  2263
    @SuppressWarnings("serial") // Same-version serialization only
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2264
    static class FontWeight extends CssValue {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2265
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2266
        int getValue() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2267
            return weight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2268
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2269
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2270
        Object parseCssValue(String value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2271
            FontWeight fw = new FontWeight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2272
            fw.svalue = value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2273
            if (value.equals("bold")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2274
                fw.weight = 700;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2275
            } else if (value.equals("normal")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2276
                fw.weight = 400;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2277
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2278
                // PENDING(prinz) add support for relative values
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2279
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2280
                    fw.weight = Integer.parseInt(value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2281
                } catch (NumberFormatException nfe) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2282
                    fw = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2283
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2284
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2285
            return fw;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2286
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2287
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2288
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2289
         * Converts a <code>StyleConstants</code> attribute value to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2290
         * a CSS attribute value.  If there is no conversion
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2291
         * returns <code>null</code>.  By default, there is no conversion.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2292
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2293
         * @param key the <code>StyleConstants</code> attribute
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2294
         * @param value the value of a <code>StyleConstants</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2295
         *   attribute to be converted
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2296
         * @return the CSS value that represents the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2297
         *   <code>StyleConstants</code> value
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2298
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2299
        Object fromStyleConstants(StyleConstants key, Object value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2300
            if (value.equals(Boolean.TRUE)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2301
                return parseCssValue("bold");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2302
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2303
            return parseCssValue("normal");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2304
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2305
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2306
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2307
         * Converts a CSS attribute value to a <code>StyleConstants</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2308
         * value.  If there is no conversion, returns <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2309
         * By default, there is no conversion.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2310
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2311
         * @param key the <code>StyleConstants</code> attribute
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2312
         * @return the <code>StyleConstants</code> attribute value that
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2313
         *   represents the CSS attribute value
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2314
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2315
        Object toStyleConstants(StyleConstants key, View v) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2316
            return (weight > 500) ? Boolean.TRUE : Boolean.FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2317
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2318
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2319
        boolean isBold() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2320
            return (weight > 500);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2321
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2322
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2323
        int weight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2324
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2325
23697
e556a715949f 8034169: Fix serial lint warnings in javax.swing
darcy
parents: 23010
diff changeset
  2326
    @SuppressWarnings("serial") // Same-version serialization only
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2327
    static class ColorValue extends CssValue {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2328
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2329
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2330
         * Returns the color to use.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2331
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2332
        Color getValue() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2333
            return c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2334
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2335
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2336
        Object parseCssValue(String value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2337
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2338
            Color c = stringToColor(value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2339
            if (c != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2340
                ColorValue cv = new ColorValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2341
                cv.svalue = value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2342
                cv.c = c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2343
                return cv;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2344
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2345
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2346
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2347
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2348
        Object parseHtmlValue(String value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2349
            return parseCssValue(value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2350
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2351
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2352
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2353
         * Converts a <code>StyleConstants</code> attribute value to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2354
         * a CSS attribute value.  If there is no conversion
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2355
         * returns <code>null</code>.  By default, there is no conversion.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2356
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2357
         * @param key the <code>StyleConstants</code> attribute
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2358
         * @param value the value of a <code>StyleConstants</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2359
         *   attribute to be converted
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2360
         * @return the CSS value that represents the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2361
         *   <code>StyleConstants</code> value
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2362
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2363
        Object fromStyleConstants(StyleConstants key, Object value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2364
            ColorValue colorValue = new ColorValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2365
            colorValue.c = (Color)value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2366
            colorValue.svalue = colorToHex(colorValue.c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2367
            return colorValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2368
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2369
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2370
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2371
         * Converts a CSS attribute value to a <code>StyleConstants</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2372
         * value.  If there is no conversion, returns <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2373
         * By default, there is no conversion.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2374
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2375
         * @param key the <code>StyleConstants</code> attribute
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2376
         * @return the <code>StyleConstants</code> attribute value that
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2377
         *   represents the CSS attribute value
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2378
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2379
        Object toStyleConstants(StyleConstants key, View v) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2380
            return c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2381
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2382
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2383
        Color c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2384
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2385
23697
e556a715949f 8034169: Fix serial lint warnings in javax.swing
darcy
parents: 23010
diff changeset
  2386
    @SuppressWarnings("serial") // Same-version serialization only
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2387
    static class BorderStyle extends CssValue {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2388
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2389
        CSS.Value getValue() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2390
            return style;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2391
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2392
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2393
        Object parseCssValue(String value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2394
            CSS.Value cssv = CSS.getValue(value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2395
            if (cssv != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2396
                if ((cssv == CSS.Value.INSET) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2397
                    (cssv == CSS.Value.OUTSET) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2398
                    (cssv == CSS.Value.NONE) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2399
                    (cssv == CSS.Value.DOTTED) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2400
                    (cssv == CSS.Value.DASHED) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2401
                    (cssv == CSS.Value.SOLID) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2402
                    (cssv == CSS.Value.DOUBLE) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2403
                    (cssv == CSS.Value.GROOVE) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2404
                    (cssv == CSS.Value.RIDGE)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2405
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2406
                    BorderStyle bs = new BorderStyle();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2407
                    bs.svalue = value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2408
                    bs.style = cssv;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2409
                    return bs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2410
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2411
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2412
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2413
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2414
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2415
        private void writeObject(java.io.ObjectOutputStream s)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2416
                     throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2417
            s.defaultWriteObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2418
            if (style == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2419
                s.writeObject(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2420
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2421
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2422
                s.writeObject(style.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2423
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2424
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2425
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2426
        private void readObject(ObjectInputStream s)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2427
                throws ClassNotFoundException, IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2428
            s.defaultReadObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2429
            Object value = s.readObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2430
            if (value != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2431
                style = CSS.getValue((String)value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2432
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2433
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2434
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2435
        // CSS.Values are static, don't archive it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2436
        transient private CSS.Value style;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2437
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2438
23697
e556a715949f 8034169: Fix serial lint warnings in javax.swing
darcy
parents: 23010
diff changeset
  2439
    @SuppressWarnings("serial") // Same-version serialization only
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2440
    static class LengthValue extends CssValue {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2441
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2442
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2443
         * if this length value may be negative.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2444
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2445
        boolean mayBeNegative;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2446
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2447
        LengthValue() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2448
            this(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2449
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2450
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2451
        LengthValue(boolean mayBeNegative) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2452
            this.mayBeNegative = mayBeNegative;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2453
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2454
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2455
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2456
         * Returns the length (span) to use.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2457
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2458
        float getValue() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2459
            return getValue(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2460
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2461
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2462
        float getValue(boolean isW3CLengthUnits) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2463
            return getValue(0, isW3CLengthUnits);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2464
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2465
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2466
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2467
         * Returns the length (span) to use. If the value represents
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2468
         * a percentage, it is scaled based on <code>currentValue</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2469
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2470
        float getValue(float currentValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2471
            return getValue(currentValue, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2472
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2473
        float getValue(float currentValue, boolean isW3CLengthUnits) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2474
            if (percentage) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2475
                return span * currentValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2476
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2477
            return LengthUnit.getValue(span, units, isW3CLengthUnits);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2478
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2479
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2480
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2481
         * Returns true if the length represents a percentage of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2482
         * containing box.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2483
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2484
        boolean isPercentage() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2485
            return percentage;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2486
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2487
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2488
        Object parseCssValue(String value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2489
            LengthValue lv;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2490
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2491
                // Assume pixels
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2492
                float absolute = Float.valueOf(value).floatValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2493
                lv = new LengthValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2494
                lv.span = absolute;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2495
            } catch (NumberFormatException nfe) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2496
                // Not pixels, use LengthUnit
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2497
                LengthUnit lu = new LengthUnit(value,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2498
                                               LengthUnit.UNINITALIZED_LENGTH,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2499
                                               0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2500
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2501
                // PENDING: currently, we only support absolute values and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2502
                // percentages.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2503
                switch (lu.type) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2504
                case 0:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2505
                    // Absolute
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2506
                    lv = new LengthValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2507
                    lv.span =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2508
                        (mayBeNegative) ? lu.value : Math.max(0, lu.value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2509
                    lv.units = lu.units;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2510
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2511
                case 1:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2512
                    // %
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2513
                    lv = new LengthValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2514
                    lv.span = Math.max(0, Math.min(1, lu.value));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2515
                    lv.percentage = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2516
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2517
                default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2518
                    return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2519
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2520
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2521
            lv.svalue = value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2522
            return lv;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2523
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2524
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2525
        Object parseHtmlValue(String value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2526
            if (value.equals(HTML.NULL_ATTRIBUTE_VALUE)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2527
                value = "1";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2528
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2529
            return parseCssValue(value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2530
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2531
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2532
         * Converts a <code>StyleConstants</code> attribute value to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2533
         * a CSS attribute value.  If there is no conversion,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2534
         * returns <code>null</code>.  By default, there is no conversion.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2535
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2536
         * @param key the <code>StyleConstants</code> attribute
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2537
         * @param value the value of a <code>StyleConstants</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2538
         *   attribute to be converted
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2539
         * @return the CSS value that represents the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2540
         *   <code>StyleConstants</code> value
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2541
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2542
        Object fromStyleConstants(StyleConstants key, Object value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2543
            LengthValue v = new LengthValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2544
            v.svalue = value.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2545
            v.span = ((Float)value).floatValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2546
            return v;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2547
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2548
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2549
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2550
         * Converts a CSS attribute value to a <code>StyleConstants</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2551
         * value.  If there is no conversion, returns <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2552
         * By default, there is no conversion.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2553
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2554
         * @param key the <code>StyleConstants</code> attribute
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2555
         * @return the <code>StyleConstants</code> attribute value that
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2556
         *   represents the CSS attribute value
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2557
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2558
        Object toStyleConstants(StyleConstants key, View v) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2559
            return new Float(getValue(false));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2560
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2561
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2562
        /** If true, span is a percentage value, and that to determine
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2563
         * the length another value needs to be passed in. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2564
        boolean percentage;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2565
        /** Either the absolute value (percentage == false) or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2566
         * a percentage value. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2567
        float span;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2568
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2569
        String units = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2570
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2571
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2572
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2573
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2574
     * BorderWidthValue is used to model BORDER_XXX_WIDTH and adds support
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2575
     * for the thin/medium/thick values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2576
     */
23697
e556a715949f 8034169: Fix serial lint warnings in javax.swing
darcy
parents: 23010
diff changeset
  2577
    @SuppressWarnings("serial") // Same-version serialization only
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2578
    static class BorderWidthValue extends LengthValue {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2579
        BorderWidthValue(String svalue, int index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2580
            this.svalue = svalue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2581
            span = values[index];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2582
            percentage = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2583
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2584
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2585
        Object parseCssValue(String value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2586
            if (value != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2587
                if (value.equals("thick")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2588
                    return new BorderWidthValue(value, 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2589
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2590
                else if (value.equals("medium")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2591
                    return new BorderWidthValue(value, 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2592
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2593
                else if (value.equals("thin")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2594
                    return new BorderWidthValue(value, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2595
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2596
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2597
            // Assume its a length.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2598
            return super.parseCssValue(value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2599
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2600
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2601
        Object parseHtmlValue(String value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2602
            if (value == HTML.NULL_ATTRIBUTE_VALUE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2603
                return parseCssValue("medium");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2604
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2605
            return parseCssValue(value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2606
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2607
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2608
        /** Values used to represent border width. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2609
        private static final float[] values = { 1, 2, 4 };
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2610
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2611
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2612
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2613
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2614
     * Handles uniquing of CSS values, like lists, and background image
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2615
     * repeating.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2616
     */
23697
e556a715949f 8034169: Fix serial lint warnings in javax.swing
darcy
parents: 23010
diff changeset
  2617
    @SuppressWarnings("serial") // Same-version serialization only
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2618
    static class CssValueMapper extends CssValue {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2619
        Object parseCssValue(String value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2620
            Object retValue = cssValueToInternalValueMap.get(value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2621
            if (retValue == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2622
                retValue = cssValueToInternalValueMap.get(value.toLowerCase());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2623
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2624
            return retValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2625
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2626
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2627
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2628
        Object parseHtmlValue(String value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2629
            Object retValue = htmlValueToCssValueMap.get(value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2630
            if (retValue == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2631
                retValue = htmlValueToCssValueMap.get(value.toLowerCase());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2632
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2633
            return retValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2634
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2635
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2636
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2637
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2638
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2639
     * Used for background images, to represent the position.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2640
     */
23697
e556a715949f 8034169: Fix serial lint warnings in javax.swing
darcy
parents: 23010
diff changeset
  2641
    @SuppressWarnings("serial") // Same-version serialization only
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2642
    static class BackgroundPosition extends CssValue {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2643
        float horizontalPosition;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2644
        float verticalPosition;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2645
        // bitmask: bit 0, horizontal relative, bit 1 horizontal relative to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2646
        // font size, 2 vertical relative to size, 3 vertical relative to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2647
        // font size.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2648
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2649
        short relative;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2650
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2651
        Object parseCssValue(String value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2652
            // 'top left' and 'left top' both mean the same as '0% 0%'.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2653
            // 'top', 'top center' and 'center top' mean the same as '50% 0%'.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2654
            // 'right top' and 'top right' mean the same as '100% 0%'.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2655
            // 'left', 'left center' and 'center left' mean the same as
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2656
            //        '0% 50%'.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2657
            // 'center' and 'center center' mean the same as '50% 50%'.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2658
            // 'right', 'right center' and 'center right' mean the same as
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2659
            //        '100% 50%'.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2660
            // 'bottom left' and 'left bottom' mean the same as '0% 100%'.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2661
            // 'bottom', 'bottom center' and 'center bottom' mean the same as
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2662
            //        '50% 100%'.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2663
            // 'bottom right' and 'right bottom' mean the same as '100% 100%'.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2664
            String[]  strings = CSS.parseStrings(value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2665
            int count = strings.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2666
            BackgroundPosition bp = new BackgroundPosition();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2667
            bp.relative = 5;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2668
            bp.svalue = value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2669
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2670
            if (count > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2671
                // bit 0 for vert, 1 hor, 2 for center
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2672
                short found = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2673
                int index = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2674
                while (index < count) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2675
                    // First, check for keywords
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2676
                    String string = strings[index++];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2677
                    if (string.equals("center")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2678
                        found |= 4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2679
                        continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2680
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2681
                    else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2682
                        if ((found & 1) == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2683
                            if (string.equals("top")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2684
                                found |= 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2685
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2686
                            else if (string.equals("bottom")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2687
                                found |= 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2688
                                bp.verticalPosition = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2689
                                continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2690
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2691
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2692
                        if ((found & 2) == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2693
                            if (string.equals("left")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2694
                                found |= 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2695
                                bp.horizontalPosition = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2696
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2697
                            else if (string.equals("right")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2698
                                found |= 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2699
                                bp.horizontalPosition = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2700
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2701
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2702
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2703
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2704
                if (found != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2705
                    if ((found & 1) == 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2706
                        if ((found & 2) == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2707
                            // vert and no horiz.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2708
                            bp.horizontalPosition = .5f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2709
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2710
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2711
                    else if ((found & 2) == 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2712
                        // horiz and no vert.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2713
                        bp.verticalPosition = .5f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2714
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2715
                    else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2716
                        // no horiz, no vert, but center
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2717
                        bp.horizontalPosition = bp.verticalPosition = .5f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2718
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2719
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2720
                else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2721
                    // Assume lengths
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2722
                    LengthUnit lu = new LengthUnit(strings[0], (short)0, 0f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2723
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2724
                    if (lu.type == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2725
                        bp.horizontalPosition = lu.value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2726
                        bp.relative = (short)(1 ^ bp.relative);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2727
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2728
                    else if (lu.type == 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2729
                        bp.horizontalPosition = lu.value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2730
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2731
                    else if (lu.type == 3) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2732
                        bp.horizontalPosition = lu.value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2733
                        bp.relative = (short)((1 ^ bp.relative) | 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2734
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2735
                    if (count > 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2736
                        lu = new LengthUnit(strings[1], (short)0, 0f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2737
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2738
                        if (lu.type == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2739
                            bp.verticalPosition = lu.value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2740
                            bp.relative = (short)(4 ^ bp.relative);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2741
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2742
                        else if (lu.type == 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2743
                            bp.verticalPosition = lu.value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2744
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2745
                        else if (lu.type == 3) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2746
                            bp.verticalPosition = lu.value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2747
                            bp.relative = (short)((4 ^ bp.relative) | 8);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2748
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2749
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2750
                    else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2751
                        bp.verticalPosition = .5f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2752
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2753
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2754
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2755
            return bp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2756
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2757
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2758
        boolean isHorizontalPositionRelativeToSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2759
            return ((relative & 1) == 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2760
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2761
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2762
        boolean isHorizontalPositionRelativeToFontSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2763
            return ((relative & 2) == 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2764
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2765
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2766
        float getHorizontalPosition() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2767
            return horizontalPosition;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2768
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2769
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2770
        boolean isVerticalPositionRelativeToSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2771
            return ((relative & 4) == 4);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2772
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2773
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2774
        boolean isVerticalPositionRelativeToFontSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2775
            return ((relative & 8) == 8);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2776
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2777
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2778
        float getVerticalPosition() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2779
            return verticalPosition;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2780
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2781
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2782
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2783
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2784
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2785
     * Used for BackgroundImages.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2786
     */
23697
e556a715949f 8034169: Fix serial lint warnings in javax.swing
darcy
parents: 23010
diff changeset
  2787
    @SuppressWarnings("serial") // Same-version serialization only
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2788
    static class BackgroundImage extends CssValue {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2789
        private boolean    loadedImage;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2790
        private ImageIcon  image;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2791
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2792
        Object parseCssValue(String value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2793
            BackgroundImage retValue = new BackgroundImage();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2794
            retValue.svalue = value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2795
            return retValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2796
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2797
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2798
        Object parseHtmlValue(String value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2799
            return parseCssValue(value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2800
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2801
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2802
        // PENDING: this base is wrong for linked style sheets.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2803
        ImageIcon getImage(URL base) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2804
            if (!loadedImage) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2805
                synchronized(this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2806
                    if (!loadedImage) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2807
                        URL url = CSS.getURL(base, svalue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2808
                        loadedImage = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2809
                        if (url != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2810
                            image = new ImageIcon();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2811
                            Image tmpImg = Toolkit.getDefaultToolkit().createImage(url);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2812
                            if (tmpImg != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2813
                                image.setImage(tmpImg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2814
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2815
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2816
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2817
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2818
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2819
            return image;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2820
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2821
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2822
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2823
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2824
     * Parses a length value, this is used internally, and never added
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2825
     * to an AttributeSet or returned to the developer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2826
     */
23697
e556a715949f 8034169: Fix serial lint warnings in javax.swing
darcy
parents: 23010
diff changeset
  2827
    @SuppressWarnings("serial") // Same-version serialization only
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2828
    static class LengthUnit implements Serializable {
1287
a04aca99c77a 6722802: Code improvement and warnings removing from the javax.swing.text package
rupashka
parents: 438
diff changeset
  2829
        static Hashtable<String, Float> lengthMapping = new Hashtable<String, Float>(6);
a04aca99c77a 6722802: Code improvement and warnings removing from the javax.swing.text package
rupashka
parents: 438
diff changeset
  2830
        static Hashtable<String, Float> w3cLengthMapping = new Hashtable<String, Float>(6);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2831
        static {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2832
            lengthMapping.put("pt", new Float(1f));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2833
            // Not sure about 1.3, determined by experiementation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2834
            lengthMapping.put("px", new Float(1.3f));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2835
            lengthMapping.put("mm", new Float(2.83464f));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2836
            lengthMapping.put("cm", new Float(28.3464f));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2837
            lengthMapping.put("pc", new Float(12f));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2838
            lengthMapping.put("in", new Float(72f));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2839
            int res = 72;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2840
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2841
                res = Toolkit.getDefaultToolkit().getScreenResolution();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2842
            } catch (HeadlessException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2843
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2844
            // mapping according to the CSS2 spec
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2845
            w3cLengthMapping.put("pt", new Float(res/72f));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2846
            w3cLengthMapping.put("px", new Float(1f));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2847
            w3cLengthMapping.put("mm", new Float(res/25.4f));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2848
            w3cLengthMapping.put("cm", new Float(res/2.54f));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2849
            w3cLengthMapping.put("pc", new Float(res/6f));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2850
            w3cLengthMapping.put("in", new Float(res));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2851
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2852
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2853
        LengthUnit(String value, short defaultType, float defaultValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2854
            parse(value, defaultType, defaultValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2855
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2856
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2857
        void parse(String value, short defaultType, float defaultValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2858
            type = defaultType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2859
            this.value = defaultValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2860
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2861
            int length = value.length();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2862
            if (length > 0 && value.charAt(length - 1) == '%') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2863
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2864
                    this.value = Float.valueOf(value.substring(0, length - 1)).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2865
                                               floatValue() / 100.0f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2866
                    type = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2867
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2868
                catch (NumberFormatException nfe) { }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2869
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2870
            if (length >= 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2871
                units = value.substring(length - 2, length);
1287
a04aca99c77a 6722802: Code improvement and warnings removing from the javax.swing.text package
rupashka
parents: 438
diff changeset
  2872
                Float scale = lengthMapping.get(units);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2873
                if (scale != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2874
                    try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2875
                        this.value = Float.valueOf(value.substring(0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2876
                               length - 2)).floatValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2877
                        type = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2878
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2879
                    catch (NumberFormatException nfe) { }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2880
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2881
                else if (units.equals("em") ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2882
                         units.equals("ex")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2883
                    try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2884
                        this.value = Float.valueOf(value.substring(0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2885
                                      length - 2)).floatValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2886
                        type = 3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2887
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2888
                    catch (NumberFormatException nfe) { }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2889
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2890
                else if (value.equals("larger")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2891
                    this.value = 2f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2892
                    type = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2893
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2894
                else if (value.equals("smaller")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2895
                    this.value = -2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2896
                    type = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2897
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2898
                else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2899
                    // treat like points.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2900
                    try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2901
                        this.value = Float.valueOf(value).floatValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2902
                        type = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2903
                    } catch (NumberFormatException nfe) {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2904
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2905
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2906
            else if (length > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2907
                // treat like points.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2908
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2909
                    this.value = Float.valueOf(value).floatValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2910
                    type = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2911
                } catch (NumberFormatException nfe) {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2912
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2913
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2914
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2915
        float getValue(boolean w3cLengthUnits) {
1287
a04aca99c77a 6722802: Code improvement and warnings removing from the javax.swing.text package
rupashka
parents: 438
diff changeset
  2916
            Hashtable<String, Float> mapping = (w3cLengthUnits) ? w3cLengthMapping : lengthMapping;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2917
            float scale = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2918
            if (units != null) {
1287
a04aca99c77a 6722802: Code improvement and warnings removing from the javax.swing.text package
rupashka
parents: 438
diff changeset
  2919
                Float scaleFloat = mapping.get(units);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2920
                if (scaleFloat != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2921
                    scale = scaleFloat.floatValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2922
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2923
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2924
            return this.value * scale;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2925
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2926
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2927
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2928
        static float getValue(float value, String units, Boolean w3cLengthUnits) {
1287
a04aca99c77a 6722802: Code improvement and warnings removing from the javax.swing.text package
rupashka
parents: 438
diff changeset
  2929
            Hashtable<String, Float> mapping = (w3cLengthUnits) ? w3cLengthMapping : lengthMapping;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2930
            float scale = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2931
            if (units != null) {
1287
a04aca99c77a 6722802: Code improvement and warnings removing from the javax.swing.text package
rupashka
parents: 438
diff changeset
  2932
                Float scaleFloat = mapping.get(units);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2933
                if (scaleFloat != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2934
                    scale = scaleFloat.floatValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2935
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2936
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2937
            return value * scale;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2938
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2939
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2940
        public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2941
            return type + " " + value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2942
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2943
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2944
        // 0 - value indicates real value
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2945
        // 1 - % value, value relative to depends upon key.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2946
        //     50% will have a value = .5
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2947
        // 2 - add value to parent value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2948
        // 3 - em/ex relative to font size of element (except for
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2949
        //     font-size, which is relative to parent).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2950
        short type;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2951
        float value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2952
        String units = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2953
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2954
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2955
        static final short UNINITALIZED_LENGTH = (short)10;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2956
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2957
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2958
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2959
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2960
     * Class used to parse font property. The font property is shorthand
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2961
     * for the other font properties. This expands the properties, placing
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2962
     * them in the attributeset.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2963
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2964
    static class ShorthandFontParser {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2965
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2966
         * Parses the shorthand font string <code>value</code>, placing the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2967
         * result in <code>attr</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2968
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2969
        static void parseShorthandFont(CSS css, String value,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2970
                                       MutableAttributeSet attr) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2971
            // font is of the form:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2972
            // [ <font-style> || <font-variant> || <font-weight> ]? <font-size>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2973
            //   [ / <line-height> ]? <font-family>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2974
            String[]   strings = CSS.parseStrings(value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2975
            int        count = strings.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2976
            int        index = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2977
            // bitmask, 1 for style, 2 for variant, 3 for weight
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2978
            short      found = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2979
            int        maxC = Math.min(3, count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2980
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2981
            // Check for font-style font-variant font-weight
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2982
            while (index < maxC) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2983
                if ((found & 1) == 0 && isFontStyle(strings[index])) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2984
                    css.addInternalCSSValue(attr, CSS.Attribute.FONT_STYLE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2985
                                            strings[index++]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2986
                    found |= 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2987
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2988
                else if ((found & 2) == 0 && isFontVariant(strings[index])) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2989
                    css.addInternalCSSValue(attr, CSS.Attribute.FONT_VARIANT,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2990
                                            strings[index++]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2991
                    found |= 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2992
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2993
                else if ((found & 4) == 0 && isFontWeight(strings[index])) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2994
                    css.addInternalCSSValue(attr, CSS.Attribute.FONT_WEIGHT,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2995
                                            strings[index++]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2996
                    found |= 4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2997
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2998
                else if (strings[index].equals("normal")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2999
                    index++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3000
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3001
                else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3002
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3003
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3004
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3005
            if ((found & 1) == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3006
                css.addInternalCSSValue(attr, CSS.Attribute.FONT_STYLE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3007
                                        "normal");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3008
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3009
            if ((found & 2) == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3010
                css.addInternalCSSValue(attr, CSS.Attribute.FONT_VARIANT,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3011
                                        "normal");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3012
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3013
            if ((found & 4) == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3014
                css.addInternalCSSValue(attr, CSS.Attribute.FONT_WEIGHT,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3015
                                        "normal");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3016
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3017
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3018
            // string at index should be the font-size
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3019
            if (index < count) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3020
                String fontSize = strings[index];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3021
                int slashIndex = fontSize.indexOf('/');
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3022
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3023
                if (slashIndex != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3024
                    fontSize = fontSize.substring(0, slashIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3025
                    strings[index] = strings[index].substring(slashIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3026
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3027
                else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3028
                    index++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3029
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3030
                css.addInternalCSSValue(attr, CSS.Attribute.FONT_SIZE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3031
                                        fontSize);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3032
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3033
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3034
                css.addInternalCSSValue(attr, CSS.Attribute.FONT_SIZE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3035
                                        "medium");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3036
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3037
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3038
            // Check for line height
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3039
            if (index < count && strings[index].startsWith("/")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3040
                String lineHeight = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3041
                if (strings[index].equals("/")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3042
                    if (++index < count) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3043
                        lineHeight = strings[index++];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3044
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3045
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3046
                else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3047
                    lineHeight = strings[index++].substring(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3048
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3049
                // line height
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3050
                if (lineHeight != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3051
                    css.addInternalCSSValue(attr, CSS.Attribute.LINE_HEIGHT,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3052
                                            lineHeight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3053
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3054
                else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3055
                    css.addInternalCSSValue(attr, CSS.Attribute.LINE_HEIGHT,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3056
                                            "normal");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3057
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3058
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3059
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3060
                css.addInternalCSSValue(attr, CSS.Attribute.LINE_HEIGHT,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3061
                                        "normal");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3062
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3063
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3064
            // remainder of strings are font-family
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3065
            if (index < count) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3066
                String family = strings[index++];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3067
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3068
                while (index < count) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3069
                    family += " " + strings[index++];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3070
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3071
                css.addInternalCSSValue(attr, CSS.Attribute.FONT_FAMILY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3072
                                        family);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3073
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3074
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3075
                css.addInternalCSSValue(attr, CSS.Attribute.FONT_FAMILY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3076
                                        Font.SANS_SERIF);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3077
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3078
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3079
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3080
        private static boolean isFontStyle(String string) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3081
            return (string.equals("italic") ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3082
                    string.equals("oblique"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3083
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3084
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3085
        private static boolean isFontVariant(String string) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3086
            return (string.equals("small-caps"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3087
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3088
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3089
        private static boolean isFontWeight(String string) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3090
            if (string.equals("bold") || string.equals("bolder") ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3091
                string.equals("italic") || string.equals("lighter")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3092
                return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3093
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3094
            // test for 100-900
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3095
            return (string.length() == 3 &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3096
                    string.charAt(0) >= '1' && string.charAt(0) <= '9' &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3097
                    string.charAt(1) == '0' && string.charAt(2) == '0');
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3098
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3099
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3100
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3101
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3102
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3103
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3104
     * Parses the background property into its intrinsic values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3105
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3106
    static class ShorthandBackgroundParser {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3107
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3108
         * Parses the shorthand font string <code>value</code>, placing the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3109
         * result in <code>attr</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3110
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3111
        static void parseShorthandBackground(CSS css, String value,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3112
                                             MutableAttributeSet attr) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3113
            String[] strings = parseStrings(value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3114
            int count = strings.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3115
            int index = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3116
            // bitmask: 0 for image, 1 repeat, 2 attachment, 3 position,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3117
            //          4 color
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3118
            short found = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3119
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3120
            while (index < count) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3121
                String string = strings[index++];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3122
                if ((found & 1) == 0 && isImage(string)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3123
                    css.addInternalCSSValue(attr, CSS.Attribute.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3124
                                            BACKGROUND_IMAGE, string);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3125
                    found |= 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3126
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3127
                else if ((found & 2) == 0 && isRepeat(string)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3128
                    css.addInternalCSSValue(attr, CSS.Attribute.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3129
                                            BACKGROUND_REPEAT, string);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3130
                    found |= 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3131
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3132
                else if ((found & 4) == 0 && isAttachment(string)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3133
                    css.addInternalCSSValue(attr, CSS.Attribute.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3134
                                            BACKGROUND_ATTACHMENT, string);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3135
                    found |= 4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3136
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3137
                else if ((found & 8) == 0 && isPosition(string)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3138
                    if (index < count && isPosition(strings[index])) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3139
                        css.addInternalCSSValue(attr, CSS.Attribute.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3140
                                                BACKGROUND_POSITION,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3141
                                                string + " " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3142
                                                strings[index++]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3143
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3144
                    else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3145
                        css.addInternalCSSValue(attr, CSS.Attribute.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3146
                                                BACKGROUND_POSITION, string);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3147
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3148
                    found |= 8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3149
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3150
                else if ((found & 16) == 0 && isColor(string)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3151
                    css.addInternalCSSValue(attr, CSS.Attribute.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3152
                                            BACKGROUND_COLOR, string);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3153
                    found |= 16;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3154
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3155
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3156
            if ((found & 1) == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3157
                css.addInternalCSSValue(attr, CSS.Attribute.BACKGROUND_IMAGE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3158
                                        null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3159
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3160
            if ((found & 2) == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3161
                css.addInternalCSSValue(attr, CSS.Attribute.BACKGROUND_REPEAT,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3162
                                        "repeat");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3163
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3164
            if ((found & 4) == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3165
                css.addInternalCSSValue(attr, CSS.Attribute.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3166
                                        BACKGROUND_ATTACHMENT, "scroll");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3167
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3168
            if ((found & 8) == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3169
                css.addInternalCSSValue(attr, CSS.Attribute.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3170
                                        BACKGROUND_POSITION, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3171
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3172
            // Currently, there is no good way to express this.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3173
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3174
            if ((found & 16) == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3175
                css.addInternalCSSValue(attr, CSS.Attribute.BACKGROUND_COLOR,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3176
                                        null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3177
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3178
            */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3179
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3180
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3181
        static boolean isImage(String string) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3182
            return (string.startsWith("url(") && string.endsWith(")"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3183
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3184
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3185
        static boolean isRepeat(String string) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3186
            return (string.equals("repeat-x") || string.equals("repeat-y") ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3187
                    string.equals("repeat") || string.equals("no-repeat"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3188
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3189
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3190
        static boolean isAttachment(String string) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3191
            return (string.equals("fixed") || string.equals("scroll"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3192
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3193
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3194
        static boolean isPosition(String string) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3195
            return (string.equals("top") || string.equals("bottom") ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3196
                    string.equals("left") || string.equals("right") ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3197
                    string.equals("center") ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3198
                    (string.length() > 0 &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3199
                     Character.isDigit(string.charAt(0))));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3200
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3201
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3202
        static boolean isColor(String string) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3203
            return (CSS.stringToColor(string) != null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3204
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3205
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3206
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3207
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3208
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3209
     * Used to parser margin and padding.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3210
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3211
    static class ShorthandMarginParser {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3212
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3213
         * Parses the shorthand margin/padding/border string
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3214
         * <code>value</code>, placing the result in <code>attr</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3215
         * <code>names</code> give the 4 instrinsic property names.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3216
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3217
        static void parseShorthandMargin(CSS css, String value,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3218
                                         MutableAttributeSet attr,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3219
                                         CSS.Attribute[] names) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3220
            String[] strings = parseStrings(value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3221
            int count = strings.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3222
            int index = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3223
            switch (count) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3224
            case 0:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3225
                // empty string
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3226
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3227
            case 1:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3228
                // Identifies all values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3229
                for (int counter = 0; counter < 4; counter++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3230
                    css.addInternalCSSValue(attr, names[counter], strings[0]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3231
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3232
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3233
            case 2:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3234
                // 0 & 2 = strings[0], 1 & 3 = strings[1]
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3235
                css.addInternalCSSValue(attr, names[0], strings[0]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3236
                css.addInternalCSSValue(attr, names[2], strings[0]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3237
                css.addInternalCSSValue(attr, names[1], strings[1]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3238
                css.addInternalCSSValue(attr, names[3], strings[1]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3239
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3240
            case 3:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3241
                css.addInternalCSSValue(attr, names[0], strings[0]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3242
                css.addInternalCSSValue(attr, names[1], strings[1]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3243
                css.addInternalCSSValue(attr, names[2], strings[2]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3244
                css.addInternalCSSValue(attr, names[3], strings[1]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3245
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3246
            default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3247
                for (int counter = 0; counter < 4; counter++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3248
                    css.addInternalCSSValue(attr, names[counter],
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3249
                                            strings[counter]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3250
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3251
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3252
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3253
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3254
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3255
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3256
    static class ShorthandBorderParser {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3257
        static Attribute[] keys = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3258
            Attribute.BORDER_TOP, Attribute.BORDER_RIGHT,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3259
            Attribute.BORDER_BOTTOM, Attribute.BORDER_LEFT,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3260
        };
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3261
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3262
        static void parseShorthandBorder(MutableAttributeSet attributes,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3263
                                            CSS.Attribute key, String value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3264
            Object[] parts = new Object[CSSBorder.PARSERS.length];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3265
            String[] strings = parseStrings(value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3266
            for (String s : strings) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3267
                boolean valid = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3268
                for (int i = 0; i < parts.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3269
                    Object v = CSSBorder.PARSERS[i].parseCssValue(s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3270
                    if (v != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3271
                        if (parts[i] == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3272
                            parts[i] = v;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3273
                            valid = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3274
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3275
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3276
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3277
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3278
                if (!valid) {
21278
ef8a3a2a72f2 8022746: List of spelling errors in API doc
malenkov
parents: 20158
diff changeset
  3279
                    // Part is non-parseable or occurred more than once.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3280
                    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3281
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3282
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3283
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3284
            // Unspecified parts get default values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3285
            for (int i = 0; i < parts.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3286
                if (parts[i] == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3287
                    parts[i] = CSSBorder.DEFAULTS[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3288
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3289
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3290
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3291
            // Dispatch collected values to individual properties.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3292
            for (int i = 0; i < keys.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3293
                if ((key == Attribute.BORDER) || (key == keys[i])) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3294
                    for (int k = 0; k < parts.length; k++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3295
                        attributes.addAttribute(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3296
                                        CSSBorder.ATTRIBUTES[k][i], parts[k]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3297
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3298
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3299
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3300
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3301
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3302
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3303
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3304
     * Calculate the requirements needed to tile the requirements
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3305
     * given by the iterator that would be tiled.  The calculation
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3306
     * takes into consideration margin and border spacing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3307
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3308
    static SizeRequirements calculateTiledRequirements(LayoutIterator iter, SizeRequirements r) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3309
        long minimum = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3310
        long maximum = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3311
        long preferred = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3312
        int lastMargin = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3313
        int totalSpacing = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3314
        int n = iter.getCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3315
        for (int i = 0; i < n; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3316
            iter.setIndex(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3317
            int margin0 = lastMargin;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3318
            int margin1 = (int) iter.getLeadingCollapseSpan();
1287
a04aca99c77a 6722802: Code improvement and warnings removing from the javax.swing.text package
rupashka
parents: 438
diff changeset
  3319
            totalSpacing += Math.max(margin0, margin1);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3320
            preferred += (int) iter.getPreferredSpan(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3321
            minimum += iter.getMinimumSpan(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3322
            maximum += iter.getMaximumSpan(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3323
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3324
            lastMargin = (int) iter.getTrailingCollapseSpan();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3325
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3326
        totalSpacing += lastMargin;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3327
        totalSpacing += 2 * iter.getBorderWidth();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3328
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3329
        // adjust for the spacing area
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3330
        minimum += totalSpacing;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3331
        preferred += totalSpacing;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3332
        maximum += totalSpacing;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3333
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3334
        // set return value
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3335
        if (r == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3336
            r = new SizeRequirements();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3337
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3338
        r.minimum = (minimum > Integer.MAX_VALUE) ? Integer.MAX_VALUE : (int)minimum;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3339
        r.preferred = (preferred > Integer.MAX_VALUE) ? Integer.MAX_VALUE :(int) preferred;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3340
        r.maximum = (maximum > Integer.MAX_VALUE) ? Integer.MAX_VALUE :(int) maximum;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3341
        return r;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3342
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3343
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3344
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3345
     * Calculate a tiled layout for the given iterator.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3346
     * This should be done collapsing the neighboring
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3347
     * margins to be a total of the maximum of the two
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3348
     * neighboring margin areas as described in the CSS spec.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3349
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3350
    static void calculateTiledLayout(LayoutIterator iter, int targetSpan) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3351
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3352
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3353
         * first pass, calculate the preferred sizes, adjustments needed because
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3354
         * of margin collapsing, and the flexibility to adjust the sizes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3355
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3356
        long preferred = 0;
1287
a04aca99c77a 6722802: Code improvement and warnings removing from the javax.swing.text package
rupashka
parents: 438
diff changeset
  3357
        long currentPreferred;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3358
        int lastMargin = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3359
        int totalSpacing = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3360
        int n = iter.getCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3361
        int adjustmentWeightsCount = LayoutIterator.WorstAdjustmentWeight + 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3362
        //max gain we can get adjusting elements with adjustmentWeight <= i
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3363
        long gain[] = new long[adjustmentWeightsCount];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3364
        //max loss we can get adjusting elements with adjustmentWeight <= i
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3365
        long loss[] = new long[adjustmentWeightsCount];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3366
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3367
        for (int i = 0; i < adjustmentWeightsCount; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3368
            gain[i] = loss[i] = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3369
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3370
        for (int i = 0; i < n; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3371
            iter.setIndex(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3372
            int margin0 = lastMargin;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3373
            int margin1 = (int) iter.getLeadingCollapseSpan();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3374
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3375
            iter.setOffset(Math.max(margin0, margin1));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3376
            totalSpacing += iter.getOffset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3377
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3378
            currentPreferred = (long)iter.getPreferredSpan(targetSpan);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3379
            iter.setSpan((int) currentPreferred);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3380
            preferred += currentPreferred;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3381
            gain[iter.getAdjustmentWeight()] +=
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3382
                (long)iter.getMaximumSpan(targetSpan) - currentPreferred;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3383
            loss[iter.getAdjustmentWeight()] +=
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3384
                currentPreferred - (long)iter.getMinimumSpan(targetSpan);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3385
            lastMargin = (int) iter.getTrailingCollapseSpan();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3386
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3387
        totalSpacing += lastMargin;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3388
        totalSpacing += 2 * iter.getBorderWidth();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3389
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3390
        for (int i = 1; i < adjustmentWeightsCount; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3391
            gain[i] += gain[i - 1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3392
            loss[i] += loss[i - 1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3393
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3394
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3395
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3396
         * Second pass, expand or contract by as much as possible to reach
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3397
         * the target span.  This takes the margin collapsing into account
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3398
         * prior to adjusting the span.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3399
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3400
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3401
        // determine the adjustment to be made
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3402
        int allocated = targetSpan - totalSpacing;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3403
        long desiredAdjustment = allocated - preferred;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3404
        long adjustmentsArray[] = (desiredAdjustment > 0) ? gain : loss;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3405
        desiredAdjustment = Math.abs(desiredAdjustment);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3406
        int adjustmentLevel = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3407
        for (;adjustmentLevel <= LayoutIterator.WorstAdjustmentWeight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3408
             adjustmentLevel++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3409
            // adjustmentsArray[] is sorted. I do not bother about
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3410
            // binary search though
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3411
            if (adjustmentsArray[adjustmentLevel] >= desiredAdjustment) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3412
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3413
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3414
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3415
        float adjustmentFactor = 0.0f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3416
        if (adjustmentLevel <= LayoutIterator.WorstAdjustmentWeight) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3417
            desiredAdjustment -= (adjustmentLevel > 0) ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3418
                adjustmentsArray[adjustmentLevel - 1] : 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3419
            if (desiredAdjustment != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3420
                float maximumAdjustment =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3421
                    adjustmentsArray[adjustmentLevel] -
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3422
                    ((adjustmentLevel > 0) ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3423
                     adjustmentsArray[adjustmentLevel - 1] : 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3424
                     );
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3425
                adjustmentFactor = desiredAdjustment / maximumAdjustment;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3426
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3427
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3428
        // make the adjustments
1287
a04aca99c77a 6722802: Code improvement and warnings removing from the javax.swing.text package
rupashka
parents: 438
diff changeset
  3429
        int totalOffset = (int)iter.getBorderWidth();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3430
        for (int i = 0; i < n; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3431
            iter.setIndex(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3432
            iter.setOffset( iter.getOffset() + totalOffset);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3433
            if (iter.getAdjustmentWeight() < adjustmentLevel) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3434
                iter.setSpan((int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3435
                             ((allocated > preferred) ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3436
                              Math.floor(iter.getMaximumSpan(targetSpan)) :
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3437
                              Math.ceil(iter.getMinimumSpan(targetSpan))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3438
                              )
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3439
                             );
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3440
            } else if (iter.getAdjustmentWeight() == adjustmentLevel) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3441
                int availableSpan = (allocated > preferred) ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3442
                    (int) iter.getMaximumSpan(targetSpan) - iter.getSpan() :
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3443
                    iter.getSpan() - (int) iter.getMinimumSpan(targetSpan);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3444
                int adj = (int)Math.floor(adjustmentFactor * availableSpan);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3445
                iter.setSpan(iter.getSpan() +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3446
                             ((allocated > preferred) ? adj : -adj));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3447
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3448
            totalOffset = (int) Math.min((long) iter.getOffset() +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3449
                                         (long) iter.getSpan(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3450
                                         Integer.MAX_VALUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3451
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3452
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3453
        // while rounding we could lose several pixels.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3454
        int roundError = targetSpan - totalOffset -
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3455
            (int)iter.getTrailingCollapseSpan() -
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3456
            (int)iter.getBorderWidth();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3457
        int adj = (roundError > 0) ? 1 : -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3458
        roundError *= adj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3459
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3460
        boolean canAdjust = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3461
        while (roundError > 0 && canAdjust) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3462
            // check for infinite loop
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3463
            canAdjust = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3464
            int offsetAdjust = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3465
            // try to distribute roundError. one pixel per cell
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3466
            for (int i = 0; i < n; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3467
                iter.setIndex(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3468
                iter.setOffset(iter.getOffset() + offsetAdjust);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3469
                int curSpan = iter.getSpan();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3470
                if (roundError > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3471
                    int boundGap = (adj > 0) ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3472
                        (int)Math.floor(iter.getMaximumSpan(targetSpan)) - curSpan :
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3473
                        curSpan - (int)Math.ceil(iter.getMinimumSpan(targetSpan));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3474
                    if (boundGap >= 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3475
                        canAdjust = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3476
                        iter.setSpan(curSpan + adj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3477
                        offsetAdjust += adj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3478
                        roundError--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3479
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3480
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3481
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3482
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3483
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3484
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3485
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3486
     * An iterator to express the requirements to use when computing
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3487
     * layout.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3488
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3489
    interface LayoutIterator {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3490
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3491
        void setOffset(int offs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3492
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3493
        int getOffset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3494
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3495
        void setSpan(int span);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3496
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3497
        int getSpan();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3498
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3499
        int getCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3500
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3501
        void setIndex(int i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3502
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3503
        float getMinimumSpan(float parentSpan);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3504
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3505
        float getPreferredSpan(float parentSpan);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3506
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3507
        float getMaximumSpan(float parentSpan);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3508
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3509
        int getAdjustmentWeight(); //0 is the best weight WorstAdjustmentWeight is a worst one
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3510
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3511
        //float getAlignment();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3512
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3513
        float getBorderWidth();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3514
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3515
        float getLeadingCollapseSpan();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3516
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3517
        float getTrailingCollapseSpan();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3518
        public static final int WorstAdjustmentWeight = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3519
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3520
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3521
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3522
    // Serialization support
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3523
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3524
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3525
    private void writeObject(java.io.ObjectOutputStream s)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3526
        throws IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3527
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3528
        s.defaultWriteObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3529
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3530
        // Determine what values in valueConvertor need to be written out.
25193
187a455af8f8 8043549: Fix raw and unchecked lint warnings in javax.swing.text.*
darcy
parents: 24269
diff changeset
  3531
        Enumeration<?> keys = valueConvertor.keys();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3532
        s.writeInt(valueConvertor.size());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3533
        if (keys != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3534
            while (keys.hasMoreElements()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3535
                Object key = keys.nextElement();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3536
                Object value = valueConvertor.get(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3537
                if (!(key instanceof Serializable) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3538
                    (key = StyleContext.getStaticAttributeKey(key)) == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3539
                    // Should we throw an exception here?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3540
                    key = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3541
                    value = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3542
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3543
                else if (!(value instanceof Serializable) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3544
                    (value = StyleContext.getStaticAttributeKey(value)) == null){
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3545
                    // Should we throw an exception here?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3546
                    key = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3547
                    value = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3548
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3549
                s.writeObject(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3550
                s.writeObject(value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3551
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3552
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3553
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3554
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3555
    private void readObject(ObjectInputStream s)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3556
      throws ClassNotFoundException, IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3557
    {
26001
991e1be0b235 8038937: Validate fields on Swing classes deserialization
alexsch
parents: 25777
diff changeset
  3558
        ObjectInputStream.GetField f = s.readFields();
991e1be0b235 8038937: Validate fields on Swing classes deserialization
alexsch
parents: 25777
diff changeset
  3559
        int newBaseFontSize = f.get("baseFontSize", 0);
991e1be0b235 8038937: Validate fields on Swing classes deserialization
alexsch
parents: 25777
diff changeset
  3560
        setBaseFontSize(newBaseFontSize);
991e1be0b235 8038937: Validate fields on Swing classes deserialization
alexsch
parents: 25777
diff changeset
  3561
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3562
        // Reconstruct the hashtable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3563
        int numValues = s.readInt();
26001
991e1be0b235 8038937: Validate fields on Swing classes deserialization
alexsch
parents: 25777
diff changeset
  3564
        valueConvertor = new Hashtable<>(Math.max(1, numValues));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3565
        while (numValues-- > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3566
            Object key = s.readObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3567
            Object value = s.readObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3568
            Object staticKey = StyleContext.getStaticAttribute(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3569
            if (staticKey != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3570
                key = staticKey;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3571
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3572
            Object staticValue = StyleContext.getStaticAttribute(value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3573
            if (staticValue != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3574
                value = staticValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3575
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3576
            if (key != null && value != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3577
                valueConvertor.put(key, value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3578
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3579
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3580
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3581
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3582
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3583
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3584
     * we need StyleSheet for resolving lenght units. (see
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3585
     * isW3CLengthUnits)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3586
     * we can not pass stylesheet for handling relative sizes. (do not
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3587
     * think changing public API is necessary)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3588
     * CSS is not likely to be accessed from more then one thread.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3589
     * Having local storage for StyleSheet for resolving relative
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3590
     * sizes is safe
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3591
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3592
     * idk 08/30/2004
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3593
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3594
    private StyleSheet getStyleSheet(StyleSheet ss) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3595
        if (ss != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3596
            styleSheet = ss;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3597
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3598
        return styleSheet;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3599
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3600
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3601
    // Instance variables
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3602
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3603
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3604
    /** Maps from CSS key to CssValue. */
1287
a04aca99c77a 6722802: Code improvement and warnings removing from the javax.swing.text package
rupashka
parents: 438
diff changeset
  3605
    private transient Hashtable<Object, Object> valueConvertor;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3606
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3607
    /** Size used for relative units. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3608
    private int baseFontSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3609
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3610
    private transient StyleSheet styleSheet = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3611
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3612
    static int baseFontSizeIndex = 3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3613
}