private Insets parseInsets(String key) throws XPathExpressionException { Element elm = helper.xpathAsElement(key); int left = helper.getInt(elm, "left"); int top = helper.getInt(elm, "top"); int right = helper.getInt(elm, "right"); int bottom = helper.getInt(elm, "bottom"); Insets insets = new Insets(top, left, bottom, right); return insets; }
private Integer parseInteger(String key) throws LafException, XPathExpressionException { Element element = helper.xpathAsElement(key); if (element == null) return null; String value = element.getTextContent(); try { return Integer.valueOf(value, 10); } catch (NumberFormatException e) { throw new LafException(e); } }
private Color parseColor(String key) throws XPathExpressionException, LafException { Element element = helper.xpathAsElement(key); if (element == null) return null; String value = element.getTextContent(); String format = element.getAttribute("format"); Color color = null; if ("hex".equals(format)) { Integer hex = Integer.valueOf(value, 16); color = new Color(hex, false); } else throw new LafException("unknown color format: " + format); return color; }
public void installColors(UIDefaults defaults) throws LafException, XPathExpressionException { NodeList complist = helper.xpathAsNodeList(ROOT + "/color/child::*"); int complength = complist.getLength(); for (int i = 0; i < complength; ++i) { Element element = (Element) complist.item(i); String tagName = element.getTagName(); NodeList childlist = DomUtil.getChildElements(element); Color value = parseColor(ROOT + "/color/" + tagName); defaults.put(tagName, new ColorUIResource(value)); } }
public Map<String, Object> getDefaultValues() throws XPathExpressionException, LafException { Map<String, Object> map = new HashMap<String, Object>(); NodeList list = helper.xpathAsNodeList(ROOT + "/default/child::*"); int length = list.getLength(); for (int i = 0; i < length; ++i) { Element element = (Element) list.item(i); String tagName = element.getTagName(); Object value = getImpl(ROOT + "/default/" + tagName); map.put(tagName, value); } return map; }
private Font parseFont(String key) throws XPathExpressionException { Map<TextAttribute, Object> atts = new HashMap<TextAttribute, Object>(); NodeList list = helper.xpathAsNodeList(key + "/child::*"); int length = list.getLength(); for (int i = 0; i < length; ++i) { Element element = (Element) list.item(i); String name = element.getTagName(); TextAttribute att = FONT_ATTRIBUTES.get(name); if (att == null) continue; Object value = element.getTextContent(); if (att == TextAttribute.SIZE) { value = Float.parseFloat(value.toString()); } else if (att == TextAttribute.WEIGHT) { value = Float.parseFloat(value.toString()); } atts.put(att, value); } return new Font(atts); }
public void installComponents(UIDefaults defaults, Map<String, Object> defaultValues) throws LafException, XPathExpressionException { NodeList complist = helper.xpathAsNodeList(ROOT + "/component/child::*"); int complength = complist.getLength(); for (int i = 0; i < complength; ++i) { Element element = (Element) complist.item(i); String tagName = element.getTagName(); for (String defaultKey : defaultValues.keySet()) UIManager.put(tagName + "." + defaultKey, defaultValues.get(defaultKey)); NodeList childlist = DomUtil.getChildElements(element); int childlength = childlist.getLength(); for (int j = 0; j < childlength; ++j) { Element childElement = (Element) childlist.item(j); String childName = childElement.getTagName(); Object value = getImpl(ROOT + "/component/" + tagName + "/" + childName); defaults.put(tagName + "." + childName, value); } } }
private String getLastPathComponentType(String path) throws XPathExpressionException { Node node = helper.xpathAsNode(path + "/attribute::type"); if (node == null) return ""; return node.getNodeValue(); }