Package org.tools.xml

Examples of org.tools.xml.Node


     *
     * @return xml object
     */
    @Override
    public Node toXML() {
        Node element = new Node(XML_NAME);

        element.appendChild(properties.toXML());
        element.appendChild(provinces.toXML());
        element.appendChild(units.toXML());

        return element;
    }
View Full Code Here


     *
     * @return xml object
     */
    @Override
    public Node toXML() {
        Node element = new Node(XML_NAME);
        element.addAttribute("id", Integer.toString(id));
        element.addAttribute("name", name);
        element.addAttribute("town-row", String.valueOf(town.row));
        element.addAttribute("town-column", String.valueOf(town.column));

        return element;
    }
View Full Code Here

        return position;
    }

    @Override
    public Node toXML() {
        Node element = new Node(XML_NAME);

        element.addAttribute("type", type.name());
        element.addAttribute("position-row", String.valueOf(position.row));
        element.addAttribute("position-column", String.valueOf(position.column));

        return element;
    }
View Full Code Here

     *
     * @return
     */
    @Override
    public Node toXML() {
        Node parent = new Node(XML_NAME);

        // update sizes and write properties
        properties.putInt("rows", rows);
        properties.putInt("columns", columns);
        parent.appendChild(properties.toXML());

        Node child = new Node("Maps");
        parent.appendChild(child);

        // terrain map
        BitBuffer terrainMapBuffer = new BitBuffer(BITSIZE_TERRAINID * rows * columns);
        for (int row = 0; row < rows; row++) {
            for (int column = 0; column < columns; column++) {
                terrainMapBuffer.add(map[row][column].terrainID, BITSIZE_TERRAINID);
            }
        }
        Node schild = new Node("Terrains");
        schild.appendChild(terrainMapBuffer.toXMLString());
        child.appendChild(schild);

        // resources map
        BitBuffer resourcesMapBuffer = new BitBuffer((BITSIZE_RESOURCEID + 1) * rows * columns);
        for (int row = 0; row < rows; row++) {
            for (int column = 0; column < columns; column++) {
                resourcesMapBuffer.add(map[row][column].resourceID, BITSIZE_RESOURCEID);
                resourcesMapBuffer.add(map[row][column].resourceVisible);
            }
        }
        schild = new Node("Resources");
        schild.appendChild(resourcesMapBuffer.toXMLString());
        child.appendChild(schild);

        // provinces
        BitBuffer provinceMapBuffer = new BitBuffer(BITSIZE_PROVINCEID * rows * columns);
        for (int row = 0; row < rows; row++) {
            for (int column = 0; column < columns; column++) {
                provinceMapBuffer.add(map[row][column].provinceID, BITSIZE_PROVINCEID);
            }
        }
        schild = new Node("Provinces");
        schild.appendChild(provinceMapBuffer.toXMLString());
        child.appendChild(schild);

        // railroads
        BitBuffer railMapBuffer = new BitBuffer(BITSIZE_RAILROAD_CONFIG * rows * columns);
        for (int row = 0; row < rows; row++) {
            for (int column = 0; column < columns; column++) {
                railMapBuffer.add(map[row][column].railroadConfig, BITSIZE_RAILROAD_CONFIG);
            }
        }
        schild = new Node("Railroads");
        schild.appendChild(railMapBuffer.toXMLString());
        child.appendChild(schild);

        // river overlay
        BitBuffer riverBuffer = new BitBuffer(BITSIZE_RIVERID * rows * columns);
        for (int row = 0; row < rows; row++) {
            for (int column = 0; column < columns; column++) {
                riverBuffer.add(map[row][column].riverID, BITSIZE_RIVERID);
            }
        }
        schild = new Node("Rivers");
        schild.appendChild(riverBuffer.toXMLString());
        child.appendChild(schild);

        // nation list
        parent.appendChild(nations.toXML());

View Full Code Here

            public void actionPerformed(ActionEvent e) {
                JFileChooser fileChooser = IOManager.getFileChooser();
                if (FrameManager.getInstance().showOpenDialog(fileChooser) == JFileChooser.APPROVE_OPTION) {
                    File f = fileChooser.getSelectedFile();
                    // read file and parse to xml
                    Node xml;
                    try (InputStream is = new FileInputStream(f)) {
                        xml = XMLHelper.read(is);
                    } catch (ParsingException | IOException ex) {
                        // LOG.log(Level.SEVERE, null, ex);
                        // NotificationFactory.createInfoPane(dialog, "Loading failed.");
                        // TODO also make it working with dialogs
                        return;
                    }
                    scenario.fromXML(xml);
                    initOnLoad();
                    FrameManager.getInstance().scheduleInfoMessage("Scenario " + scenario.getTitle() + " loaded.");
                }
            }
        });

        // save scenario button
        JButton saveButton = Button.ScenarioSave.create();
        saveButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {

                JFileChooser fileChooser = IOManager.getFileChooser();
                if (FrameManager.getInstance().showSaveDialog(fileChooser) == JFileChooser.APPROVE_OPTION) {
                    File f = fileChooser.getSelectedFile();
                    String name = f.getAbsolutePath();
                    if (!name.endsWith(".xml")) {
                        f = new File(name + ".xml");
                    }
                    Node xml = scenario.toXML();
                    OutputStream os;
                    try {
                        os = new FileOutputStream(f);
                        XMLHelper.write(os, xml);
                    } catch (IOException ex) {
View Full Code Here

        rows = properties.getInt("rows");
        columns = properties.getInt("columns");
        int size = rows * columns;
        map = new Tile[rows][columns];

        Node child = parent.getFirstChild("Maps");

        // readingt of terrain map
        String content = child.getFirstChild("Terrains").getValue();
        BitBuffer terbuffer = BitBuffer.fromXMLString(content);
        terbuffer.trimTo(BITSIZE_TERRAINID * size);

        // readingt of terrain map
        content = child.getFirstChild("Resources").getValue();
        BitBuffer resbuffer = BitBuffer.fromXMLString(content);
        resbuffer.trimTo((BITSIZE_RESOURCEID + 1) * size);

        // reading of provinces map
        // TODO if no such element returns null and getValue will throw exception
        content = child.getFirstChild("Provinces").getValue();
        BitBuffer probuffer = BitBuffer.fromXMLString(content);
        probuffer.trimTo(BITSIZE_PROVINCEID * size);

        // reading of railroads map
        content = child.getFirstChild("Railroads").getValue();
        BitBuffer railbuffer = BitBuffer.fromXMLString(content);
        railbuffer.trimTo(BITSIZE_RAILROAD_CONFIG * size);

        // reading of rivers map
        content = child.getFirstChild("Rivers").getValue();
        BitBuffer riverbuffer = BitBuffer.fromXMLString(content);
        riverbuffer.trimTo(BITSIZE_RIVERID * size);

        // TODO test size of string with size
        // TODO more checks (positivity)
View Full Code Here

        child.addAttribute("name", name);
        return child;
    }

    private static Node createResourceSettings() {
        Node parent = new Node("Resources");
        parent.appendChild(addResourceType(1, "Grain", true));
        parent.appendChild(addResourceType(2, "Orchard", true));
        parent.appendChild(addResourceType(3, "Buffalo", true));
        parent.appendChild(addResourceType(4, "Cotton", true));
        parent.appendChild(addResourceType(5, "Sheep", true));
        parent.appendChild(addResourceType(6, "Forest", true));
        parent.appendChild(addResourceType(7, "Scrub forest", true));
        parent.appendChild(addResourceType(8, "Oil", false));
        parent.appendChild(addResourceType(9, "Coal", false));
        parent.appendChild(addResourceType(10, "Ore", false));
        return parent;
    }
View Full Code Here

        parent.appendChild(addResourceType(10, "Ore", false));
        return parent;
    }

    private static Node addResourceType(int id, String name, boolean visible) {
        Node child = new Node("Resource");
        child.addAttribute("id", String.valueOf(id));
        child.addAttribute("name", name);
        child.addAttribute("visible", String.valueOf(visible));
        return child;
    }
View Full Code Here

        } catch (IOException ex) {
            updateStatus("Cannot open save location.");
            return;
        }

        Node parent = new Node("Scenario-Importer");
        JTextComponent[] components = {importmapTextField, scenarioTextField, titleTextField, nationNamesTextField, nationColorsTextField, provinceReplacementsTextField};

        for (JTextComponent component : components) {
            Node child = new Node("Component-" + component.getName());
            // child.appendChild(component.getText());
            child.addAttribute("content", component.getText());
            parent.appendChild(child);
        }
        try {
            XMLHelper.write(resource, parent);
        } catch (IOException ex) {
View Full Code Here

        } catch (IOException ex) {
            updateStatus("Cannot open load location.");
            return;
        }

        Node parent;
        try {
            parent = XMLHelper.read(resource);
        } catch (IOException | ParsingException ex) {
            updateStatus("Cannot load content.");
            return;
        }

        if (parent.getChildCount() != 6) {
            updateStatus("Wrong number of elements in xml.");
            return;
        }

        JTextComponent[] components = {importmapTextField, scenarioTextField, titleTextField, nationNamesTextField, nationColorsTextField, provinceReplacementsTextField};

        for (JTextComponent component : components) {
            component.setText(parent.getFirstChild("Component-" + component.getName()).getAttributeValue("content"));
        }

        updateStatus("All content read.");
    }//GEN-LAST:event_loadButtonActionPerformed
View Full Code Here

TOP

Related Classes of org.tools.xml.Node

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.