当前位置: 首页>>代码示例>>Java>>正文


Java BlockLink.disconnect方法代码示例

本文整理汇总了Java中edu.mit.blocks.codeblocks.BlockLink.disconnect方法的典型用法代码示例。如果您正苦于以下问题:Java BlockLink.disconnect方法的具体用法?Java BlockLink.disconnect怎么用?Java BlockLink.disconnect使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在edu.mit.blocks.codeblocks.BlockLink的用法示例。


在下文中一共展示了BlockLink.disconnect方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: changeType

import edu.mit.blocks.codeblocks.BlockLink; //导入方法依赖的package包/类
/**
 * Changes the output block types in the given list, disconnecting
 * blocks if necessary.
 */
private static void changeType(OutputInfo info, 
                               WorkspaceWidget w, List<WorkspaceEvent> e) 
{
    String type = info.type;
    for (Long id : info.outputs) {
        Block b = workspace.getEnv().getBlock(id);
        
        // If there is nothing connected to it, we just change the socket
        // type.
        BlockConnector socket = b.getSocketAt(0);
        Block b2 = getBlock(socket.getBlockID());
        if (b2 == null && !socket.getKind().equals(type)) {
            socket.setKind(type);
            b.notifyRenderable();
        }
        
        // Otherwise, we might have to disconnect what's already there.
        else if (!socket.getKind().endsWith(type)) {
            BlockLink link = BlockLink.getBlockLink(workspace, b, b2, socket, b2.getPlug());
            link.disconnect();
            workspace.getEnv().getRenderableBlock(id).blockDisconnected(socket);
            e.add(new WorkspaceEvent(workspace, w, link, WorkspaceEvent.BLOCKS_DISCONNECTED));
        }
    }
}
 
开发者ID:heqichen,项目名称:openblocks,代码行数:30,代码来源:ProcedureOutputManager.java

示例2: disconnectBlock

import edu.mit.blocks.codeblocks.BlockLink; //导入方法依赖的package包/类
/**
 * @param childBlock
 * @param widget
 *
 * @requires widget != null
 * @modifies
 * @effects Does nothing if: childBlock is invalid (null)
 * 			Otherwise, remove childBlock from it's parent block
 * 			if the childBlock has a parent.  If it does not have
 * 			a parent, do nothing.
 */
private void disconnectBlock(Block childBlock, WorkspaceWidget widget) {
    if (childBlock == null || invalidBlockID(childBlock.getBlockID())) {
        return;
    }
    BlockConnector childPlug = BlockLinkChecker.getPlugEquivalent(childBlock);
    if (childPlug == null || !childPlug.hasBlock() || isNullBlockInstance(childPlug.getBlockID())) {
        return;
    }
    Block parentBlock = workspace.getEnv().getBlock(childPlug.getBlockID());
    BlockConnector parentSocket = parentBlock.getConnectorTo(childBlock.getBlockID());
    if (parentSocket == null) {
        return;
    }
    //disconector if child connector exists and has a block connected to it
    BlockLink link = BlockLink.getBlockLink(workspace, childBlock, parentBlock, childPlug, parentSocket);
    if (link == null) {
        return;
    }

    link.disconnect();

    RenderableBlock parentRenderable = workspace.getEnv().getRenderableBlock(parentBlock.getBlockID());
    if (parentRenderable == null) {
        throw new RuntimeException("INCONSISTANCY VIOLATION: "
                + "parent block was valid, non-null, and existed.\n\tBut yet, when we get it's renderable"
                + "representation, we recieve a null instance.\n\tIf the Block instance of an ID is non-null"
                + "then its graphical RenderableBlock should be non-null as well");
    }
    parentRenderable.blockDisconnected(parentSocket);
    workspace.notifyListeners(new WorkspaceEvent(workspace, widget, link, WorkspaceEvent.BLOCKS_DISCONNECTED));
}
 
开发者ID:heqichen,项目名称:openblocks,代码行数:43,代码来源:TypeBlockManager.java

示例3: mouseDragged

import edu.mit.blocks.codeblocks.BlockLink; //导入方法依赖的package包/类
public void mouseDragged(MouseEvent e) {
	if (SwingUtilities.isLeftMouseButton(e)) {
		if (!pickedUp) {
			throw new RuntimeException("dragging without prior pickup?");
		}

		Point pp = SwingUtilities.convertPoint(this, e.getPoint(),
				workspace.getMiniMap());
		if (workspace.getMiniMap().contains(pp)) {
			workspace.getMiniMap().blockDragged(this, e.getPoint());
			lastDragWidget = workspace.getMiniMap();
			return;
		}

		// drag this block if appropriate (checks bounds first)
		dragHandler.mouseDragged(e);

		// Find the widget under the mouse
		dragHandler.myLoc.move(getX() + dragHandler.mPressedX, getY()
				+ dragHandler.mPressedY);
		Point p = SwingUtilities.convertPoint(this.getParent(),
				dragHandler.myLoc, workspace);
		WorkspaceWidget widget = workspace.getWidgetAt(p);
		if (widget == null) {
			// not on a workspace widget, cancel dragging
			return;
		}

		// if this is the first call to mouseDragged
		if (!dragging) {
			Block block = getBlock();
			BlockConnector plug = BlockLinkChecker.getPlugEquivalent(block);
			if (plug != null && plug.hasBlock()) {
				Block parent = workspace.getEnv().getBlock(
						plug.getBlockID());
				BlockConnector socket = parent.getConnectorTo(blockID);
				BlockLink link = BlockLink.getBlockLink(workspace, block,
						parent, plug, socket);
				link.disconnect();
				// socket is removed internally from block's socket list if
				// socket is expandable
				workspace.getEnv().getRenderableBlock(parent.getBlockID())
						.blockDisconnected(socket);

				// NOTIFY WORKSPACE LISTENERS OF DISCONNECTION
				workspace.notifyListeners(new WorkspaceEvent(workspace,
						widget, link, WorkspaceEvent.BLOCKS_DISCONNECTED));
			}
			startDragging(this, widget);
		}

		// drag this block and all attached to it
		drag(this, dragHandler.dragDX, dragHandler.dragDY, widget, true);

		workspace.getMiniMap().repaint();
	}
}
 
开发者ID:heqichen,项目名称:openblocks,代码行数:58,代码来源:RenderableBlock.java


注:本文中的edu.mit.blocks.codeblocks.BlockLink.disconnect方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。