Package com.lightcrafts.utils.xml

Examples of com.lightcrafts.utils.xml.XmlNode


    private final static String PointTag = "Point";
    private final static String XTag = "X";
    private final static String YTag = "Y";

    void save(XmlNode node) {
        XmlNode ptsNode = node.addChild(PointsTag);
        ptsNode.setAttribute(SizeTag, Integer.toString(size));
        for (int n=0; n<points.length; n++) {
            if (points[n] >= 0) {
                Integer key = n;
                Double value = points[n];
                XmlNode ptNode = ptsNode.addChild(PointTag);
                ptNode.setAttribute(XTag, key.toString());
                ptNode.setAttribute(YTag, value.toString());
            }
        }
    }
View Full Code Here


            }
        }
    }

    void restore(XmlNode node) throws XMLException {
        XmlNode ptsNode = node.getChild(PointsTag);
        try {
            int s = Integer.parseInt(ptsNode.getAttribute(SizeTag));
            if (s != size) {
                throw new XMLException("Unsupported size change");
            }
            reset();
        }
        catch (NumberFormatException e) {
            throw new XMLException(
                "Not an integer: \"" + ptsNode.getAttribute(SizeTag) + "\"", e
            );
        }
        XmlNode[] ptNodes = ptsNode.getChildren(PointTag);
        for (XmlNode ptNode : ptNodes) {
            Integer key;
            Double value;
            try {
                key = Integer.valueOf(ptNode.getAttribute(XTag));
View Full Code Here

    private final static String ColorTag = "Color";

    public void save(XmlNode node) {
        super.save(node);
        Color color = getWhitePoint();
        XmlNode whiteNode = node.addChild(ColorTag);
        whiteNode.setAttribute("r", Integer.toString(color.getRed()));
        whiteNode.setAttribute("g", Integer.toString(color.getGreen()));
        whiteNode.setAttribute("b", Integer.toString(color.getBlue()));
    }
View Full Code Here

        whiteNode.setAttribute("b", Integer.toString(color.getBlue()));
    }

    public void restore(XmlNode node) throws XMLException {
        super.restore(node);
        XmlNode whiteNode = node.getChild(ColorTag);
        int r = Integer.parseInt(whiteNode.getAttribute("r"));
        int g = Integer.parseInt(whiteNode.getAttribute("g"));
        int b = Integer.parseInt(whiteNode.getAttribute("b"));
        Color color = new Color(r, g, b);
        undoSupport.restoreStart();
        setWhitePoint(color);
        if (dropperButton.isSelected()) {
            dropperButton.setSelected(false);
View Full Code Here

    private final static String ChoiceTag = "Choice";

    public void save(XmlNode node) {
        super.save(node);
        Set keys;
        XmlNode sliderNode = node.addChild(SliderTag);
        keys = sliders.keySet();
        for (Iterator i=keys.iterator(); i.hasNext(); ) {
            String key = (String) i.next();
            GenericSlider slider = (GenericSlider) sliders.get(key);
            double value = slider.getConfiguredValue();
            sliderNode.setAttribute(key, Double.toString(value));
        }
        XmlNode checkboxNode = node.addChild(CheckBoxTag);
        keys = checkboxes.keySet();
        for (Iterator i=keys.iterator(); i.hasNext(); ) {
            String key = (String) i.next();
            JCheckBox checkbox = (JCheckBox) checkboxes.get(key);
            boolean value = checkbox.isSelected();
            checkboxNode.setAttribute(key, value ? "True" : "False");
        }
        XmlNode choiceNode = node.addChild(ChoiceTag);
        keys = choices.keySet();
        for (Iterator i=keys.iterator(); i.hasNext(); ) {
            String key = (String) i.next();
            JComboBox choice = (JComboBox) choices.get(key);
            String value = (String) choice.getSelectedItem();
            choiceNode.setAttribute(key, value);
        }
    }
View Full Code Here

        super.restore(node);
        undoSupport.restoreStart();
        op.changeBatchStarted();
        Set keys;
        if (node.hasChild(SliderTag)) {
            XmlNode sliderNode = node.getChild(SliderTag);
            keys = sliders.keySet();
            for (Iterator i=keys.iterator(); i.hasNext(); ) {
                String key = (String) i.next();
                GenericSlider slider = (GenericSlider) sliders.get(key);
                try {
                    int version = sliderNode.getVersion();
                    if ((version >= 3) || (version < 0)) {
                        double value = Double.parseDouble(
                            sliderNode.getAttribute(key)
                        );
                        slider.setConfiguredValue(value);
                    }
                    else {
                        int value = Integer.parseInt(sliderNode.getAttribute(key));
                        slider.setSliderPosition(value);
                    }
                }
                catch (NumberFormatException e) {
                    throw new XMLException(
                        "Value at attribute \"" + key + "\" is not a number", e
                    );
                }
            }
        }
        if (node.hasChild(CheckBoxTag)) {
            XmlNode checkboxNode = node.getChild(CheckBoxTag);
            keys = checkboxes.keySet();
            for (Iterator i=keys.iterator(); i.hasNext(); ) {
                String key = (String) i.next();
                JCheckBox checkbox = (JCheckBox) checkboxes.get(key);
                String value = checkboxNode.getAttribute(key);
                checkbox.setSelected(value.equals("True"));
            }
        }
        if (node.hasChild(ChoiceTag)) {
            XmlNode choiceNode = node.getChild(ChoiceTag);
            keys = choices.keySet();
            for (Iterator i=keys.iterator(); i.hasNext(); ) {
                String key = (String) i.next();
                JComboBox choice = (JComboBox) choices.get(key);
                String value = choiceNode.getAttribute(key);
                choice.setSelectedItem(value);
            }
        }
        op.changeBatchEnded();
        undoSupport.restoreEnd();
View Full Code Here

               UnknownImageTypeException,
               UserCanceledException,
               MissingImageFileException,
               ImagingException
    {
        XmlNode root = doc.getRoot();
        int version = root.getVersion();
        if (version > SavedDocVersion) {
            throw new XMLException(LOCALE.get("FutureLznError"));
        }
        if (version < 0) {
            throw new XMLException(LOCALE.get("MissingLznVersionError"));
        }
        if (meta == null) {

            // Find the original image:
            XmlNode node = root.getChild(ImageTag);
            String path = node.getAttribute(ImagePathTag);
            File file = new File(path);
            if (! file.isFile()) {
                throw new MissingImageFileException(file);
            }
            // Override with a relative path, if one was defined:
            if (node.hasAttribute(ImageRelativePathTag)) {
                path = node.getAttribute(ImageRelativePathTag);
                File relativeFile = new File(path);
                if (relativeFile.isFile()) {
                    file = relativeFile;
                }
            }
            ImageInfo info = ImageInfo.getInstanceFor(file);
            try {
                meta = info.getMetadata();
            }
            catch (FileNotFoundException e) {
                throw new MissingImageFileException(file);
            }
        }
        this.meta = meta;

        // Enforce the saved original image orientation, which defines the
        // coordinate system used for regions and crop bounds:
        XmlNode imageNode = root.getChild(ImageTag);
        if (imageNode.hasAttribute(ImageOrientationTag)) {
            String value = imageNode.getAttribute(ImageOrientationTag);
            try {
                ImageOrientation oldOrientation =
                    ImageOrientation.getOrientationFor(Short.parseShort(value));
                ImageOrientation newOrientation = meta.getOrientation();
                if (oldOrientation != newOrientation) {
                    meta.setOrientation(oldOrientation);
                }
            }
            catch (NumberFormatException e) {
                throw new XMLException(
                    "Image orientation \"" + value + "\" is not a number", e
                );
            }
        }
        // Backwards compatibility: before XMP support, the convention in LZN
        // files was that the image orientation was its original orientation,
        // before any browser rotations.
        else {
            // Make sure this pre-XMP LZN structure is not a Template.
            // (See Application.saveTemplate().)
            if (! root.getName().equals("Template")) {
                ImageOrientation origOrient = meta.getOriginalOrientation();
                meta.setOrientation(origOrient);
            }
        }
        engine = EngineFactory.createEngine(meta, versionInfo, thread);

        xform = new XFormModel(engine);

        regions = new RegionManager();
        crop = new CropRotateManager(engine, xform);

        scale = new ScaleModel(engine);
        XmlNode scaleNode = root.getChild(ScaleTag);
        Scale s = new Scale(scaleNode);
        scale.setScale(s);

        editor = new Editor(engine, scale, xform, regions, crop, this);
        editor.showWait(LOCALE.get("EditorWaitText"));
        crop.setEditor( editor );

        XmlNode controlNode = root.getChild(ControlTag);

        // this does the inverse of save(XmlNode):
        try {
            editor.restore(controlNode);
        } catch (XMLException e) {
            dispose();
            throw e;
        }

        commonInitialization();

        if (root.hasChild(SaveTag)) {
            XmlNode saveNode = root.getChild(SaveTag);
            save = SaveOptions.restore(saveNode);
        }
        if (root.hasChild(PrintTag)) {
            XmlNode printNode = root.getChild(PrintTag);
            Dimension size = engine.getNaturalSize();
            print = new PrintLayoutModel(size.width, size.height);
            print.restore(printNode);
        }
        if (root.hasChild(ExportTag)) {
            XmlNode exportNode = root.getChild(ExportTag);
            export = ImageExportOptions.read(exportNode);
        }
    }
View Full Code Here

    private final static String ExportTag = "Export";

    public void save(XmlNode node) {
        node.setVersion(SavedDocVersion);

        XmlNode scaleNode = node.addChild(ScaleTag);
        scale.getCurrentScale().save(scaleNode);

        XmlNode imageNode = node.addChild(ImageTag);
        imageNode.setAttribute(
            ImagePathTag, meta.getFile().getAbsolutePath()
        );
        imageNode.setAttribute(
            ImageOrientationTag,
            Integer.toString(meta.getOrientation().getTIFFConstant())
        );
        if (save != null) {
            String path;
            try {
                path = RelativePathUtility.getRelativePath(
                    save.getFile(), meta.getFile()
                );
            }
            catch (IOException e) {
                path = meta.getFile().getName();
            }
            imageNode.setAttribute(ImageRelativePathTag, path);
        }
        XmlNode controlNode = node.addChild(ControlTag);
        editor.save(controlNode);

        if (save != null) {
            XmlNode saveNode = node.addChild(SaveTag);
            save.save(saveNode);
        }
        if (print != null) {
            XmlNode printNode = node.addChild(PrintTag);
            print.save(printNode);
        }
        if (export != null) {
            XmlNode exportNode = node.addChild(ExportTag);
            export.write(exportNode);
        }
    }
View Full Code Here

    // empty image pointer, and no image relative path.  The result may
    // be used either in a Document constructor or in applyTemplate().
    public void saveTemplate(XmlNode node) {
        node.setVersion(SavedDocVersion);

        XmlNode scaleNode = node.addChild(ScaleTag);
        scale.getCurrentScale().save(scaleNode);

        XmlNode imageNode = node.addChild(ImageTag);
        imageNode.setAttribute(ImagePathTag, "");
        XmlNode controlNode = node.addChild(ControlTag);
        editor.save(controlNode);
    }
View Full Code Here

        if (version < 0) {
            throw new XMLException(LOCALE.get("MissingTemplateVersionError"));
        }
        // Ignore the scale factor under ScaleTag.

        XmlNode controlNode = node.getChild(ControlTag);
        editor.addControls(controlNode);
    }
View Full Code Here

TOP

Related Classes of com.lightcrafts.utils.xml.XmlNode

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.