Search in sources :

Example 1 with ITreeWriter

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

the class AttributeBuilder method registerBy.

/**
 */
public void registerBy(final ReadManager reader, final WriteManager writer) {
    reader.addElementHandler("attribute_registry", this);
    reader.addElementHandler(AttributeBuilder.XML_NODE_ATTRIBUTE, this);
    reader.addElementHandler(AttributeBuilder.XML_NODE_REGISTERED_ATTRIBUTE_NAME, this);
    reader.addElementHandler(AttributeBuilder.XML_NODE_REGISTERED_ATTRIBUTE_VALUE, this);
    writer.addExtensionElementWriter(NodeAttributeTableModel.class, new IExtensionElementWriter() {

        public void writeContent(final ITreeWriter writer, final Object node, final IExtension extension) throws IOException {
            final NodeAttributeTableModel attributes = (NodeAttributeTableModel) extension;
            save((NodeModel) node, attributes, writer);
        }
    });
    writer.addExtensionElementWriter(AttributeRegistry.class, new IExtensionElementWriter() {

        public void writeContent(final ITreeWriter writer, final Object node, final IExtension extension) throws IOException {
            final AttributeRegistry attributes = (AttributeRegistry) extension;
            attributes.write(writer);
        }
    });
    writer.addAttributeWriter(XML_NODE_ATTRIBUTE_LAYOUT, AttributeWriter.INSTANCE);
    registerAttributeHandlers(reader);
}
Also used : NodeModel(org.freeplane.features.map.NodeModel) IExtension(org.freeplane.core.extension.IExtension) ITreeWriter(org.freeplane.core.io.ITreeWriter) IOException(java.io.IOException) IExtensionElementWriter(org.freeplane.core.io.IExtensionElementWriter)

Example 2 with ITreeWriter

use of org.freeplane.core.io.ITreeWriter 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 3 with ITreeWriter

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

the class PresentationWriter method register.

void register(MapController mapController, final PresentationController presentationController) {
    mapController.getReadManager().addElementHandler("hook", new IElementDOMHandler() {

        private final ConditionFactory conditionFactory = FilterController.getCurrentFilterController().getConditionFactory();

        @Override
        public Object createElement(Object parent, String tag, XMLElement attributes) {
            if (attributes == null) {
                return null;
            }
            if (!PRESENTATIONS.equals(attributes.getAttribute("NAME", null))) {
                return null;
            }
            return parent;
        }

        @Override
        public void endElement(Object parent, String tag, Object element, XMLElement dom) {
            final NodeModel node = (NodeModel) parent;
            final MapModel map = node.getMap();
            final NamedElementFactory<Slide> slideFactory = presentationController.getSlideFactory(map);
            MapPresentations mapPresentationExtension = presentationController.getPresentations(map);
            NamedElementCollection<Presentation> presentations = mapPresentationExtension.presentations;
            Enumeration<XMLElement> xmlPresentations = dom.enumerateChildren();
            while (xmlPresentations.hasMoreElements()) {
                XMLElement xmlPresentation = xmlPresentations.nextElement();
                presentations.add(xmlPresentation.getAttribute(NAME, "noname"));
                Enumeration<XMLElement> xmlSlides = xmlPresentation.enumerateChildren();
                NamedElementCollection<Slide> slides = presentations.getCurrentElement().slides;
                while (xmlSlides.hasMoreElements()) {
                    XMLElement xmlSlide = xmlSlides.nextElement();
                    final String name = xmlSlide.getAttribute(NAME, "noname");
                    Slide s = slideFactory.create(name);
                    Slide slide = applySlideAttributes(xmlSlide, s);
                    slides.add(slide);
                }
                if (slides.getSize() > 1)
                    slides.selectCurrentElement(0);
            }
            if (presentations.getSize() > 1)
                presentations.selectCurrentElement(0);
            node.addExtension(mapPresentationExtension);
        }

        Slide applySlideAttributes(XMLElement xmlSlide, Slide s) {
            s.setShowsAncestors(toBoolean(xmlSlide, SHOWS_ANCESTORS));
            s.setShowsDescendants(toBoolean(xmlSlide, SHOWS_DESCENDANTS));
            s.setShowsOnlySpecificNodes(toBoolean(xmlSlide, SHOWS_ONLY_SPECIFIC_NODES));
            s.setChangesZoom(toBoolean(xmlSlide, CHANGES_ZOOM));
            final String centeredNodeId = toString(xmlSlide, CENTERED_NODE_ID);
            if (centeredNodeId != null) {
                s.setPlacedNodeId(centeredNodeId);
            }
            final String placedNodeId = toString(xmlSlide, PLACED_NODE_ID);
            if (placedNodeId != null) {
                s.setPlacedNodeId(placedNodeId);
            }
            final String nodePosition = xmlSlide.getAttribute(PLACED_NODE_POSITION, NodePosition.CENTER.name());
            s.setPlacedNodePosition(NodePosition.valueOf(nodePosition));
            s.setZoom(toFloat(xmlSlide, ZOOM));
            Enumeration<XMLElement> childAttributes = xmlSlide.enumerateChildren();
            while (childAttributes.hasMoreElements()) {
                XMLElement xmlElement = childAttributes.nextElement();
                if (xmlElement.getName().equals(NODES_ON_SLIDE)) {
                    Set<String> ids = loadSpecificNodeIds(xmlElement);
                    s.setSelectedNodeIds(ids);
                } else if (xmlElement.getName().equals(FOLDED_NODES)) {
                    Set<String> ids = loadSpecificNodeIds(xmlElement);
                    s.setFoldedNodeIDs(ids);
                } else if (xmlElement.getName().equals(SLIDE_CONDITION)) {
                    ASelectableCondition condition = loadFilterCondition(xmlElement);
                    s.setFilterCondition(condition);
                }
            }
            return s;
        }

        private Set<String> loadSpecificNodeIds(XMLElement xmlNodeIds) {
            LinkedHashSet<String> nodeIds = new LinkedHashSet<>();
            Enumeration<XMLElement> nodesEnumeration = xmlNodeIds.enumerateChildren();
            while (nodesEnumeration.hasMoreElements()) {
                XMLElement nodeIdXml = nodesEnumeration.nextElement();
                if (nodeIdXml.getName().equals(NODE_ON_SLIDE)) {
                    String id = nodeIdXml.getAttribute(NODE_ID, null);
                    if (id != null)
                        nodeIds.add(id);
                }
            }
            return nodeIds;
        }

        private ASelectableCondition loadFilterCondition(XMLElement xmlElement) {
            return conditionFactory.loadCondition(xmlElement.getChildAtIndex(0));
        }

        private float toFloat(XMLElement element, String attribute) {
            return Float.parseFloat(element.getAttribute(attribute, "1f"));
        }

        private boolean toBoolean(XMLElement element, String attribute) {
            return Boolean.parseBoolean(element.getAttribute(attribute, ""));
        }

        private String toString(XMLElement element, String attribute) {
            return element.getAttribute(attribute, null);
        }
    });
    mapController.getWriteManager().addExtensionElementWriter(MapPresentations.class, new IExtensionElementWriter() {

        @Override
        public void writeContent(ITreeWriter writer, Object element, IExtension extension) throws IOException {
            new PresentationWriter(((NodeModel) element).getMap()).writeContent(writer, extension);
        }
    });
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Enumeration(java.util.Enumeration) LinkedHashSet(java.util.LinkedHashSet) Set(java.util.Set) IElementDOMHandler(org.freeplane.core.io.IElementDOMHandler) MapModel(org.freeplane.features.map.MapModel) IOException(java.io.IOException) XMLElement(org.freeplane.n3.nanoxml.XMLElement) ASelectableCondition(org.freeplane.features.filter.condition.ASelectableCondition) IExtensionElementWriter(org.freeplane.core.io.IExtensionElementWriter) NodeModel(org.freeplane.features.map.NodeModel) ConditionFactory(org.freeplane.features.filter.condition.ConditionFactory) IExtension(org.freeplane.core.extension.IExtension) ITreeWriter(org.freeplane.core.io.ITreeWriter)

Aggregations

ITreeWriter (org.freeplane.core.io.ITreeWriter)3 NodeModel (org.freeplane.features.map.NodeModel)3 IOException (java.io.IOException)2 IExtension (org.freeplane.core.extension.IExtension)2 IExtensionElementWriter (org.freeplane.core.io.IExtensionElementWriter)2 Enumeration (java.util.Enumeration)1 LinkedHashSet (java.util.LinkedHashSet)1 Set (java.util.Set)1 IAttributeHandler (org.freeplane.core.io.IAttributeHandler)1 IAttributeWriter (org.freeplane.core.io.IAttributeWriter)1 IElementDOMHandler (org.freeplane.core.io.IElementDOMHandler)1 ReadManager (org.freeplane.core.io.ReadManager)1 WriteManager (org.freeplane.core.io.WriteManager)1 TranslatedObject (org.freeplane.core.resources.TranslatedObject)1 ASelectableCondition (org.freeplane.features.filter.condition.ASelectableCondition)1 ConditionFactory (org.freeplane.features.filter.condition.ConditionFactory)1 MapController (org.freeplane.features.map.MapController)1 MapModel (org.freeplane.features.map.MapModel)1 ModeController (org.freeplane.features.mode.ModeController)1 XMLElement (org.freeplane.n3.nanoxml.XMLElement)1