private void registerAttributeHandlers(final ReadManager reader) {
final IAttributeHandler colorHandler = new IAttributeHandler() {
public void setAttribute(final Object userObject, final String value) {
if (value.length() == 7) {
final NodeModel node = (NodeModel) userObject;
NodeStyleModel.setColor(node, ColorUtils.stringToColor(value));
}
}
};
reader.addAttributeHandler(NodeBuilder.XML_NODE, "COLOR", colorHandler);
reader.addAttributeHandler(NodeBuilder.XML_STYLENODE, "COLOR", colorHandler);
final IAttributeHandler bgHandler = new IAttributeHandler() {
public void setAttribute(final Object userObject, final String value) {
if (value.length() == 7) {
final NodeModel node = (NodeModel) userObject;
NodeStyleModel.setBackgroundColor(node, ColorUtils.stringToColor(value));
}
}
};
reader.addAttributeHandler(NodeBuilder.XML_NODE, "BACKGROUND_COLOR", bgHandler);
reader.addAttributeHandler(NodeBuilder.XML_STYLENODE, "BACKGROUND_COLOR", bgHandler);
final IAttributeHandler styleHandler = 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", styleHandler);
reader.addAttributeHandler(NodeBuilder.XML_STYLENODE, "STYLE", styleHandler);
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", "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);
}
final IAttributeHandler nodeMaxNodeWidthHandler = new IAttributeHandler() {
public void setAttribute(final Object userObject, final String value) {
final NodeModel node = (NodeModel) userObject;
NodeSizeModel.setNodeMaxNodeWidth(node, Integer.valueOf(value));
}
};
reader.addAttributeHandler(NodeBuilder.XML_NODE, "MAX_WIDTH", nodeMaxNodeWidthHandler);
reader.addAttributeHandler(NodeBuilder.XML_STYLENODE, "MAX_WIDTH", nodeMaxNodeWidthHandler);
final IAttributeHandler nodeMinWidthHandler = new IAttributeHandler() {
public void setAttribute(final Object userObject, final String value) {
final NodeModel node = (NodeModel) userObject;
NodeSizeModel.setNodeMinWidth(node, Integer.valueOf(value));
}
};
reader.addAttributeHandler(NodeBuilder.XML_NODE, "MIN_WIDTH", nodeMinWidthHandler);
reader.addAttributeHandler(NodeBuilder.XML_STYLENODE, "MIN_WIDTH", nodeMinWidthHandler);