private Area loadScreenArea(String pngFile) throws Exception { Area area = null; String xmlArea = "./workspace/" + file.substring(0, file.indexOf("/")) + "/screen_area.xml"; System.out.println(xmlArea); XmlUtil xmlUtil = new XmlUtil(xmlArea); Document doc = xmlUtil.parse(xmlArea); Element root = doc.getDocumentElement(); NodeList childs = root.getChildNodes(); if (childs != null) { for (int i = 0; i < childs.getLength(); i++) { Node node = childs.item(i); if (node.getNodeType() == Node.ELEMENT_NODE) { NamedNodeMap map = node.getAttributes(); String fileName = map.getNamedItem("file").getNodeValue(); if (fileName.equals(pngFile)) { area = new Area(); area.setFile(fileName); area.setX(Integer.parseInt(map.getNamedItem("x").getNodeValue())); area.setY(Integer.parseInt(map.getNamedItem("y").getNodeValue())); area.setWidth(Integer.parseInt(map.getNamedItem("width").getNodeValue())); area.setHeight(Integer.parseInt(map.getNamedItem("height").getNodeValue())); } } } } return area; }
private void updateScreenArea(String pngFile, Area area) throws Exception { String xmlArea = "./workspace/" + file.substring(0, file.indexOf("/")) + "/screen_area.xml"; XmlUtil xmlUtil = new XmlUtil(xmlArea); Document doc = xmlUtil.parse(xmlArea); Element root = doc.getDocumentElement(); NodeList childs = root.getChildNodes(); if (childs != null) { // del for (int i = 0; i < childs.getLength(); i++) { Node node = childs.item(i); if (node.getNodeType() == Node.ELEMENT_NODE) { NamedNodeMap map = node.getAttributes(); String fileName = map.getNamedItem("file").getNodeValue(); if (fileName.equals(pngFile)) { root.removeChild(node); break; } } } } // add Hashtable<String, String> attri = new Hashtable(); attri.put("file", area.getFile()); attri.put("x", String.valueOf(area.getX())); attri.put("y", String.valueOf(area.getY())); attri.put("width", String.valueOf(area.getWidth())); attri.put("height", String.valueOf(area.getHeight())); xmlUtil.appendNode(root.getOwnerDocument(), "area", "", attri); xmlUtil.flush(doc); }