Search in sources :

Example 11 with NodeView

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

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

Example 13 with NodeView

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

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

the class EditNodeTextField method layout.

private void layout() {
    if (textfield == null) {
        return;
    }
    final int lastWidth = textfield.getWidth();
    final int lastHeight = textfield.getHeight();
    final boolean lineWrap = lastWidth == maxWidth;
    Dimension preferredSize = textfield.getPreferredSize();
    if (!lineWrap) {
        preferredSize.width++;
        if (preferredSize.width > maxWidth) {
            setLineWrap();
            preferredSize = textfield.getPreferredSize();
        } else {
            if (preferredSize.width < lastWidth) {
                preferredSize.width = lastWidth;
            } else {
                preferredSize.width = Math.min(preferredSize.width + extraWidth, maxWidth);
                if (preferredSize.width == maxWidth) {
                    setLineWrap();
                }
            }
        }
    } else {
        preferredSize.width = Math.max(maxWidth, preferredSize.width);
    }
    if (preferredSize.width != lastWidth) {
        preferredSize.height = lastHeight;
        SwingUtilities.invokeLater(new Runnable() {

            public void run() {
                layout();
            }
        });
    } else {
        preferredSize.height = Math.max(preferredSize.height, lastHeight);
    }
    if (preferredSize.width == lastWidth && preferredSize.height == lastHeight) {
        textfield.repaint();
        return;
    }
    textfield.setSize(preferredSize);
    if (layoutMapOnTextChange)
        parent.setPreferredSize(new Dimension(preferredSize.width + horizontalSpace, preferredSize.height + verticalSpace));
    textfield.revalidate();
    final NodeView nodeView = (NodeView) SwingUtilities.getAncestorOfClass(NodeView.class, parent);
    final MapView mapView = (MapView) SwingUtilities.getAncestorOfClass(MapView.class, nodeView);
    if (mapView == null)
        return;
    if (layoutMapOnTextChange)
        mapView.scrollNodeToVisible(nodeView);
    else
        mapView.scrollRectToVisible(textfield.getBounds());
}
Also used : MapView(org.freeplane.view.swing.map.MapView) Dimension(java.awt.Dimension) NodeView(org.freeplane.view.swing.map.NodeView) Point(java.awt.Point)

Example 15 with NodeView

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

the class DetailsViewMouseListener method mouseClicked.

@Override
public void mouseClicked(MouseEvent e) {
    final ModeController mc = Controller.getCurrentController().getModeController();
    if (Compat.isMacOsX()) {
        final JPopupMenu popupmenu = mc.getUserInputListenerFactory().getNodePopupMenu();
        if (popupmenu.isShowing()) {
            return;
        }
    }
    final NodeView nodeView = nodeSelector.getRelatedNodeView(e);
    if (nodeView == null)
        return;
    final NodeModel model = nodeView.getModel();
    TextController controller = TextController.getController();
    if (eventFromHideDisplayArea(e)) {
        final IMapSelection selection = Controller.getCurrentController().getSelection();
        selection.keepNodePosition(model, 0.0f, 0.0f);
        controller.setDetailsHidden(model, !DetailTextModel.getDetailText(model).isHidden());
    } else {
        nodeSelector.extendSelection(e);
        if (canEdit(controller) && isEditingStartEvent(e)) {
            ((MTextController) controller).editDetails(model, e, e.isAltDown());
        } else
            super.mouseClicked(e);
    }
}
Also used : NodeModel(org.freeplane.features.map.NodeModel) IMapSelection(org.freeplane.features.map.IMapSelection) TextController(org.freeplane.features.text.TextController) MTextController(org.freeplane.features.text.mindmapmode.MTextController) ModeController(org.freeplane.features.mode.ModeController) MTextController(org.freeplane.features.text.mindmapmode.MTextController) NodeView(org.freeplane.view.swing.map.NodeView) JPopupMenu(javax.swing.JPopupMenu)

Aggregations

NodeView (org.freeplane.view.swing.map.NodeView)43 NodeModel (org.freeplane.features.map.NodeModel)20 MapView (org.freeplane.view.swing.map.MapView)17 ModeController (org.freeplane.features.mode.ModeController)14 MainView (org.freeplane.view.swing.map.MainView)11 Point (java.awt.Point)8 INodeView (org.freeplane.features.map.INodeView)8 Controller (org.freeplane.features.mode.Controller)6 JPopupMenu (javax.swing.JPopupMenu)5 ResourceController (org.freeplane.core.resources.ResourceController)5 MapController (org.freeplane.features.map.MapController)5 MMapController (org.freeplane.features.map.mindmapmode.MMapController)5 Dimension (java.awt.Dimension)4 MTextController (org.freeplane.features.text.mindmapmode.MTextController)4 Color (java.awt.Color)3 Component (java.awt.Component)3 JComponent (javax.swing.JComponent)3 IMapSelection (org.freeplane.features.map.IMapSelection)3 LocationController (org.freeplane.features.nodelocation.LocationController)3 MLocationController (org.freeplane.features.nodelocation.mindmapmode.MLocationController)3