Example usage for com.google.gwt.xml.client Node getNextSibling

List of usage examples for com.google.gwt.xml.client Node getNextSibling

Introduction

In this page you can find the example usage for com.google.gwt.xml.client Node getNextSibling.

Prototype

Node getNextSibling();

Source Link

Document

This method retrieves the next sibling.

Usage

From source file:edu.ucla.loni.pipeline.client.Charts.LineChartPanel.java

License:Open Source License

private void parseXML(String xml) {
    // remove whitespace
    String cleanXml = xml.replaceAll("\t", "");
    cleanXml.replaceAll("\n", "");

    try {//from   ww w  .j a va 2  s.co m
        Document doc = XMLParser.parse(cleanXml);

        if (monitorType.equals("Memory")) {
            // parse MemoryUsage tree
            Node memRoot = doc.getElementsByTagName("MemoryUsage").item(0);
            if (memRoot == null) {
                System.out.println("couldn't find MemoryUsage tag");
                return;
            }
            NodeList memPoints = memRoot.getChildNodes();

            for (int i = 0; i < memPoints.getLength(); i++) {
                Node stepNode = memPoints.item(i);
                /*
                 * NamedNodeMap memPointAttr = stepNode.getAttributes();
                 * Node stepAttrNode = memPointAttr.getNamedItem("ID");
                 * times.add(Integer.parseInt(stepAttrNode.getNodeValue()));
                 */

                Node initNode = stepNode.getFirstChild();
                initMem.add(Integer.parseInt(initNode.getFirstChild().getNodeValue()));

                Node usedNode = initNode.getNextSibling();
                usedMem.add(Integer.parseInt(usedNode.getFirstChild().getNodeValue()));

                Node commNode = usedNode.getNextSibling();
                commMem.add(Integer.parseInt(commNode.getFirstChild().getNodeValue()));

                Node maxNode = commNode.getNextSibling();
                maxMem.add(Integer.parseInt(maxNode.getFirstChild().getNodeValue()));
            }

            timeUsed = true;
            initUsed = true;
            usedUsed = true;
            commUsed = true;
            maxUsed = true;

            calculateStatistics();
        } else if (monitorType.equals("Thread")) {
            // parse ThreadUsage tree
            Node threadRoot = doc.getElementsByTagName("ThreadUsage").item(0);
            if (threadRoot == null) {
                System.out.println("couldn't find ThreadUsage tag");
                return;
            }
            NodeList threadPoints = threadRoot.getChildNodes();

            for (int i = 0; i < threadPoints.getLength(); i++) {
                Node stepNode = threadPoints.item(i);
                /*
                 * NamedNodeMap threadPointAttr = stepNode.getAttributes();
                 * Node stepAttrNode = threadPointAttr.getNamedItem("ID");
                 * times.add(Integer.parseInt(stepAttrNode.getNodeValue()));
                 */

                Node cntNode = stepNode.getFirstChild();
                threadCnt.add(Integer.parseInt(cntNode.getFirstChild().getNodeValue()));

                Node pkNode = cntNode.getNextSibling();
                threadPk.add(Integer.parseInt(pkNode.getFirstChild().getNodeValue()));
            }

            timeUsed = true;
            threadUsed = true;

            calculateStatistics();
        } else {
            System.err.println(
                    "Incorrect monitorType provided. Check parseXML() in LineChartPanel.java for errors.");
            return;
        }
    } catch (DOMParseException e) {
        System.err.println("Could not parse XML file. Check XML file format.");
        return;
    }
}

From source file:javawars.client.ui.MatchViewerClassic.java

License:Open Source License

public void show(String string) {

    Document d = XMLParser.parse(string);
    Node match = d.getFirstChild();
    NodeList matchContent = match.getChildNodes();
    matchContent.getLength();//from  w  w  w .j  a va2s .  com

    Node boardNode = getNode(match, "board");
    int boardWidth = Integer.parseInt(boardNode.getAttributes().getNamedItem("width").getNodeValue());
    int boardHeight = Integer.parseInt(boardNode.getAttributes().getNamedItem("height").getNodeValue());
    timestamps = getTimestamps(match);

    Board[] boards = new Board[timestamps.length + 1];

    Board startBoard = new Board(boardWidth, boardHeight);
    //      add (new Label("" + string));
    //        int fieldCounter = 0;
    Node focus = getNode(boardNode, "field");
    while (focus != null) {
        try {
            NamedNodeMap fieldAttributes = focus.getAttributes();
            int x = Integer.parseInt(fieldAttributes.getNamedItem("x").getNodeValue());
            //            add (new Label("x: " + x));
            int y = Integer.parseInt(fieldAttributes.getNamedItem("y").getNodeValue());
            int elevation = Integer.parseInt(fieldAttributes.getNamedItem("elevation").getNodeValue());
            int gem = Integer.parseInt(fieldAttributes.getNamedItem("gem").getNodeValue());
            int robot = Integer.parseInt(fieldAttributes.getNamedItem("robot").getNodeValue());
            startBoard.setElevationAt(x, y, elevation);
            startBoard.setGemAt(x, y, gem);
            startBoard.setRobotAt(x, y, robot);
            //            focus = getNode(boardNode, "field", ++fieldCounter);
            do {
                focus = focus.getNextSibling();
            } while (focus.getNodeName().equals("field") == false && focus != null);

        } catch (Exception e) {
            break;
        }
    }
    startBoard.setTime(0);

    boards[0] = startBoard;

    Node robotsNode = getNode(match, "robots");
    int robotsCount = Integer.parseInt(robotsNode.getAttributes().getNamedItem("count").getNodeValue());
    Node[] initialRobots = getRobots(robotsNode);

    robots = new Robot[timestamps.length + 1][robotsCount];

    for (int a = 0; a < robots.length; a++) {
        Node[] robotsAlive;
        if (a != 0) {
            robotsAlive = getRobots(timestamps[a - 1]);
        } else {
            robotsAlive = initialRobots;
        }

        for (int b = 1; b < robotsAlive.length; b++) {
            if (robotsAlive[b] != null) {
                NamedNodeMap robotAttributes = robotsAlive[b].getAttributes();
                //                    int id = 0;
                //                    try {
                //                        id = Integer.parseInt(robotAttributes.getNamedItem("id").getNodeValue());
                //                    } catch (Exception e) {
                //                    }
                String name = "null";
                try {
                    name = robotAttributes.getNamedItem("name").getNodeValue();
                } catch (Exception e) {
                }
                String author = "null";
                try {
                    author = robotAttributes.getNamedItem("author").getNodeValue();
                } catch (Exception e) {
                }
                int health = 100;
                try {
                    health = Integer.parseInt(robotAttributes.getNamedItem("health").getNodeValue());
                } catch (Exception e) {
                }
                int score = 0;
                try {
                    score = Integer.parseInt(robotAttributes.getNamedItem("score").getNodeValue());
                } catch (Exception e) {
                }
                int kills = 0;
                try {
                    kills = Integer.parseInt(robotAttributes.getNamedItem("kills").getNodeValue());
                } catch (Exception e) {
                }
                String action = "null";
                try {
                    action = robotAttributes.getNamedItem("action").getNodeValue();
                } catch (Exception e) {
                }
                int waitTime = 0;
                try {
                    waitTime = Integer.parseInt(robotAttributes.getNamedItem("waitTime").getNodeValue());
                } catch (Exception e) {
                }
                robots[a][b - 1] = new Robot(b, name, author, health, score, kills, action, waitTime);
            }
        }
    }

    display = new Display(boards);
    display.draw();
    mainPanel.add(display);

}

From source file:javawars.client.ui.MatchViewerClassic.java

License:Open Source License

private Node getNode(Node parent, String name) {
    Node focus = parent.getFirstChild();
    while (focus != null) {
        if (focus.getNodeName().equals(name)) {
            return focus;
        }/*from w  w  w  .j  av  a2s. c o m*/
        focus = focus.getNextSibling();
    }
    return null;
}

From source file:javawars.client.ui.MatchViewerClassic.java

License:Open Source License

private Node getNode(Node parent, String name, int position) {
    Node focus = parent.getFirstChild();
    while (focus != null) {
        if (focus.getNodeName().equals(name)) {
            position--;/*from w  ww .j  a  v a2 s .  c o  m*/
            if (position <= 0) {
                return focus;
            }
        }
        focus = focus.getNextSibling();
    }
    return null;
}

From source file:javawars.client.ui.MatchViewerFast.java

License:Open Source License

public void show(final String matchReport) {
    this.matchReport = matchReport;

    // reinitializing the variables; the method 'show' is reuesable.
    currentTime = 0;//from w  ww .j  av  a2s .c  om

    if (showActionProgress.isChecked() == true)
        showAction = true;
    else
        showAction = false;

    // Creating initial documents, parsers...
    Document d = XMLParser.parse(matchReport);
    Node match = d.getFirstChild();
    match.normalize();

    // Getting the board's node...
    Node boardNode = getNode(match, "board");
    // ...its width and elevation...
    int boardWidth = Integer.parseInt(boardNode.getAttributes().getNamedItem("width").getNodeValue());
    int boardHeight = Integer.parseInt(boardNode.getAttributes().getNamedItem("height").getNodeValue());
    // ...and creating a fields table.
    fields = new Field[boardWidth][boardHeight];

    // populating fields table with the exact values from the match_report
    Node fieldNode = getNode(boardNode, "field");
    while (fieldNode != null) {
        try {
            NamedNodeMap fieldAttributes = fieldNode.getAttributes();
            int x = Integer.parseInt(fieldAttributes.getNamedItem("x").getNodeValue());
            int y = Integer.parseInt(fieldAttributes.getNamedItem("y").getNodeValue());
            int elevation = Integer.parseInt(fieldAttributes.getNamedItem("elevation").getNodeValue());
            int gem = Integer.parseInt(fieldAttributes.getNamedItem("gem").getNodeValue());
            int robot = Integer.parseInt(fieldAttributes.getNamedItem("robot").getNodeValue());

            fields[x][y] = new Field(elevation, gem, robot);

            do {
                fieldNode = fieldNode.getNextSibling();
            } while (fieldNode.getNodeName().equals("field") == false && fieldNode != null);

        } catch (Exception e) {
            break;
        }
    }

    Node robotsNode = getNode(match, "robots");
    int robotsCount = Integer.parseInt(robotsNode.getAttributes().getNamedItem("count").getNodeValue());
    robots = new Robot[robotsCount];
    Node robotNode = getNode(robotsNode, "robot");
    while (robotNode != null) {
        try {
            NamedNodeMap robotAttributes = robotNode.getAttributes();
            int id = Integer.parseInt(robotAttributes.getNamedItem("id").getNodeValue());
            String author = robotAttributes.getNamedItem("author").getNodeValue().toUpperCase();
            String name = robotAttributes.getNamedItem("name").getNodeValue().toUpperCase();

            robots[id - 1] = new Robot(id, name, author);
            do {
                robotNode = robotNode.getNextSibling();
            } while (robotNode.getNodeName().equals("robot") == false && robotNode != null);

        } catch (Exception e) {
            break;
        }
    }

    table.clear();
    for (int a = 0; a < boardWidth; a++) {
        for (int b = 0; b < boardHeight; b++) {
            table.setHTML(b, a, renderCell(fields[a][b], a, b));
        }
    }

    table.setCellPadding(0);
    table.setCellSpacing(0);
    table.setStyleName("MatchViewerTable");

    tableWidth = table.getOffsetWidth();
    robotsDescription.setHTML(renderRobotsDescription(robots, tableWidth));
    if (showAction == true) {
        currentTimeHTML.setHTML(generateCurrentTimeHTML());
    } else {
        currentTimeHTML.setHTML("<div style='font-size: 10px; width: " + tableWidth
                + "px; background-color: #aaa; color: #fff; text-align: center; '> &nbsp; </div>");
    }

    currentNode = getNode(match, "timestamp");
}

From source file:javawars.client.ui.MatchViewerFast.java

License:Open Source License

public void nextFrame() {
    currentTime += 1;//from   w ww.  j av  a2s  . com
    Node timestamp = currentNode;

    do {
        timestamp = timestamp.getNextSibling();
        //    Window.alert("safetyCounter: " + safetyCounter + ", timestamp.getNodeName(): " + timestamp.getNodeName() );
    } while (timestamp != null && timestamp.getNodeName().equals("timestamp") == false);

    int timestampTime = -1;
    try {
        timestampTime = Integer.parseInt(timestamp.getAttributes().getNamedItem("time").getNodeValue());
    } catch (NullPointerException ex) {
        if (timer != null)
            timer.cancel();
        Window.alert("Koniec pojedynku.");
        return;
    }

    if (currentTime >= timestampTime) {
        currentNode = timestamp;

        Node declaration = currentNode.getFirstChild();
        while (declaration != null) {
            if (declaration.getNodeName().equals("declaration")) {
                NamedNodeMap declarationAttributes = declaration.getAttributes();
                int callerId = Integer.parseInt(declarationAttributes.getNamedItem("callerid").getNodeValue());
                String param1 = "";
                try {
                    param1 = declarationAttributes.getNamedItem("parameter1").getNodeValue();
                } catch (Exception ex) {
                    ;
                }
                if (showAction == true)
                    robots[callerId - 1].newAction = true;
                robots[callerId - 1].param1 = param1;
            }
            declaration = declaration.getNextSibling();
        }

        Node robot = currentNode.getFirstChild();
        int id = 0;
        while (robot != null) {
            if (robot.getNodeName().equals("robot")) {
                id += 1;
                NamedNodeMap robotAttributes = robot.getAttributes();
                int score = Integer.parseInt(robotAttributes.getNamedItem("score").getNodeValue());
                int waitTime = Integer.parseInt(robotAttributes.getNamedItem("waitTime").getNodeValue());
                // int id = Integer.parseInt(fieldAttributes.getNamedItem("id").getNodeValue());
                robots[id - 1].gems = score;

                if (showAction == true) {
                    // due to some bug... - because time is stretched when another robot performs
                    // an action within the timespan of one robot's waiting.
                    robots[id - 1].actionDuration += 1;

                    if (robots[id - 1].newAction == true) {
                        robots[id - 1].newAction = false;
                        robots[id - 1].actionStart = currentTime;
                        robots[id - 1].actionDuration = waitTime;
                    }
                }

            }
            robot = robot.getNextSibling();
        }

        Node field = currentNode.getFirstChild();
        while (field != null) {
            if (field.getNodeName().equals("field")) {
                NamedNodeMap fieldAttributes = field.getAttributes();
                int x = Integer.parseInt(fieldAttributes.getNamedItem("x").getNodeValue());
                int y = Integer.parseInt(fieldAttributes.getNamedItem("y").getNodeValue());
                int elevation = Integer.parseInt(fieldAttributes.getNamedItem("elevation").getNodeValue());
                int gem = Integer.parseInt(fieldAttributes.getNamedItem("gem").getNodeValue());
                int robotId = Integer.parseInt(fieldAttributes.getNamedItem("robot").getNodeValue());
                fields[x][y] = new Field(elevation, gem, robotId);

                table.setHTML(y, x, renderCell(fields[x][y], x, y));
            }
            field = field.getNextSibling();
        }

    }
    if (showAction == true) {
        currentTimeHTML.setHTML(generateCurrentTimeHTML());
        for (Robot r : robots) {
            table.setHTML(r.y, r.x, renderCell(fields[r.x][r.y], r.x, r.y));
        }
    }
}

From source file:org.gk.ui.client.com.tree.xml.gkTreeHandler.java

License:Open Source License

public gkTreeHandler(TreePanel tree, final Operation op) {
    new TreePanelDragSource(tree) {
        /**/*from www  . j a v a 2 s  .co  m*/
         * ?drop???TreeNode?path
         */
        @Override
        protected void onDragDrop(DNDEvent event) {
            event.setOperation(op);
        }
    };
    target = new TreePanelDropTarget(tree) {
        @Override
        protected void onDragFail(DNDEvent event) {
            // treetraceMouseOver
            tree.setTrackMouseOver(true);
            super.onDragFail(event);
        }

        @Override
        protected void showFeedback(DNDEvent event) {
            final TreeNode overItem = tree.findNode(event.getTarget());
            if (overItem == null) {
                clearStyles(event);
            }

            // :?????
            if (overItem != null
                    && event.getDropTarget().getComponent() == event.getDragSource().getComponent()) {

                List<TreeModel> list = event.getData();
                ModelData overModel = overItem.getModel();
                for (int i = 0; i < list.size(); i++) {
                    ModelData sel = (ModelData) list.get(i).get("model");
                    if (overModel == sel) {
                        clearStyles(event);
                        return;
                    }

                    List<ModelData> children = tree.getStore().getChildren(sel, true);

                    if (children.contains(overItem.getModel())) {
                        clearStyles(event);
                        return;
                    }
                }
            }
            // ================================

            boolean append = feedback == Feedback.APPEND || feedback == Feedback.BOTH;
            boolean insert = feedback == Feedback.INSERT || feedback == Feedback.BOTH;

            if (overItem == null) {
                handleAppend(event, overItem);
            } else if (insert) {
                handleInsert(event, overItem);
            } else if ((!overItem.isLeaf() || isAllowDropOnLeaf()) && append) {
                handleAppend(event, overItem);
            } else {
                if (activeItem != null) {
                    tree.getView().onDropChange(activeItem, false);
                }
                status = -1;
                activeItem = null;
                appendItem = null;
                Insert.get().hide();
                event.getStatus().setStatus(false);
            }

            // 
            if (activeItem == null) {
                event.getStatus().setStatus(false);
            }
        }

        @Override
        protected void onDragEnter(DNDEvent event) {
            removeDuplicateNode(event);

            super.onDragEnter(event);
            super.clearStyles(event);// ? IE ????
        }

        private void removeDuplicateNode(DNDEvent event) {
            List<TreeStoreModel> modelList = (List<TreeStoreModel>) event.getData();

            // 1. Parent Node
            Set<String> parentNodeSet = new HashSet<String>();
            for (TreeStoreModel model : modelList) {
                Node node = model.getModel().get("node");
                if (!model.isLeaf()) {
                    parentNodeSet.add(node.toString());
                }
            }

            // 2.?? Leaf Node (Leaf's Parent in parentNodeSet)
            Iterator<TreeStoreModel> modelIt = modelList.iterator();
            while (modelIt.hasNext()) {
                TreeStoreModel model = modelIt.next();

                Node node = model.getModel().get("node");
                if (model.isLeaf()) {
                    if (node.getParentNode() != null
                            && parentNodeSet.contains(node.getParentNode().toString())) {
                        modelIt.remove();
                    }
                } else {
                    parentNodeSet.add(node.toString());
                }
            }

            // 3.?
            event.getStatus()
                    .update(Format.substitute(event.getDragSource().getStatusText(), modelList.size()));
        }

        /**
         * ?
         */
        @Override
        protected void onDragDrop(DNDEvent e) {
            TreePanel srcTree = (TreePanel) e.getDragSource().getComponent();
            if (activeItem == null) {
                super.onDragDrop(e);
                return;
            }
            List treeStoreModelList = (List) e.getData();

            // ?XML Node
            Node dropNode = activeItem.getModel().get("node");
            Node dropParentNode = dropNode.getParentNode();

            // state=1,activeItem????Node
            // state=0,?TreeNode
            // ?xml doc????.???????
            if (dropParentNode != null && dropParentNode.toString().equals(dropNode.toString())) {
                status = -1;
            }

            // Copy Mode
            // 1.????
            // 2.?appendChild??
            // 3.??
            if (Operation.COPY == e.getOperation()) {
                List newModels = genNewTreeStoreModelList(srcTree, treeStoreModelList);
                e.setData(newModels);
                treeStoreModelList = newModels;
            }

            List<Node> dragNodeList = getNodeList(treeStoreModelList);

            String tarNodeId = "";
            // 2011/06/28 ???
            TreeNode srcTreeNode = srcTree.findNode((Element) e.getDragEvent().getStartElement());
            switch (status) {
            case -1: // ?
                for (Node node : dragNodeList) {
                    dropNode.appendChild(node);
                }

                tarNodeId = TreeUtils.getNodeId(activeItem, srcTreeNode, status);
                break;
            case 1: // ?
                Node siblingNode = dropNode.getNextSibling();
                for (Node node : dragNodeList) {
                    dropParentNode.insertBefore(node, siblingNode);
                }
                // ?
                tarNodeId = TreeUtils.getNodeId(activeItem, srcTreeNode, 1);
                break;
            case 0: // ?
                for (Node node : dragNodeList) {
                    dropParentNode.insertBefore(node, dropNode);
                }
                // ?
                tarNodeId = TreeUtils.getNodeId(activeItem, srcTreeNode, 0);
                break;
            }

            // Move Mode
            // ??tree
            if (Operation.MOVE == e.getOperation()) {
                List<TreeModel> sel = e.getData();
                for (TreeModel tm : sel) {
                    srcTree.getStore().remove((ModelData) tm.get("model"));
                }
            }

            // 
            update(compositeInfo(srcTree, tree, TreeUtils.getNodeId(srcTreeNode), tarNodeId));
            super.onDragDrop(e);
        }
    };
    target.setAllowSelfAsSource(true);
    target.setFeedback(Feedback.BOTH);
}

From source file:org.gwm.splice.client.form.HtmlForm.java

License:Apache License

private void init() {

    Document doc = null;//w  w  w . j  a  v a2  s .  c o m

    try {
        doc = XMLParser.parse(html);
    } catch (Throwable e) {
        logInfo("bugger - " + e.getMessage());
    }
    NodeList nodeList = doc.getElementsByTagName("body");
    Node node = nodeList.item(0);
    node = node.getFirstChild();
    for (;;) {
        if (node.getNodeName().equalsIgnoreCase("div")) {
            String attrVal = getAttribute(node, "id");
            if (attrVal != null && attrVal.equals("pageAfter")) {
                formPageAfter = new HTML(node.toString());
            } else {
                formNodes.add(node);
            }
        }
        node = node.getNextSibling();
        if (node == null) {
            break;
        }
    }

    formPanel.remove(waitMsg);

    formPages = new HTML[formNodes.size()];
    for (int i = 0; i < formPages.length; i++) {
        formPages[i] = new HTML(formNodes.get(i).toString());
        formPanel.add(formPages[i]);
    }
    formPanel.showWidget(0);
}

From source file:org.metawidget.gwt.client.ui.GwtPipeline.java

License:LGPL

@Override
protected Element getFirstChildElement(Element parent) {

    Node node = parent.getFirstChild();

    while (node != null && !(node instanceof Element)) {

        node = node.getNextSibling();
    }//from  w  w w.  ja va2  s. c o  m

    return (Element) node;
}

From source file:org.metawidget.gwt.client.ui.GwtPipeline.java

License:LGPL

@Override
protected Element getNextSiblingElement(Element element) {

    Node node = element.getNextSibling();

    while (node != null && !(node instanceof Element)) {

        node = node.getNextSibling();
    }//from ww w  . j  a v  a2 s . com

    return (Element) node;
}