📄 synthparser.java
字号:
if (center && (sourceInsets != null || destInsets != null || paintCenterSpecified || stretchSpecified)) { throw new SAXException("The attributes: sourceInsets, " + "destinationInsets, paintCenter and stretch " + " are not legal when center is true"); } painter = new ImagePainter(!stretch, paintCenter, sourceInsets, destInsets, getResource(path), center); } register(id, painter); if (_stateInfo != null) { addPainterOrMerge(_statePainters, method, painter, direction); } else if (_style != null) { addPainterOrMerge(_stylePainters, method, painter, direction); } } private void addPainterOrMerge(java.util.List painters, String method, SynthPainter painter, int direction) { ParsedSynthStyle.PainterInfo painterInfo; painterInfo = new ParsedSynthStyle.PainterInfo(method, painter, direction); for (Object infoObject: painters) { ParsedSynthStyle.PainterInfo info; info = (ParsedSynthStyle.PainterInfo) infoObject; if (painterInfo.equalsPainter(info)) { info.addPainter(painter); return; } } painters.add(painterInfo); } 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 + -