Search in sources :

Example 6 with MainView

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

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

the class MNodeMotionListener method mouseDragged.

@Override
public void mouseDragged(final MouseEvent e) {
    if (!isDragActive())
        return;
    if ((e.getModifiersEx() & InputEvent.BUTTON1_DOWN_MASK) == (InputEvent.BUTTON1_DOWN_MASK)) {
        final MainView mainView = (MainView) e.getSource();
        final NodeView nodeV = getNodeView(e);
        final MapView mapView = nodeV.getMap();
        final Point point = e.getPoint();
        findGridPoint(point);
        UITools.convertPointToAncestor(nodeV, point, JScrollPane.class);
        ModeController c = Controller.getCurrentController().getModeController();
        final Point dragNextPoint = point;
        if (!Compat.isCtrlEvent(e)) {
            final NodeModel node = nodeV.getModel();
            final LocationModel locationModel = LocationModel.createLocationModel(node);
            final int hGapChange = getHGapChange(dragNextPoint, node);
            if (hGapChange != 0) {
                locationModel.setHGap(originalHGap + hGapChange);
            }
            final int shiftYChange = getNodeShiftYChange(dragNextPoint, node);
            if (shiftYChange != 0) {
                locationModel.setShiftY(originalShiftY + shiftYChange);
            }
            if (hGapChange != 0 || shiftYChange != 0)
                c.getMapController().nodeRefresh(node);
            else
                return;
        } else {
            final NodeModel parentNode = nodeV.getVisibleParentView().getModel();
            final int vGapChange = getVGapChange(dragNextPoint, parentNode);
            if (vGapChange != 0) {
                LocationModel.createLocationModel(parentNode).setVGap(Math.max(0, originalParentVGap - vGapChange));
                final MapController mapController = c.getMapController();
                mapController.nodeRefresh(parentNode);
                mapController.nodeRefresh(nodeV.getModel());
            } else
                return;
        }
        EventQueue.invokeLater(new Runnable() {

            public void run() {
                final Rectangle r = mainView.getBounds();
                UITools.convertRectangleToAncestor(mainView.getParent(), r, mapView);
                final boolean isEventPointVisible = mapView.getVisibleRect().contains(r);
                if (!isEventPointVisible) {
                    mapView.scrollRectToVisible(r);
                }
            }
        });
    }
}
Also used : NodeModel(org.freeplane.features.map.NodeModel) MainView(org.freeplane.view.swing.map.MainView) Rectangle(java.awt.Rectangle) MapView(org.freeplane.view.swing.map.MapView) Point(java.awt.Point) ModeController(org.freeplane.features.mode.ModeController) NodeView(org.freeplane.view.swing.map.NodeView) LocationModel(org.freeplane.features.nodelocation.LocationModel) Point(java.awt.Point) MMapController(org.freeplane.features.map.mindmapmode.MMapController) MapController(org.freeplane.features.map.MapController)

Example 8 with MainView

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

the class MNodeMotionListener method mouseMoved.

@Override
public void mouseMoved(final MouseEvent e) {
    if (isDragActive())
        return;
    final MainView v = (MainView) e.getSource();
    if (v.isInDragRegion(e.getPoint())) {
        v.setMouseArea(MouseArea.MOTION);
        v.setCursor(Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR));
        return;
    }
    super.mouseMoved(e);
}
Also used : MainView(org.freeplane.view.swing.map.MainView)

Example 9 with MainView

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

the class SharpEdgeView method createStart.

@Override
protected void createStart() {
    super.createStart();
    final int delta = getMap().getZoomed(getWidth() + 1);
    if (getSource().isRoot()) {
        final MainView mainView = getSource().getMainView();
        final double w = mainView.getWidth() / 2;
        final double x0 = start.x - w;
        final double w2 = w * w;
        final double x02 = x0 * x0;
        if (Double.compare(w2, x02) == 0) {
            deltaX = 0;
            deltaY = delta;
        } else {
            final int h = mainView.getHeight() / 2;
            final int y0 = start.y - h;
            final double k = h / w * x0 / Math.sqrt(w2 - x02);
            final double dx = delta / Math.sqrt(1 + k * k);
            deltaX = (int) dx;
            deltaY = (int) (k * dx);
            if (y0 > 0) {
                deltaY = -deltaY;
            }
        }
    } else {
        deltaX = 0;
        deltaY = delta;
    }
}
Also used : MainView(org.freeplane.view.swing.map.MainView)

Example 10 with MainView

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

the class OutlineLinkView method createStart.

@Override
protected void createStart() {
    final MainView startMainView = getSource().getMainView();
    start = new Point(startMainView.getWidth(), startMainView.getHeight() / 2);
    final MainView targetMainView = getTarget().getMainView();
    end = new Point(targetMainView.getWidth(), targetMainView.getHeight() / 2);
}
Also used : MainView(org.freeplane.view.swing.map.MainView) Point(java.awt.Point)

Aggregations

MainView (org.freeplane.view.swing.map.MainView)26 NodeView (org.freeplane.view.swing.map.NodeView)11 NodeModel (org.freeplane.features.map.NodeModel)10 ModeController (org.freeplane.features.mode.ModeController)9 MapView (org.freeplane.view.swing.map.MapView)9 Point (java.awt.Point)7 MapController (org.freeplane.features.map.MapController)6 Controller (org.freeplane.features.mode.Controller)5 Component (java.awt.Component)4 ResourceController (org.freeplane.core.resources.ResourceController)4 MMapController (org.freeplane.features.map.mindmapmode.MMapController)4 Dimension (java.awt.Dimension)3 Rectangle (java.awt.Rectangle)3 MTextController (org.freeplane.features.text.mindmapmode.MTextController)3 Color (java.awt.Color)2 Cursor (java.awt.Cursor)2 Transferable (java.awt.datatransfer.Transferable)2 JPopupMenu (javax.swing.JPopupMenu)2 LinkController (org.freeplane.features.link.LinkController)2 LocationController (org.freeplane.features.nodelocation.LocationController)2