Search in sources :

Example 11 with MMapController

use of org.freeplane.features.map.mindmapmode.MMapController 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 12 with MMapController

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

the class NodeProxy method appendAsCloneImpl.

private Node appendAsCloneImpl(NodeModel toBeCloned, boolean withSubtree) {
    final NodeModel target = getDelegate();
    final MMapController mapController = (MMapController) Controller.getCurrentModeController().getMapController();
    if (toBeCloned.getParentNode() == null || toBeCloned.isRoot())
        throw new IllegalArgumentException("can't clone root node or node without parent");
    if (!toBeCloned.getMap().equals(getDelegate().getMap()))
        throw new IllegalArgumentException("can't clone a node from another map");
    if (toBeCloned.subtreeContainsCloneOf(target))
        throw new IllegalArgumentException("can't clone a node which has this node as child");
    final NodeModel clone = withSubtree ? toBeCloned.cloneTree() : toBeCloned.cloneContent();
    mapController.addNewNode(clone, target, target.getChildCount(), target.isNewChildLeft());
    return new NodeProxy(clone, getScriptContext());
}
Also used : NodeModel(org.freeplane.features.map.NodeModel) MMapController(org.freeplane.features.map.mindmapmode.MMapController)

Example 13 with MMapController

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

the class NewUserStyleAction method actionPerformed.

public void actionPerformed(final ActionEvent e) {
    final String styleName = JOptionPane.showInputDialog(TextUtils.getText("enter_new_style_name"));
    if (styleName == null) {
        return;
    }
    final Controller controller = Controller.getCurrentController();
    final NodeModel selectedNode = controller.getSelection().getSelected();
    final MapModel map = controller.getMap();
    final MapStyleModel styleModel = MapStyleModel.getExtension(map);
    final MapModel styleMap = styleModel.getStyleMap();
    final IStyle newStyle = StyleFactory.create(styleName);
    if (null != styleModel.getStyleNode(newStyle)) {
        UITools.errorMessage(TextUtils.getText("style_already_exists"));
        return;
    }
    final MMapController mapController = (MMapController) Controller.getCurrentModeController().getMapController();
    final NodeModel newNode = new NodeModel(styleMap);
    newNode.setUserObject(newStyle);
    final LogicalStyleController styleController = LogicalStyleController.getController();
    final ArrayList<IStyle> styles = new ArrayList<IStyle>(styleController.getStyles(selectedNode));
    for (int i = styles.size() - 1; i >= 0; i--) {
        IStyle style = styles.get(i);
        if (MapStyleModel.DEFAULT_STYLE.equals(style)) {
            continue;
        }
        final NodeModel styleNode = styleModel.getStyleNode(style);
        if (styleNode == null) {
            continue;
        }
        Controller.getCurrentModeController().copyExtensions(LogicalStyleKeys.NODE_STYLE, styleNode, newNode);
    }
    Controller.getCurrentModeController().copyExtensions(LogicalStyleKeys.NODE_STYLE, selectedNode, newNode);
    Controller.getCurrentModeController().copyExtensions(Keys.ICONS, selectedNode, newNode);
    NodeModel userStyleParentNode = styleModel.getStyleNodeGroup(styleMap, MapStyleModel.STYLES_USER_DEFINED);
    if (userStyleParentNode == null) {
        userStyleParentNode = new NodeModel(styleMap);
        userStyleParentNode.setUserObject(new StyleTranslatedObject(MapStyleModel.STYLES_USER_DEFINED));
        mapController.insertNode(userStyleParentNode, styleMap.getRootNode(), false, false, true);
    }
    mapController.insertNode(newNode, userStyleParentNode, false, false, true);
    mapController.select(newNode);
    final IActor actor = new IActor() {

        public void undo() {
            styleModel.removeStyleNode(newNode);
            styleController.refreshMap(map);
        }

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

        public void act() {
            styleModel.addStyleNode(newNode);
            styleController.refreshMap(map);
        }
    };
    Controller.getCurrentModeController().execute(actor, styleMap);
}
Also used : MapStyleModel(org.freeplane.features.styles.MapStyleModel) MMapController(org.freeplane.features.map.mindmapmode.MMapController) LogicalStyleController(org.freeplane.features.styles.LogicalStyleController) ArrayList(java.util.ArrayList) MapModel(org.freeplane.features.map.MapModel) Controller(org.freeplane.features.mode.Controller) LogicalStyleController(org.freeplane.features.styles.LogicalStyleController) MMapController(org.freeplane.features.map.mindmapmode.MMapController) IStyle(org.freeplane.features.styles.IStyle) StyleTranslatedObject(org.freeplane.features.styles.StyleTranslatedObject) NodeModel(org.freeplane.features.map.NodeModel) IActor(org.freeplane.core.undo.IActor)

Example 14 with MMapController

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

the class MTextController method splitNode.

public void splitNode(final NodeModel node, final int caretPosition, final String newText) {
    if (node.isRoot()) {
        return;
    }
    final String oldText = node.getText();
    final String futureText = newText != null ? newText : oldText;
    final String[] strings = getContent(futureText, caretPosition);
    if (strings == null) {
        final String mayBePlainText = makePlainIfNoFormattingFound(futureText);
        if (!Objects.equals(mayBePlainText, oldText))
            setNodeObject(node, mayBePlainText);
        return;
    }
    final String newUpperContent = makePlainIfNoFormattingFound(strings[0]);
    final String newLowerContent = makePlainIfNoFormattingFound(strings[1]);
    setNodeObject(node, newUpperContent);
    final NodeModel parent = node.getParentNode();
    final ModeController modeController = Controller.getCurrentModeController();
    final NodeModel lowerNode = ((MMapController) modeController.getMapController()).addNewNode(parent, parent.getIndex(node) + 1, node.isLeft());
    final MNodeStyleController nodeStyleController = (MNodeStyleController) NodeStyleController.getController();
    nodeStyleController.copyStyle(node, lowerNode);
    setNodeObject(lowerNode, newLowerContent);
}
Also used : NodeModel(org.freeplane.features.map.NodeModel) MNodeStyleController(org.freeplane.features.nodestyle.mindmapmode.MNodeStyleController) MMapController(org.freeplane.features.map.mindmapmode.MMapController) ModeController(org.freeplane.features.mode.ModeController) MModeController(org.freeplane.features.mode.mindmapmode.MModeController)

Example 15 with MMapController

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

the class MTextController method joinNodes.

public void joinNodes(final List<NodeModel> selectedNodes, final String separator) {
    if (selectedNodes.isEmpty())
        return;
    final NodeModel selectedNode = selectedNodes.get(0);
    for (final NodeModel node : selectedNodes) {
        if (node != selectedNode && node.subtreeContainsCloneOf(selectedNode)) {
            UITools.errorMessage(TextUtils.getText("cannot_move_into_child_node"));
            return;
        }
    }
    String joinedContent = "";
    final Controller controller = Controller.getCurrentController();
    boolean isHtml = false;
    final LinkedHashSet<MindIcon> icons = new LinkedHashSet<MindIcon>();
    for (final NodeModel node : selectedNodes) {
        final String nodeContent = node.getText();
        icons.addAll(node.getIcons());
        final boolean isHtmlNode = HtmlUtils.isHtmlNode(nodeContent);
        joinedContent = addContent(joinedContent, isHtml, nodeContent, isHtmlNode, separator);
        if (node != selectedNode) {
            final MMapController mapController = (MMapController) Controller.getCurrentModeController().getMapController();
            mapController.moveNodes(node.getChildren(), selectedNode, selectedNode.getChildCount());
            mapController.deleteNode(node);
        }
        isHtml = isHtml || isHtmlNode;
    }
    controller.getSelection().selectAsTheOnlyOneSelected(selectedNode);
    setNodeText(selectedNode, joinedContent);
    final MIconController iconController = (MIconController) IconController.getController();
    iconController.removeAllIcons(selectedNode);
    for (final MindIcon icon : icons) {
        iconController.addIcon(selectedNode, icon);
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) NodeModel(org.freeplane.features.map.NodeModel) MIconController(org.freeplane.features.icon.mindmapmode.MIconController) MMapController(org.freeplane.features.map.mindmapmode.MMapController) MindIcon(org.freeplane.features.icon.MindIcon) MMapController(org.freeplane.features.map.mindmapmode.MMapController) MapController(org.freeplane.features.map.MapController) MIconController(org.freeplane.features.icon.mindmapmode.MIconController) IconController(org.freeplane.features.icon.IconController) Controller(org.freeplane.features.mode.Controller) TextController(org.freeplane.features.text.TextController) MLinkController(org.freeplane.features.link.mindmapmode.MLinkController) NodeStyleController(org.freeplane.features.nodestyle.NodeStyleController) FormatController(org.freeplane.features.format.FormatController) LogicalStyleController(org.freeplane.features.styles.LogicalStyleController) ResourceController(org.freeplane.core.resources.ResourceController) ViewController(org.freeplane.features.ui.ViewController) LinkController(org.freeplane.features.link.LinkController) ModeController(org.freeplane.features.mode.ModeController) MNodeStyleController(org.freeplane.features.nodestyle.mindmapmode.MNodeStyleController) MModeController(org.freeplane.features.mode.mindmapmode.MModeController) ScannerController(org.freeplane.features.format.ScannerController)

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