Search in sources :

Example 1 with IFormattedObject

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)));
        }
    });
}
Also used : NodeModel(org.freeplane.features.map.NodeModel) IAttributeHandler(org.freeplane.core.io.IAttributeHandler) IFormattedObject(org.freeplane.features.format.IFormattedObject) StyleTranslatedObject(org.freeplane.features.styles.StyleTranslatedObject) IFormattedObject(org.freeplane.features.format.IFormattedObject) TranslatedObject(org.freeplane.core.resources.TranslatedObject) StyleString(org.freeplane.features.styles.StyleString) IOException(java.io.IOException)

Example 2 with IFormattedObject

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;
}
Also used : NodeModel(org.freeplane.features.map.NodeModel) IFormattedObject(org.freeplane.features.format.IFormattedObject)

Aggregations

IFormattedObject (org.freeplane.features.format.IFormattedObject)2 NodeModel (org.freeplane.features.map.NodeModel)2 IOException (java.io.IOException)1 IAttributeHandler (org.freeplane.core.io.IAttributeHandler)1 TranslatedObject (org.freeplane.core.resources.TranslatedObject)1 StyleString (org.freeplane.features.styles.StyleString)1 StyleTranslatedObject (org.freeplane.features.styles.StyleTranslatedObject)1