Search in sources :

Example 21 with MMapController

use of org.freeplane.features.map.mindmapmode.MMapController in project freeplane by freeplane.

the class MClipboardController method paste.

void paste(final Transferable t, final IDataFlavorHandler handler, final NodeModel target, final boolean asSibling, final boolean isLeft, int dropAction) {
    if (handler == null) {
        return;
    }
    final MMapController mapController = (MMapController) Controller.getCurrentModeController().getMapController();
    if (asSibling && !mapController.isWriteable(target.getParentNode()) || !asSibling && !mapController.isWriteable(target)) {
        final String message = TextUtils.getText("node_is_write_protected");
        UITools.errorMessage(message);
        return;
    }
    try {
        Controller.getCurrentController().getViewController().setWaitingCursor(true);
        if (newNodes == null) {
            newNodes = new LinkedList<NodeModel>();
        }
        newNodes.clear();
        handler.paste(t, target, asSibling, isLeft, dropAction);
        final ModeController modeController = Controller.getCurrentModeController();
        if (!asSibling && modeController.getMapController().isFolded(target) && ResourceController.getResourceController().getBooleanProperty(RESOURCE_UNFOLD_ON_PASTE)) {
            modeController.getMapController().unfoldAndScroll(target);
        }
        for (final NodeModel child : newNodes) {
            AttributeController.getController().performRegistrySubtreeAttributes(child);
        }
    } finally {
        Controller.getCurrentController().getViewController().setWaitingCursor(false);
    }
}
Also used : NodeModel(org.freeplane.features.map.NodeModel) MMapController(org.freeplane.features.map.mindmapmode.MMapController) ModeController(org.freeplane.features.mode.ModeController)

Example 22 with MMapController

use of org.freeplane.features.map.mindmapmode.MMapController in project freeplane by freeplane.

the class MClipboardController method processTransferable.

@SuppressWarnings("unchecked")
private void processTransferable(final Transferable transferable, final NodeModel target, Operation operation) {
    try {
        final Collection<NodeModel> clonedNodes;
        final boolean asSingleNodes;
        if (operation == Operation.CLONE && transferable.isDataFlavorSupported(MindMapNodesSelection.mindMapNodeSingleObjectsFlavor)) {
            clonedNodes = (Collection<NodeModel>) transferable.getTransferData(MindMapNodesSelection.mindMapNodeSingleObjectsFlavor);
            asSingleNodes = true;
        } else if (transferable.isDataFlavorSupported(MindMapNodesSelection.mindMapNodeObjectsFlavor)) {
            clonedNodes = (Collection<NodeModel>) transferable.getTransferData(MindMapNodesSelection.mindMapNodeObjectsFlavor);
            asSingleNodes = false;
        } else
            return;
        final List<NodeModel> movedNodes = new ArrayList<NodeModel>(clonedNodes.size());
        final MMapController mapController = (MMapController) Controller.getCurrentModeController().getMapController();
        for (NodeModel clonedNode : clonedNodes) {
            if (clonedNode.getParentNode() == null || !clonedNode.getMap().equals(target.getMap()))
                return;
            if (!clonedNode.isRoot() && !clonedNode.subtreeContainsCloneOf(target)) {
                switch(operation) {
                    case CLONE:
                        try {
                            final NodeModel clone = asSingleNodes ? clonedNode.cloneContent() : clonedNode.cloneTree();
                            mapController.addNewNode(clone, target, target.getChildCount(), target.isNewChildLeft());
                        } catch (CloneEncryptedNodeException e) {
                            UITools.errorMessage(TextUtils.getText("can_not_clone_encrypted_node"));
                        }
                        break;
                    case MOVE:
                        movedNodes.add(clonedNode);
                        break;
                }
            }
        }
        switch(operation) {
            case MOVE:
                mapController.moveNodesAsChildren(movedNodes, target, target.isNewChildLeft(), true);
                break;
            default:
                break;
        }
    } catch (Exception e) {
        LogUtils.severe(e);
    }
}
Also used : NodeModel(org.freeplane.features.map.NodeModel) CloneEncryptedNodeException(org.freeplane.features.map.CloneEncryptedNodeException) MMapController(org.freeplane.features.map.mindmapmode.MMapController) ArrayList(java.util.ArrayList) Collection(java.util.Collection) XMLException(org.freeplane.n3.nanoxml.XMLException) UnsupportedFlavorException(java.awt.datatransfer.UnsupportedFlavorException) BadLocationException(javax.swing.text.BadLocationException) CloneEncryptedNodeException(org.freeplane.features.map.CloneEncryptedNodeException) IOException(java.io.IOException)

Example 23 with MMapController

use of org.freeplane.features.map.mindmapmode.MMapController in project freeplane by freeplane.

the class NodeProxy method sortChildrenBy.

@Override
public void sortChildrenBy(Closure<Comparable<Object>> closure) {
    getScriptContext().accessNode(getDelegate());
    NodeModel node = getDelegate();
    final ArrayList<NodeModel> children = new ArrayList<NodeModel>(node.getChildren());
    Collections.sort(children, comparatorByClosureResult(closure));
    final MMapController mapController = (MMapController) Controller.getCurrentModeController().getMapController();
    int i = 0;
    for (final NodeModel child : children) {
        ((FreeNode) Controller.getCurrentModeController().getExtension(FreeNode.class)).undoableDeactivateHook(child);
        mapController.moveNode(child, i++);
    }
}
Also used : NodeModel(org.freeplane.features.map.NodeModel) MMapController(org.freeplane.features.map.mindmapmode.MMapController) ArrayList(java.util.ArrayList) FreeNode(org.freeplane.features.map.FreeNode)

Example 24 with MMapController

use of org.freeplane.features.map.mindmapmode.MMapController in project freeplane by freeplane.

the class ImportBranchAction method actionPerformed.

public void actionPerformed(final ActionEvent e) {
    final NodeModel parent = Controller.getCurrentModeController().getMapController().getSelectedNode();
    if (parent == null) {
        return;
    }
    final JFileChooser chooser = new JFileChooser();
    final FileFilter fileFilter = ((MFileManager) UrlManager.getController()).getFileFilter();
    if (fileFilter != null) {
        chooser.addChoosableFileFilter(fileFilter);
    }
    final int returnVal = chooser.showOpenDialog(Controller.getCurrentController().getViewController().getCurrentRootComponent());
    if (returnVal == JFileChooser.APPROVE_OPTION) {
        try {
            final MapModel map = parent.getMap();
            final URL url = map.getURL();
            final NodeModel node = ((MFileManager) UrlManager.getController()).loadTree(map, chooser.getSelectedFile());
            map.setURL(url);
            PersistentNodeHook.removeMapExtensions(node);
            ((MMapController) Controller.getCurrentModeController().getMapController()).insertNode(node, parent);
        } catch (final Exception ex) {
            UrlManager.getController().handleLoadingException(ex);
        }
    }
}
Also used : NodeModel(org.freeplane.features.map.NodeModel) JFileChooser(javax.swing.JFileChooser) MMapController(org.freeplane.features.map.mindmapmode.MMapController) MapModel(org.freeplane.features.map.MapModel) FileFilter(javax.swing.filechooser.FileFilter) URL(java.net.URL)

Example 25 with MMapController

use of org.freeplane.features.map.mindmapmode.MMapController in project freeplane by freeplane.

the class ImportExplorerFavoritesAction method importExplorerFavorites.

public boolean importExplorerFavorites(final File folder, final NodeModel target, final boolean redisplay) {
    boolean favoritesFound = false;
    final File[] list = folder.listFiles();
    if (list != null) {
        for (int i = 0; i < list.length; i++) {
            if (list[i].isDirectory()) {
                final String nodeContent = list[i].getName();
                final NodeModel node = addNode(target, nodeContent);
                final boolean favoritesFoundInSubfolder = importExplorerFavorites(list[i], node, false);
                if (favoritesFoundInSubfolder) {
                    favoritesFound = true;
                } else {
                    ((MMapController) Controller.getCurrentModeController().getMapController()).deleteNode(node);
                }
            }
        }
        for (int i = 0; i < list.length; i++) {
            if (!list[i].isDirectory() && FileUtils.getExtension(list[i]).equals("url")) {
                favoritesFound = true;
                BufferedReader in = null;
                try {
                    final NodeModel node = addNode(target, FileUtils.removeExtension(list[i].getName()));
                    in = new BufferedReader(new FileReader(list[i]));
                    String line = null;
                    while ((line = in.readLine()) != null) {
                        if (line.startsWith("URL=")) {
                            final String link = line.substring(4);
                            ((MLinkController) LinkController.getController()).setLink(node, LinkController.createURI(link), LinkController.LINK_ABSOLUTE);
                            break;
                        }
                    }
                } catch (final Exception e) {
                    LogUtils.severe(e);
                } finally {
                    try {
                        if (in != null) {
                            in.close();
                        }
                    } catch (final IOException e) {
                        LogUtils.warn(e);
                    }
                }
            }
        }
    }
    if (redisplay) {
        Controller.getCurrentModeController().getMapController().nodeChanged(target);
    }
    return favoritesFound;
}
Also used : NodeModel(org.freeplane.features.map.NodeModel) MLinkController(org.freeplane.features.link.mindmapmode.MLinkController) MMapController(org.freeplane.features.map.mindmapmode.MMapController) BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader) IOException(java.io.IOException) File(java.io.File) IOException(java.io.IOException)

Aggregations

MMapController (org.freeplane.features.map.mindmapmode.MMapController)38 NodeModel (org.freeplane.features.map.NodeModel)26 ModeController (org.freeplane.features.mode.ModeController)16 Controller (org.freeplane.features.mode.Controller)13 MLinkController (org.freeplane.features.link.mindmapmode.MLinkController)11 LinkController (org.freeplane.features.link.LinkController)9 MapModel (org.freeplane.features.map.MapModel)9 MModeController (org.freeplane.features.mode.mindmapmode.MModeController)9 File (java.io.File)7 MNodeStyleController (org.freeplane.features.nodestyle.mindmapmode.MNodeStyleController)7 TextController (org.freeplane.features.text.TextController)7 ResourceController (org.freeplane.core.resources.ResourceController)6 MapController (org.freeplane.features.map.MapController)6 LogicalStyleController (org.freeplane.features.styles.LogicalStyleController)6 MTextController (org.freeplane.features.text.mindmapmode.MTextController)6 IOException (java.io.IOException)5 MalformedURLException (java.net.MalformedURLException)5 URL (java.net.URL)5 IActor (org.freeplane.core.undo.IActor)5 IconController (org.freeplane.features.icon.IconController)4