use of edu.mit.blocks.codeblocks.BlockConnector in project openblocks by mikaelhg.
the class MiniMap method blockDropped.
/**
* @param block
* @modifies block
* @effects Set block to whatever page it is on is one exist.
* Otherwise, set it to whatever Widget is currently underneath
* it.
*/
public void blockDropped(RenderableBlock block) {
// TODO - djwendel - this needs to choose the widget of the top block of the stack, not the widget under the block necessarily
Point location = block.getLocation();
if (location.getY() <= 0) {
location.setLocation(location.getX(), 1);
}
// find page that it should drop on. w could be null. so watch out.
WorkspaceWidget w = workspace.getWidgetAt(location);
for (Page page : this.blockCanvas.getPages()) {
if (page.contains(SwingUtilities.convertPoint(block.getParent(), location, page.getJComponent()))) {
w = page;
}
}
/* before dropping, check if any connected blocks were dropped elsewhere.
if they were, drop there instead. (this relies on the fact that stacks
of blocks are dropped bottom-first, so the place to check is at the
socket blocks. If stacks were dropped top-first, this would check the
blocks up the stack rather than down the stack. TODO - this doesn't
always work, because there can be multiple "branches" that might get
dropped on different places. Need to find a way to drop according the
widget of the top block of the stack...*/
RenderableBlock socketBlock;
for (BlockConnector con : (workspace.getEnv().getBlock(block.getBlockID()).getSockets())) {
socketBlock = block.getWorkspace().getEnv().getRenderableBlock(con.getBlockID());
if (socketBlock != null) {
w = socketBlock.getParentWidget();
}
}
w.blockDropped(block);
this.repaint();
}
Aggregations