Search in sources :

Example 21 with NodeView

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

the class MapViewDockingWindows method focusMapViewLater.

public void focusMapViewLater(final MapView mapView) {
    Timer timer = new Timer(40, new ActionListener() {

        int retryCount = 5;

        public void actionPerformed(final ActionEvent event) {
            final Timer eventTimer = (Timer) event.getSource();
            focusMapLater(mapView, eventTimer);
        }

        private void focusMapLater(final MapView mapView, final Timer eventTimer) {
            if (mapView.isShowing() && Controller.getCurrentController().getMapViewManager().getMapViewComponent() == mapView) {
                final NodeView selected = mapView.getSelected();
                if (selected != null) {
                    final Frame frame = JOptionPane.getFrameForComponent(mapView);
                    if (frame.isFocused())
                        selected.requestFocusInWindow();
                    else
                        frame.addWindowFocusListener(new WindowAdapter() {

                            @Override
                            public void windowGainedFocus(WindowEvent e) {
                                frame.removeWindowFocusListener(this);
                                selected.requestFocusInWindow();
                                retryCount = 2;
                                eventTimer.start();
                            }
                        });
                }
            }
            if (retryCount > 1) {
                retryCount--;
                eventTimer.start();
            }
        }
    });
    timer.setRepeats(false);
    timer.start();
}
Also used : Frame(java.awt.Frame) Timer(javax.swing.Timer) ActionListener(java.awt.event.ActionListener) ActionEvent(java.awt.event.ActionEvent) WindowEvent(java.awt.event.WindowEvent) MapView(org.freeplane.view.swing.map.MapView) WindowAdapter(java.awt.event.WindowAdapter) DockingWindowAdapter(net.infonode.docking.DockingWindowAdapter) NodeView(org.freeplane.view.swing.map.NodeView)

Example 22 with NodeView

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

the class Node method selectAsTheOnlyOneSelected.

public void selectAsTheOnlyOneSelected() {
    final NodeView node = getNodeView();
    node.getMap().selectAsTheOnlyOneSelected(node);
}
Also used : NodeView(org.freeplane.view.swing.map.NodeView)

Example 23 with NodeView

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

the class OutlineEdgeView method getStroke.

@Override
protected Stroke getStroke() {
    final NodeView target = getTarget();
    int edgeWidth = target.getEdgeWidth();
    final EdgeStyle style = target.getEdgeStyle();
    final int nodeLineWidth = style.getNodeLineWidth(edgeWidth);
    final int zoomedWidth;
    if (edgeWidth != 0)
        zoomedWidth = getTarget().getZoomed(nodeLineWidth);
    else
        zoomedWidth = nodeLineWidth;
    return new BasicStroke(zoomedWidth);
}
Also used : BasicStroke(java.awt.BasicStroke) NodeView(org.freeplane.view.swing.map.NodeView) Point(java.awt.Point) EdgeStyle(org.freeplane.features.edge.EdgeStyle)

Example 24 with NodeView

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

the class MNodeDropListener method drop.

public void drop(final DropTargetDropEvent dtde) {
    try {
        int dropAction = dtde.getDropAction();
        final Transferable t = dtde.getTransferable();
        final MainView mainView = (MainView) dtde.getDropTargetContext().getComponent();
        final NodeView targetNodeView = mainView.getNodeView();
        final MapView mapView = targetNodeView.getMap();
        mapView.select();
        final NodeModel targetNode = targetNodeView.getModel();
        final Controller controller = Controller.getCurrentController();
        if (dtde.isLocalTransfer() && t.isDataFlavorSupported(MindMapNodesSelection.dropActionFlavor)) {
            final String sourceAction = (String) t.getTransferData(MindMapNodesSelection.dropActionFlavor);
            if (sourceAction.equals("LINK")) {
                dropAction = DnDConstants.ACTION_LINK;
            }
            if (sourceAction.equals("COPY")) {
                dropAction = DnDConstants.ACTION_COPY;
            }
        }
        mainView.setDraggedOver(NodeView.DRAGGED_OVER_NO);
        mainView.repaint();
        if (dtde.isLocalTransfer() && (dropAction == DnDConstants.ACTION_MOVE) && !isDropAcceptable(dtde)) {
            dtde.rejectDrop();
            return;
        }
        final boolean dropAsSibling = mainView.dropAsSibling(dtde.getLocation().getX());
        ModeController modeController = controller.getModeController();
        final MMapController mapController = (MMapController) modeController.getMapController();
        if ((dropAction == DnDConstants.ACTION_MOVE || dropAction == DnDConstants.ACTION_COPY)) {
            final NodeModel parent = dropAsSibling ? targetNode.getParentNode() : targetNode;
            if (!mapController.isWriteable(parent)) {
                dtde.rejectDrop();
                final String message = TextUtils.getText("node_is_write_protected");
                UITools.errorMessage(message);
                return;
            }
        }
        final boolean isLeft = mainView.dropLeft(dtde.getLocation().getX());
        if (!dtde.isLocalTransfer()) {
            dtde.acceptDrop(DnDConstants.ACTION_COPY);
            ((MClipboardController) ClipboardController.getController()).paste(t, targetNode, dropAsSibling, isLeft, dropAction);
            dtde.dropComplete(true);
            return;
        }
        dtde.acceptDrop(dropAction);
        if (dropAction == DnDConstants.ACTION_LINK) {
            int yesorno = JOptionPane.YES_OPTION;
            if (controller.getSelection().size() >= 5) {
                yesorno = JOptionPane.showConfirmDialog(controller.getViewController().getContentPane(), TextUtils.getText("lots_of_links_warning"), Integer.toString(controller.getSelection().size()) + " links to the same node", JOptionPane.YES_NO_OPTION);
            }
            if (yesorno == JOptionPane.YES_OPTION) {
                for (final Iterator<NodeModel> it = controller.getSelection().getSelection().iterator(); it.hasNext(); ) {
                    final NodeModel selectedNodeModel = (it.next());
                    ((MLinkController) LinkController.getController(modeController)).addConnector(selectedNodeModel, targetNode);
                }
            }
        } else {
            Transferable trans = null;
            final Collection<NodeModel> selecteds = mapController.getSelectedNodes();
            if (DnDConstants.ACTION_MOVE == dropAction) {
                NodeModel actualNode = targetNode;
                do {
                    if (selecteds.contains(actualNode)) {
                        final String message = TextUtils.getText("cannot_move_to_child");
                        JOptionPane.showMessageDialog(controller.getViewController().getContentPane(), message, "Freeplane", JOptionPane.WARNING_MESSAGE);
                        dtde.dropComplete(true);
                        return;
                    }
                    actualNode = (actualNode.isRoot()) ? null : actualNode.getParentNode();
                } while (actualNode != null);
                final NodeModel[] array = selecteds.toArray(new NodeModel[selecteds.size()]);
                final List<NodeModel> sortedSelection = controller.getSelection().getSortedSelection(true);
                for (final NodeModel node : sortedSelection) {
                    boolean changeSide = isLeft != node.isLeft();
                    if (dropAsSibling) {
                        mapController.moveNodeBefore(node, targetNode, isLeft, changeSide);
                    } else {
                        mapController.moveNodeAsChild(node, targetNode, isLeft, changeSide);
                    }
                }
                if (dropAsSibling || !targetNode.isFolded())
                    controller.getSelection().replaceSelection(array);
                else
                    controller.getSelection().selectAsTheOnlyOneSelected(targetNode);
            } else {
                trans = ClipboardController.getController().copy(controller.getSelection());
                ((MClipboardController) ClipboardController.getController()).paste(trans, targetNode, dropAsSibling, isLeft);
                controller.getSelection().selectAsTheOnlyOneSelected(targetNode);
            }
        }
    } catch (final Exception e) {
        LogUtils.severe("Drop exception:", e);
        dtde.dropComplete(false);
        return;
    }
    dtde.dropComplete(true);
}
Also used : MainView(org.freeplane.view.swing.map.MainView) MMapController(org.freeplane.features.map.mindmapmode.MMapController) Transferable(java.awt.datatransfer.Transferable) ModeController(org.freeplane.features.mode.ModeController) NodeView(org.freeplane.view.swing.map.NodeView) ClipboardController(org.freeplane.features.clipboard.ClipboardController) MMapController(org.freeplane.features.map.mindmapmode.MMapController) LinkController(org.freeplane.features.link.LinkController) Controller(org.freeplane.features.mode.Controller) ModeController(org.freeplane.features.mode.ModeController) MLinkController(org.freeplane.features.link.mindmapmode.MLinkController) MClipboardController(org.freeplane.features.clipboard.mindmapmode.MClipboardController) NodeModel(org.freeplane.features.map.NodeModel) MLinkController(org.freeplane.features.link.mindmapmode.MLinkController) MClipboardController(org.freeplane.features.clipboard.mindmapmode.MClipboardController) MapView(org.freeplane.view.swing.map.MapView)

Example 25 with NodeView

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

the class MNodeMotionListener method mouseReleased.

@Override
public void mouseReleased(final MouseEvent e) {
    final MainView v = (MainView) e.getSource();
    if (!v.contains(e.getX(), e.getY())) {
        v.setMouseArea(MouseArea.OUT);
    }
    if (!isDragActive()) {
        super.mouseReleased(e);
        return;
    }
    final NodeView nodeV = getNodeView(e);
    final NodeModel node = nodeV.getModel();
    final ModeController modeController = nodeV.getMap().getModeController();
    final NodeModel parentNode = nodeV.getModel().getParentNode();
    final int parentVGap = LocationModel.getModel(parentNode).getVGap();
    int hgap = LocationModel.getModel(node).getHGap();
    final int shiftY = LocationModel.getModel(node).getShiftY();
    adjustNodeIndices(nodeV);
    resetPositions(node);
    final Controller controller = modeController.getController();
    MLocationController locationController = (MLocationController) LocationController.getController(controller.getModeController());
    locationController.moveNodePosition(node, parentVGap, hgap, shiftY);
    stopDrag();
}
Also used : NodeModel(org.freeplane.features.map.NodeModel) MainView(org.freeplane.view.swing.map.MainView) MLocationController(org.freeplane.features.nodelocation.mindmapmode.MLocationController) 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) Point(java.awt.Point)

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