Search in sources :

Example 1 with IAttributeHandler

use of org.freeplane.core.io.IAttributeHandler in project freeplane by freeplane.

the class CloudBuilder method registerAttributeHandlers.

private void registerAttributeHandlers(final ReadManager reader) {
    reader.addAttributeHandler("cloud", "STYLE", new IAttributeHandler() {

        public void setAttribute(final Object userObject, final String value) {
        // final CloudModel cloud = (CloudModel) userObject;
        // cloud.setStyle(value.toString());
        }
    });
    reader.addAttributeHandler("cloud", "COLOR", new IAttributeHandler() {

        public void setAttribute(final Object userObject, final String value) {
            final CloudModel cloud = (CloudModel) userObject;
            cloud.setColor(ColorUtils.stringToColor(value, cloud.getColor()));
        }
    });
    reader.addAttributeHandler("cloud", "ALPHA", new IAttributeHandler() {

        public void setAttribute(final Object userObject, final String value) {
            final CloudModel cloud = (CloudModel) userObject;
            cloud.setColor(ColorUtils.alphaToColor(value, cloud.getColor()));
        }
    });
    reader.addAttributeHandler("cloud", "SHAPE", new IAttributeHandler() {

        public void setAttribute(final Object userObject, final String value) {
            final CloudModel cloud = (CloudModel) userObject;
            cloud.setShape(CloudModel.Shape.valueOf(value));
        }
    });
    reader.addAttributeHandler("cloud", "WIDTH", new IAttributeHandler() {

        public void setAttribute(final Object userObject, final String value) {
        // final CloudModel cloud = (CloudModel) userObject;
        // cloud.setWidth(Integer.parseInt(value.toString()));
        }
    });
}
Also used : IAttributeHandler(org.freeplane.core.io.IAttributeHandler)

Example 2 with IAttributeHandler

use of org.freeplane.core.io.IAttributeHandler in project freeplane by freeplane.

the class LinkBuilder method registerAttributeHandlers.

private void registerAttributeHandlers(final ReadManager reader) {
    reader.addAttributeHandler(NodeBuilder.XML_NODE, LINK, new IAttributeHandler() {

        public void setAttribute(final Object userObject, final String value) {
            final NodeModel node = (NodeModel) userObject;
            linkController.loadLink(node, value);
            final Collection<NodeLinkModel> links = NodeLinks.getLinks(node);
            processedLinks.addAll(links);
        }
    });
    final IAttributeHandler hyperlinkHandler = new IAttributeHandler() {

        public void setAttribute(final Object userObject, final String value) {
            final NodeModel node = (NodeModel) userObject;
            linkController.loadLinkFormat(node, Boolean.parseBoolean(value));
        }
    };
    reader.addAttributeHandler(NodeBuilder.XML_NODE, FORMAT_AS_HYPERLINK, hyperlinkHandler);
    reader.addAttributeHandler(NodeBuilder.XML_STYLENODE, FORMAT_AS_HYPERLINK, hyperlinkHandler);
    reader.addAttributeHandler("arrowlink", "EDGE_LIKE", new IAttributeHandler() {

        public void setAttribute(final Object userObject, final String value) {
            final ConnectorModel arrowLink = (ConnectorModel) userObject;
            arrowLink.setShape(Shape.EDGE_LIKE);
        }
    });
    reader.addAttributeHandler("arrowlink", "SHAPE", new IAttributeHandler() {

        public void setAttribute(final Object userObject, final String value) {
            final ConnectorModel arrowLink = (ConnectorModel) userObject;
            arrowLink.setShape(Shape.valueOf(value));
        }
    });
    reader.addAttributeHandler("arrowlink", "DASH", new IAttributeHandler() {

        public void setAttribute(final Object userObject, final String value) {
            final ConnectorModel arrowLink = (ConnectorModel) userObject;
            final String[] split = value.split(" ");
            int[] dash = new int[split.length];
            int i = 0;
            for (String s : split) {
                dash[i++] = Integer.parseInt(s);
            }
            arrowLink.setDash(dash);
        }
    });
    reader.addAttributeHandler("arrowlink", "DESTINATION", new IAttributeHandler() {

        public void setAttribute(final Object userObject, final String value) {
            final ConnectorModel arrowLink = (ConnectorModel) userObject;
            arrowLink.setTargetID(value);
            processedLinks.add(arrowLink);
        }
    });
    reader.addAttributeHandler("arrowlink", "SOURCE_LABEL", new IAttributeHandler() {

        public void setAttribute(final Object userObject, final String value) {
            final ConnectorModel arrowLink = (ConnectorModel) userObject;
            arrowLink.setSourceLabel(value.toString());
        }
    });
    reader.addAttributeHandler("arrowlink", "MIDDLE_LABEL", new IAttributeHandler() {

        public void setAttribute(final Object userObject, final String value) {
            final ConnectorModel arrowLink = (ConnectorModel) userObject;
            arrowLink.setMiddleLabel(value.toString());
        }
    });
    reader.addAttributeHandler("arrowlink", "TARGET_LABEL", new IAttributeHandler() {

        public void setAttribute(final Object userObject, final String value) {
            final ConnectorModel arrowLink = (ConnectorModel) userObject;
            arrowLink.setTargetLabel(value.toString());
        }
    });
    reader.addAttributeHandler("arrowlink", "STARTINCLINATION", new IAttributeHandler() {

        public void setAttribute(final Object userObject, final String value) {
            final ConnectorModel arrowLink = (ConnectorModel) userObject;
            arrowLink.setStartInclination(TreeXmlReader.xmlToPoint(value.toString()));
        }
    });
    reader.addAttributeHandler("arrowlink", "ENDINCLINATION", new IAttributeHandler() {

        public void setAttribute(final Object userObject, final String value) {
            final ConnectorModel arrowLink = (ConnectorModel) userObject;
            arrowLink.setEndInclination(TreeXmlReader.xmlToPoint(value.toString()));
        }
    });
    reader.addAttributeHandler("arrowlink", "STARTARROW", new IAttributeHandler() {

        public void setAttribute(final Object userObject, final String value) {
            final ConnectorModel arrowLink = (ConnectorModel) userObject;
            arrowLink.setStartArrow(ArrowType.valueOf(value.toUpperCase(Locale.ENGLISH)));
        }
    });
    reader.addAttributeHandler("arrowlink", "ENDARROW", new IAttributeHandler() {

        public void setAttribute(final Object userObject, final String value) {
            final ConnectorModel arrowLink = (ConnectorModel) userObject;
            arrowLink.setEndArrow(ArrowType.valueOf(value.toUpperCase(Locale.ENGLISH)));
        }
    });
    reader.addAttributeHandler("arrowlink", "WIDTH", new IAttributeHandler() {

        public void setAttribute(final Object userObject, final String value) {
            final ConnectorModel arrowLink = (ConnectorModel) userObject;
            arrowLink.setWidth(Integer.parseInt(value.toString()));
        }
    });
    reader.addAttributeHandler("arrowlink", "FONT_FAMILY", new IAttributeHandler() {

        public void setAttribute(final Object userObject, final String value) {
            final ConnectorModel arrowLink = (ConnectorModel) userObject;
            arrowLink.setLabelFontFamily(value.toString());
        }
    });
    reader.addAttributeHandler("arrowlink", "FONT_SIZE", new IAttributeHandler() {

        public void setAttribute(final Object userObject, final String value) {
            final ConnectorModel arrowLink = (ConnectorModel) userObject;
            arrowLink.setLabelFontSize(Integer.parseInt(value.toString()));
        }
    });
}
Also used : NodeModel(org.freeplane.features.map.NodeModel) IAttributeHandler(org.freeplane.core.io.IAttributeHandler) Collection(java.util.Collection)

Example 3 with IAttributeHandler

use of org.freeplane.core.io.IAttributeHandler in project freeplane by freeplane.

the class NodeStyleBuilder method registerAttributeHandlers.

private void registerAttributeHandlers(final ReadManager reader) {
    final IAttributeHandler colorHandler = new IAttributeHandler() {

        public void setAttribute(final Object userObject, final String value) {
            final NodeModel node = (NodeModel) userObject;
            NodeStyleModel.setColor(node, ColorUtils.stringToColor(value, NodeStyleModel.getColor(node)));
        }
    };
    final IAttributeHandler alphaHandler = new IAttributeHandler() {

        public void setAttribute(final Object userObject, final String value) {
            final NodeModel node = (NodeModel) userObject;
            NodeStyleModel.setColor(node, ColorUtils.alphaToColor(value, NodeStyleModel.getColor(node)));
        }
    };
    reader.addAttributeHandler(NodeBuilder.XML_NODE, "COLOR", colorHandler);
    reader.addAttributeHandler(NodeBuilder.XML_NODE, "ALPHA", alphaHandler);
    reader.addAttributeHandler(NodeBuilder.XML_STYLENODE, "COLOR", colorHandler);
    reader.addAttributeHandler(NodeBuilder.XML_STYLENODE, "ALPHA", alphaHandler);
    final IAttributeHandler bgHandler = new IAttributeHandler() {

        public void setAttribute(final Object userObject, final String value) {
            final NodeModel node = (NodeModel) userObject;
            NodeStyleModel.setBackgroundColor(node, ColorUtils.stringToColor(value, NodeStyleModel.getBackgroundColor(node)));
        }
    };
    final IAttributeHandler bgAlphaHandler = new IAttributeHandler() {

        public void setAttribute(final Object userObject, final String value) {
            final NodeModel node = (NodeModel) userObject;
            NodeStyleModel.setBackgroundColor(node, ColorUtils.alphaToColor(value, NodeStyleModel.getBackgroundColor(node)));
        }
    };
    reader.addAttributeHandler(NodeBuilder.XML_NODE, "BACKGROUND_COLOR", bgHandler);
    reader.addAttributeHandler(NodeBuilder.XML_NODE, "BACKGROUND_ALPHA", bgAlphaHandler);
    reader.addAttributeHandler(NodeBuilder.XML_STYLENODE, "BACKGROUND_COLOR", bgHandler);
    reader.addAttributeHandler(NodeBuilder.XML_STYLENODE, "BACKGROUND_ALPHA", bgAlphaHandler);
    final IAttributeHandler shapeHandler = new IAttributeHandler() {

        public void setAttribute(final Object userObject, final String value) {
            final NodeModel node = (NodeModel) userObject;
            NodeStyleModel.setShape(node, value);
        }
    };
    reader.addAttributeHandler(NodeBuilder.XML_NODE, "STYLE", shapeHandler);
    reader.addAttributeHandler(NodeBuilder.XML_STYLENODE, "STYLE", shapeHandler);
    final IAttributeHandler shapeHorizontalMarginHandler = new IAttributeHandler() {

        public void setAttribute(final Object userObject, final String value) {
            final NodeModel node = (NodeModel) userObject;
            NodeStyleModel.setShapeHorizontalMargin(node, Quantity.fromString(value, LengthUnits.px));
        }
    };
    reader.addAttributeHandler(NodeBuilder.XML_NODE, "SHAPE_HORIZONTAL_MARGIN", shapeHorizontalMarginHandler);
    reader.addAttributeHandler(NodeBuilder.XML_STYLENODE, "SHAPE_HORIZONTAL_MARGIN", shapeHorizontalMarginHandler);
    final IAttributeHandler shapeVerticalMarginHandler = new IAttributeHandler() {

        public void setAttribute(final Object userObject, final String value) {
            final NodeModel node = (NodeModel) userObject;
            NodeStyleModel.setShapeVerticalMargin(node, Quantity.fromString(value, LengthUnits.px));
        }
    };
    reader.addAttributeHandler(NodeBuilder.XML_NODE, "SHAPE_VERTICAL_MARGIN", shapeVerticalMarginHandler);
    reader.addAttributeHandler(NodeBuilder.XML_STYLENODE, "SHAPE_VERTICAL_MARGIN", shapeVerticalMarginHandler);
    final IAttributeHandler uniformShapeHandler = new IAttributeHandler() {

        public void setAttribute(final Object userObject, final String value) {
            final NodeModel node = (NodeModel) userObject;
            NodeStyleModel.setShapeUniform(node, Boolean.valueOf(value));
        }
    };
    reader.addAttributeHandler(NodeBuilder.XML_NODE, "UNIFORM_SHAPE", uniformShapeHandler);
    reader.addAttributeHandler(NodeBuilder.XML_STYLENODE, "UNIFORM_SHAPE", uniformShapeHandler);
    reader.addAttributeHandler("font", "SIZE", new IAttributeHandler() {

        public void setAttribute(final Object userObject, final String value) {
            final FontProperties fp = (FontProperties) userObject;
            fp.fontSize = Integer.parseInt(value.toString());
        }
    });
    reader.addAttributeHandler("font", "NAME", new IAttributeHandler() {

        public void setAttribute(final Object userObject, final String value) {
            final FontProperties fp = (FontProperties) userObject;
            fp.fontName = value;
        }
    });
    reader.addAttributeHandler("font", "BOLD", new IAttributeHandler() {

        public void setAttribute(final Object userObject, final String value) {
            final FontProperties fp = (FontProperties) userObject;
            fp.isBold = value.equals("true");
        }
    });
    reader.addAttributeHandler("font", "STRIKETHROUGH", new IAttributeHandler() {

        public void setAttribute(final Object userObject, final String value) {
            final FontProperties fp = (FontProperties) userObject;
            fp.isStrikedThrough = value.equals("true");
        }
    });
    reader.addAttributeHandler("font", "ITALIC", new IAttributeHandler() {

        public void setAttribute(final Object userObject, final String value) {
            final FontProperties fp = (FontProperties) userObject;
            fp.isItalic = value.equals("true");
        }
    });
    final IAttributeHandler nodenumberingHandler = new IAttributeHandler() {

        public void setAttribute(final Object userObject, final String value) {
            final NodeModel node = (NodeModel) userObject;
            NodeStyleModel.setNodeNumbering(node, value.equals("true"));
        }
    };
    reader.addAttributeHandler(NodeBuilder.XML_NODE, "NUMBERED", nodenumberingHandler);
    reader.addAttributeHandler(NodeBuilder.XML_STYLENODE, "NUMBERED", nodenumberingHandler);
    final IAttributeHandler formatHandler = new IAttributeHandler() {

        public void setAttribute(final Object userObject, final String value) {
            final NodeModel node = (NodeModel) userObject;
            NodeStyleModel.setNodeFormat(node, value);
        }
    };
    reader.addAttributeHandler(NodeBuilder.XML_NODE, "FORMAT", formatHandler);
    reader.addAttributeHandler(NodeBuilder.XML_STYLENODE, "FORMAT", formatHandler);
    if (FreeplaneVersion.getVersion().isOlderThan(new FreeplaneVersion(1, 3, 0))) {
        // compatibility for a view 1.2.X preview versions - remove after release 1.3
        reader.addAttributeHandler(NodeBuilder.XML_NODE, "TEMPLATE", formatHandler);
        reader.addAttributeHandler(NodeBuilder.XML_STYLENODE, "TEMPLATE", formatHandler);
    }
    // save to 1.1: MAX_WIDTH="200" MAX_WIDTH_QUANTITY="200.0 px"
    // save: MAX_WIDTH="200.0 px"
    final IAttributeHandler nodeMaxNodeWidthQuantityHandler = new IAttributeHandler() {

        public void setAttribute(final Object userObject, final String value) {
            final NodeModel node = (NodeModel) userObject;
            Quantity<LengthUnits> width = Quantity.fromString(value, LengthUnits.px);
            NodeSizeModel.setMaxNodeWidth(node, width);
        }
    };
    reader.addAttributeHandler(NodeBuilder.XML_NODE, "MAX_WIDTH_QUANTITY", nodeMaxNodeWidthQuantityHandler);
    reader.addAttributeHandler(NodeBuilder.XML_STYLENODE, "MAX_WIDTH_QUANTITY", nodeMaxNodeWidthQuantityHandler);
    final IAttributeHandler nodeMaxNodeWidthHandler = new IAttributeHandler() {

        public void setAttribute(final Object userObject, final String value) {
            final NodeModel node = (NodeModel) userObject;
            if (NodeSizeModel.getMaxNodeWidth(node) == null) {
                nodeMaxNodeWidthQuantityHandler.setAttribute(node, value);
            }
        }
    };
    reader.addAttributeHandler(NodeBuilder.XML_NODE, "MAX_WIDTH", nodeMaxNodeWidthHandler);
    reader.addAttributeHandler(NodeBuilder.XML_STYLENODE, "MAX_WIDTH", nodeMaxNodeWidthHandler);
    final IAttributeHandler nodeIconSizeHandler = new IAttributeHandler() {

        public void setAttribute(final Object userObject, final String value) {
            final NodeModel node = (NodeModel) userObject;
            Quantity<LengthUnits> iconSize = Quantity.fromString(value, LengthUnits.px);
            node.getSharedData().getIcons().setIconSize(iconSize);
        }
    };
    reader.addAttributeHandler(NodeBuilder.XML_NODE, "ICON_SIZE", nodeIconSizeHandler);
    reader.addAttributeHandler(NodeBuilder.XML_STYLENODE, "ICON_SIZE", nodeIconSizeHandler);
    final IAttributeHandler nodeMinNodeWidthQuantityHandler = new IAttributeHandler() {

        public void setAttribute(final Object userObject, final String value) {
            final NodeModel node = (NodeModel) userObject;
            Quantity<LengthUnits> width = Quantity.fromString(value, LengthUnits.px);
            NodeSizeModel.setNodeMinWidth(node, width);
        }
    };
    reader.addAttributeHandler(NodeBuilder.XML_NODE, "MIN_WIDTH_QUANTITY", nodeMinNodeWidthQuantityHandler);
    reader.addAttributeHandler(NodeBuilder.XML_STYLENODE, "MIN_WIDTH_QUANTITY", nodeMinNodeWidthQuantityHandler);
    final IAttributeHandler nodeMinWidthHandler = new IAttributeHandler() {

        public void setAttribute(final Object userObject, final String value) {
            final NodeModel node = (NodeModel) userObject;
            if (NodeSizeModel.getMinNodeWidth(node) == null) {
                nodeMinNodeWidthQuantityHandler.setAttribute(node, value);
            }
        }
    };
    reader.addAttributeHandler(NodeBuilder.XML_NODE, "MIN_WIDTH", nodeMinWidthHandler);
    reader.addAttributeHandler(NodeBuilder.XML_STYLENODE, "MIN_WIDTH", nodeMinWidthHandler);
    final IAttributeHandler textAlignHandler = new IAttributeHandler() {

        public void setAttribute(final Object userObject, final String value) {
            final NodeModel node = (NodeModel) userObject;
            NodeStyleModel.setHorizontalTextAlignment(node, HorizontalTextAlignment.valueOf(value));
        }
    };
    reader.addAttributeHandler(NodeBuilder.XML_NODE, "TEXT_ALIGN", textAlignHandler);
    reader.addAttributeHandler(NodeBuilder.XML_STYLENODE, "TEXT_ALIGN", textAlignHandler);
    final IAttributeHandler borderWidthMatchesEdgeWidthHandler = new IAttributeHandler() {

        public void setAttribute(final Object userObject, final String value) {
            final NodeModel node = (NodeModel) userObject;
            NodeBorderModel.setBorderWidthMatchesEdgeWidth(node, Boolean.valueOf(value));
        }
    };
    reader.addAttributeHandler(NodeBuilder.XML_NODE, "BORDER_WIDTH_LIKE_EDGE", borderWidthMatchesEdgeWidthHandler);
    reader.addAttributeHandler(NodeBuilder.XML_STYLENODE, "BORDER_WIDTH_LIKE_EDGE", borderWidthMatchesEdgeWidthHandler);
    final IAttributeHandler borderWidthHandler = new IAttributeHandler() {

        public void setAttribute(final Object userObject, final String value) {
            final NodeModel node = (NodeModel) userObject;
            NodeBorderModel.setBorderWidth(node, Quantity.fromString(value, LengthUnits.px));
        }
    };
    reader.addAttributeHandler(NodeBuilder.XML_NODE, "BORDER_WIDTH", borderWidthHandler);
    reader.addAttributeHandler(NodeBuilder.XML_STYLENODE, "BORDER_WIDTH", borderWidthHandler);
    final IAttributeHandler borderDashMatchesEdgeDashHandler = new IAttributeHandler() {

        public void setAttribute(final Object userObject, final String value) {
            final NodeModel node = (NodeModel) userObject;
            NodeBorderModel.setBorderDashMatchesEdgeDash(node, Boolean.valueOf(value));
        }
    };
    reader.addAttributeHandler(NodeBuilder.XML_NODE, "BORDER_DASH_LIKE_EDGE", borderDashMatchesEdgeDashHandler);
    reader.addAttributeHandler(NodeBuilder.XML_STYLENODE, "BORDER_DASH_LIKE_EDGE", borderDashMatchesEdgeDashHandler);
    final IAttributeHandler borderDashHandler = new IAttributeHandler() {

        public void setAttribute(final Object userObject, final String value) {
            final NodeModel node = (NodeModel) userObject;
            NodeBorderModel.setBorderDash(node, DashVariant.valueOf(value));
        }
    };
    reader.addAttributeHandler(NodeBuilder.XML_NODE, "BORDER_DASH", borderDashHandler);
    reader.addAttributeHandler(NodeBuilder.XML_STYLENODE, "BORDER_DASH", borderDashHandler);
    final IAttributeHandler borderColorMatchesEdgeColorHandler = new IAttributeHandler() {

        public void setAttribute(final Object userObject, final String value) {
            final NodeModel node = (NodeModel) userObject;
            NodeBorderModel.setBorderColorMatchesEdgeColor(node, Boolean.valueOf(value));
        }
    };
    reader.addAttributeHandler(NodeBuilder.XML_NODE, "BORDER_COLOR_LIKE_EDGE", borderColorMatchesEdgeColorHandler);
    reader.addAttributeHandler(NodeBuilder.XML_STYLENODE, "BORDER_COLOR_LIKE_EDGE", borderColorMatchesEdgeColorHandler);
    final IAttributeHandler borderColorHandler = new IAttributeHandler() {

        public void setAttribute(final Object userObject, final String value) {
            final NodeModel node = (NodeModel) userObject;
            NodeBorderModel.setBorderColor(node, ColorUtils.stringToColor(value, NodeBorderModel.getBorderColor(node)));
        }
    };
    final IAttributeHandler borderColorAlphaHandler = new IAttributeHandler() {

        public void setAttribute(final Object userObject, final String value) {
            final NodeModel node = (NodeModel) userObject;
            NodeBorderModel.setBorderColor(node, ColorUtils.alphaToColor(value, NodeBorderModel.getBorderColor(node)));
        }
    };
    reader.addAttributeHandler(NodeBuilder.XML_NODE, "BORDER_COLOR", borderColorHandler);
    reader.addAttributeHandler(NodeBuilder.XML_NODE, "BORDER_COLOR_ALPHA", borderColorAlphaHandler);
    reader.addAttributeHandler(NodeBuilder.XML_STYLENODE, "BORDER_COLOR", borderColorHandler);
    reader.addAttributeHandler(NodeBuilder.XML_STYLENODE, "BORDER_COLOR_ALPHA", borderColorAlphaHandler);
}
Also used : NodeModel(org.freeplane.features.map.NodeModel) LengthUnits(org.freeplane.core.ui.LengthUnits) IAttributeHandler(org.freeplane.core.io.IAttributeHandler) FreeplaneVersion(org.freeplane.core.util.FreeplaneVersion)

Example 4 with IAttributeHandler

use of org.freeplane.core.io.IAttributeHandler in project freeplane by freeplane.

the class LocationBuilder method registerAttributeHandlers.

private void registerAttributeHandlers(final ReadManager reader) {
    final IAttributeHandler vShiftHandler = new IAttributeHandler() {

        public void setAttribute(final Object userObject, final String value) {
            final NodeModel node = (NodeModel) userObject;
            LocationModel.createLocationModel(node).setShiftY(Quantity.fromString(value, LengthUnits.px));
        }
    };
    reader.addAttributeHandler(NodeBuilder.XML_NODE, "VSHIFT", vShiftHandler);
    reader.addAttributeHandler(NodeBuilder.XML_NODE, "VSHIFT_QUANTITY", vShiftHandler);
    final IAttributeHandler vgapHandler = new IAttributeHandler() {

        public void setAttribute(final Object userObject, final String value) {
            final NodeModel node = (NodeModel) userObject;
            LocationModel.createLocationModel(node).setVGap(Quantity.fromString(value, LengthUnits.px));
        }
    };
    reader.addAttributeHandler(NodeBuilder.XML_NODE, "VGAP", vgapHandler);
    reader.addAttributeHandler(NodeBuilder.XML_NODE, "VGAP_QUANTITY", vgapHandler);
    reader.addAttributeHandler(NodeBuilder.XML_STYLENODE, "VGAP", vgapHandler);
    reader.addAttributeHandler(NodeBuilder.XML_STYLENODE, "VGAP_QUANTITY", vgapHandler);
    final IAttributeHandler hgapHandler = new IAttributeHandler() {

        public void setAttribute(final Object userObject, final String value) {
            final NodeModel node = (NodeModel) userObject;
            LocationModel.createLocationModel(node).setHGap(Quantity.fromString(value, LengthUnits.px));
        }
    };
    reader.addAttributeHandler(NodeBuilder.XML_NODE, "HGAP_QUANTITY", hgapHandler);
    reader.addAttributeHandler(NodeBuilder.XML_NODE, "HGAP", hgapHandler);
}
Also used : NodeModel(org.freeplane.features.map.NodeModel) IAttributeHandler(org.freeplane.core.io.IAttributeHandler)

Example 5 with IAttributeHandler

use of org.freeplane.core.io.IAttributeHandler in project freeplane by freeplane.

the class EdgeBuilder method registerAttributeHandlers.

private void registerAttributeHandlers(final ReadManager reader) {
    reader.addAttributeHandler("edge", "STYLE", new IAttributeHandler() {

        public void setAttribute(final Object userObject, final String value) {
            final EdgeModel edge = (EdgeModel) userObject;
            edge.setStyle(EdgeStyle.getStyle(value));
        }
    });
    reader.addAttributeHandler("edge", "HIDE", new IAttributeHandler() {

        public void setAttribute(final Object userObject, final String value) {
            final EdgeModel edge = (EdgeModel) userObject;
            edge.setStyle(EdgeStyle.EDGESTYLE_HIDDEN);
        }
    });
    reader.addAttributeHandler("edge", "COLOR", new IAttributeHandler() {

        public void setAttribute(final Object userObject, final String value) {
            final EdgeModel edge = (EdgeModel) userObject;
            edge.setColor(ColorUtils.stringToColor(value, edge.getColor()));
        }
    });
    reader.addAttributeHandler("edge", "ALPHA", new IAttributeHandler() {

        public void setAttribute(final Object userObject, final String value) {
            final EdgeModel edge = (EdgeModel) userObject;
            edge.setColor(ColorUtils.alphaToColor(value, edge.getColor()));
        }
    });
    reader.addAttributeHandler("edge", "WIDTH", new IAttributeHandler() {

        public void setAttribute(final Object userObject, final String value) {
            final EdgeModel edge = (EdgeModel) userObject;
            if (value.equals(EdgeModel.EDGEWIDTH_THIN)) {
                edge.setWidth(EdgeModel.WIDTH_THIN);
            } else {
                edge.setWidth(Integer.parseInt(value.toString()));
            }
        }
    });
    reader.addAttributeHandler("edge", "DASH", new IAttributeHandler() {

        public void setAttribute(final Object userObject, final String value) {
            final EdgeModel edge = (EdgeModel) userObject;
            edge.setDash(DashVariant.valueOf(value));
        }
    });
}
Also used : IAttributeHandler(org.freeplane.core.io.IAttributeHandler)

Aggregations

IAttributeHandler (org.freeplane.core.io.IAttributeHandler)9 NodeModel (org.freeplane.features.map.NodeModel)6 TranslatedObject (org.freeplane.core.resources.TranslatedObject)2 IOException (java.io.IOException)1 Collection (java.util.Collection)1 List (java.util.List)1 IAttributeWriter (org.freeplane.core.io.IAttributeWriter)1 IElementHandler (org.freeplane.core.io.IElementHandler)1 IReadCompletionListener (org.freeplane.core.io.IReadCompletionListener)1 ITreeWriter (org.freeplane.core.io.ITreeWriter)1 ReadManager (org.freeplane.core.io.ReadManager)1 WriteManager (org.freeplane.core.io.WriteManager)1 ResourceController (org.freeplane.core.resources.ResourceController)1 LengthUnits (org.freeplane.core.ui.LengthUnits)1 FreeplaneVersion (org.freeplane.core.util.FreeplaneVersion)1 IFormattedObject (org.freeplane.features.format.IFormattedObject)1 MapController (org.freeplane.features.map.MapController)1 Hint (org.freeplane.features.map.MapWriter.Hint)1 ModeController (org.freeplane.features.mode.ModeController)1 StyleString (org.freeplane.features.styles.StyleString)1