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