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