jdk/src/share/classes/javax/swing/plaf/synth/SynthParser.java
author darcy
Sun, 23 Mar 2014 13:49:48 -0700
changeset 23697 e556a715949f
parent 7668 d4a77089c587
child 25089 e032b0161576
permissions -rw-r--r--
8034169: Fix serial lint warnings in javax.swing Reviewed-by: alanb, prr
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
23697
e556a715949f 8034169: Fix serial lint warnings in javax.swing
darcy
parents: 7668
diff changeset
     2
 * Copyright (c) 2003, 2014, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1853
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: 1853
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: 1853
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1853
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1853
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
package javax.swing.plaf.synth;
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.Component;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.awt.Font;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.awt.Graphics;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.awt.Image;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.awt.Insets;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.awt.Toolkit;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.io.BufferedInputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.io.IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.io.InputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.net.MalformedURLException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import java.net.URL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import java.net.URLClassLoader;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import java.text.ParseException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import java.util.ArrayList;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import java.util.HashMap;
1290
da8902cd496c 6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents: 2
diff changeset
    43
import java.util.List;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
import java.util.Locale;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
import java.util.Map;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
import java.util.StringTokenizer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
import java.util.regex.PatternSyntaxException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
import javax.swing.ImageIcon;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
import javax.swing.JSplitPane;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
import javax.swing.SwingConstants;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
import javax.swing.UIDefaults;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
import javax.swing.plaf.ColorUIResource;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
import javax.swing.plaf.DimensionUIResource;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
import javax.swing.plaf.FontUIResource;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
import javax.swing.plaf.InsetsUIResource;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
import javax.swing.plaf.UIResource;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
import javax.xml.parsers.ParserConfigurationException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
import javax.xml.parsers.SAXParser;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
import javax.xml.parsers.SAXParserFactory;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
1844
ac2cf8242428 4864117: RFE: Make XMLDecoder API more reusable
malenkov
parents: 1290
diff changeset
    62
import org.xml.sax.Attributes;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
import org.xml.sax.InputSource;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
import org.xml.sax.Locator;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
import org.xml.sax.SAXException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
import org.xml.sax.SAXParseException;
1844
ac2cf8242428 4864117: RFE: Make XMLDecoder API more reusable
malenkov
parents: 1290
diff changeset
    67
import org.xml.sax.helpers.DefaultHandler;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
1844
ac2cf8242428 4864117: RFE: Make XMLDecoder API more reusable
malenkov
parents: 1290
diff changeset
    69
import com.sun.beans.decoder.DocumentHandler;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
1844
ac2cf8242428 4864117: RFE: Make XMLDecoder API more reusable
malenkov
parents: 1290
diff changeset
    71
class SynthParser extends DefaultHandler {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    // Known element names
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    private static final String ELEMENT_SYNTH = "synth";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    private static final String ELEMENT_STYLE = "style";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    private static final String ELEMENT_STATE = "state";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    private static final String ELEMENT_FONT = "font";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    private static final String ELEMENT_COLOR = "color";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    private static final String ELEMENT_IMAGE_PAINTER = "imagePainter";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    private static final String ELEMENT_PAINTER = "painter";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    private static final String ELEMENT_PROPERTY = "property";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    private static final String ELEMENT_SYNTH_GRAPHICS = "graphicsUtils";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    private static final String ELEMENT_IMAGE_ICON = "imageIcon";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    private static final String ELEMENT_BIND = "bind";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    private static final String ELEMENT_BIND_KEY = "bindKey";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    private static final String ELEMENT_INSETS = "insets";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    private static final String ELEMENT_OPAQUE = "opaque";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    private static final String ELEMENT_DEFAULTS_PROPERTY =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
                                        "defaultsProperty";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    private static final String ELEMENT_INPUT_MAP = "inputMap";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    // Known attribute names
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    private static final String ATTRIBUTE_ACTION = "action";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    private static final String ATTRIBUTE_ID = "id";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    private static final String ATTRIBUTE_IDREF = "idref";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    private static final String ATTRIBUTE_CLONE = "clone";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    private static final String ATTRIBUTE_VALUE = "value";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    private static final String ATTRIBUTE_NAME = "name";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    private static final String ATTRIBUTE_STYLE = "style";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    private static final String ATTRIBUTE_SIZE = "size";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    private static final String ATTRIBUTE_TYPE = "type";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    private static final String ATTRIBUTE_TOP = "top";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    private static final String ATTRIBUTE_LEFT = "left";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    private static final String ATTRIBUTE_BOTTOM = "bottom";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    private static final String ATTRIBUTE_RIGHT = "right";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    private static final String ATTRIBUTE_KEY = "key";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    private static final String ATTRIBUTE_SOURCE_INSETS = "sourceInsets";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    private static final String ATTRIBUTE_DEST_INSETS = "destinationInsets";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    private static final String ATTRIBUTE_PATH = "path";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    private static final String ATTRIBUTE_STRETCH = "stretch";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    private static final String ATTRIBUTE_PAINT_CENTER = "paintCenter";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    private static final String ATTRIBUTE_METHOD = "method";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    private static final String ATTRIBUTE_DIRECTION = "direction";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    private static final String ATTRIBUTE_CENTER = "center";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     * Lazily created, used for anything we don't understand.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     */
1844
ac2cf8242428 4864117: RFE: Make XMLDecoder API more reusable
malenkov
parents: 1290
diff changeset
   122
    private DocumentHandler _handler;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     * Indicates the depth of how many elements we've encountered but don't
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     * understand. This is used when forwarding to beans persistance to know
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     * when we hsould stop forwarding.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    private int _depth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     * Factory that new styles are added to.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    private DefaultSynthStyleFactory _factory;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     * Array of state infos for the current style. These are pushed to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     * style when </style> is received.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     */
1290
da8902cd496c 6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents: 2
diff changeset
   140
    private List<ParsedSynthStyle.StateInfo> _stateInfos;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     * Current style.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    private ParsedSynthStyle _style;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     * Current state info.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    private ParsedSynthStyle.StateInfo _stateInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     * Bindings for the current InputMap
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     */
1290
da8902cd496c 6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents: 2
diff changeset
   155
    private List<String> _inputMapBindings;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     * ID for the input map. This is cached as
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     * the InputMap is created AFTER the inputMapProperty has ended.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
    private String _inputMapID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
     * Object references outside the scope of persistance.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    private Map<String,Object> _mapping;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
     * Based URL used to resolve paths.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
    private URL _urlResourceBase;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
     * Based class used to resolve paths.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
    private Class<?> _classResourceBase;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     * List of ColorTypes. This is populated in startColorType.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     */
1290
da8902cd496c 6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents: 2
diff changeset
   181
    private List<ColorType> _colorTypes;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
     * defaultsPropertys are placed here.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
     */
1290
da8902cd496c 6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents: 2
diff changeset
   186
    private Map<String, Object> _defaultsMap;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
     * List of SynthStyle.Painters that will be applied to the current style.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
     */
1290
da8902cd496c 6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents: 2
diff changeset
   191
    private List<ParsedSynthStyle.PainterInfo> _stylePainters;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     * List of SynthStyle.Painters that will be applied to the current state.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     */
1290
da8902cd496c 6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents: 2
diff changeset
   196
    private List<ParsedSynthStyle.PainterInfo> _statePainters;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
    SynthParser() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        _mapping = new HashMap<String,Object>();
1290
da8902cd496c 6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents: 2
diff changeset
   200
        _stateInfos = new ArrayList<ParsedSynthStyle.StateInfo>();
da8902cd496c 6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents: 2
diff changeset
   201
        _colorTypes = new ArrayList<ColorType>();
da8902cd496c 6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents: 2
diff changeset
   202
        _inputMapBindings = new ArrayList<String>();
da8902cd496c 6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents: 2
diff changeset
   203
        _stylePainters = new ArrayList<ParsedSynthStyle.PainterInfo>();
da8902cd496c 6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents: 2
diff changeset
   204
        _statePainters = new ArrayList<ParsedSynthStyle.PainterInfo>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
     * Parses a set of styles from <code>inputStream</code>, adding the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
     * resulting styles to the passed in DefaultSynthStyleFactory.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
     * Resources are resolved either from a URL or from a Class. When calling
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
     * this method, one of the URL or the Class must be null but not both at
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
     * the same time.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
     * @param inputStream XML document containing the styles to read
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
     * @param factory DefaultSynthStyleFactory that new styles are added to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     * @param urlResourceBase the URL used to resolve any resources, such as Images
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     * @param classResourceBase the Class used to resolve any resources, such as Images
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     * @param defaultsMap Map that UIDefaults properties are placed in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
    public void parse(InputStream inputStream,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
                      DefaultSynthStyleFactory factory,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
                      URL urlResourceBase, Class<?> classResourceBase,
1290
da8902cd496c 6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents: 2
diff changeset
   223
                      Map<String, Object> defaultsMap)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
                      throws ParseException, IllegalArgumentException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
        if (inputStream == null || factory == null ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
            (urlResourceBase == null && classResourceBase == null)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
            throw new IllegalArgumentException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
                "You must supply an InputStream, StyleFactory and Class or URL");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
        assert(!(urlResourceBase != null && classResourceBase != null));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
        _factory = factory;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
        _classResourceBase = classResourceBase;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
        _urlResourceBase = urlResourceBase;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
        _defaultsMap = defaultsMap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
                SAXParser saxParser = SAXParserFactory.newInstance().
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
                                                   newSAXParser();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
                saxParser.parse(new BufferedInputStream(inputStream), this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
            } catch (ParserConfigurationException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
                throw new ParseException("Error parsing: " + e, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
            catch (SAXException se) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
                throw new ParseException("Error parsing: " + se + " " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
                                         se.getException(), 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
            catch (IOException ioe) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
                throw new ParseException("Error parsing: " + ioe, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
            reset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
     * Returns the path to a resource.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
    private URL getResource(String path) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
        if (_classResourceBase != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
            return _classResourceBase.getResource(path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
                return new URL(_urlResourceBase, path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
            } catch (MalformedURLException mue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
     * Clears our internal state.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
    private void reset() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
        _handler = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
        _depth = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
        _mapping.clear();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
        _stateInfos.clear();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
        _colorTypes.clear();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
        _statePainters.clear();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
        _stylePainters.clear();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
     * Returns true if we are forwarding to persistance.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
    private boolean isForwarding() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
        return (_depth > 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
     * Handles beans persistance.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
     */
1844
ac2cf8242428 4864117: RFE: Make XMLDecoder API more reusable
malenkov
parents: 1290
diff changeset
   295
    private DocumentHandler getHandler() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
        if (_handler == null) {
1844
ac2cf8242428 4864117: RFE: Make XMLDecoder API more reusable
malenkov
parents: 1290
diff changeset
   297
            _handler = new DocumentHandler();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
            if (_urlResourceBase != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
                // getHandler() is never called before parse() so it is safe
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
                // to create a URLClassLoader with _resourceBase.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
                //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
                // getResource(".") is called to ensure we have the directory
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
                // containing the resources in the case the resource base is a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
                // .class file.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
                URL[] urls = new URL[] { getResource(".") };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
                ClassLoader parent = Thread.currentThread().getContextClassLoader();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
                ClassLoader urlLoader = new URLClassLoader(urls, parent);
1844
ac2cf8242428 4864117: RFE: Make XMLDecoder API more reusable
malenkov
parents: 1290
diff changeset
   308
                _handler.setClassLoader(urlLoader);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
            } else {
1844
ac2cf8242428 4864117: RFE: Make XMLDecoder API more reusable
malenkov
parents: 1290
diff changeset
   310
                _handler.setClassLoader(_classResourceBase.getClassLoader());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
            for (String key : _mapping.keySet()) {
1844
ac2cf8242428 4864117: RFE: Make XMLDecoder API more reusable
malenkov
parents: 1290
diff changeset
   314
                _handler.setVariable(key, _mapping.get(key));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
        return _handler;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
     * If <code>value</code> is an instance of <code>type</code> it is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
     * returned, otherwise a SAXException is thrown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
    private Object checkCast(Object value, Class type) throws SAXException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
        if (!type.isInstance(value)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
            throw new SAXException("Expected type " + type + " got " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
                                   value.getClass());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
        return value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
     * Returns an object created with id=key. If the object is not of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
     * type type, this will throw an exception.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
    private Object lookup(String key, Class type) throws SAXException {
1290
da8902cd496c 6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents: 2
diff changeset
   337
        Object value;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
        if (_handler != null) {
1844
ac2cf8242428 4864117: RFE: Make XMLDecoder API more reusable
malenkov
parents: 1290
diff changeset
   339
            if (_handler.hasVariable(key)) {
ac2cf8242428 4864117: RFE: Make XMLDecoder API more reusable
malenkov
parents: 1290
diff changeset
   340
                return checkCast(_handler.getVariable(key), type);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
        value = _mapping.get(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
        if (value == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
            throw new SAXException("ID " + key + " has not been defined");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
        return checkCast(value, type);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
     * Registers an object by name. This will throw an exception if an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
     * object has already been registered under the given name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
    private void register(String key, Object value) throws SAXException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
        if (key != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
            if (_mapping.get(key) != null ||
1844
ac2cf8242428 4864117: RFE: Make XMLDecoder API more reusable
malenkov
parents: 1290
diff changeset
   357
                     (_handler != null && _handler.hasVariable(key))) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
                throw new SAXException("ID " + key + " is already defined");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
            if (_handler != null) {
1844
ac2cf8242428 4864117: RFE: Make XMLDecoder API more reusable
malenkov
parents: 1290
diff changeset
   361
                _handler.setVariable(key, value);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
                _mapping.put(key, value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
     * Convenience method to return the next int, or throw if there are no
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
     * more valid ints.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
    private int nextInt(StringTokenizer tok, String errorMsg) throws
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
                   SAXException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
        if (!tok.hasMoreTokens()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
            throw new SAXException(errorMsg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
            return Integer.parseInt(tok.nextToken());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
        } catch (NumberFormatException nfe) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
            throw new SAXException(errorMsg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
     * Convenience method to return an Insets object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
    private Insets parseInsets(String insets, String errorMsg) throws
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
                        SAXException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
        StringTokenizer tokenizer = new StringTokenizer(insets);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
        return new Insets(nextInt(tokenizer, errorMsg),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
                          nextInt(tokenizer, errorMsg),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
                          nextInt(tokenizer, errorMsg),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
                          nextInt(tokenizer, errorMsg));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
    // The following methods are invoked from startElement/stopElement
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
1844
ac2cf8242428 4864117: RFE: Make XMLDecoder API more reusable
malenkov
parents: 1290
diff changeset
   403
    private void startStyle(Attributes attributes) throws SAXException {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
        String id = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
        _style = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
        for(int i = attributes.getLength() - 1; i >= 0; i--) {
1844
ac2cf8242428 4864117: RFE: Make XMLDecoder API more reusable
malenkov
parents: 1290
diff changeset
   408
            String key = attributes.getQName(i);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
            if (key.equals(ATTRIBUTE_CLONE)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
                _style = (ParsedSynthStyle)((ParsedSynthStyle)lookup(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
                         attributes.getValue(i), ParsedSynthStyle.class)).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
                         clone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
            else if (key.equals(ATTRIBUTE_ID)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
                id = attributes.getValue(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
        if (_style == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
            _style = new ParsedSynthStyle();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
        register(id, _style);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
1844
ac2cf8242428 4864117: RFE: Make XMLDecoder API more reusable
malenkov
parents: 1290
diff changeset
   424
    private void endStyle() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
        int size = _stylePainters.size();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
        if (size > 0) {
1290
da8902cd496c 6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents: 2
diff changeset
   427
            _style.setPainters(_stylePainters.toArray(new ParsedSynthStyle.PainterInfo[size]));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
            _stylePainters.clear();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
        size = _stateInfos.size();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
        if (size > 0) {
1290
da8902cd496c 6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents: 2
diff changeset
   432
            _style.setStateInfo(_stateInfos.toArray(new ParsedSynthStyle.StateInfo[size]));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
            _stateInfos.clear();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
        _style = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
1844
ac2cf8242428 4864117: RFE: Make XMLDecoder API more reusable
malenkov
parents: 1290
diff changeset
   438
    private void startState(Attributes attributes) throws SAXException {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
        ParsedSynthStyle.StateInfo stateInfo = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
        int state = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
        String id = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
        _stateInfo = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
        for(int i = attributes.getLength() - 1; i >= 0; i--) {
1844
ac2cf8242428 4864117: RFE: Make XMLDecoder API more reusable
malenkov
parents: 1290
diff changeset
   445
            String key = attributes.getQName(i);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
            if (key.equals(ATTRIBUTE_ID)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
                id = attributes.getValue(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
            else if (key.equals(ATTRIBUTE_IDREF)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
                _stateInfo = (ParsedSynthStyle.StateInfo)lookup(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
                   attributes.getValue(i), ParsedSynthStyle.StateInfo.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
            else if (key.equals(ATTRIBUTE_CLONE)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
                _stateInfo = (ParsedSynthStyle.StateInfo)((ParsedSynthStyle.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
                             StateInfo)lookup(attributes.getValue(i),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
                             ParsedSynthStyle.StateInfo.class)).clone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
            else if (key.equals(ATTRIBUTE_VALUE)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
                StringTokenizer tokenizer = new StringTokenizer(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
                                   attributes.getValue(i));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
                while (tokenizer.hasMoreTokens()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
                    String stateString = tokenizer.nextToken().toUpperCase().
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
                                                   intern();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
                    if (stateString == "ENABLED") {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
                        state |= SynthConstants.ENABLED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
                    else if (stateString == "MOUSE_OVER") {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
                        state |= SynthConstants.MOUSE_OVER;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
                    else if (stateString == "PRESSED") {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
                        state |= SynthConstants.PRESSED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
                    else if (stateString == "DISABLED") {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
                        state |= SynthConstants.DISABLED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
                    else if (stateString == "FOCUSED") {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
                        state |= SynthConstants.FOCUSED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
                    else if (stateString == "SELECTED") {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
                        state |= SynthConstants.SELECTED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
                    else if (stateString == "DEFAULT") {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
                        state |= SynthConstants.DEFAULT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
                    else if (stateString != "AND") {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
                        throw new SAXException("Unknown state: " + state);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
        if (_stateInfo == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
            _stateInfo = new ParsedSynthStyle.StateInfo();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
        _stateInfo.setComponentState(state);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
        register(id, _stateInfo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
        _stateInfos.add(_stateInfo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
1844
ac2cf8242428 4864117: RFE: Make XMLDecoder API more reusable
malenkov
parents: 1290
diff changeset
   499
    private void endState() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
        int size = _statePainters.size();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
        if (size > 0) {
1290
da8902cd496c 6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents: 2
diff changeset
   502
            _stateInfo.setPainters(_statePainters.toArray(new ParsedSynthStyle.PainterInfo[size]));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
            _statePainters.clear();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
        _stateInfo = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
1844
ac2cf8242428 4864117: RFE: Make XMLDecoder API more reusable
malenkov
parents: 1290
diff changeset
   508
    private void startFont(Attributes attributes) throws SAXException {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
        Font font = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
        int style = Font.PLAIN;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
        int size = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
        String id = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
        String name = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
        for(int i = attributes.getLength() - 1; i >= 0; i--) {
1844
ac2cf8242428 4864117: RFE: Make XMLDecoder API more reusable
malenkov
parents: 1290
diff changeset
   516
            String key = attributes.getQName(i);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
            if (key.equals(ATTRIBUTE_ID)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
                id = attributes.getValue(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
            else if (key.equals(ATTRIBUTE_IDREF)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
                font = (Font)lookup(attributes.getValue(i), Font.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
            else if (key.equals(ATTRIBUTE_NAME)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
                name = attributes.getValue(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
            else if (key.equals(ATTRIBUTE_SIZE)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
                    size = Integer.parseInt(attributes.getValue(i));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
                } catch (NumberFormatException nfe) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
                    throw new SAXException("Invalid font size: " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
                                           attributes.getValue(i));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
            else if (key.equals(ATTRIBUTE_STYLE)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
                StringTokenizer tok = new StringTokenizer(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
                                                attributes.getValue(i));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
                while (tok.hasMoreTokens()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
                    String token = tok.nextToken().intern();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
                    if (token == "BOLD") {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
                        style = ((style | Font.PLAIN) ^ Font.PLAIN) |
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
                                Font.BOLD;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
                    else if (token == "ITALIC") {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
                        style |= Font.ITALIC;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
        if (font == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
            if (name == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
                throw new SAXException("You must define a name for the font");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
            if (size == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
                throw new SAXException("You must define a size for the font");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
            font = new FontUIResource(name, style, size);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
        else if (name != null || size != 0 || style != Font.PLAIN) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
            throw new SAXException("Name, size and style are not for use " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
                                   "with idref");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
        register(id, font);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
        if (_stateInfo != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
            _stateInfo.setFont(font);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
        else if (_style != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
            _style.setFont(font);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
1844
ac2cf8242428 4864117: RFE: Make XMLDecoder API more reusable
malenkov
parents: 1290
diff changeset
   571
    private void startColor(Attributes attributes) throws SAXException {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
        Color color = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
        String id = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
        _colorTypes.clear();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
        for(int i = attributes.getLength() - 1; i >= 0; i--) {
1844
ac2cf8242428 4864117: RFE: Make XMLDecoder API more reusable
malenkov
parents: 1290
diff changeset
   577
            String key = attributes.getQName(i);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
            if (key.equals(ATTRIBUTE_ID)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
                id = attributes.getValue(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
            else if (key.equals(ATTRIBUTE_IDREF)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
                color = (Color)lookup(attributes.getValue(i), Color.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
            else if (key.equals(ATTRIBUTE_NAME)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
            else if (key.equals(ATTRIBUTE_VALUE)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
                String value = attributes.getValue(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
                if (value.startsWith("#")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
                    try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
                        int argb;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
                        boolean hasAlpha;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
                        int length = value.length();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
                        if (length < 8) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
                            // Just RGB, or some portion of it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
                            argb = Integer.decode(value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
                            hasAlpha = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
                        } else if (length == 8) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
                            // Single character alpha: #ARRGGBB.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
                            argb = Integer.decode(value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
                            hasAlpha = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
                        } else if (length == 9) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
                            // Color has alpha and is of the form
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
                            // #AARRGGBB.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
                            // The following split decoding is mandatory due to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
                            // Integer.decode() behavior which won't decode
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
                            // hexadecimal values higher than #7FFFFFFF.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
                            // Thus, when an alpha channel is detected, it is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
                            // decoded separately from the RGB channels.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
                            int rgb = Integer.decode('#' +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
                                                     value.substring(3, 9));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
                            int a = Integer.decode(value.substring(0, 3));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
                            argb = (a << 24) | rgb;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
                            hasAlpha = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
                        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
                            throw new SAXException("Invalid Color value: "
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
                                + value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
                        color = new ColorUIResource(new Color(argb, hasAlpha));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
                    } catch (NumberFormatException nfe) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
                        throw new SAXException("Invalid Color value: " +value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
                    }
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
                    try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
                        color = new ColorUIResource((Color)Color.class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
                              getField(value.toUpperCase()).get(Color.class));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
                    } catch (NoSuchFieldException nsfe) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
                        throw new SAXException("Invalid color name: " + value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
                    } catch (IllegalAccessException iae) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
                        throw new SAXException("Invalid color name: " + value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
            else if (key.equals(ATTRIBUTE_TYPE)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
                StringTokenizer tokenizer = new StringTokenizer(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
                                   attributes.getValue(i));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
                while (tokenizer.hasMoreTokens()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
                    String typeName = tokenizer.nextToken();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
                    int classIndex = typeName.lastIndexOf('.');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
                    Class typeClass;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
                    if (classIndex == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
                        typeClass = ColorType.class;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
                        classIndex = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
                    else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
                        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
                            typeClass = Class.forName(typeName.substring(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
                                                      0, classIndex));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
                        } catch (ClassNotFoundException cnfe) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
                            throw new SAXException("Unknown class: " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
                                      typeName.substring(0, classIndex));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
                        classIndex++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
                    try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
                        _colorTypes.add((ColorType)checkCast(typeClass.
5768
2016aba51689 6771547: SynthParser throws StringIndexOutOfBoundsException parsing custom ColorTypes
alexp
parents: 5506
diff changeset
   661
                              getField(typeName.substring(classIndex)).
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
                              get(typeClass), ColorType.class));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
                    } catch (NoSuchFieldException nsfe) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
                        throw new SAXException("Unable to find color type: " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
                                               typeName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
                    } catch (IllegalAccessException iae) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
                        throw new SAXException("Unable to find color type: " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
                                               typeName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
        if (color == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
            throw new SAXException("color: you must specificy a value");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
        register(id, color);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
        if (_stateInfo != null && _colorTypes.size() > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
            Color[] colors = _stateInfo.getColors();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
            int max = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
            for (int counter = _colorTypes.size() - 1; counter >= 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
                     counter--) {
1290
da8902cd496c 6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents: 2
diff changeset
   682
                max = Math.max(max, _colorTypes.get(counter).getID());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
            if (colors == null || colors.length <= max) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
                Color[] newColors = new Color[max + 1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
                if (colors != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
                    System.arraycopy(colors, 0, newColors, 0, colors.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
                colors = newColors;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
            for (int counter = _colorTypes.size() - 1; counter >= 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
                     counter--) {
1290
da8902cd496c 6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents: 2
diff changeset
   693
                colors[_colorTypes.get(counter).getID()] = color;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
            _stateInfo.setColors(colors);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
1844
ac2cf8242428 4864117: RFE: Make XMLDecoder API more reusable
malenkov
parents: 1290
diff changeset
   699
    private void startProperty(Attributes attributes,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
                               Object property) throws SAXException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
        Object value = null;
1290
da8902cd496c 6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents: 2
diff changeset
   702
        String key = null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
        // Type of the value: 0=idref, 1=boolean, 2=dimension, 3=insets,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
        // 4=integer,5=string
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
        int iType = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
        String aValue = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
        for(int i = attributes.getLength() - 1; i >= 0; i--) {
1844
ac2cf8242428 4864117: RFE: Make XMLDecoder API more reusable
malenkov
parents: 1290
diff changeset
   709
            String aName = attributes.getQName(i);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
            if (aName.equals(ATTRIBUTE_TYPE)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
                String type = attributes.getValue(i).toUpperCase();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
                if (type.equals("IDREF")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
                    iType = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
                else if (type.equals("BOOLEAN")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
                    iType = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
                else if (type.equals("DIMENSION")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
                    iType = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
                else if (type.equals("INSETS")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
                    iType = 3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
                else if (type.equals("INTEGER")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
                    iType = 4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
                else if (type.equals("STRING")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
                    iType = 5;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
                else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
                    throw new SAXException(property + " unknown type, use" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
                        "idref, boolean, dimension, insets or integer");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
            else if (aName.equals(ATTRIBUTE_VALUE)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
                aValue = attributes.getValue(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
            else if (aName.equals(ATTRIBUTE_KEY)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
                key = attributes.getValue(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
        if (aValue != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
            switch (iType) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
            case 0: // idref
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
                value = lookup(aValue, Object.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
            case 1: // boolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
                if (aValue.toUpperCase().equals("TRUE")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
                    value = Boolean.TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
                else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
                    value = Boolean.FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
            case 2: // dimension
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
                StringTokenizer tok = new StringTokenizer(aValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
                value = new DimensionUIResource(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
                    nextInt(tok, "Invalid dimension"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
                    nextInt(tok, "Invalid dimension"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
            case 3: // insets
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
                value = parseInsets(aValue, property + " invalid insets");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
            case 4: // integer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
                    value = new Integer(Integer.parseInt(aValue));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
                } catch (NumberFormatException nfe) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
                    throw new SAXException(property + " invalid value");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
            case 5: //string
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
                value = aValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
        if (value == null || key == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
            throw new SAXException(property + ": you must supply a " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
                                   "key and value");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
        if (property == ELEMENT_DEFAULTS_PROPERTY) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
            _defaultsMap.put(key, value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
        else if (_stateInfo != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
            if (_stateInfo.getData() == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
                _stateInfo.setData(new HashMap());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
            _stateInfo.getData().put(key, value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
        else if (_style != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
            if (_style.getData() == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
                _style.setData(new HashMap());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
            _style.getData().put(key, value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
1844
ac2cf8242428 4864117: RFE: Make XMLDecoder API more reusable
malenkov
parents: 1290
diff changeset
   797
    private void startGraphics(Attributes attributes) throws SAXException {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
        SynthGraphicsUtils graphics = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
        for(int i = attributes.getLength() - 1; i >= 0; i--) {
1844
ac2cf8242428 4864117: RFE: Make XMLDecoder API more reusable
malenkov
parents: 1290
diff changeset
   801
            String key = attributes.getQName(i);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
            if (key.equals(ATTRIBUTE_IDREF)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
                graphics = (SynthGraphicsUtils)lookup(attributes.getValue(i),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
                                                 SynthGraphicsUtils.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
        if (graphics == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
            throw new SAXException("graphicsUtils: you must supply an idref");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
        if (_style != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
            _style.setGraphicsUtils(graphics);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
1844
ac2cf8242428 4864117: RFE: Make XMLDecoder API more reusable
malenkov
parents: 1290
diff changeset
   815
    private void startInsets(Attributes attributes) throws SAXException {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
        int top = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
        int bottom = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
        int left = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
        int right = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
        Insets insets = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
        String id = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
        for(int i = attributes.getLength() - 1; i >= 0; i--) {
1844
ac2cf8242428 4864117: RFE: Make XMLDecoder API more reusable
malenkov
parents: 1290
diff changeset
   824
            String key = attributes.getQName(i);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
                if (key.equals(ATTRIBUTE_IDREF)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
                    insets = (Insets)lookup(attributes.getValue(i),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
                                                   Insets.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
                else if (key.equals(ATTRIBUTE_ID)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
                    id = attributes.getValue(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
                else if (key.equals(ATTRIBUTE_TOP)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
                    top = Integer.parseInt(attributes.getValue(i));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
                else if (key.equals(ATTRIBUTE_LEFT)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
                    left = Integer.parseInt(attributes.getValue(i));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
                else if (key.equals(ATTRIBUTE_BOTTOM)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
                    bottom = Integer.parseInt(attributes.getValue(i));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
                else if (key.equals(ATTRIBUTE_RIGHT)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
                    right = Integer.parseInt(attributes.getValue(i));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
            } catch (NumberFormatException nfe) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
                throw new SAXException("insets: bad integer value for " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
                                       attributes.getValue(i));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
        if (insets == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
            insets = new InsetsUIResource(top, left, bottom, right);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
        register(id, insets);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
        if (_style != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
            _style.setInsets(insets);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
1844
ac2cf8242428 4864117: RFE: Make XMLDecoder API more reusable
malenkov
parents: 1290
diff changeset
   860
    private void startBind(Attributes attributes) throws SAXException {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
        ParsedSynthStyle style = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
        String path = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
        int type = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
        for(int i = attributes.getLength() - 1; i >= 0; i--) {
1844
ac2cf8242428 4864117: RFE: Make XMLDecoder API more reusable
malenkov
parents: 1290
diff changeset
   866
            String key = attributes.getQName(i);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
            if (key.equals(ATTRIBUTE_STYLE)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
                style = (ParsedSynthStyle)lookup(attributes.getValue(i),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
                                                  ParsedSynthStyle.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
            else if (key.equals(ATTRIBUTE_TYPE)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
                String typeS = attributes.getValue(i).toUpperCase();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
                if (typeS.equals("NAME")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
                    type = DefaultSynthStyleFactory.NAME;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
                else if (typeS.equals("REGION")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
                    type = DefaultSynthStyleFactory.REGION;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
                else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
                    throw new SAXException("bind: unknown type " + typeS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
            else if (key.equals(ATTRIBUTE_KEY)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
                path = attributes.getValue(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
        if (style == null || path == null || type == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
            throw new SAXException("bind: you must specify a style, type " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
                                   "and key");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
            _factory.addStyle(style, path, type);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
        } catch (PatternSyntaxException pse) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
            throw new SAXException("bind: " + path + " is not a valid " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
                                   "regular expression");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
1844
ac2cf8242428 4864117: RFE: Make XMLDecoder API more reusable
malenkov
parents: 1290
diff changeset
   901
    private void startPainter(Attributes attributes, String type) throws SAXException {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
        Insets sourceInsets = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
        Insets destInsets = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
        String path = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
        boolean paintCenter = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
        boolean stretch = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
        SynthPainter painter = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
        String method = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
        String id = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
        int direction = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
        boolean center = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
        boolean stretchSpecified = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
        boolean paintCenterSpecified = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
        for(int i = attributes.getLength() - 1; i >= 0; i--) {
1844
ac2cf8242428 4864117: RFE: Make XMLDecoder API more reusable
malenkov
parents: 1290
diff changeset
   917
            String key = attributes.getQName(i);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
            String value = attributes.getValue(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
            if (key.equals(ATTRIBUTE_ID)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
                id = value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
            else if (key.equals(ATTRIBUTE_METHOD)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
                method = value.toLowerCase(Locale.ENGLISH);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
            else if (key.equals(ATTRIBUTE_IDREF)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
                painter = (SynthPainter)lookup(value, SynthPainter.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
            else if (key.equals(ATTRIBUTE_PATH)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
                path = value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
            else if (key.equals(ATTRIBUTE_SOURCE_INSETS)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
                sourceInsets = parseInsets(value, type +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
                   ": sourceInsets must be top left bottom right");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
            else if (key.equals(ATTRIBUTE_DEST_INSETS)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
                destInsets = parseInsets(value, type +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
                  ": destinationInsets must be top left bottom right");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
            else if (key.equals(ATTRIBUTE_PAINT_CENTER)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   941
                paintCenter = value.toLowerCase().equals("true");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   942
                paintCenterSpecified = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   944
            else if (key.equals(ATTRIBUTE_STRETCH)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
                stretch = value.toLowerCase().equals("true");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
                stretchSpecified = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
            else if (key.equals(ATTRIBUTE_DIRECTION)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
                value = value.toUpperCase().intern();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
                if (value == "EAST") {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
                    direction = SwingConstants.EAST;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   953
                else if (value == "NORTH") {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   954
                    direction = SwingConstants.NORTH;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   955
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   956
                else if (value == "SOUTH") {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   957
                    direction = SwingConstants.SOUTH;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   958
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
                else if (value == "WEST") {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
                    direction = SwingConstants.WEST;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   961
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   962
                else if (value == "TOP") {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   963
                    direction = SwingConstants.TOP;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   964
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   965
                else if (value == "LEFT") {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   966
                    direction = SwingConstants.LEFT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   967
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   968
                else if (value == "BOTTOM") {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   969
                    direction = SwingConstants.BOTTOM;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   970
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   971
                else if (value == "RIGHT") {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   972
                    direction = SwingConstants.RIGHT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   973
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   974
                else if (value == "HORIZONTAL") {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   975
                    direction = SwingConstants.HORIZONTAL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   976
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   977
                else if (value == "VERTICAL") {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   978
                    direction = SwingConstants.VERTICAL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   979
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   980
                else if (value == "HORIZONTAL_SPLIT") {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   981
                    direction = JSplitPane.HORIZONTAL_SPLIT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   982
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   983
                else if (value == "VERTICAL_SPLIT") {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   984
                    direction = JSplitPane.VERTICAL_SPLIT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   985
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   986
                else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   987
                    throw new SAXException(type + ": unknown direction");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   988
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   989
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   990
            else if (key.equals(ATTRIBUTE_CENTER)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   991
                center = value.toLowerCase().equals("true");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   992
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   993
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   994
        if (painter == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   995
            if (type == ELEMENT_PAINTER) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   996
                throw new SAXException(type +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   997
                             ": you must specify an idref");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   998
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   999
            if (sourceInsets == null && !center) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1000
                throw new SAXException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1001
                             "property: you must specify sourceInsets");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1002
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1003
            if (path == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1004
                throw new SAXException("property: you must specify a path");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1005
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1006
            if (center && (sourceInsets != null || destInsets != null ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1007
                           paintCenterSpecified || stretchSpecified)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1008
                throw new SAXException("The attributes: sourceInsets, " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1009
                                       "destinationInsets, paintCenter and stretch " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1010
                                       " are not legal when center is true");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1011
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1012
            painter = new ImagePainter(!stretch, paintCenter,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1013
                     sourceInsets, destInsets, getResource(path), center);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1014
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1015
        register(id, painter);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1016
        if (_stateInfo != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1017
            addPainterOrMerge(_statePainters, method, painter, direction);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1018
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1019
        else if (_style != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1020
            addPainterOrMerge(_stylePainters, method, painter, direction);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1021
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1022
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1023
1290
da8902cd496c 6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents: 2
diff changeset
  1024
    private void addPainterOrMerge(List<ParsedSynthStyle.PainterInfo> painters, String method,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1025
                                   SynthPainter painter, int direction) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1026
        ParsedSynthStyle.PainterInfo painterInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1027
        painterInfo = new ParsedSynthStyle.PainterInfo(method,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1028
                                                       painter,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1029
                                                       direction);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1030
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1031
        for (Object infoObject: painters) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1032
            ParsedSynthStyle.PainterInfo info;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1033
            info = (ParsedSynthStyle.PainterInfo) infoObject;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1034
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1035
            if (painterInfo.equalsPainter(info)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1036
                info.addPainter(painter);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1037
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1038
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1039
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1040
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1041
        painters.add(painterInfo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1042
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1043
1844
ac2cf8242428 4864117: RFE: Make XMLDecoder API more reusable
malenkov
parents: 1290
diff changeset
  1044
    private void startImageIcon(Attributes attributes) throws SAXException {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1045
        String path = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1046
        String id = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1047
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1048
        for(int i = attributes.getLength() - 1; i >= 0; i--) {
1844
ac2cf8242428 4864117: RFE: Make XMLDecoder API more reusable
malenkov
parents: 1290
diff changeset
  1049
            String key = attributes.getQName(i);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1050
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1051
            if (key.equals(ATTRIBUTE_ID)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1052
                id = attributes.getValue(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1053
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1054
            else if (key.equals(ATTRIBUTE_PATH)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1055
                path = attributes.getValue(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1056
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1057
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1058
        if (path == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1059
            throw new SAXException("imageIcon: you must specify a path");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1060
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1061
        register(id, new LazyImageIcon(getResource(path)));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1062
       }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1063
1844
ac2cf8242428 4864117: RFE: Make XMLDecoder API more reusable
malenkov
parents: 1290
diff changeset
  1064
    private void startOpaque(Attributes attributes) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1065
        if (_style != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1066
            _style.setOpaque(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1067
            for(int i = attributes.getLength() - 1; i >= 0; i--) {
1844
ac2cf8242428 4864117: RFE: Make XMLDecoder API more reusable
malenkov
parents: 1290
diff changeset
  1068
                String key = attributes.getQName(i);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1069
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1070
                if (key.equals(ATTRIBUTE_VALUE)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1071
                    _style.setOpaque("true".equals(attributes.getValue(i).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1072
                                                   toLowerCase()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1073
                }
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
1844
ac2cf8242428 4864117: RFE: Make XMLDecoder API more reusable
malenkov
parents: 1290
diff changeset
  1078
    private void startInputMap(Attributes attributes) throws SAXException {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1079
        _inputMapBindings.clear();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1080
        _inputMapID = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1081
        if (_style != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1082
            for(int i = attributes.getLength() - 1; i >= 0; i--) {
1844
ac2cf8242428 4864117: RFE: Make XMLDecoder API more reusable
malenkov
parents: 1290
diff changeset
  1083
                String key = attributes.getQName(i);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1084
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1085
                if (key.equals(ATTRIBUTE_ID)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1086
                    _inputMapID = attributes.getValue(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1087
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1088
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1089
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1090
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1091
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1092
    private void endInputMap() throws SAXException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1093
        if (_inputMapID != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1094
            register(_inputMapID, new UIDefaults.LazyInputMap(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1095
                     _inputMapBindings.toArray(new Object[_inputMapBindings.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1096
                     size()])));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1097
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1098
        _inputMapBindings.clear();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1099
        _inputMapID = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1100
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1101
1844
ac2cf8242428 4864117: RFE: Make XMLDecoder API more reusable
malenkov
parents: 1290
diff changeset
  1102
    private void startBindKey(Attributes attributes) throws SAXException {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1103
        if (_inputMapID == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1104
            // Not in an inputmap, bail.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1105
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1106
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1107
        if (_style != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1108
            String key = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1109
            String value = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1110
            for(int i = attributes.getLength() - 1; i >= 0; i--) {
1844
ac2cf8242428 4864117: RFE: Make XMLDecoder API more reusable
malenkov
parents: 1290
diff changeset
  1111
                String aKey = attributes.getQName(i);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1112
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1113
                if (aKey.equals(ATTRIBUTE_KEY)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1114
                    key = attributes.getValue(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1115
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1116
                else if (aKey.equals(ATTRIBUTE_ACTION)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1117
                    value = attributes.getValue(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1118
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1119
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1120
            if (key == null || value == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1121
                throw new SAXException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1122
                    "bindKey: you must supply a key and action");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1123
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1124
            _inputMapBindings.add(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1125
            _inputMapBindings.add(value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1126
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1127
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1128
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1129
    //
1844
ac2cf8242428 4864117: RFE: Make XMLDecoder API more reusable
malenkov
parents: 1290
diff changeset
  1130
    // SAX methods, these forward to the DocumentHandler if we don't know
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1131
    // the element name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1132
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1133
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1134
    public InputSource resolveEntity(String publicId, String systemId)
1844
ac2cf8242428 4864117: RFE: Make XMLDecoder API more reusable
malenkov
parents: 1290
diff changeset
  1135
                              throws IOException, SAXException {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1136
        if (isForwarding()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1137
            return getHandler().resolveEntity(publicId, systemId);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1138
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1139
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1140
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1141
1844
ac2cf8242428 4864117: RFE: Make XMLDecoder API more reusable
malenkov
parents: 1290
diff changeset
  1142
    public void notationDecl(String name, String publicId, String systemId) throws SAXException {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1143
        if (isForwarding()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1144
            getHandler().notationDecl(name, publicId, systemId);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1145
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1146
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1147
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1148
    public void unparsedEntityDecl(String name, String publicId,
1844
ac2cf8242428 4864117: RFE: Make XMLDecoder API more reusable
malenkov
parents: 1290
diff changeset
  1149
                                   String systemId, String notationName) throws SAXException {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1150
        if (isForwarding()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1151
            getHandler().unparsedEntityDecl(name, publicId, systemId,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1152
                                            notationName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1153
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1154
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1155
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1156
    public void setDocumentLocator(Locator locator) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1157
        if (isForwarding()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1158
            getHandler().setDocumentLocator(locator);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1159
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1160
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1161
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1162
    public void startDocument() throws SAXException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1163
        if (isForwarding()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1164
            getHandler().startDocument();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1165
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1166
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1167
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1168
    public void endDocument() throws SAXException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1169
        if (isForwarding()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1170
            getHandler().endDocument();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1171
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1172
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1173
1844
ac2cf8242428 4864117: RFE: Make XMLDecoder API more reusable
malenkov
parents: 1290
diff changeset
  1174
    public void startElement(String uri, String local, String name, Attributes attributes)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1175
                     throws SAXException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1176
        name = name.intern();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1177
        if (name == ELEMENT_STYLE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1178
            startStyle(attributes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1179
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1180
        else if (name == ELEMENT_STATE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1181
            startState(attributes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1182
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1183
        else if (name == ELEMENT_FONT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1184
            startFont(attributes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1185
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1186
        else if (name == ELEMENT_COLOR) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1187
            startColor(attributes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1188
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1189
        else if (name == ELEMENT_PAINTER) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1190
            startPainter(attributes, name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1191
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1192
        else if (name == ELEMENT_IMAGE_PAINTER) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1193
            startPainter(attributes, name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1194
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1195
        else if (name == ELEMENT_PROPERTY) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1196
            startProperty(attributes, ELEMENT_PROPERTY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1197
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1198
        else if (name == ELEMENT_DEFAULTS_PROPERTY) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1199
            startProperty(attributes, ELEMENT_DEFAULTS_PROPERTY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1200
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1201
        else if (name == ELEMENT_SYNTH_GRAPHICS) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1202
            startGraphics(attributes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1203
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1204
        else if (name == ELEMENT_INSETS) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1205
            startInsets(attributes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1206
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1207
        else if (name == ELEMENT_BIND) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1208
            startBind(attributes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1209
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1210
        else if (name == ELEMENT_BIND_KEY) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1211
            startBindKey(attributes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1212
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1213
        else if (name == ELEMENT_IMAGE_ICON) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1214
            startImageIcon(attributes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1215
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1216
        else if (name == ELEMENT_OPAQUE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1217
            startOpaque(attributes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1218
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1219
        else if (name == ELEMENT_INPUT_MAP) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1220
            startInputMap(attributes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1221
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1222
        else if (name != ELEMENT_SYNTH) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1223
            if (_depth++ == 0) {
1844
ac2cf8242428 4864117: RFE: Make XMLDecoder API more reusable
malenkov
parents: 1290
diff changeset
  1224
                getHandler().startDocument();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1225
            }
1844
ac2cf8242428 4864117: RFE: Make XMLDecoder API more reusable
malenkov
parents: 1290
diff changeset
  1226
            getHandler().startElement(uri, local, name, attributes);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1227
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1228
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1229
1844
ac2cf8242428 4864117: RFE: Make XMLDecoder API more reusable
malenkov
parents: 1290
diff changeset
  1230
    public void endElement(String uri, String local, String name) throws SAXException {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1231
        if (isForwarding()) {
1844
ac2cf8242428 4864117: RFE: Make XMLDecoder API more reusable
malenkov
parents: 1290
diff changeset
  1232
            getHandler().endElement(uri, local, name);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1233
            _depth--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1234
            if (!isForwarding()) {
1844
ac2cf8242428 4864117: RFE: Make XMLDecoder API more reusable
malenkov
parents: 1290
diff changeset
  1235
                getHandler().startDocument();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1236
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1237
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1238
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1239
            name = name.intern();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1240
            if (name == ELEMENT_STYLE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1241
                endStyle();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1242
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1243
            else if (name == ELEMENT_STATE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1244
                endState();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1245
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1246
            else if (name == ELEMENT_INPUT_MAP) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1247
                endInputMap();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1248
            }
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
    public void characters(char ch[], int start, int length)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1253
                           throws SAXException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1254
        if (isForwarding()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1255
            getHandler().characters(ch, start, length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1256
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1257
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1258
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1259
    public void ignorableWhitespace (char ch[], int start, int length)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1260
        throws SAXException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1261
        if (isForwarding()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1262
            getHandler().ignorableWhitespace(ch, start, length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1263
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1264
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1265
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1266
    public void processingInstruction(String target, String data)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1267
                                     throws SAXException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1268
        if (isForwarding()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1269
            getHandler().processingInstruction(target, data);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1270
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1271
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1272
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1273
    public void warning(SAXParseException e) throws SAXException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1274
        if (isForwarding()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1275
            getHandler().warning(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1276
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1277
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1278
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1279
    public void error(SAXParseException e) throws SAXException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1280
        if (isForwarding()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1281
            getHandler().error(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1282
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1283
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1284
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1285
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1286
    public void fatalError(SAXParseException e) throws SAXException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1287
        if (isForwarding()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1288
            getHandler().fatalError(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1289
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1290
        throw e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1291
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1292
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1293
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1294
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1295
     * ImageIcon that lazily loads the image until needed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1296
     */
23697
e556a715949f 8034169: Fix serial lint warnings in javax.swing
darcy
parents: 7668
diff changeset
  1297
    @SuppressWarnings("serial") // Superclass is not serializable across versions
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1298
    private static class LazyImageIcon extends ImageIcon implements UIResource {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1299
        private URL location;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1300
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1301
        public LazyImageIcon(URL location) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1302
            super();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1303
            this.location = location;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1304
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1305
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1306
        public void paintIcon(Component c, Graphics g, int x, int y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1307
            if (getImage() != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1308
                super.paintIcon(c, g, x, y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1309
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1310
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1311
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1312
        public int getIconWidth() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1313
            if (getImage() != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1314
                return super.getIconWidth();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1315
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1316
            return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1317
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1318
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1319
        public int getIconHeight() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1320
            if (getImage() != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1321
                return super.getIconHeight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1322
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1323
            return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1324
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1325
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1326
        public Image getImage() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1327
            if (location != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1328
                setImage(Toolkit.getDefaultToolkit().getImage(location));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1329
                location = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1330
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1331
            return super.getImage();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1332
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1333
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1334
}