本文整理汇总了Java中edu.mit.blocks.codeblocks.BlockLink.connect方法的典型用法代码示例。如果您正苦于以下问题:Java BlockLink.connect方法的具体用法?Java BlockLink.connect怎么用?Java BlockLink.connect使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类edu.mit.blocks.codeblocks.BlockLink
的用法示例。
在下文中一共展示了BlockLink.connect方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: actionPerformed
import edu.mit.blocks.codeblocks.BlockLink; //导入方法依赖的package包/类
public void actionPerformed(ActionEvent e) {
if (childBlock.getLocation().distance(focusPoint) < 75) {
//if parent block exist, then preform automatic linking
childBlock.setLocation(focusPoint);
if (parentBlock != null && parentBlock.getBlockID() != null && !parentBlock.getBlockID().equals(Block.NULL)) {
BlockLink link = LinkFinderUtil.connectBlocks(workspace, workspace.getEnv().getBlock(childBlock.getBlockID()), workspace.getEnv().getBlock(parentBlock.getBlockID()));
if (link == null) {
dropBlock(childBlock);
childBlock.repaintBlock();
childBlock.repaint();
} else {
// drop and link the new block
link.connect();
dropBlock(childBlock);
workspace.notifyListeners(new WorkspaceEvent(
workspace,
workspace.getEnv().getRenderableBlock(link.getPlugBlockID()).getParentWidget(),
link, WorkspaceEvent.BLOCKS_CONNECTED));
workspace.getEnv().getRenderableBlock(link.getSocketBlockID()).moveConnectedBlocks();
workspace.getEnv().getRenderableBlock(link.getSocketBlockID()).repaintBlock();
workspace.getEnv().getRenderableBlock(link.getSocketBlockID()).repaint();
}
} else {
dropBlock(childBlock);
childBlock.repaintBlock();
childBlock.repaint();
}
//stop the timer
timer.stop();
if (workspace.getEnv().getBlock(childBlock.getBlockID()).getGenusName().equals("number")) {
childBlock.switchToLabelEditingMode(false);
} else {
childBlock.switchToLabelEditingMode(true);
}
//TODO: check if focumanager's before parent is same as
//the parent we have here and check if new focusblock is child block
PageChangeEventManager.notifyListeners();
} else {
//childBlock.setLocation(focusPoint);
// TODO: This needs to change if the parent block doesn't have any more sockets for children
// Need to adjust focusPoint somehow.
childBlock.setLocation(
(int) (focusPoint.getX() * 0.67) + (int) (childBlock.getX() * 0.34),
(int) (focusPoint.getY() * 0.67) + (int) (childBlock.getY() * 0.34));
}
}
示例2: mouseReleased
import edu.mit.blocks.codeblocks.BlockLink; //导入方法依赖的package包/类
public void mouseReleased(MouseEvent e) {
if (SwingUtilities.isLeftMouseButton(e)) {
if (!pickedUp) {
throw new RuntimeException("dropping without prior dragging?");
}
dragHandler.mouseReleased(e);
// if the block was dragged before...then
if (dragging) {
BlockLink link = getNearbyLink(); // look for nearby link
// opportunities
WorkspaceWidget widget = null;
// if a suitable link wasn't found, just drop the block
if (link == null) {
widget = lastDragWidget;
stopDragging(this, widget);
} // otherwise, if a link WAS found...
else {
/*
* 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();
}