Search in sources :

Example 6 with IExtension

use of org.freeplane.core.extension.IExtension in project freeplane by freeplane.

the class PersistentNodeHook method toggle.

protected IExtension toggle(final NodeModel node, IExtension extension) {
    final IExtension before;
    final IExtension after;
    if (extension != null && node.containsExtension(extension.getClass())) {
        before = extension;
        after = null;
        remove(node, extension);
    } else {
        if (extension == null) {
            extension = createExtension(node);
        }
        if (extension != null) {
            add(node, extension);
        }
        before = null;
        after = extension;
    }
    Controller.getCurrentModeController().getMapController().nodeChanged(node, getExtensionClass(), before, after);
    return extension;
}
Also used : IExtension(org.freeplane.core.extension.IExtension)

Example 7 with IExtension

use of org.freeplane.core.extension.IExtension in project freeplane by freeplane.

the class MMapMouseListener method mouseClicked.

@Override
public void mouseClicked(MouseEvent e) {
    if (e.getClickCount() == 2 && Compat.isCtrlEvent(e)) {
        final MapView mapView = (MapView) e.getComponent();
        final Object object = mapView.detectCollision(new Point(originX, originY));
        if (object != null)
            return;
        final ModeController modeController = Controller.getCurrentModeController();
        final IExtension freeNode = modeController.getExtension(FreeNode.class);
        if (freeNode != null && modeController instanceof MModeController) {
            final JComponent rootContent = mapView.getRoot().getMainView();
            final Point contentPt = new Point();
            UITools.convertPointToAncestor(rootContent, contentPt, mapView);
            final float zoom = mapView.getZoom();
            final Point eventPoint = e.getPoint();
            int x = (int) ((eventPoint.x - contentPt.x) / zoom);
            final int y = (int) ((eventPoint.y - contentPt.y) / zoom);
            final int rootContentNormalWidth = (int) (rootContent.getWidth() / zoom);
            final boolean newNodeIsLeft = x < rootContentNormalWidth / 2;
            if (newNodeIsLeft) {
                x = rootContentNormalWidth - x;
            }
            final Point pt = new Point(x, y);
            ((MMapController) modeController.getMapController()).addFreeNode(pt, newNodeIsLeft);
        }
    } else
        super.mouseClicked(e);
}
Also used : IExtension(org.freeplane.core.extension.IExtension) MMapController(org.freeplane.features.map.mindmapmode.MMapController) JComponent(javax.swing.JComponent) MapView(org.freeplane.view.swing.map.MapView) Point(java.awt.Point) ModeController(org.freeplane.features.mode.ModeController) MModeController(org.freeplane.features.mode.mindmapmode.MModeController) Point(java.awt.Point) MModeController(org.freeplane.features.mode.mindmapmode.MModeController)

Example 8 with IExtension

use of org.freeplane.core.extension.IExtension in project freeplane by freeplane.

the class MapStyle method copyStyle.

public void copyStyle(final URL source, final MapModel targetMap, boolean undoable) {
    final MapModel styleMapContainer = new MapModel();
    final IExtension oldStyleModel = targetMap.getRootNode().removeExtension(MapStyleModel.class);
    UrlManager.getController().loadCatchExceptions(source, styleMapContainer);
    onCreate(styleMapContainer);
    moveStyle(styleMapContainer, targetMap, true);
    LogicalStyleController.getController().refreshMap(targetMap);
    if (!undoable) {
        return;
    }
    final IExtension newStyleModel = targetMap.getRootNode().getExtension(MapStyleModel.class);
    IActor actor = new IActor() {

        public void undo() {
            targetMap.getRootNode().putExtension(oldStyleModel);
        }

        public String getDescription() {
            return "moveStyle";
        }

        public void act() {
            targetMap.getRootNode().putExtension(newStyleModel);
        }
    };
    Controller.getCurrentModeController().execute(actor, targetMap);
}
Also used : IExtension(org.freeplane.core.extension.IExtension) IActor(org.freeplane.core.undo.IActor) MapModel(org.freeplane.features.map.MapModel)

Example 9 with IExtension

use of org.freeplane.core.extension.IExtension in project freeplane by freeplane.

the class PersistentNodeHook method moveExtension.

public void moveExtension(ModeController modeController, MapModel sourceMap, MapModel targetMap) {
    final NodeModel sourceNode = sourceMap.getRootNode();
    final Class<? extends IExtension> extensionClass = getExtensionClass();
    final IExtension sourceExtension = sourceNode.getExtension(extensionClass);
    final NodeModel targetNode = targetMap.getRootNode();
    final IExtension targetExtension = targetNode.getExtension(extensionClass);
    if (sourceExtension == targetExtension)
        return;
    IActor actor = new IActor() {

        @Override
        public void act() {
            if (targetExtension != null)
                targetNode.removeExtension(targetExtension);
            if (sourceExtension != null)
                targetNode.addExtension(sourceExtension);
        }

        @Override
        public void undo() {
            if (sourceExtension != null)
                targetNode.removeExtension(sourceExtension);
            if (targetExtension != null)
                targetNode.addExtension(targetExtension);
        }

        @Override
        public String getDescription() {
            return "move extension " + extensionClass.getName();
        }
    };
    modeController.execute(actor, targetMap);
}
Also used : NodeModel(org.freeplane.features.map.NodeModel) IExtension(org.freeplane.core.extension.IExtension) IActor(org.freeplane.core.undo.IActor)

Example 10 with IExtension

use of org.freeplane.core.extension.IExtension 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

IExtension (org.freeplane.core.extension.IExtension)18 NodeModel (org.freeplane.features.map.NodeModel)7 ModeController (org.freeplane.features.mode.ModeController)4 Point (java.awt.Point)3 IOException (java.io.IOException)3 IExtensionElementWriter (org.freeplane.core.io.IExtensionElementWriter)3 IActor (org.freeplane.core.undo.IActor)3 MapModel (org.freeplane.features.map.MapModel)3 Color (java.awt.Color)2 ITreeWriter (org.freeplane.core.io.ITreeWriter)2 AutomaticLayout (org.freeplane.features.styles.AutomaticLayout)2 AutomaticLayoutController (org.freeplane.features.styles.AutomaticLayoutController)2 LogicalStyleController (org.freeplane.features.styles.LogicalStyleController)2 File (java.io.File)1 Method (java.lang.reflect.Method)1 MalformedURLException (java.net.MalformedURLException)1 URI (java.net.URI)1 Enumeration (java.util.Enumeration)1 Iterator (java.util.Iterator)1 LinkedHashSet (java.util.LinkedHashSet)1