Package org.tools.xml

Examples of org.tools.xml.Node


     *
     * @param file
     * @return
     */
    public static Node addPiece(String file) {
        Node child = new Node("Piece");
        child.appendChild(file);
        return child;
    }
View Full Code Here


     * @param args the command line arguments
     * @throws IOException
     */
    public static void main(String[] args) throws IOException {

        Node parent = new Node("Settings");
        parent.appendChild(createTerrainSettings());
        parent.appendChild(createResourceSettings());

        Resource resource = ResourceUtils.asResource("settings.xml");
        XMLHelper.write(resource, parent);
    }
View Full Code Here

        Resource resource = ResourceUtils.asResource("settings.xml");
        XMLHelper.write(resource, parent);
    }

    private static Node createTerrainSettings() {
        Node parent = new Node("Terrains");
        parent.addAttribute("default-id", "1");
        parent.appendChild(addTerrainType(1, "Sea"));
        parent.appendChild(addTerrainType(2, "Plains"));
        parent.appendChild(addTerrainType(3, "Hills"));
        parent.appendChild(addTerrainType(4, "Mountains"));
        parent.appendChild(addTerrainType(5, "Tundra"));
        parent.appendChild(addTerrainType(6, "Swamp"));
        parent.appendChild(addTerrainType(7, "Desert"));
        return parent;
    }
View Full Code Here

        parent.appendChild(addTerrainType(7, "Desert"));
        return parent;
    }

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

            public void actionPerformed(ActionEvent e) {
                // choose xml file
                if (fileChooser.showOpenDialog(TableEditorFrame.this) == 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(TableEditorFrame.this, "Loading failed."); // TODO fix
                        return;
                    }
                    // initialize from xml
                    model.fromXML(xml);
                    // NotificationFactory.createInfoPane(TableEditorFrame.this, "Table loaded."); // TODO fix
                }
            }
        });
        // save table button action
        saveButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                if (fileChooser.showSaveDialog(TableEditorFrame.this) == JFileChooser.APPROVE_OPTION) {
                    File f = fileChooser.getSelectedFile();
                    String name = f.getAbsolutePath();
                    if (!name.endsWith(extension)) {
                        f = new File(name + extension);
                    }
                    Node xml = model.toXML();
                    OutputStream os;
                    try {
                        os = new FileOutputStream(f);
                        XMLHelper.write(os, xml);
                    } catch (IOException ex) {
View Full Code Here

        int width = parent.getAttributeValueAsInt("tile-width");
        int height = parent.getAttributeValueAsInt("tile-height");
        tileSize = new Dimension(width, height);

        // import terrain tiles
        Node element = parent.getFirstChild("Terrain-Tiles");

        String base = element.getAttributeValue("base");

        for (Node child : element.getChildren()) {
            child.checkNode("Tile");

            Integer id = child.getAttributeValueAsInt("id");
            Tile tile = new Tile();

            Image inner = IOManager.getAsImage(Places.GraphicsScenario, base + "/" + child.getAttributeValue("inner"));
            Image outer = inner;
            if (child.hasAttribute("outer")) {
                outer = IOManager.getAsImage(Places.GraphicsScenario, base + "/" + child.getAttributeValue("outer"));
            }
            tile.content = new EnhancedTile(inner, outer);
            tile.color = GraphicsUtils.convertHexToColor(child.getAttributeValue("color"));

           
            terrainTiles.put(id, tile);
        }

        for (Tile tile : terrainTiles.values()) {
            Dimension size = tile.content.getSize();
            if (!tileSize.equals(size)) {
                RuntimeException ex = new RuntimeException("Terrain tiles differ in size");
                LOG.log(Level.SEVERE, null, ex);
                throw ex;
            }
        }

        {
            // import river overlay
            element = parent.getFirstChild("River-Overlays");
            String location = element.getAttributeValue("location");
            BufferedImage rivers = IOManager.getAsImage(Places.GraphicsScenario, location);
            // test if width and height is a multiple of tileSize
            if (rivers.getWidth(null) % tileSize.width != 0 || rivers.getHeight(null) % tileSize.height != 0) {
                // LOG
            }
            int columns = rivers.getWidth(null) / tileSize.width;
            int rows = rivers.getHeight(null) / tileSize.height;
            // image too small
            if (rows * columns < 36) {
            }
            // lets copy out the parts and store them
            riverOverlays = new Image[36];
            for (int i = 0; i < 36; i++) {
                int x = i % 8 * tileSize.width;
                int y = i / 8 * tileSize.height;
                riverOverlays[i] = rivers.getSubimage(x, y, tileSize.width, tileSize.height);
            }
        }

        // import resource overlays
        element = parent.getFirstChild("Resource-Overlays");

        base = element.getAttributeValue("base");

        for (Node child : element.getChildren()) {
            child.checkNode("Overlay");

            Integer id = child.getAttributeValueAsInt("id");
            // TODO what if images cannot be loaded because they aren't there, image == null, check
            Image inner = IOManager.getAsImage(Places.GraphicsScenario, base + "/" + child.getAttributeValue("inner"));
            Image outer = inner;
            if (child.hasAttribute("outer")) {
                outer = IOManager.getAsImage(Places.GraphicsScenario, base + "/" + child.getAttributeValue("outer"));
            }           
            resourceOverlays.put(id, new EnhancedTile(inner, outer));
        }

        // import misc overlays
        element = parent.getFirstChild("Miscellaneous-Overlays");

        for (Node child : element.getChildren()) {
            child.checkNode("Overlay");

            String id = child.getAttributeValue("id");
            String location = child.getAttributeValue("location");
            Image image = IOManager.getAsImage(Places.GraphicsScenario, location);
            miscOverlays.put(id, image);
        }

        // import unit overlays
        element = parent.getFirstChild("Unit-Overlays");
        base = element.getAttributeValue("base");

        for (Node child : element.getChildren()) {
            child.checkNode("Unit");

            String type = child.getAttributeValue("type");
            String action = child.getAttributeValue("action");
            String location = child.getAttributeValue("location");
View Full Code Here

    /**
     * @param args the command line arguments
     * @throws IOException
     */
    public static void main(String[] args) throws IOException {
        Node parent = new Node("Tile-Graphics");
        parent.addAttribute("tile-width", "80");
        parent.addAttribute("tile-height", "80");

        parent.appendChild(createTerrain());
        parent.appendChild(createRiver());
        parent.appendChild(createResources());
        parent.appendChild(createMisc());
        parent.appendChild(createUnits());
        Resource resource = ResourceUtils.asResource("content.xml");
        XMLHelper.write(resource, parent);
    }
View Full Code Here

    /**
     *
     * @return
     */
    public static Node createRiver() {
        Node parent = new Node("River-Overlays");
        parent.addAttribute("location", "river.overlays.png");
        return parent;
    }
View Full Code Here

    /**
     *
     * @return
     */
    public static Node createUnits() {
        Node parent = new Node("Unit-Overlays");
        parent.addAttribute("base", "units");
        parent.appendChild(addUnitTile("infantry", "stand", "infantry.stand.png"));
        parent.appendChild(addUnitTile("infantry", "shoot", "infantry.shoot.png"));
        parent.appendChild(addUnitTile("infantry", "charge", "infantry.charge.png"));
        return parent;
    }
View Full Code Here

     */
    @Override
    public void fromXML(Node parent) {
        parent.checkNode(XML_NAME);

        Node node = parent.getFirstChild("Background");

        String base = node.getAttributeValue("base");

        list = new ArrayList<>(node.getChildCount());
        for (Node child: node.getChildren()) {
            child.checkNode("Piece");

            Resource resource = IOManager.getAsResource(Places.Music, base + "/" + child.getValue());
            list.add(resource);
        }
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.