Search in sources :

Example 6 with MapView

use of org.freeplane.view.swing.map.MapView 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 7 with MapView

use of org.freeplane.view.swing.map.MapView in project freeplane by freeplane.

the class MMapMouseListener method mouseDragged.

public void mouseDragged(final MouseEvent e) {
    final MapView mapView = (MapView) e.getComponent();
    if (draggedLink != null && mapView.getLayoutType().equals(MapViewLayout.MAP)) {
        final int deltaX = (int) ((e.getX() - originX) / mapView.getZoom());
        final int deltaY = (int) ((e.getY() - originY) / mapView.getZoom());
        double distSqToTarget = 0;
        double distSqToSource = 0;
        final NodeModel target = draggedLink.getTarget();
        final NodeView targetView = mapView.getNodeView(target);
        final NodeView sourceView = mapView.getNodeView(draggedLink.getSource());
        if (targetView != null && sourceView != null) {
            final Point targetLinkPoint = targetView.getLinkPoint(draggedLink.getEndInclination());
            final Point sourceLinkPoint = sourceView.getLinkPoint(draggedLink.getStartInclination());
            distSqToTarget = targetLinkPoint.distanceSq(originX, originY);
            distSqToSource = sourceLinkPoint.distanceSq(originX, originY);
        }
        if ((targetView == null || sourceView != null) && distSqToSource <= distSqToTarget * 2.25) {
            final Point changedInclination = draggedLink.getStartInclination();
            draggedLink.changeInclination(deltaX, deltaY, draggedLink.getSource(), changedInclination);
            draggedLink.setStartInclination(changedInclination);
        }
        if ((sourceView == null || targetView != null) && distSqToTarget <= distSqToSource * 2.25) {
            final Point changedInclination = draggedLink.getEndInclination();
            draggedLink.changeInclination(deltaX, deltaY, target, changedInclination);
            draggedLink.setEndInclination(changedInclination);
        }
        originX = e.getX();
        originY = e.getY();
        mapView.repaintVisible();
    } else {
        super.mouseDragged(e);
    }
}
Also used : NodeModel(org.freeplane.features.map.NodeModel) MapView(org.freeplane.view.swing.map.MapView) Point(java.awt.Point) NodeView(org.freeplane.view.swing.map.NodeView) Point(java.awt.Point)

Example 8 with MapView

use of org.freeplane.view.swing.map.MapView in project freeplane by freeplane.

the class MMapMouseListener method mousePressed.

public void mousePressed(final MouseEvent e) {
    super.mousePressed(e);
    if (e.isPopupTrigger())
        return;
    final MapView mapView = (MapView) e.getComponent();
    final Object object = mapView.detectCollision(new Point(originX, originY));
    if (object instanceof ConnectorModel) {
        final ConnectorModel arrowLinkModel = (ConnectorModel) object;
        final Shape shape = arrowLinkModel.getShape();
        if (Shape.EDGE_LIKE.equals(shape) || Shape.LINE.equals(shape) && !arrowLinkModel.isSelfLink()) {
            return;
        }
        draggedLink = arrowLinkModel;
        draggedLinkOldStartPoint = draggedLink.getStartInclination();
        draggedLinkOldEndPoint = draggedLink.getEndInclination();
        draggedLink.setShowControlPoints(true);
        mapView.repaintVisible();
    }
}
Also used : Shape(org.freeplane.features.link.ConnectorModel.Shape) ConnectorModel(org.freeplane.features.link.ConnectorModel) MapView(org.freeplane.view.swing.map.MapView) Point(java.awt.Point)

Example 9 with MapView

use of org.freeplane.view.swing.map.MapView in project freeplane by freeplane.

the class MNodeDragListener method dragGestureRecognized.

public void dragGestureRecognized(final DragGestureEvent e) {
    final MainView mainView = (MainView) e.getComponent();
    final NodeView nodeView = mainView.getNodeView();
    final MapView mapView = nodeView.getMap();
    mapView.select();
    if (!nodeView.isSelected()) {
        nodeView.getMap().getModeController().getController().getSelection().selectAsTheOnlyOneSelected(nodeView.getModel());
    }
    Rectangle bounds = new Rectangle(0, 0, mainView.getWidth(), mainView.getHeight());
    if (!bounds.contains(e.getDragOrigin()))
        return;
    final int dragActionType = e.getDragAction();
    if (dragActionType == DnDConstants.ACTION_MOVE) {
        final NodeModel node = nodeView.getModel();
        if (node.isRoot()) {
            if (!isLinkDragEvent(e))
                return;
        }
    }
    final String dragActionName;
    Cursor cursor = getCursorByAction(dragActionType);
    if (isLinkDragEvent(e)) {
        cursor = DragSource.DefaultLinkDrop;
        dragActionName = "LINK";
    } else if ((e.getTriggerEvent().getModifiersEx() & InputEvent.BUTTON2_DOWN_MASK) != 0) {
        cursor = DragSource.DefaultCopyDrop;
        dragActionName = "COPY";
    } else {
        dragActionName = "MOVE";
    }
    final Transferable t = ClipboardController.getController().copy(Controller.getCurrentController().getSelection());
    ((MindMapNodesSelection) t).setDropAction(dragActionName);
    try {
        e.startDrag(cursor, t, new DragSourceListener() {

            public void dragDropEnd(final DragSourceDropEvent dsde) {
            }

            public void dragEnter(final DragSourceDragEvent e) {
            }

            public void dragExit(final DragSourceEvent dse) {
            }

            public void dragOver(final DragSourceDragEvent dsde) {
            }

            public void dropActionChanged(final DragSourceDragEvent dsde) {
                dsde.getDragSourceContext().setCursor(getCursorByAction(dsde.getUserAction()));
            }
        });
    } catch (final InvalidDnDOperationException ex) {
    }
}
Also used : InvalidDnDOperationException(java.awt.dnd.InvalidDnDOperationException) MainView(org.freeplane.view.swing.map.MainView) DragSourceDragEvent(java.awt.dnd.DragSourceDragEvent) Rectangle(java.awt.Rectangle) Transferable(java.awt.datatransfer.Transferable) NodeView(org.freeplane.view.swing.map.NodeView) Cursor(java.awt.Cursor) DragSourceListener(java.awt.dnd.DragSourceListener) DragSourceEvent(java.awt.dnd.DragSourceEvent) NodeModel(org.freeplane.features.map.NodeModel) MapView(org.freeplane.view.swing.map.MapView) DragSourceDropEvent(java.awt.dnd.DragSourceDropEvent) MindMapNodesSelection(org.freeplane.features.clipboard.MindMapNodesSelection)

Example 10 with MapView

use of org.freeplane.view.swing.map.MapView in project freeplane by freeplane.

the class MNodeMotionListener method adjustNodeIndices.

private void adjustNodeIndices(final NodeView nodeV) {
    NodeModel[] selectedsBackup = null;
    final NodeModel node = nodeV.getModel();
    if (FreeNode.isFreeNode(node)) {
        selectedsBackup = adjustNodeIndexBackupSelection(nodeV, selectedsBackup);
    } else {
        final MapView map = nodeV.getMap();
        final NodeModel[] siblingNodes = node.getParentNode().getChildren().toArray(new NodeModel[] {});
        for (NodeModel sibling : siblingNodes) {
            if (FreeNode.isFreeNode(sibling)) {
                final NodeView siblingV = map.getNodeView(sibling);
                selectedsBackup = adjustNodeIndexBackupSelection(siblingV, selectedsBackup);
            }
        }
    }
    if (selectedsBackup != null) {
        final ModeController modeController = nodeV.getMap().getModeController();
        final Controller controller = modeController.getController();
        controller.getSelection().replaceSelection(selectedsBackup);
    }
}
Also used : NodeModel(org.freeplane.features.map.NodeModel) MapView(org.freeplane.view.swing.map.MapView) ModeController(org.freeplane.features.mode.ModeController) NodeView(org.freeplane.view.swing.map.NodeView) MTextController(org.freeplane.features.text.mindmapmode.MTextController) ResourceController(org.freeplane.core.resources.ResourceController) MMapController(org.freeplane.features.map.mindmapmode.MMapController) MapController(org.freeplane.features.map.MapController) LocationController(org.freeplane.features.nodelocation.LocationController) Controller(org.freeplane.features.mode.Controller) ModeController(org.freeplane.features.mode.ModeController) MLocationController(org.freeplane.features.nodelocation.mindmapmode.MLocationController)

Aggregations

MapView (org.freeplane.view.swing.map.MapView)55 NodeView (org.freeplane.view.swing.map.NodeView)20 ModeController (org.freeplane.features.mode.ModeController)19 Point (java.awt.Point)15 NodeModel (org.freeplane.features.map.NodeModel)13 Controller (org.freeplane.features.mode.Controller)11 Component (java.awt.Component)9 MainView (org.freeplane.view.swing.map.MainView)9 Dimension (java.awt.Dimension)8 JComponent (javax.swing.JComponent)8 MMapController (org.freeplane.features.map.mindmapmode.MMapController)7 ResourceController (org.freeplane.core.resources.ResourceController)6 MapController (org.freeplane.features.map.MapController)6 MTextController (org.freeplane.features.text.mindmapmode.MTextController)5 IMapViewManager (org.freeplane.features.ui.IMapViewManager)5 Color (java.awt.Color)4 Rectangle (java.awt.Rectangle)4 LocationController (org.freeplane.features.nodelocation.LocationController)4 MLocationController (org.freeplane.features.nodelocation.mindmapmode.MLocationController)4 NodeStyleController (org.freeplane.features.nodestyle.NodeStyleController)4