use of org.freeplane.features.format.IFormattedObject in project freeplane by freeplane.
the class NodeTextBuilder method registerAttributeHandlers.
private void registerAttributeHandlers(final ReadManager reader) {
reader.addAttributeHandler(NodeBuilder.XML_NODE, NodeTextBuilder.XML_NODE_TEXT, new IAttributeHandler() {
public void setAttribute(final Object userObject, final String value) {
final NodeModel node = ((NodeModel) userObject);
final Object nodeContent = node.getUserObject();
if (nodeContent == null || nodeContent.equals("")) {
node.setText(value);
}
}
});
reader.addAttributeHandler(NodeBuilder.XML_NODE, NodeTextBuilder.XML_NODE_OBJECT, new IAttributeHandler() {
public void setAttribute(final Object userObject, final String value) {
final NodeModel node = ((NodeModel) userObject);
final Object newInstance = TypeReference.create(value);
// because formatting is saved as an extra attribute
if (newInstance instanceof IFormattedObject)
node.setUserObject(((IFormattedObject) newInstance).getObject());
else
node.setUserObject(newInstance);
}
});
IAttributeHandler textShortenedHandler = new IAttributeHandler() {
public void setAttribute(final Object userObject, final String value) {
final NodeModel node = ((NodeModel) userObject);
try {
if (Boolean.valueOf(value)) {
node.addExtension(new ShortenedTextModel());
}
} catch (Exception e) {
LogUtils.warn(e);
}
}
};
reader.addAttributeHandler(NodeBuilder.XML_NODE, NodeTextBuilder.XML_NODE_TEXT_SHORTENED, textShortenedHandler);
reader.addAttributeHandler(NodeBuilder.XML_STYLENODE, NodeTextBuilder.XML_NODE_TEXT_SHORTENED, textShortenedHandler);
reader.addAttributeHandler(NodeBuilder.XML_STYLENODE, NodeTextBuilder.XML_NODE_TEXT, new IAttributeHandler() {
public void setAttribute(final Object userObject, final String value) {
final NodeModel node = ((NodeModel) userObject);
node.setUserObject(StyleFactory.create(value));
}
});
reader.addAttributeHandler(NodeBuilder.XML_NODE, NodeTextBuilder.XML_NODE_LOCALIZED_TEXT, new IAttributeHandler() {
public void setAttribute(final Object userObject, final String value) {
final NodeModel node = ((NodeModel) userObject);
node.setUserObject(StyleFactory.create(TranslatedObject.format(value)));
}
});
reader.addAttributeHandler(NodeBuilder.XML_STYLENODE, NodeTextBuilder.XML_NODE_LOCALIZED_TEXT, new IAttributeHandler() {
public void setAttribute(final Object userObject, final String value) {
final NodeModel node = ((NodeModel) userObject);
node.setUserObject(StyleFactory.create(TranslatedObject.format(value)));
}
});
}
use of org.freeplane.features.format.IFormattedObject in project freeplane by freeplane.
the class NodeProxy method getFormat.
// NodeRO: R
public String getFormat() {
final NodeModel nodeModel = getDelegate();
final String format = TextController.getController().getNodeFormat(nodeModel);
if (format == null && nodeModel.getUserObject() instanceof IFormattedObject)
return ((IFormattedObject) nodeModel.getUserObject()).getPattern();
return format;
}
Aggregations