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);
}
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);
}
}
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();
}
}
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) {
}
}
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);
}
}
Aggregations