*/
public void mouseReleased(MouseEvent e)
{
if (graphComponent.isEnabled() && isEnabled() && !e.isConsumed())
{
mxGraph graph = graphComponent.getGraph();
double dx = 0;
double dy = 0;
if (first != null && (cellBounds != null || movePreview.isActive()))
{
double scale = graph.getView().getScale();
mxPoint trans = graph.getView().getTranslate();
// TODO: Simplify math below, this was copy pasted from
// getPreviewLocation with the rounding removed
dx = e.getX() - first.x;
dy = e.getY() - first.y;
if (cellBounds != null)
{
double dxg = ((cellBounds.getX() + dx) / scale)
- trans.getX();
double dyg = ((cellBounds.getY() + dy) / scale)
- trans.getY();
if (gridEnabledEvent)
{
dxg = graph.snap(dxg);
dyg = graph.snap(dyg);
}
double x = ((dxg + trans.getX()) * scale) + (bbox.getX())
- (cellBounds.getX());
double y = ((dyg + trans.getY()) * scale) + (bbox.getY())
- (cellBounds.getY());
dx = Math.round((x - bbox.getX()) / scale);
dy = Math.round((y - bbox.getY()) / scale);
}
}
if (first == null
|| !graphComponent.isSignificant(e.getX() - first.x,
e.getY() - first.y))
{
// Delayed handling of selection
if (cell != null && !e.isPopupTrigger() && isSelectEnabled()
&& (first != null || !isMoveEnabled()))
{
graphComponent.selectCellForEvent(cell, e);
}
// Delayed folding for cell that was initially under the mouse
if (graphComponent.isFoldingEnabled()
&& graphComponent.hitFoldingIcon(initialCell, e.getX(),
e.getY()))
{
fold(initialCell);
}
else
{
// Handles selection if no cell was initially under the mouse
Object tmp = graphComponent.getCellAt(e.getX(), e.getY(),
graphComponent.isSwimlaneSelectionEnabled());
if (cell == null && first == null)
{
if (tmp == null)
{
if (!graphComponent.isToggleEvent(e))
{
graph.clearSelection();
}
}
else if (graph.isSwimlane(tmp)
&& graphComponent.getCanvas()
.hitSwimlaneContent(graphComponent,
graph.getView().getState(tmp),
e.getX(), e.getY()))
{
graphComponent.selectCellForEvent(tmp, e);
}
}
if (graphComponent.isFoldingEnabled()
&& graphComponent.hitFoldingIcon(tmp, e.getX(),
e.getY()))
{
fold(tmp);
e.consume();
}
}
}
else if (movePreview.isActive())
{
if (graphComponent.isConstrainedEvent(e))
{
if (Math.abs(dx) > Math.abs(dy))
{
dy = 0;
}
else
{
dx = 0;
}
}
mxCellState markedState = marker.getMarkedState();
Object target = (markedState != null) ? markedState.getCell()
: null;
// FIXME: Cell is null if selection was carried out, need other variable
//trace("cell", cell);
if (target == null
&& isRemoveCellsFromParent()
&& shouldRemoveCellFromParent(graph.getModel()
.getParent(initialCell), cells, e))
{
target = graph.getDefaultParent();
}
boolean clone = isCloneEnabled()
&& graphComponent.isCloneEvent(e);
Object[] result = movePreview.stop(true, e, dx, dy, clone,
target);
if (cells != result)
{
graph.setSelectionCells(result);
}
e.consume();
}
else if (isVisible())
{
if (constrainedEvent)
{
if (Math.abs(dx) > Math.abs(dy))
{
dy = 0;
}
else
{
dx = 0;
}
}
mxCellState targetState = marker.getValidState();
Object target = (targetState != null) ? targetState.getCell()
: null;
if (graph.isSplitEnabled()
&& graph.isSplitTarget(target, cells))
{
graph.splitEdge(target, cells, dx, dy);
}
else
{
moveCells(cells, dx, dy, target, e);
}