use of net.drewke.tdme.gui.nodes.GUIHorizontalScrollbarInternalNode 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();
}
}
Aggregations