use of edu.mit.blocks.workspace.MiniMap in project openblocks by mikaelhg.
the class RenderableBlock method mouseReleased.
public void mouseReleased(MouseEvent e) {
if (SwingUtilities.isLeftMouseButton(e)) {
if (pickedUp) {
dragHandler.mouseReleased(e);
// if the block was dragged before...then
if (dragging) {
// look for nearby link opportunities
BlockLink link = getNearbyLink();
WorkspaceWidget widget = null;
// if a suitable link wasn't found, just drop the block
if (link == null) {
widget = lastDragWidget;
stopDragging(this, widget);
} else // otherwise, if a link WAS found...
{
/* Make sure that no matter who's connecting to whom, the block
* that's being dragged gets dropped on the parent widget of the
* block that's already on the canvas.
*/
if (blockID.equals(link.getSocketBlockID())) {
// dragged block is the socket block, so take plug's parent.
widget = workspace.getEnv().getRenderableBlock(link.getPlugBlockID()).getParentWidget();
} else {
// dragged block is the plug block, so take the socket block's parent.
widget = workspace.getEnv().getRenderableBlock(link.getSocketBlockID()).getParentWidget();
}
// drop the block and connect its link
stopDragging(this, widget);
link.connect();
workspace.notifyListeners(new WorkspaceEvent(workspace, widget, link, WorkspaceEvent.BLOCKS_CONNECTED));
workspace.getEnv().getRenderableBlock(link.getSocketBlockID()).moveConnectedBlocks();
}
// set the locations for X and Y based on zoom at 1.0
this.unzoomedX = this.calculateUnzoomedX(this.getX());
this.unzoomedY = this.calculateUnzoomedY(this.getY());
workspace.notifyListeners(new WorkspaceEvent(workspace, widget, link, WorkspaceEvent.BLOCK_MOVED, true));
if (widget instanceof MiniMap) {
workspace.getMiniMap().animateAutoCenter(this);
}
}
}
}
pickedUp = false;
if (e.isPopupTrigger() || SwingUtilities.isRightMouseButton(e) || e.isControlDown()) {
// add context menu at right click location to provide functionality
// for adding new comments and removing comments
PopupMenu popup = ContextMenu.getContextMenuFor(this);
add(popup);
popup.show(this, e.getX(), e.getY());
}
workspace.getMiniMap().repaint();
}
Aggregations