Search in sources :

Example 1 with IAttributeWriter

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

the class LogicalStyleController method createBuilder.

private void createBuilder() {
    ModeController modeController = Controller.getCurrentModeController();
    final MapController mapController = modeController.getMapController();
    final ReadManager readManager = mapController.getReadManager();
    readManager.addAttributeHandler(NodeBuilder.XML_NODE, "STYLE_REF", new IAttributeHandler() {

        public void setAttribute(final Object node, final String value) {
            final LogicalStyleModel extension = LogicalStyleModel.createExtension((NodeModel) node);
            extension.setStyle(StyleFactory.create(value));
        }
    });
    readManager.addAttributeHandler(NodeBuilder.XML_NODE, "LOCALIZED_STYLE_REF", new IAttributeHandler() {

        public void setAttribute(final Object node, final String value) {
            final LogicalStyleModel extension = LogicalStyleModel.createExtension((NodeModel) node);
            extension.setStyle(StyleFactory.create(TranslatedObject.format(value)));
        }
    });
    final WriteManager writeManager = mapController.getWriteManager();
    writeManager.addAttributeWriter(NodeBuilder.XML_NODE, new IAttributeWriter() {

        public void writeAttributes(final ITreeWriter writer, final Object node, final String tag) {
            if (!NodeWriter.shouldWriteSharedContent(writer))
                return;
            final LogicalStyleModel extension = LogicalStyleModel.getExtension((NodeModel) node);
            if (extension == null) {
                return;
            }
            final IStyle style = extension.getStyle();
            if (style == null) {
                return;
            }
            final String value = StyleTranslatedObject.toKeyString(style);
            if (style instanceof StyleTranslatedObject) {
                writer.addAttribute("LOCALIZED_STYLE_REF", value);
            } else {
                writer.addAttribute("STYLE_REF", value);
            }
        }
    });
}
Also used : IAttributeWriter(org.freeplane.core.io.IAttributeWriter) IAttributeHandler(org.freeplane.core.io.IAttributeHandler) ModeController(org.freeplane.features.mode.ModeController) MapController(org.freeplane.features.map.MapController) NodeModel(org.freeplane.features.map.NodeModel) ReadManager(org.freeplane.core.io.ReadManager) ITreeWriter(org.freeplane.core.io.ITreeWriter) TranslatedObject(org.freeplane.core.resources.TranslatedObject) WriteManager(org.freeplane.core.io.WriteManager)

Example 2 with IAttributeWriter

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

the class TreeXmlWriter method addElement.

@SuppressWarnings("unchecked")
public void addElement(final Object userObject, final XMLElement element) throws IOException {
    final boolean isString = userObject instanceof String;
    if (elementStarted == false && xmlElement != null) {
        xmlwriter.write(xmlElement, !isString, 0, true, false);
    }
    final String name = element.getName();
    xmlElement = element;
    elementStarted = false;
    {
        final Iterator<IAttributeWriter> iterator = getAttributeWriters().iterator(name);
        while (iterator.hasNext()) {
            final IAttributeWriter as = iterator.next();
            as.writeAttributes(this, userObject, name);
        }
        if (userObject instanceof List<?>) {
            addExtensionAttributes(userObject, (List<IExtension>) userObject);
        }
    }
    if (isString) {
        addElementContent((String) userObject);
    } else {
        final Iterator<IElementWriter> iterator = getNodeWriters().iterator(name);
        while (iterator.hasNext()) {
            final IElementWriter nw = iterator.next();
            nw.writeContent(this, userObject, name);
        }
        if (userObject instanceof List<?>) {
            addExtensionNodes(userObject, (List<IExtension>) userObject);
        }
    }
    if (elementStarted == false) {
        xmlwriter.write(xmlElement, true, 0, true, true);
        elementStarted = true;
    } else {
        xmlwriter.endElement(name, true);
    }
}
Also used : IAttributeWriter(org.freeplane.core.io.IAttributeWriter) IElementWriter(org.freeplane.core.io.IElementWriter) IExtension(org.freeplane.core.extension.IExtension) Iterator(java.util.Iterator) ListIterator(java.util.ListIterator) List(java.util.List)

Aggregations

IAttributeWriter (org.freeplane.core.io.IAttributeWriter)2 Iterator (java.util.Iterator)1 List (java.util.List)1 ListIterator (java.util.ListIterator)1 IExtension (org.freeplane.core.extension.IExtension)1 IAttributeHandler (org.freeplane.core.io.IAttributeHandler)1 IElementWriter (org.freeplane.core.io.IElementWriter)1 ITreeWriter (org.freeplane.core.io.ITreeWriter)1 ReadManager (org.freeplane.core.io.ReadManager)1 WriteManager (org.freeplane.core.io.WriteManager)1 TranslatedObject (org.freeplane.core.resources.TranslatedObject)1 MapController (org.freeplane.features.map.MapController)1 NodeModel (org.freeplane.features.map.NodeModel)1 ModeController (org.freeplane.features.mode.ModeController)1