⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 synthparser.java

📁 JAVA的一些源码 JAVA2 STANDARD EDITION DEVELOPMENT KIT 5.0
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
                        state |= SynthConstants.SELECTED;                    }                    else if (stateString == "DEFAULT") {                        state |= SynthConstants.DEFAULT;                    }                    else if (stateString != "AND") {                        throw new SAXException("Unknown state: " + state);                    }                }            }        }        if (_stateInfo == null) {            _stateInfo = new ParsedSynthStyle.StateInfo();        }        _stateInfo.setComponentState(state);        register(id, _stateInfo);        _stateInfos.add(_stateInfo);    }    private void endState() throws SAXException {        int size = _statePainters.size();        if (size > 0) {            _stateInfo.setPainters((ParsedSynthStyle.PainterInfo[])                  _statePainters.toArray(new ParsedSynthStyle.                  PainterInfo[size]));            _statePainters.clear();        }        _stateInfo = null;    }    private void startFont(AttributeList attributes) throws SAXException {        Font font = null;        int style = Font.PLAIN;        int size = 0;        String id = null;        String name = null;        for(int i = attributes.getLength() - 1; i >= 0; i--) {            String key = attributes.getName(i);            if (key.equals(ATTRIBUTE_ID)) {                id = attributes.getValue(i);            }            else if (key.equals(ATTRIBUTE_IDREF)) {                font = (Font)lookup(attributes.getValue(i), Font.class);            }            else if (key.equals(ATTRIBUTE_NAME)) {                name = attributes.getValue(i);            }            else if (key.equals(ATTRIBUTE_SIZE)) {                try {                    size = Integer.parseInt(attributes.getValue(i));                } catch (NumberFormatException nfe) {                    throw new SAXException("Invalid font size: " +                                           attributes.getValue(i));                }            }            else if (key.equals(ATTRIBUTE_STYLE)) {                StringTokenizer tok = new StringTokenizer(                                                attributes.getValue(i));                while (tok.hasMoreTokens()) {                    String token = tok.nextToken().intern();                    if (token == "BOLD") {                        style = ((style | Font.PLAIN) ^ Font.PLAIN) |                                Font.BOLD;                    }                    else if (token == "ITALIC") {                        style |= Font.ITALIC;                    }                }            }        }        if (font == null) {            if (name == null) {                throw new SAXException("You must define a name for the font");            }            if (size == 0) {                throw new SAXException("You must define a size for the font");            }            font = new FontUIResource(name, style, size);        }        else if (name != null || size != 0 || style != Font.PLAIN) {            throw new SAXException("Name, size and style are not for use " +                                   "with idref");        }        register(id, font);        if (_stateInfo != null) {            _stateInfo.setFont(font);        }        else if (_style != null) {            _style.setFont(font);        }    }    private void startColor(AttributeList attributes) throws SAXException {        Color color = null;        String id = null;        _colorTypes.clear();        for(int i = attributes.getLength() - 1; i >= 0; i--) {            String key = attributes.getName(i);            if (key.equals(ATTRIBUTE_ID)) {                id = attributes.getValue(i);            }            else if (key.equals(ATTRIBUTE_IDREF)) {                color = (Color)lookup(attributes.getValue(i), Color.class);            }            else if (key.equals(ATTRIBUTE_NAME)) {            }            else if (key.equals(ATTRIBUTE_VALUE)) {                String value = attributes.getValue(i);                if (value.startsWith("#")) {                    try {                        int rgba = Integer.decode(value).intValue();                        color = new ColorUIResource(new Color(                                              rgba, value.length() > 7));                    } catch (NumberFormatException nfe) {                        throw new SAXException("Invalid Color value: " +value);                    }                }                else {                    try {                        color = new ColorUIResource((Color)Color.class.                              getField(value.toUpperCase()).get(Color.class));                    } catch (NoSuchFieldException nsfe) {                        throw new SAXException("Invalid color name: " + value);                    } catch (IllegalAccessException iae) {                        throw new SAXException("Invalid color name: " + value);                    }                }            }            else if (key.equals(ATTRIBUTE_TYPE)) {                StringTokenizer tokenizer = new StringTokenizer(                                   attributes.getValue(i));                while (tokenizer.hasMoreTokens()) {                    String typeName = tokenizer.nextToken();                    int classIndex = typeName.lastIndexOf('.');                    Class typeClass;                    if (classIndex == -1) {                        typeClass = ColorType.class;                        classIndex = 0;                    }                    else {                        try {                            typeClass = Class.forName(typeName.substring(                                                      0, classIndex));                        } catch (ClassNotFoundException cnfe) {                            throw new SAXException("Unknown class: " +                                      typeName.substring(0, classIndex));                        }                        classIndex++;                    }                    try {                        _colorTypes.add((ColorType)checkCast(typeClass.                              getField(typeName.substring(classIndex,                              typeName.length() - classIndex)).                              get(typeClass), ColorType.class));                    } catch (NoSuchFieldException nsfe) {                        throw new SAXException("Unable to find color type: " +                                               typeName);                    } catch (IllegalAccessException iae) {                        throw new SAXException("Unable to find color type: " +                                               typeName);                    }                }            }        }        if (color == null) {            throw new SAXException("color: you must specificy a value");        }        register(id, color);        if (_stateInfo != null && _colorTypes.size() > 0) {            Color[] colors = _stateInfo.getColors();            int max = 0;            for (int counter = _colorTypes.size() - 1; counter >= 0;                     counter--) {                max = Math.max(max, ((ColorType)_colorTypes.get(counter)).                               getID());            }            if (colors == null || colors.length <= max) {                Color[] newColors = new Color[max + 1];                if (colors != null) {                    System.arraycopy(colors, 0, newColors, 0, colors.length);                }                colors = newColors;            }            for (int counter = _colorTypes.size() - 1; counter >= 0;                     counter--) {                colors[((ColorType)_colorTypes.get(counter)).getID()] = color;            }            _stateInfo.setColors(colors);        }    }    private void startProperty(AttributeList attributes,                               Object property) throws SAXException {        Object value = null;        Object key = null;        // Type of the value: 0=idref, 1=boolean, 2=dimension, 3=insets,        // 4=integer        int iType = 0;        String aValue = null;        for(int i = attributes.getLength() - 1; i >= 0; i--) {            String aName = attributes.getName(i);            if (aName.equals(ATTRIBUTE_TYPE)) {                String type = attributes.getValue(i).toUpperCase();                if (type.equals("IDREF")) {                    iType = 0;                }                else if (type.equals("BOOLEAN")) {                    iType = 1;                }                else if (type.equals("DIMENSION")) {                    iType = 2;                }                else if (type.equals("INSETS")) {                    iType = 3;                }                else if (type.equals("INTEGER")) {                    iType = 4;                }                else {                    throw new SAXException(property + " unknown type, use" +                        "idref, boolean, dimension, insets or integer");                }            }            else if (aName.equals(ATTRIBUTE_VALUE)) {                aValue = attributes.getValue(i);            }            else if (aName.equals(ATTRIBUTE_KEY)) {                key = attributes.getValue(i);            }        }        if (aValue != null) {            switch (iType) {            case 0: // idref                value = lookup(aValue, Object.class);                break;            case 1: // boolean                if (aValue.toUpperCase().equals("TRUE")) {                    value = Boolean.TRUE;                }                else {                    value = Boolean.FALSE;                }                break;            case 2: // dimension                StringTokenizer tok = new StringTokenizer(aValue);                value = new DimensionUIResource(                    nextInt(tok, "Invalid dimension"),                    nextInt(tok, "Invalid dimension"));                break;            case 3: // insets                value = parseInsets(aValue, property + " invalid insets");                break;            case 4: // integer                try {                    value = new Integer(Integer.parseInt(aValue));                } catch (NumberFormatException nfe) {                    throw new SAXException(property + " invalid value");                }                break;            }        }        if (value == null || key == null) {            throw new SAXException(property + ": you must supply a " +                                   "key and value");        }        if (property == ELEMENT_DEFAULTS_PROPERTY) {            _defaultsMap.put(key, value);        }        else if (_stateInfo != null) {            if (_stateInfo.getData() == null) {                _stateInfo.setData(new HashMap());            }            _stateInfo.getData().put(key, value);        }        else if (_style != null) {            if (_style.getData() == null) {                _style.setData(new HashMap());            }            _style.getData().put(key, value);        }    }    private void startGraphics(AttributeList attributes) throws SAXException {        SynthGraphicsUtils graphics = null;        for(int i = attributes.getLength() - 1; i >= 0; i--) {            String key = attributes.getName(i);            if (key.equals(ATTRIBUTE_IDREF)) {                graphics = (SynthGraphicsUtils)lookup(attributes.getValue(i),                                                 SynthGraphicsUtils.class);            }        }        if (graphics == null) {            throw new SAXException("graphicsUtils: you must supply an idref");        }        if (_style != null) {            _style.setGraphicsUtils(graphics);        }    }    private void startInsets(AttributeList attributes) throws SAXException {        int top = 0;        int bottom = 0;        int left = 0;        int right = 0;        Insets insets = null;        String id = null;        for(int i = attributes.getLength() - 1; i >= 0; i--) {            String key = attributes.getName(i);            try {                if (key.equals(ATTRIBUTE_IDREF)) {                    insets = (Insets)lookup(attributes.getValue(i),                                                   Insets.class);                }                else if (key.equals(ATTRIBUTE_ID)) {                    id = attributes.getValue(i);                }                else if (key.equals(ATTRIBUTE_TOP)) {                    top = Integer.parseInt(attributes.getValue(i));                }                else if (key.equals(ATTRIBUTE_LEFT)) {                    left = Integer.parseInt(attributes.getValue(i));                }                else if (key.equals(ATTRIBUTE_BOTTOM)) {                    bottom = Integer.parseInt(attributes.getValue(i));                }                else if (key.equals(ATTRIBUTE_RIGHT)) {                    right = Integer.parseInt(attributes.getValue(i));                }            } catch (NumberFormatException nfe) {                throw new SAXException("insets: bad integer value for " +                                       attributes.getValue(i));            }        }        if (insets == null) {            insets = new InsetsUIResource(top, left, bottom, right);        }        register(id, insets);        if (_style != null) {            _style.setInsets(insets);        }    }    private void startBind(AttributeList attributes) throws SAXException {        ParsedSynthStyle style = null;        String path = null;        int type = -1;        for(int i = attributes.getLength() - 1; i >= 0; i--) {            String key = attributes.getName(i);            if (key.equals(ATTRIBUTE_STYLE)) {                style = (ParsedSynthStyle)lookup(attributes.getValue(i),                                                  ParsedSynthStyle.class);            }            else if (key.equals(ATTRIBUTE_TYPE)) {                String typeS = attributes.getValue(i).toUpperCase();                if (typeS.equals("NAME")) {                    type = DefaultSynthStyleFactory.NAME;                }                else if (typeS.equals("REGION")) {                    type = DefaultSynthStyleFactory.REGION;                }                else {                    throw new SAXException("bind: unknown type " + typeS);                }            }            else if (key.equals(ATTRIBUTE_KEY)) {                path = attributes.getValue(i);             }        }        if (style == null || path == null || type == -1) {            throw new SAXException("bind: you must specify a style, type " +                                   "and key");        }        try {            _factory.addStyle(style, path, type);        } catch (PatternSyntaxException pse) {            throw new SAXException("bind: " + path + " is not a valid " +                                   "regular expression");        }    }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -