📄 synthparser.java
字号:
} 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,5=string 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 if (type.equals("STRING")) { iType = 5; } 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; case 5: //string value = aValue; 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"); } } 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; boolean center = false; boolean stretchSpecified = false; boolean paintCenterSpecified = false; 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.toLowerCase(Locale.ENGLISH); } 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"); paintCenterSpecified = true; } else if (key.equals(ATTRIBUTE_STRETCH)) { stretch = value.toLowerCase().equals("true"); stretchSpecified = 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 == "TOP") { direction = SwingConstants.TOP; } else if (value == "LEFT") { direction = SwingConstants.LEFT; } else if (value == "BOTTOM") { direction = SwingConstants.BOTTOM; } else if (value == "RIGHT") { direction = SwingConstants.RIGHT; } 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"); } } else if (key.equals(ATTRIBUTE_CENTER)) { center = value.toLowerCase().equals("true"); } } if (painter == null) { if (type == ELEMENT_PAINTER) { throw new SAXException(type + ": you must specify an idref"); } if (sourceInsets == null && !center) { throw new SAXException( "property: you must specify sourceInsets"); } if (path == null) { throw new SAXException("property: you must specify a path"); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -