Search in sources :

Example 36 with MapView

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

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

the class MNodeMotionListener method mousePressed.

@Override
public void mousePressed(MouseEvent e) {
    final MapView mapView = MapView.getMapView(e.getComponent());
    mapView.select();
    doubleClickTimer.cancel();
    setClickDelay();
    if (isInDragRegion(e)) {
        if ((e.getModifiersEx() & InputEvent.BUTTON1_DOWN_MASK) == (InputEvent.BUTTON1_DOWN_MASK)) {
            nodeSelector.stopTimerForDelayedSelection();
            final NodeView nodeV = getNodeView(e);
            final Point point = e.getPoint();
            findGridPoint(point);
            UITools.convertPointToAncestor(nodeV, point, JScrollPane.class);
            setDragStartingPoint(point, nodeV.getModel());
        }
    } else
        super.mousePressed(e);
}
Also used : MapView(org.freeplane.view.swing.map.MapView) Point(java.awt.Point) NodeView(org.freeplane.view.swing.map.NodeView)

Example 38 with MapView

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

the class MNodeMotionListener method getVGapChange.

/**
 */
private int getVGapChange(final Point dragNextPoint, final NodeModel node) {
    final Controller controller = Controller.getCurrentController();
    final MapView mapView = ((MapView) controller.getMapViewManager().getMapViewComponent());
    final int vGapChange = (int) ((dragNextPoint.y - dragStartingPoint.y) / mapView.getZoom());
    return vGapChange;
}
Also used : MapView(org.freeplane.view.swing.map.MapView) 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)

Example 39 with MapView

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

the class MNodeMotionListener method getHGapChange.

/**
 */
private int getHGapChange(final Point dragNextPoint, final NodeModel node) {
    final Controller controller = Controller.getCurrentController();
    final MapView mapView = ((MapView) controller.getMapViewManager().getMapViewComponent());
    int hGapChange = (int) ((dragNextPoint.x - dragStartingPoint.x) / mapView.getZoom());
    if (node.isLeft()) {
        hGapChange = -hGapChange;
    }
    return hGapChange;
}
Also used : MapView(org.freeplane.view.swing.map.MapView) 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)

Example 40 with MapView

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

the class MMapViewController method createEditor.

public EditNodeBase createEditor(final NodeModel node, final EditNodeBase.IEditControl editControl, String text, final boolean editLong) {
    final String htmlEditingOption = ResourceController.getResourceController().getProperty("html_editing_option");
    final boolean editInternalWysiwyg = editLong && StringUtils.equals(htmlEditingOption, "internal-wysiwyg");
    final boolean editExternal = editLong && StringUtils.equals(htmlEditingOption, "external");
    if (!HtmlUtils.isHtmlNode(text)) {
        text = HtmlUtils.plainToHTML(text);
    }
    if (editInternalWysiwyg) {
        final EditNodeWYSIWYG editNodeWYSIWYG = new EditNodeWYSIWYG(node, text, editControl, true);
        final ViewController viewController = Controller.getCurrentModeController().getController().getViewController();
        if (EditedComponent.TEXT.equals(editControl.getEditType())) {
            int preferredHeight = (int) (getComponent(node).getHeight() * 1.2);
            preferredHeight = Math.max(preferredHeight, Integer.parseInt(ResourceController.getResourceController().getProperty("el__min_default_window_height")));
            preferredHeight = Math.min(preferredHeight, Integer.parseInt(ResourceController.getResourceController().getProperty("el__max_default_window_height")));
            int preferredWidth = (int) (getComponent(node).getWidth() * 1.2);
            preferredWidth = Math.max(preferredWidth, Integer.parseInt(ResourceController.getResourceController().getProperty("el__min_default_window_width")));
            preferredWidth = Math.min(preferredWidth, Integer.parseInt(ResourceController.getResourceController().getProperty("el__max_default_window_width")));
            final Dimension preferredSize = new Dimension(preferredWidth, preferredHeight);
            editNodeWYSIWYG.setPreferredSize(preferredSize);
        }
        final MainView mainView = (MainView) getComponent(node);
        final NodeView nodeView = mainView.getNodeView();
        if (EditedComponent.TEXT.equals(editControl.getEditType())) {
            final Font font = getFont(node);
            editNodeWYSIWYG.setTitle("edit_long_node");
            editNodeWYSIWYG.setFont(font);
            final Color nodeTextColor = getTextColor(node);
            editNodeWYSIWYG.setTextColor(nodeTextColor);
            editNodeWYSIWYG.setBackground(nodeView.getTextBackground());
        } else if (EditedComponent.DETAIL.equals(editControl.getEditType())) {
            final MapView map = nodeView.getMap();
            editNodeWYSIWYG.setTitle("edit_details");
            editNodeWYSIWYG.setFont(map.getDetailFont());
            editNodeWYSIWYG.setTextColor(map.getDetailForeground());
            editNodeWYSIWYG.setBackground(nodeView.getDetailBackground());
        } else if (EditedComponent.NOTE.equals(editControl.getEditType())) {
            final MapView map = nodeView.getMap();
            editNodeWYSIWYG.setTitle("edit_note");
            editNodeWYSIWYG.setFont(map.getDefaultNoteFont());
            editNodeWYSIWYG.setBackground(Color.WHITE);
        }
        return editNodeWYSIWYG;
    } else if (editExternal) {
        return new EditNodeExternalApplication(node, text, editControl);
    } else {
        final EditNodeBase textfield = createEditor(node, editControl.getEditType(), text, editControl);
        if (textfield != null)
            return textfield;
    }
    return createEditor(node, editControl, text, true);
}
Also used : MainView(org.freeplane.view.swing.map.MainView) EditNodeBase(org.freeplane.features.text.mindmapmode.EditNodeBase) Color(java.awt.Color) Dimension(java.awt.Dimension) EditNodeWYSIWYG(org.freeplane.features.text.mindmapmode.EditNodeWYSIWYG) NodeView(org.freeplane.view.swing.map.NodeView) Font(java.awt.Font) MapViewController(org.freeplane.view.swing.map.MapViewController) ViewController(org.freeplane.features.ui.ViewController) MapView(org.freeplane.view.swing.map.MapView)

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