Search in sources :

Example 11 with MLinkController

use of org.freeplane.features.link.mindmapmode.MLinkController in project freeplane by freeplane.

the class ImportLinkedBranchAction method actionPerformed.

public void actionPerformed(final ActionEvent e) {
    final MapModel map = Controller.getCurrentController().getMap();
    final ModeController modeController = Controller.getCurrentModeController();
    final NodeModel selected = modeController.getMapController().getSelectedNode();
    final IMapViewManager viewController = Controller.getCurrentController().getMapViewManager();
    if (selected == null || NodeLinks.getLink(selected) == null) {
        JOptionPane.showMessageDialog((viewController.getMapViewComponent()), TextUtils.getText("import_linked_branch_no_link"));
        return;
    }
    final URI uri = NodeLinks.getLink(selected);
    try {
        final File file = uri.isAbsolute() && !uri.isOpaque() ? new File(uri) : new File(new URL(map.getURL(), uri.getPath()).getFile());
        final NodeModel node = ((MFileManager) UrlManager.getController()).loadTree(map, file);
        PersistentNodeHook.removeMapExtensions(node);
        ((MMapController) modeController.getMapController()).insertNode(node, selected);
        ((MLinkController) LinkController.getController()).setLink(selected, (URI) null, LinkController.LINK_ABSOLUTE);
        ((MLinkController) LinkController.getController()).setLink(node, (URI) null, LinkController.LINK_ABSOLUTE);
    } catch (final MalformedURLException ex) {
        UITools.errorMessage(TextUtils.format("invalid_url_msg", uri.toString()));
        LogUtils.warn(ex);
        return;
    } catch (final IllegalArgumentException ex) {
        UITools.errorMessage(TextUtils.format("invalid_file_msg", uri.toString()));
        LogUtils.warn(ex);
        return;
    } catch (final Exception ex) {
        UrlManager.getController().handleLoadingException(ex);
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) MMapController(org.freeplane.features.map.mindmapmode.MMapController) MapModel(org.freeplane.features.map.MapModel) ModeController(org.freeplane.features.mode.ModeController) URI(java.net.URI) URL(java.net.URL) MalformedURLException(java.net.MalformedURLException) IMapViewManager(org.freeplane.features.ui.IMapViewManager) NodeModel(org.freeplane.features.map.NodeModel) MLinkController(org.freeplane.features.link.mindmapmode.MLinkController) File(java.io.File)

Example 12 with MLinkController

use of org.freeplane.features.link.mindmapmode.MLinkController in project freeplane by freeplane.

the class ImportLinkedBranchWithoutRootAction method actionPerformed.

public void actionPerformed(final ActionEvent e) {
    final MapModel map = Controller.getCurrentController().getMap();
    final ModeController modeController = Controller.getCurrentModeController();
    final NodeModel selected = modeController.getMapController().getSelectedNode();
    if (selected == null || NodeLinks.getLink(selected) == null) {
        JOptionPane.showMessageDialog(Controller.getCurrentController().getMapViewManager().getMapViewComponent(), TextUtils.getText("import_linked_branch_no_link"));
        return;
    }
    try {
        final URI uri = NodeLinks.getLink(selected);
        final URL url = map.getURL();
        final File file = uri.isAbsolute() && !uri.isOpaque() ? new File(uri) : new File(new URL(url, uri.getPath()).getFile());
        final NodeModel node = ((MFileManager) UrlManager.getController()).loadTree(map, file);
        map.setURL(url);
        for (final NodeModel child : Controller.getCurrentModeController().getMapController().childrenUnfolded(node)) {
            child.setParent(null);
            ((MMapController) modeController.getMapController()).insertNode(child, selected);
        }
        ((MLinkController) LinkController.getController()).setLink(selected, (URI) null, LinkController.LINK_ABSOLUTE);
    } catch (final Exception ex) {
        UrlManager.getController().handleLoadingException(ex);
    }
}
Also used : NodeModel(org.freeplane.features.map.NodeModel) MLinkController(org.freeplane.features.link.mindmapmode.MLinkController) MMapController(org.freeplane.features.map.mindmapmode.MMapController) MapModel(org.freeplane.features.map.MapModel) ModeController(org.freeplane.features.mode.ModeController) URI(java.net.URI) File(java.io.File) URL(java.net.URL)

Example 13 with MLinkController

use of org.freeplane.features.link.mindmapmode.MLinkController in project freeplane by freeplane.

the class ExportBranchAction method actionPerformed.

public void actionPerformed(final ActionEvent e) {
    final NodeModel existingNode = Controller.getCurrentModeController().getMapController().getSelectedNode();
    final Controller controller = Controller.getCurrentController();
    final MapModel parentMap = controller.getMap();
    if (parentMap == null || existingNode == null || existingNode.isRoot()) {
        controller.getViewController().err("Could not export branch.");
        return;
    }
    if (parentMap.getFile() == null) {
        controller.getViewController().out("You must save the current map first!");
        ((MModeController) Controller.getCurrentModeController()).save();
    }
    JFileChooser chooser;
    final File file = parentMap.getFile();
    if (file == null) {
        return;
    }
    chooser = new JFileChooser(file.getParentFile());
    chooser.setSelectedFile(new File(createFileName(TextController.getController().getShortPlainText(existingNode))));
    if (((MFileManager) UrlManager.getController()).getFileFilter() != null) {
        chooser.addChoosableFileFilter(((MFileManager) UrlManager.getController()).getFileFilter());
    }
    final int returnVal = chooser.showSaveDialog(controller.getViewController().getCurrentRootComponent());
    if (returnVal == JFileChooser.APPROVE_OPTION) {
        File chosenFile = chooser.getSelectedFile();
        final String ext = FileUtils.getExtension(chosenFile.getName());
        if (!ext.equals(org.freeplane.features.url.UrlManager.FREEPLANE_FILE_EXTENSION_WITHOUT_DOT)) {
            chosenFile = new File(chosenFile.getParent(), chosenFile.getName() + org.freeplane.features.url.UrlManager.FREEPLANE_FILE_EXTENSION);
        }
        try {
            Compat.fileToUrl(chosenFile);
        } catch (final MalformedURLException ex) {
            UITools.errorMessage(TextUtils.getText("invalid_url"));
            return;
        }
        if (chosenFile.exists()) {
            final int overwriteMap = JOptionPane.showConfirmDialog(controller.getMapViewManager().getMapViewComponent(), TextUtils.getText("map_already_exists"), "Freeplane", JOptionPane.YES_NO_OPTION);
            if (overwriteMap != JOptionPane.YES_OPTION) {
                return;
            }
        }
        /*
			 * Now make a copy from the node, remove the node from the map and
			 * create a new Map with the node as root, store the new Map, add
			 * the copy of the node to the parent, and set a link from the copy
			 * to the new Map.
			 */
        final NodeModel parent = existingNode.getParentNode();
        final File oldFile = parentMap.getFile();
        final URI newUri = LinkController.toLinkTypeDependantURI(oldFile, chosenFile);
        final URI oldUri = LinkController.toLinkTypeDependantURI(chosenFile, file);
        ((MLinkController) LinkController.getController()).setLink(existingNode, oldUri, LinkController.LINK_ABSOLUTE);
        final int nodePosition = parent.getIndex(existingNode);
        final ModeController modeController = Controller.getCurrentModeController();
        modeController.undoableResolveParentExtensions(LogicalStyleKeys.NODE_STYLE, existingNode);
        final MMapController mMapController = (MMapController) modeController.getMapController();
        mMapController.deleteNode(existingNode);
        {
            final IActor actor = new IActor() {

                private final boolean wasFolded = existingNode.isFolded();

                public void undo() {
                    PersistentNodeHook.removeMapExtensions(existingNode);
                    existingNode.setMap(parentMap);
                    existingNode.setFolded(wasFolded);
                }

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

                public void act() {
                    existingNode.setFolded(false);
                }
            };
            Controller.getCurrentModeController().execute(actor, parentMap);
        }
        mMapController.newModel(existingNode);
        final MapModel newMap = existingNode.getMap();
        IExtension[] oldExtensions = newMap.getRootNode().getSharedExtensions().values().toArray(new IExtension[] {});
        for (final IExtension extension : oldExtensions) {
            final Class<? extends IExtension> clazz = extension.getClass();
            if (MapExtensions.isMapExtension(clazz)) {
                existingNode.removeExtension(clazz);
            }
        }
        final Collection<IExtension> newExtensions = parentMap.getRootNode().getSharedExtensions().values();
        for (final IExtension extension : newExtensions) {
            final Class<? extends IExtension> clazz = extension.getClass();
            if (MapExtensions.isMapExtension(clazz)) {
                existingNode.addExtension(extension);
            }
        }
        ((MFileManager) UrlManager.getController()).save(newMap, chosenFile);
        final NodeModel newNode = mMapController.addNewNode(parent, nodePosition, existingNode.isLeft());
        ((MTextController) TextController.getController()).setNodeText(newNode, existingNode.getText());
        modeController.undoableCopyExtensions(LogicalStyleKeys.NODE_STYLE, existingNode, newNode);
        newMap.getFile();
        ((MLinkController) LinkController.getController()).setLink(newNode, newUri, LinkController.LINK_ABSOLUTE);
        newMap.destroy();
        existingNode.setParent(null);
        mMapController.select(newNode);
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) MMapController(org.freeplane.features.map.mindmapmode.MMapController) MapModel(org.freeplane.features.map.MapModel) ModeController(org.freeplane.features.mode.ModeController) MModeController(org.freeplane.features.mode.mindmapmode.MModeController) MTextController(org.freeplane.features.text.mindmapmode.MTextController) MMapController(org.freeplane.features.map.mindmapmode.MMapController) LinkController(org.freeplane.features.link.LinkController) Controller(org.freeplane.features.mode.Controller) TextController(org.freeplane.features.text.TextController) ModeController(org.freeplane.features.mode.ModeController) MLinkController(org.freeplane.features.link.mindmapmode.MLinkController) MModeController(org.freeplane.features.mode.mindmapmode.MModeController) URI(java.net.URI) NodeModel(org.freeplane.features.map.NodeModel) MLinkController(org.freeplane.features.link.mindmapmode.MLinkController) JFileChooser(javax.swing.JFileChooser) IExtension(org.freeplane.core.extension.IExtension) IActor(org.freeplane.core.undo.IActor) MTextController(org.freeplane.features.text.mindmapmode.MTextController) File(java.io.File) MModeController(org.freeplane.features.mode.mindmapmode.MModeController)

Example 14 with MLinkController

use of org.freeplane.features.link.mindmapmode.MLinkController in project freeplane by freeplane.

the class MMapController method convertClonesToIndependentNodes.

public void convertClonesToIndependentNodes(final NodeModel node) {
    final MLinkController linkController = (MLinkController) MLinkController.getController();
    if (node.isCloneTreeRoot()) {
        linkController.deleteMapLinksForClone(node);
        convertCloneToNode(node);
        linkController.insertMapLinksForClone(node);
    }
}
Also used : MLinkController(org.freeplane.features.link.mindmapmode.MLinkController)

Example 15 with MLinkController

use of org.freeplane.features.link.mindmapmode.MLinkController in project freeplane by freeplane.

the class MMapMouseListener method mouseReleased.

public void mouseReleased(final MouseEvent e) {
    super.mouseReleased(e);
    if (draggedLink != null) {
        draggedLink.setShowControlPoints(false);
        final Point draggedLinkNewStartPoint = draggedLink.getStartInclination();
        final Point draggedLinkNewEndPoint = draggedLink.getEndInclination();
        draggedLink.setStartInclination(draggedLinkOldStartPoint);
        draggedLink.setEndInclination(draggedLinkOldEndPoint);
        ((MLinkController) LinkController.getController(Controller.getCurrentController().getModeController())).setArrowLinkEndPoints(draggedLink, draggedLinkNewStartPoint, draggedLinkNewEndPoint);
        final MapView mapView = (MapView) e.getComponent();
        mapView.repaintVisible();
        draggedLink = null;
    }
}
Also used : MLinkController(org.freeplane.features.link.mindmapmode.MLinkController) MapView(org.freeplane.view.swing.map.MapView) Point(java.awt.Point)

Aggregations

MLinkController (org.freeplane.features.link.mindmapmode.MLinkController)16 MMapController (org.freeplane.features.map.mindmapmode.MMapController)10 LinkController (org.freeplane.features.link.LinkController)8 NodeModel (org.freeplane.features.map.NodeModel)7 Controller (org.freeplane.features.mode.Controller)6 File (java.io.File)5 URI (java.net.URI)5 ModeController (org.freeplane.features.mode.ModeController)5 MTextController (org.freeplane.features.text.mindmapmode.MTextController)5 MIconController (org.freeplane.features.icon.mindmapmode.MIconController)4 MapModel (org.freeplane.features.map.MapModel)4 MModeController (org.freeplane.features.mode.mindmapmode.MModeController)4 ResourceController (org.freeplane.core.resources.ResourceController)3 AttributeController (org.freeplane.features.attribute.AttributeController)3 MAttributeController (org.freeplane.features.attribute.mindmapmode.MAttributeController)3 ClipboardController (org.freeplane.features.clipboard.ClipboardController)3 MClipboardController (org.freeplane.features.clipboard.mindmapmode.MClipboardController)3 CloudController (org.freeplane.features.cloud.CloudController)3 MCloudController (org.freeplane.features.cloud.mindmapmode.MCloudController)3 EdgeController (org.freeplane.features.edge.EdgeController)3