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