Search in sources :

Example 1 with GUIImageNode

use of net.drewke.tdme.gui.nodes.GUIImageNode in project tdme by andreasdr.

the class GUIParser method parseGUINode.

/**
	 * Parse GUI node
	 * @param gui parent node
	 * @param xml parent node
	 * @param gui element
	 * @throws Exception
	 */
private static void parseGUINode(GUIParentNode guiParentNode, Element xmlParentNode, GUIElement guiElement) throws Exception {
    //
    GUINodeController guiElementController = null;
    boolean guiElementControllerInstalled = false;
    // parse sub nodes
    for (Element node : getChildrenTags(xmlParentNode)) {
        if (node.getNodeName().equals("panel")) {
            // TODO: validate root node
            GUIPanelNode guiPanelNode = new GUIPanelNode(guiParentNode.getScreenNode(), guiParentNode, node.getAttribute("id"), GUINode.createFlow(node.getAttribute("flow")), GUIParentNode.createOverflow(node.getAttribute("overflow-x")), GUIParentNode.createOverflow(node.getAttribute("overflow-y")), GUINode.createAlignments(node.getAttribute("horizontal-align"), node.getAttribute("vertical-align")), GUIParentNode.createRequestedConstraints(node.getAttribute("left"), node.getAttribute("top"), node.getAttribute("width"), node.getAttribute("height")), GUINode.getRequestedColor(node.getAttribute("background-color"), new GUIColor("#F0F0F0")), GUINode.createBorder(node.getAttribute("border"), node.getAttribute("border-left"), node.getAttribute("border-top"), node.getAttribute("border-right"), node.getAttribute("border-bottom"), node.getAttribute("border-color"), node.getAttribute("border-color-left"), node.getAttribute("border-color-top"), node.getAttribute("border-color-right"), node.getAttribute("border-color-bottom")), GUINode.createPadding(node.getAttribute("padding"), node.getAttribute("padding-left"), node.getAttribute("padding-top"), node.getAttribute("padding-right"), node.getAttribute("padding-bottom")), GUINode.createConditions(node.getAttribute("show-on")), GUINode.createConditions(node.getAttribute("hide-on")), GUILayoutNode.createAlignment(node.getAttribute("alignment")));
            guiParentNode.addSubNode(guiPanelNode);
            // install gui element controller if not yet done
            if (guiElement != null && guiElementControllerInstalled == false) {
                guiElementController = guiElement.createController(guiPanelNode);
                if (guiElementController != null) {
                    guiPanelNode.setController(guiElementController);
                }
                guiElementControllerInstalled = true;
            }
            // parse child nodes
            parseGUINode(guiPanelNode, node, null);
        } else if (node.getNodeName().equals("layout")) {
            // TODO: validate root node
            GUILayoutNode guiLayoutNode = new GUILayoutNode(guiParentNode.getScreenNode(), guiParentNode, node.getAttribute("id"), GUINode.createFlow(node.getAttribute("flow")), GUIParentNode.createOverflow(node.getAttribute("overflow-x")), GUIParentNode.createOverflow(node.getAttribute("overflow-y")), GUINode.createAlignments(node.getAttribute("horizontal-align"), node.getAttribute("vertical-align")), GUIParentNode.createRequestedConstraints(node.getAttribute("left"), node.getAttribute("top"), node.getAttribute("width"), node.getAttribute("height")), GUINode.getRequestedColor(node.getAttribute("background-color"), GUIColor.TRANSPARENT), GUINode.createBorder(node.getAttribute("border"), node.getAttribute("border-left"), node.getAttribute("border-top"), node.getAttribute("border-right"), node.getAttribute("border-bottom"), node.getAttribute("border-color"), node.getAttribute("border-color-left"), node.getAttribute("border-color-top"), node.getAttribute("border-color-right"), node.getAttribute("border-color-bottom")), GUINode.createPadding(node.getAttribute("padding"), node.getAttribute("padding-left"), node.getAttribute("padding-top"), node.getAttribute("padding-right"), node.getAttribute("padding-bottom")), GUINode.createConditions(node.getAttribute("show-on")), GUINode.createConditions(node.getAttribute("hide-on")), GUILayoutNode.createAlignment(node.getAttribute("alignment")));
            guiParentNode.addSubNode(guiLayoutNode);
            // install gui element controller if not yet done
            if (guiElement != null && guiElementControllerInstalled == false) {
                guiElementController = guiElement.createController(guiLayoutNode);
                if (guiElementController != null) {
                    guiLayoutNode.setController(guiElementController);
                }
                guiElementControllerInstalled = true;
            }
            // parse child nodes
            parseGUINode(guiLayoutNode, node, null);
        } else if (node.getNodeName().equals("space")) {
            // TODO: validate root node
            GUISpaceNode guiSpaceNode = new GUISpaceNode(guiParentNode.getScreenNode(), guiParentNode, node.getAttribute("id"), GUINode.createFlow(node.getAttribute("flow")), GUINode.createAlignments(node.getAttribute("horizontal-align"), node.getAttribute("vertical-align")), GUISpaceNode.createRequestedConstraints(node.getAttribute("left"), node.getAttribute("top"), node.getAttribute("width"), node.getAttribute("height")), GUINode.getRequestedColor(node.getAttribute("background-color"), GUIColor.TRANSPARENT), GUINode.createBorder(node.getAttribute("border"), node.getAttribute("border-left"), node.getAttribute("border-top"), node.getAttribute("border-right"), node.getAttribute("border-bottom"), node.getAttribute("border-color"), node.getAttribute("border-color-left"), node.getAttribute("border-color-top"), node.getAttribute("border-color-right"), node.getAttribute("border-color-bottom")), GUINode.createPadding(node.getAttribute("padding"), node.getAttribute("padding-left"), node.getAttribute("padding-top"), node.getAttribute("padding-right"), node.getAttribute("padding-bottom")), GUINode.createConditions(node.getAttribute("show-on")), GUINode.createConditions(node.getAttribute("hide-on")));
            guiParentNode.addSubNode(guiSpaceNode);
            // install gui element controller if not yet done
            if (guiElement != null && guiElementControllerInstalled == false) {
                guiElementController = guiElement.createController(guiSpaceNode);
                if (guiElementController != null) {
                    guiSpaceNode.setController(guiElementController);
                }
                guiElementControllerInstalled = true;
            }
        } else if (node.getNodeName().equals("element")) {
            // TODO: validate root node
            GUIElementNode guiElementNode = new GUIElementNode(guiParentNode.getScreenNode(), guiParentNode, node.getAttribute("id"), GUINode.createFlow(node.getAttribute("flow")), GUIParentNode.createOverflow(node.getAttribute("overflow-x")), GUIParentNode.createOverflow(node.getAttribute("overflow-y")), GUINode.createAlignments(node.getAttribute("horizontal-align"), node.getAttribute("vertical-align")), GUINode.createRequestedConstraints(node.getAttribute("left"), node.getAttribute("top"), node.getAttribute("width"), node.getAttribute("height")), GUINode.getRequestedColor(node.getAttribute("background-color"), GUIColor.TRANSPARENT), GUINode.createBorder(node.getAttribute("border"), node.getAttribute("border-left"), node.getAttribute("border-top"), node.getAttribute("border-right"), node.getAttribute("border-bottom"), node.getAttribute("border-color"), node.getAttribute("border-color-left"), node.getAttribute("border-color-top"), node.getAttribute("border-color-right"), node.getAttribute("border-color-bottom")), GUINode.createPadding(node.getAttribute("padding"), node.getAttribute("padding-left"), node.getAttribute("padding-top"), node.getAttribute("padding-right"), node.getAttribute("padding-bottom")), GUINode.createConditions(node.getAttribute("show-on")), GUINode.createConditions(node.getAttribute("hide-on")), unescapeQuotes(node.getAttribute("name")), unescapeQuotes(node.getAttribute("value")), node.getAttribute("selected").trim().equalsIgnoreCase("true"), node.getAttribute("disabled").trim().equalsIgnoreCase("true"), node.getAttribute("focusable").trim().equalsIgnoreCase("true"), node.getAttribute("ignore-events").trim().equalsIgnoreCase("true"));
            guiParentNode.addSubNode(guiElementNode);
            // install gui element controller if not yet done
            if (guiElement != null && guiElementControllerInstalled == false) {
                guiElementController = guiElement.createController(guiElementNode);
                if (guiElementController != null) {
                    guiElementNode.setController(guiElementController);
                }
                guiElementControllerInstalled = true;
            }
            // parse child nodes
            parseGUINode(guiElementNode, node, null);
        } else if (node.getNodeName().equals("image")) {
            // TODO: validate root node
            GUIImageNode guiImageNode = new GUIImageNode(guiParentNode.getScreenNode(), guiParentNode, node.getAttribute("id"), GUINode.createFlow(node.getAttribute("flow")), GUINode.createAlignments(node.getAttribute("horizontal-align"), node.getAttribute("vertical-align")), GUINode.createRequestedConstraints(node.getAttribute("left"), node.getAttribute("top"), node.getAttribute("width"), node.getAttribute("height")), GUINode.getRequestedColor(node.getAttribute("background-color"), GUIColor.TRANSPARENT), GUINode.createBorder(node.getAttribute("border"), node.getAttribute("border-left"), node.getAttribute("border-top"), node.getAttribute("border-right"), node.getAttribute("border-bottom"), node.getAttribute("border-color"), node.getAttribute("border-color-left"), node.getAttribute("border-color-top"), node.getAttribute("border-color-right"), node.getAttribute("border-color-bottom")), GUINode.createPadding(node.getAttribute("padding"), node.getAttribute("padding-left"), node.getAttribute("padding-top"), node.getAttribute("padding-right"), node.getAttribute("padding-bottom")), GUINode.createConditions(node.getAttribute("show-on")), GUINode.createConditions(node.getAttribute("hide-on")), unescapeQuotes(node.getAttribute("src")), GUINode.getRequestedColor(node.getAttribute("effect-color-mul"), GUIColor.EFFECT_COLOR_MUL), GUINode.getRequestedColor(node.getAttribute("effect-color-add"), GUIColor.EFFECT_COLOR_ADD));
            guiParentNode.addSubNode(guiImageNode);
            // install gui element controller if not yet done
            if (guiElement != null && guiElementControllerInstalled == false) {
                guiElementController = guiElement.createController(guiImageNode);
                if (guiElementController != null) {
                    guiImageNode.setController(guiElementController);
                }
                guiElementControllerInstalled = true;
            }
        } else if (node.getNodeName().equals("text")) {
            // TODO: validate root node
            GUITextNode guiTextNode = new GUITextNode(guiParentNode.getScreenNode(), guiParentNode, node.getAttribute("id"), GUINode.createFlow(node.getAttribute("flow")), GUINode.createAlignments(node.getAttribute("horizontal-align"), node.getAttribute("vertical-align")), GUINode.createRequestedConstraints(node.getAttribute("left"), node.getAttribute("top"), node.getAttribute("width"), node.getAttribute("height")), GUINode.getRequestedColor(node.getAttribute("background-color"), GUIColor.TRANSPARENT), GUINode.createBorder(node.getAttribute("border"), node.getAttribute("border-left"), node.getAttribute("border-top"), node.getAttribute("border-right"), node.getAttribute("border-bottom"), node.getAttribute("border-color"), node.getAttribute("border-color-left"), node.getAttribute("border-color-top"), node.getAttribute("border-color-right"), node.getAttribute("border-color-bottom")), GUINode.createPadding(node.getAttribute("padding"), node.getAttribute("padding-left"), node.getAttribute("padding-top"), node.getAttribute("padding-right"), node.getAttribute("padding-bottom")), GUINode.createConditions(node.getAttribute("show-on")), GUINode.createConditions(node.getAttribute("hide-on")), node.getAttribute("font"), node.getAttribute("color"), new MutableString(unescapeQuotes(node.getAttribute("text"))));
            guiParentNode.addSubNode(guiTextNode);
            // install gui element controller if not yet done
            if (guiElement != null && guiElementControllerInstalled == false) {
                guiElementController = guiElement.createController(guiTextNode);
                if (guiElementController != null) {
                    guiTextNode.setController(guiElementController);
                }
                guiElementControllerInstalled = true;
            }
        } else if (node.getNodeName().equals("input-internal")) {
            // TODO: validate root node
            GUIInputInternalNode guiInputInternalNode = new GUIInputInternalNode(guiParentNode.getScreenNode(), guiParentNode, node.getAttribute("id"), GUINode.createFlow(node.getAttribute("flow")), GUINode.createAlignments(node.getAttribute("horizontal-align"), node.getAttribute("vertical-align")), GUINode.createRequestedConstraints(node.getAttribute("left"), node.getAttribute("top"), node.getAttribute("width"), node.getAttribute("height")), GUINode.getRequestedColor(node.getAttribute("background-color"), GUIColor.TRANSPARENT), GUINode.createBorder(node.getAttribute("border"), node.getAttribute("border-left"), node.getAttribute("border-top"), node.getAttribute("border-right"), node.getAttribute("border-bottom"), node.getAttribute("border-color"), node.getAttribute("border-color-left"), node.getAttribute("border-color-top"), node.getAttribute("border-color-right"), node.getAttribute("border-color-bottom")), GUINode.createPadding(node.getAttribute("padding"), node.getAttribute("padding-left"), node.getAttribute("padding-top"), node.getAttribute("padding-right"), node.getAttribute("padding-bottom")), GUINode.createConditions(node.getAttribute("show-on")), GUINode.createConditions(node.getAttribute("hide-on")), node.getAttribute("font"), node.getAttribute("color"), node.getAttribute("color-disabled"), new MutableString(unescapeQuotes(node.getAttribute("text"))), GUIInputInternalNode.createMaxLength(node.getAttribute("maxlength")));
            guiParentNode.addSubNode(guiInputInternalNode);
            // install gui element controller if not yet done
            if (guiElement != null && guiElementControllerInstalled == false) {
                guiElementController = guiElement.createController(guiInputInternalNode);
                if (guiElementController != null) {
                    guiInputInternalNode.setController(guiElementController);
                }
                guiElementControllerInstalled = true;
            }
        } else if (node.getNodeName().equals("vertical-scrollbar-internal")) {
            // TODO: validate root node
            GUIVerticalScrollbarInternalNode guiVerticalScrollbarInternalNode = new GUIVerticalScrollbarInternalNode(guiParentNode.getScreenNode(), guiParentNode, node.getAttribute("id"), GUINode.createFlow(node.getAttribute("flow")), GUINode.createAlignments(node.getAttribute("horizontal-align"), node.getAttribute("vertical-align")), GUINode.createRequestedConstraints(node.getAttribute("left"), node.getAttribute("top"), node.getAttribute("width"), node.getAttribute("height")), GUINode.getRequestedColor(node.getAttribute("background-color"), GUIColor.TRANSPARENT), GUINode.createBorder(node.getAttribute("border"), node.getAttribute("border-left"), node.getAttribute("border-top"), node.getAttribute("border-right"), node.getAttribute("border-bottom"), node.getAttribute("border-color"), node.getAttribute("border-color-left"), node.getAttribute("border-color-top"), node.getAttribute("border-color-right"), node.getAttribute("border-color-bottom")), GUINode.createPadding(node.getAttribute("padding"), node.getAttribute("padding-left"), node.getAttribute("padding-top"), node.getAttribute("padding-right"), node.getAttribute("padding-bottom")), GUINode.createConditions(node.getAttribute("show-on")), GUINode.createConditions(node.getAttribute("hide-on")), GUINode.getRequestedColor(node.getAttribute("color-none"), GUIColor.BLACK), GUINode.getRequestedColor(node.getAttribute("color-mouseover"), GUIColor.BLACK), GUINode.getRequestedColor(node.getAttribute("color-dragging"), GUIColor.BLACK));
            guiParentNode.addSubNode(guiVerticalScrollbarInternalNode);
            // install gui element controller if not yet done
            if (guiElement != null && guiElementControllerInstalled == false) {
                guiElementController = guiElement.createController(guiVerticalScrollbarInternalNode);
                if (guiElementController != null) {
                    guiVerticalScrollbarInternalNode.setController(guiElementController);
                }
                guiElementControllerInstalled = true;
            }
        } else if (node.getNodeName().equals("horizontal-scrollbar-internal")) {
            // TODO: validate root node
            GUIHorizontalScrollbarInternalNode guiHorizontalScrollbarInternalNode = new GUIHorizontalScrollbarInternalNode(guiParentNode.getScreenNode(), guiParentNode, node.getAttribute("id"), GUINode.createFlow(node.getAttribute("flow")), GUINode.createAlignments(node.getAttribute("horizontal-align"), node.getAttribute("vertical-align")), GUINode.createRequestedConstraints(node.getAttribute("left"), node.getAttribute("top"), node.getAttribute("width"), node.getAttribute("height")), GUINode.getRequestedColor(node.getAttribute("background-color"), GUIColor.TRANSPARENT), GUINode.createBorder(node.getAttribute("border"), node.getAttribute("border-left"), node.getAttribute("border-top"), node.getAttribute("border-right"), node.getAttribute("border-bottom"), node.getAttribute("border-color"), node.getAttribute("border-color-left"), node.getAttribute("border-color-top"), node.getAttribute("border-color-right"), node.getAttribute("border-color-bottom")), GUINode.createPadding(node.getAttribute("padding"), node.getAttribute("padding-left"), node.getAttribute("padding-top"), node.getAttribute("padding-right"), node.getAttribute("padding-bottom")), GUINode.createConditions(node.getAttribute("show-on")), GUINode.createConditions(node.getAttribute("hide-on")), GUINode.getRequestedColor(node.getAttribute("color-none"), GUIColor.BLACK), GUINode.getRequestedColor(node.getAttribute("color-mouseover"), GUIColor.BLACK), GUINode.getRequestedColor(node.getAttribute("color-dragging"), GUIColor.BLACK));
            guiParentNode.addSubNode(guiHorizontalScrollbarInternalNode);
            // install gui element controller if not yet done
            if (guiElement != null && guiElementControllerInstalled == false) {
                guiElementController = guiElement.createController(guiHorizontalScrollbarInternalNode);
                if (guiElementController != null) {
                    guiHorizontalScrollbarInternalNode.setController(guiElementController);
                }
                guiElementControllerInstalled = true;
            }
        } else {
            // Try to load from GUI elements
            GUIElement newGuiElement = elements.get(node.getNodeName());
            if (newGuiElement == null) {
                throw new GUIParserException("Unknown element '" + node.getNodeName() + "'");
            }
            // create final template, replace attributes
            String newGuiElementTemplate = newGuiElement.getTemplate();
            for (int i = 0; i < node.getAttributes().getLength(); i++) {
                Node attribute = node.getAttributes().item(i);
                newGuiElementTemplate = newGuiElementTemplate.replace("{$" + attribute.getNodeName() + "}", escapeQuotes(attribute.getNodeValue()));
            }
            HashMap<String, String> newGuiElementAttributes = newGuiElement.getAttributes(guiParentNode.getScreenNode());
            for (String newGuiElementAttributeKey : newGuiElementAttributes.getKeysIterator()) {
                String guiElementAttributeValue = escapeQuotes(newGuiElementAttributes.get(newGuiElementAttributeKey));
                newGuiElementTemplate = newGuiElementTemplate.replace("{$" + newGuiElementAttributeKey + "}", guiElementAttributeValue);
            }
            newGuiElementTemplate = newGuiElementTemplate.replace("{$innerXml}", getInnerXml(node));
            // create xml document and parse
            DocumentBuilder newGuiElementBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
            Document newGuiElementDocument = newGuiElementBuilder.parse(new ByteArrayInputStream(new String("<gui-element>\n" + newGuiElementTemplate + "</gui-element>\n").getBytes()));
            parseGUINode(guiParentNode, newGuiElementDocument.getDocumentElement(), newGuiElement);
        }
    }
    // if we have a GUI element controller just init it, after element has been loaded
    if (guiElementController != null) {
        guiElementController.init();
    }
}
Also used : GUIInputInternalNode(net.drewke.tdme.gui.nodes.GUIInputInternalNode) GUIVerticalScrollbarInternalNode(net.drewke.tdme.gui.nodes.GUIVerticalScrollbarInternalNode) GUIElement(net.drewke.tdme.gui.elements.GUIElement) Element(org.w3c.dom.Element) GUIHorizontalScrollbarInternalNode(net.drewke.tdme.gui.nodes.GUIHorizontalScrollbarInternalNode) GUIVerticalScrollbarInternalNode(net.drewke.tdme.gui.nodes.GUIVerticalScrollbarInternalNode) GUIScreenNode(net.drewke.tdme.gui.nodes.GUIScreenNode) GUIParentNode(net.drewke.tdme.gui.nodes.GUIParentNode) GUILayoutNode(net.drewke.tdme.gui.nodes.GUILayoutNode) GUISpaceNode(net.drewke.tdme.gui.nodes.GUISpaceNode) GUITextNode(net.drewke.tdme.gui.nodes.GUITextNode) GUIPanelNode(net.drewke.tdme.gui.nodes.GUIPanelNode) Node(org.w3c.dom.Node) GUINode(net.drewke.tdme.gui.nodes.GUINode) GUIElementNode(net.drewke.tdme.gui.nodes.GUIElementNode) GUIInputInternalNode(net.drewke.tdme.gui.nodes.GUIInputInternalNode) GUIImageNode(net.drewke.tdme.gui.nodes.GUIImageNode) GUIElement(net.drewke.tdme.gui.elements.GUIElement) MutableString(net.drewke.tdme.utils.MutableString) Document(org.w3c.dom.Document) GUIHorizontalScrollbarInternalNode(net.drewke.tdme.gui.nodes.GUIHorizontalScrollbarInternalNode) GUILayoutNode(net.drewke.tdme.gui.nodes.GUILayoutNode) GUIPanelNode(net.drewke.tdme.gui.nodes.GUIPanelNode) GUIColor(net.drewke.tdme.gui.nodes.GUIColor) GUITextNode(net.drewke.tdme.gui.nodes.GUITextNode) GUISpaceNode(net.drewke.tdme.gui.nodes.GUISpaceNode) DocumentBuilder(javax.xml.parsers.DocumentBuilder) ByteArrayInputStream(java.io.ByteArrayInputStream) GUINodeController(net.drewke.tdme.gui.nodes.GUINodeController) MutableString(net.drewke.tdme.utils.MutableString) GUIElementNode(net.drewke.tdme.gui.nodes.GUIElementNode) GUIImageNode(net.drewke.tdme.gui.nodes.GUIImageNode)

Aggregations

ByteArrayInputStream (java.io.ByteArrayInputStream)1 DocumentBuilder (javax.xml.parsers.DocumentBuilder)1 GUIElement (net.drewke.tdme.gui.elements.GUIElement)1 GUIColor (net.drewke.tdme.gui.nodes.GUIColor)1 GUIElementNode (net.drewke.tdme.gui.nodes.GUIElementNode)1 GUIHorizontalScrollbarInternalNode (net.drewke.tdme.gui.nodes.GUIHorizontalScrollbarInternalNode)1 GUIImageNode (net.drewke.tdme.gui.nodes.GUIImageNode)1 GUIInputInternalNode (net.drewke.tdme.gui.nodes.GUIInputInternalNode)1 GUILayoutNode (net.drewke.tdme.gui.nodes.GUILayoutNode)1 GUINode (net.drewke.tdme.gui.nodes.GUINode)1 GUINodeController (net.drewke.tdme.gui.nodes.GUINodeController)1 GUIPanelNode (net.drewke.tdme.gui.nodes.GUIPanelNode)1 GUIParentNode (net.drewke.tdme.gui.nodes.GUIParentNode)1 GUIScreenNode (net.drewke.tdme.gui.nodes.GUIScreenNode)1 GUISpaceNode (net.drewke.tdme.gui.nodes.GUISpaceNode)1 GUITextNode (net.drewke.tdme.gui.nodes.GUITextNode)1 GUIVerticalScrollbarInternalNode (net.drewke.tdme.gui.nodes.GUIVerticalScrollbarInternalNode)1 MutableString (net.drewke.tdme.utils.MutableString)1 Document (org.w3c.dom.Document)1 Element (org.w3c.dom.Element)1