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

📄 synthparser.java

📁 JAVA的一些源码 JAVA2 STANDARD EDITION DEVELOPMENT KIT 5.0
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
    private void startPainter(AttributeList attributes, String type) throws SAXException {        Insets sourceInsets = null;        Insets destInsets = null;        String path = null;        boolean paintCenter = true;        boolean stretch = true;        SynthPainter painter = null;        String method = null;        String id = null;        int direction = -1;        for(int i = attributes.getLength() - 1; i >= 0; i--) {            String key = attributes.getName(i);            String value = attributes.getValue(i);            if (key.equals(ATTRIBUTE_ID)) {                id = value;            }            else if (key.equals(ATTRIBUTE_METHOD)) {                method = value;            }            else if (key.equals(ATTRIBUTE_IDREF)) {                painter = (SynthPainter)lookup(value, SynthPainter.class);            }            else if (key.equals(ATTRIBUTE_PATH)) {                path = value;            }            else if (key.equals(ATTRIBUTE_SOURCE_INSETS)) {                sourceInsets = parseInsets(value, type +                   ": sourceInsets must be top left bottom right");            }            else if (key.equals(ATTRIBUTE_DEST_INSETS)) {                destInsets = parseInsets(value, type +                  ": destinationInsets must be top left bottom right");            }            else if (key.equals(ATTRIBUTE_PAINT_CENTER)) {                paintCenter = value.toLowerCase().equals("true");            }            else if (key.equals(ATTRIBUTE_STRETCH)) {                stretch = value.toLowerCase().equals("true");            }            else if (key.equals(ATTRIBUTE_DIRECTION)) {                value = value.toUpperCase().intern();                if (value == "EAST") {                    direction = SwingConstants.EAST;                }                else if (value == "NORTH") {                    direction = SwingConstants.NORTH;                }                else if (value == "SOUTH") {                    direction = SwingConstants.SOUTH;                }                else if (value == "WEST") {                    direction = SwingConstants.WEST;                }                else if (value == "HORIZONTAL") {                    direction = SwingConstants.HORIZONTAL;                }                else if (value == "VERTICAL") {                    direction = SwingConstants.VERTICAL;                }                else if (value == "HORIZONTAL_SPLIT") {                    direction = JSplitPane.HORIZONTAL_SPLIT;                }                else if (value == "VERTICAL_SPLIT") {                    direction = JSplitPane.VERTICAL_SPLIT;                }                else {                    throw new SAXException(type + ": unknown direction");                }            }        }        if (painter == null) {            if (type == ELEMENT_PAINTER) {                throw new SAXException(type +                              ": you must specify an idref");            }            if (sourceInsets == null) {                throw new SAXException(                             "property: you must specify sourceInsets");            }            if (path == null) {                throw new SAXException("property: you must specify a path");            }            painter = new ImagePainter(!stretch, paintCenter, null,                     sourceInsets, destInsets, getResource(path));        }        register(id, painter);        if (_stateInfo != null) {            _statePainters.add(new ParsedSynthStyle.PainterInfo(                                   method, painter, direction));        }        else if (_style != null) {            _stylePainters.add(new ParsedSynthStyle.PainterInfo(                                   method, painter, direction));        }    }    private void startImageIcon(AttributeList attributes) throws SAXException {        String path = null;        String id = 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_PATH)) {                path = attributes.getValue(i);            }        }        if (path == null) {            throw new SAXException("imageIcon: you must specify a path");        }        register(id, new LazyImageIcon(getResource(path)));        }    private void startOpaque(AttributeList attributes) throws                      SAXException {        if (_style != null) {            _style.setOpaque(true);            for(int i = attributes.getLength() - 1; i >= 0; i--) {                String key = attributes.getName(i);                if (key.equals(ATTRIBUTE_VALUE)) {                    _style.setOpaque("true".equals(attributes.getValue(i).                                                   toLowerCase()));                }            }        }    }    private void startInputMap(AttributeList attributes) throws SAXException {        _inputMapBindings.clear();        _inputMapID = null;        if (_style != null) {            for(int i = attributes.getLength() - 1; i >= 0; i--) {                String key = attributes.getName(i);                if (key.equals(ATTRIBUTE_ID)) {                    _inputMapID = attributes.getValue(i);                }            }        }    }    private void endInputMap() throws SAXException {        if (_inputMapID != null) {            register(_inputMapID, new UIDefaults.LazyInputMap(                     _inputMapBindings.toArray(new Object[_inputMapBindings.                     size()])));        }        _inputMapBindings.clear();        _inputMapID = null;    }    private void startBindKey(AttributeList attributes) throws SAXException {        if (_inputMapID == null) {            // Not in an inputmap, bail.            return;        }        if (_style != null) {            String key = null;            String value = null;            for(int i = attributes.getLength() - 1; i >= 0; i--) {                String aKey = attributes.getName(i);                if (aKey.equals(ATTRIBUTE_KEY)) {                    key = attributes.getValue(i);                }                else if (aKey.equals(ATTRIBUTE_ACTION)) {                    value = attributes.getValue(i);                }            }            if (key == null || value == null) {                throw new SAXException(                    "bindKey: you must supply a key and action");            }            _inputMapBindings.add(key);            _inputMapBindings.add(value);        }    }    //    // SAX methods, these forward to the ObjectHandler if we don't know    // the element name.    //    public InputSource resolveEntity(String publicId, String systemId)                              throws SAXException {        if (isForwarding()) {            return getHandler().resolveEntity(publicId, systemId);        }        return null;    }    public void notationDecl(String name, String publicId, String systemId) {        if (isForwarding()) {            getHandler().notationDecl(name, publicId, systemId);        }    }    public void unparsedEntityDecl(String name, String publicId,                                   String systemId, String notationName) {        if (isForwarding()) {            getHandler().unparsedEntityDecl(name, publicId, systemId,                                            notationName);        }    }    public void setDocumentLocator(Locator locator) {        if (isForwarding()) {            getHandler().setDocumentLocator(locator);        }    }    public void startDocument() throws SAXException {        if (isForwarding()) {            getHandler().startDocument();        }    }    public void endDocument() throws SAXException {        if (isForwarding()) {            getHandler().endDocument();        }    }    public void startElement(String name, AttributeList attributes)	             throws SAXException {        name = name.intern();        if (name == ELEMENT_STYLE) {            startStyle(attributes);        }        else if (name == ELEMENT_STATE) {            startState(attributes);        }        else if (name == ELEMENT_FONT) {            startFont(attributes);        }        else if (name == ELEMENT_COLOR) {            startColor(attributes);        }        else if (name == ELEMENT_PAINTER) {            startPainter(attributes, name);        }        else if (name == ELEMENT_IMAGE_PAINTER) {            startPainter(attributes, name);        }        else if (name == ELEMENT_PROPERTY) {            startProperty(attributes, ELEMENT_PROPERTY);        }        else if (name == ELEMENT_DEFAULTS_PROPERTY) {            startProperty(attributes, ELEMENT_DEFAULTS_PROPERTY);        }        else if (name == ELEMENT_SYNTH_GRAPHICS) {            startGraphics(attributes);        }        else if (name == ELEMENT_INSETS) {            startInsets(attributes);        }        else if (name == ELEMENT_BIND) {            startBind(attributes);        }        else if (name == ELEMENT_BIND_KEY) {            startBindKey(attributes);        }        else if (name == ELEMENT_IMAGE_ICON) {            startImageIcon(attributes);        }        else if (name == ELEMENT_OPAQUE) {            startOpaque(attributes);        }        else if (name == ELEMENT_INPUT_MAP) {            startInputMap(attributes);        }        else if (name != ELEMENT_SYNTH) {            if (_depth++ == 0) {                getHandler().reset();            }            getHandler().startElement(name, attributes);        }    }    public void endElement(String name) throws SAXException {        if (isForwarding()) {            getHandler().endElement(name);            _depth--;            if (!isForwarding()) {                getHandler().reset();            }        }        else {            name = name.intern();            if (name == ELEMENT_STYLE) {                endStyle();            }            else if (name == ELEMENT_STATE) {                endState();            }            else if (name == ELEMENT_INPUT_MAP) {                endInputMap();            }        }    }    public void characters(char ch[], int start, int length)                           throws SAXException {        if (isForwarding()) {            getHandler().characters(ch, start, length);        }    }    public void ignorableWhitespace (char ch[], int start, int length)	throws SAXException {        if (isForwarding()) {            getHandler().ignorableWhitespace(ch, start, length);        }    }    public void processingInstruction(String target, String data)                                     throws SAXException {        if (isForwarding()) {            getHandler().processingInstruction(target, data);        }    }    public void warning(SAXParseException e) throws SAXException {        if (isForwarding()) {            getHandler().warning(e);        }    }    public void error(SAXParseException e) throws SAXException {        if (isForwarding()) {            getHandler().error(e);        }    }            public void fatalError(SAXParseException e) throws SAXException {        if (isForwarding()) {            getHandler().fatalError(e);        }	throw e;    }    /**     * ImageIcon that lazily loads the image until needed.     */    private static class LazyImageIcon extends ImageIcon implements UIResource {        private URL location;        public LazyImageIcon(URL location) {            super();            this.location = location;        }        public void paintIcon(Component c, Graphics g, int x, int y) {            if (getImage() != null) {                super.paintIcon(c, g, x, y);            }        }            public int getIconWidth() {            if (getImage() != null) {                return super.getIconWidth();            }            return 0;        }        public int getIconHeight() {            if (getImage() != null) {                return super.getIconHeight();            }            return 0;        }        public Image getImage() {            if (location != null) {                setImage(Toolkit.getDefaultToolkit().getImage(location));                location = null;            }            return super.getImage();        }    }}

⌨️ 快捷键说明

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