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


Java BlockLinkChecker.getPlugEquivalent方法代码示例

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


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

示例1: disconnectBlock

import edu.mit.blocks.codeblocks.BlockLinkChecker; //导入方法依赖的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

示例2: synchronizeLabelsAndSockets

import edu.mit.blocks.codeblocks.BlockLinkChecker; //导入方法依赖的package包/类
/**
 * Updates all the labels within this block. Returns true if this update
 * found any changed labels; false otherwise
 * 
 * @return true if this update found any changed labels; false otherwise.
 */
private boolean synchronizeLabelsAndSockets() {
	boolean blockLabelChanged = getBlock().getBlockLabel() != null
			&& !blockLabel.getText().equals(getBlock().getBlockLabel());
	boolean pageLabelChanged = getBlock().getPageLabel() != null
			&& !pageLabel.getText().equals(getBlock().getPageLabel());
	boolean socketLabelsChanged = false;

	// If tag label isn't the same as socket label, synchronize.
	// If the block doesn't have an editable socket label, synchronize.
	//
	// Needed to not synchronize the socket if it is label editable so it
	// doesn't synchronize when
	// it gains focus.
	//
	// May possibly be done better if synchronizeSockets is rewritten. It
	// has to be written such that
	// it doesn't remove the sockets' JComponents/remake them. Currently
	// relies on the synchronizeSockets()
	// call in getSocketPixelPoint(BlockConnector) to make sure the
	// dimensions and number of sockets
	// are consistent.
	for (int i = 0; i < getBlock().getNumSockets(); i++) {
		BlockConnector socket = getBlock().getSocketAt(i);
		ConnectorTag tag = this.getConnectorTag(socket);
		if (tag != null) {
			if (tag.getLabel() != null) {
				if (!tag.getLabel().getText().equals(socket.getLabel())) {
					socketLabelsChanged = synchronizeSockets();
					break;
				}
			}
		}
		if (!socket.isLabelEditable()) {
			socketLabelsChanged = synchronizeSockets();
			break;
		}
	}
	if (blockLabelChanged) {
		blockLabel.setText(getBlock().getBlockLabel());
	}
	if (pageLabelChanged) {
		pageLabel.setText(getBlock().getPageLabel());
	}
	if (blockLabelChanged || pageLabelChanged || socketLabelsChanged
			|| commentLabelChanged) {
		reformBlockShape();
		commentLabelChanged = false;
	}
	if (BlockLinkChecker.hasPlugEquivalent(getBlock())) {
		BlockConnector plug = BlockLinkChecker
				.getPlugEquivalent(getBlock());
		Block plugBlock = workspace.getEnv().getBlock(plug.getBlockID());
		if (plugBlock != null) {
			if (plugBlock.getConnectorTo(blockID) == null) {
				throw new RuntimeException("one-sided connection from "
						+ getBlock().getBlockLabel()
						+ " to "
						+ workspace.getEnv().getBlock(blockID)
								.getBlockLabel());
			}
			workspace
					.getEnv()
					.getRenderableBlock(plug.getBlockID())
					.updateSocketSpace(plugBlock.getConnectorTo(blockID),
							blockID, true);
		}
	}
	return false;
}
 
开发者ID:heqichen,项目名称:openblocks,代码行数:76,代码来源:RenderableBlock.java

示例3: updateSocketSpace

import edu.mit.blocks.codeblocks.BlockLinkChecker; //导入方法依赖的package包/类
/**
 * Updates the socket socket space of the specified connectedSocket of this
 * after a block connection/disconnection. The socket space specifies the
 * dimensions of the block with id connectedToBlockID. RenderableBlock will
 * use these dimensions to determine the appropriate bounds to stretch the
 * connectedSocket by.
 * 
 * @param connectedSocket
 *            BlockConnector which block connection/disconnection occurred
 * @param connectedToBlockID
 *            the Long block ID of the block connected/disconnected to the
 *            specified connectedSocket
 * @param isConnected
 *            boolean flag to determine if a block connected or disconnected
 *            to the connectedSocket
 */
private void updateSocketSpace(BlockConnector connectedSocket,
		long connectedToBlockID, boolean isConnected) {
	// System.out.println("updating socket space of :" +
	// connectedSocket.getLabel() +" of rb: "+this);
	if (!isConnected) {
		// remove the mapping
		this.getConnectorTag(connectedSocket).setDimension(null);

	} else {
		// if no before block, then no recursion
		// if command connector with position type bottom (just a control
		// connector socket)
		// and we have a before, then skip and recurse up
		if (getBlock().getBeforeBlockID() != Block.NULL
				&& BlockConnectorShape.isCommandConnector(connectedSocket)
				&& connectedSocket.getPositionType() == BlockConnector.PositionType.BOTTOM) {

			// get before connector
			Long beforeID = getBlock().getBeforeBlockID();
			BlockConnector beforeSocket = workspace.getEnv()
					.getBlock(beforeID).getConnectorTo(getBlockID());
			workspace.getEnv().getRenderableBlock(beforeID)
					.updateSocketSpace(beforeSocket, getBlockID(), true);
			return;
		}

		// add dimension to the mapping
		this.getConnectorTag(connectedSocket).setDimension(
				calcDimensionOfSocket(connectedSocket));
	}

	// reform shape with new socket dimension
	reformBlockShape();
	// next time, redraw with new positions and moving children blocks
	clearBufferedImage();

	// after everything on this block has been updated, recurse upward if
	// possible
	BlockConnector plugEquiv = BlockLinkChecker
			.getPlugEquivalent(getBlock());
	if (plugEquiv != null && plugEquiv.hasBlock()) {
		Long plugID = plugEquiv.getBlockID();
		BlockConnector socketEquiv = workspace.getEnv().getBlock(plugID)
				.getConnectorTo(getBlockID());
		// update the socket space of a connected before/parent block
		workspace.getEnv().getRenderableBlock(plugID)
				.updateSocketSpace(socketEquiv, getBlockID(), true);
	}
}
 
开发者ID:heqichen,项目名称:openblocks,代码行数:66,代码来源:RenderableBlock.java

示例4: mouseDragged

import edu.mit.blocks.codeblocks.BlockLinkChecker; //导入方法依赖的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

示例5: findTopBlock

import edu.mit.blocks.codeblocks.BlockLinkChecker; //导入方法依赖的package包/类
private Long findTopBlock(Long blockID) {
	BlockConnector plug = BlockLinkChecker.getPlugEquivalent(workspace.getEnv().getBlock(blockID));
	if (plug == null || !plug.hasBlock())
		return blockID;
	return findTopBlock(plug.getBlockID());
}
 
开发者ID:heqichen,项目名称:openblocks,代码行数:7,代码来源:StackRule.java


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