use of org.freeplane.features.map.NodeModel in project freeplane by freeplane.
the class NodeStyleBuilder method writeAttributes.
public void writeAttributes(final ITreeWriter writer, final Object userObject, final IExtension extension) {
final boolean forceFormatting = Boolean.TRUE.equals(writer.getHint(MapWriter.WriterHint.FORCE_FORMATTING));
if (forceFormatting) {
return;
}
final NodeModel node = (NodeModel) userObject;
if (extension instanceof NodeStyleModel) {
final NodeStyleModel style = (NodeStyleModel) extension;
writeAttributes(writer, node, style, false);
return;
}
if (extension instanceof NodeSizeModel) {
final NodeSizeModel size = (NodeSizeModel) extension;
writeAttributes(writer, node, size, false);
return;
}
if (extension instanceof NodeBorderModel) {
final NodeBorderModel border = (NodeBorderModel) extension;
writeAttributes(writer, null, border, false);
return;
}
}
use of org.freeplane.features.map.NodeModel 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);
}
use of org.freeplane.features.map.NodeModel in project freeplane by freeplane.
the class NodeStyleBuilder method writeContent.
public void writeContent(final ITreeWriter writer, final Object userObject, final String tag) throws IOException {
final boolean forceFormatting = Boolean.TRUE.equals(writer.getHint(MapWriter.WriterHint.FORCE_FORMATTING));
if (!forceFormatting) {
return;
}
final NodeModel node = (NodeModel) userObject;
writeContent(writer, node, null, true);
}
use of org.freeplane.features.map.NodeModel in project freeplane by freeplane.
the class NodeStyleBuilder method writeAttributes.
public void writeAttributes(final ITreeWriter writer, final Object userObject, final String tag) {
final boolean forceFormatting = Boolean.TRUE.equals(writer.getHint(MapWriter.WriterHint.FORCE_FORMATTING));
if (!forceFormatting) {
return;
}
final NodeModel node = (NodeModel) userObject;
writeAttributes(writer, node, (NodeStyleModel) null, true);
writeAttributes(writer, node, (NodeSizeModel) null, true);
writeAttributes(writer, node, (NodeBorderModel) null, true);
}
use of org.freeplane.features.map.NodeModel in project freeplane by freeplane.
the class NodeStyleController method getNodeFormat.
public String getNodeFormat(NodeModel node) {
Collection<IStyle> collection = LogicalStyleController.getController(modeController).getStyles(node);
final MapStyleModel model = MapStyleModel.getExtension(node.getMap());
for (IStyle styleKey : collection) {
final NodeModel styleNode = model.getStyleNode(styleKey);
if (styleNode == null) {
continue;
}
final String format = NodeStyleModel.getNodeFormat(styleNode);
if (format != null) {
return format;
}
}
// automatically disable all IContentTransformers!
return PatternFormat.STANDARD_FORMAT_PATTERN;
}
Aggregations