1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 | @Override public String toString() { StringBuffer sb = new StringBuffer(); String namespacePrefix = ""; // insert indenting ... 2 spaces for now. if(isRoot) { sb.append(XMLPI + "\n"); sb.append(API_COMMENT + "\n"); } else { sb.append("\n"); for(int s = 0; s < level; s++) { sb.append(" "); } } sb.append("<"); // get namespaces for this node Enumeration keys = nameSpaces.keys(); String names = ""; while(keys.hasMoreElements()) { String uri = (String)keys.nextElement(); String prefix = (String)nameSpaces.get(uri); /* if its the xsi namespace (XML Schema Instance), * ignore it, this isn't part of that namespace but it is * needed for the XML Schema validator to work. */ if(!(prefix.equals("xsi"))) { sb.append(prefix + ":"); namespacePrefix = prefix; } names += (" " + "xmlns:" + prefix + "=\"" + uri + "\""); } if(beginOfNamespace) { sb.append(name + names); } else { sb.append(name); } // do attributes if there are any if(attributes.getLength() > 0) { int length = attributes.getLength(); for(int i = 0; i < length; i++) { String attributeValue = attributes.getValue(i); String attributeQName = attributes.getQName(i); sb.append(" " + attributeQName + "=\"" + attributeValue + "\""); } } sb.append(">"); sb.append(cdata); int size = childNodes.size(); for(int i = 0; i < size; i++) { XUINode e = (XUINode)childNodes.get(i); sb.append(e.toString()); } if(size > 0) { sb.append("\n"); for(int s = 0; s < (level); s++) sb.append(" "); } if(namespacePrefix.length() > 0) { sb.append("</" + namespacePrefix + ":" + name + ">"); } else { sb.append("</" + name + ">"); } return sb.toString(); } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 | public void addComponent(XUIComponent component) throws XUITypeFormatException { if(component instanceof XUIBasicDialog || component instanceof XUIOpenFileDialog || component instanceof XUICustomDialog || component instanceof XUIMenuBar || component instanceof XUIPanel || component instanceof XUISplitPanel || component instanceof XUITabbedPanel || component instanceof XUISaveFileDialog) { // get the node XUINode node = component.getNodeRepresentation(); if(!(component instanceof XUIMenuBar)) { int x = Integer.parseInt(node.getAttributeValue("x")); int y = Integer.parseInt(node.getAttributeValue("y")); int width = Integer.parseInt(node.getAttributeValue("width")); int height = Integer.parseInt(node.getAttributeValue("height")); // can't add dialogs so need to check for type here. if(component instanceof XUIBasicDialog || component instanceof XUIOpenFileDialog || component instanceof XUICustomDialog || component instanceof XUISaveFileDialog) ; // nothing else { // check to make sure it fits within the grid. Dimension localGrid = this.getGrid(); if(width > localGrid.getWidth() || height > localGrid.getHeight()) { throw new XUITypeFormatException(node.getName() + " (id: " + node.getAttributeID() + ") must be within this window's grid width and" + "height (w: " + localGrid.getWidth() + " + h: " + localGrid.getHeight() + ")"); } Rectangle rect = new Rectangle(y, x, width, height); component.getPeer().setEnabled(true); frame.getContentPane().add(component.getPeer(), rect); // for mapping components to the regions they occupy childComponentMappings.put(component, rect); } component.setComponentLocation(x, y); } else { // do specifics for a menubar frame.setJMenuBar((JMenuBar)component.getPeer()); } frame.invalidate(); frame.validate(); // add the component's node int level = win.getLevel(); node.setLevel(++level); if(win.getParent() == null) win.addChildNode(node); } else { StringBuffer sb = new StringBuffer(); sb.append("Type not supported in XUIWindow. "); sb.appen("The following types are supported:\n"); for(int i = 0; i < supportedComponents.size(); i++) { String s = (String)supportedComponents.get(i); sb.append("- " + s + "\n"); } throw new XUITypeFormatException(sb.toString()); } } |
欢迎光临 电子技术论坛_中国专业的电子工程师学习交流社区-中电网技术论坛 (http://bbs.eccn.com/) | Powered by Discuz! 7.0.0 |