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


Java BlockLink类代码示例

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


BlockLink类属于edu.mit.blocks.codeblocks包,在下文中一共展示了BlockLink类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: WorkspaceEvent

import edu.mit.blocks.codeblocks.BlockLink; //导入依赖的package包/类
public WorkspaceEvent(Workspace workspace, WorkspaceWidget widget, BlockLink link, int eventType, boolean userSpawned) {
    this.workspace = workspace;
    this.widget = widget;
    this.link = link;
    this.eventType = eventType;
    this.userSpawned = userSpawned;
}
 
开发者ID:heqichen,项目名称:openblocks,代码行数:8,代码来源:WorkspaceEvent.java

示例3: 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

示例4: workspaceEventOccurred

import edu.mit.blocks.codeblocks.BlockLink; //导入依赖的package包/类
/**
 * Handles setting/reverting POLY connectors when a BLOCKS_CONNECTED/BLOCKS_DISCONNECTED event occurs.
 * Connecting: checks which connector is the POLY CONN and which is the SETTER CONN, calls connectPoly
 * 		with the SETTER CONN. (See "Setting type specifics" for details on how to determine this and why.)
 * Disconnecting: calls revertPoly on both connectors. (See "Reverting type specifics" for details on why.)
 * Finally, calls Procedure Output Manager to handle changes in output block types (which are also POLY).
 */
public void workspaceEventOccurred(WorkspaceEvent e) {
	BlockLink link = e.getSourceLink();
	// CONNECTING
	if (e.getEventType() == WorkspaceEvent.BLOCKS_CONNECTED) {
		boolean isPolyPlug = link.getPlug().getKind().contains("poly");
		boolean isPolySocket = link.getSocket().getKind().contains("poly");
		boolean isListPlug = link.getPlug().getKind().contains("list");
		boolean isListSocket = link.getSocket().getKind().contains("list");
		// one POLY SINGLE
		if ((isPolyPlug && !isListPlug) && !(isPolySocket && !isListSocket))
			connectPoly(link.getSocketBlockID(), link.getSocket());
		else if (isPolySocket && !isListSocket)
			connectPoly(link.getPlugBlockID(), link.getPlug());
		// no POLY SINGLE, one POLY LIST
		else if ((isPolyPlug && isListPlug) && !(isPolySocket && isListSocket))
			connectPoly(link.getSocketBlockID(), link.getSocket());
		else if (isPolySocket && isListSocket)
			connectPoly(link.getPlugBlockID(), link.getPlug());
		// expandable sockets (only happens when dealing with LIST entries)
		else if (link.getSocket().isExpandable()) {
		    setPolyConnectors(link.getPlug());
		}
	}
	// DISCONNECTING
	else if (e.getEventType() == WorkspaceEvent.BLOCKS_DISCONNECTED) {
		// call for each side of the broken connection.
		revertPoly(workspace.getEnv().getBlock(link.getPlugBlockID()), link.getPlug());
		revertPoly(workspace.getEnv().getBlock(link.getSocketBlockID()), link.getSocket());
	}
	// Calls POM to deal with changes in output block types.
	if (link != null){
	//System.out.println(link.toString());
	}
	ProcedureOutputManager.procedureUpdateInfo(e);
}
 
开发者ID:heqichen,项目名称:openblocks,代码行数:43,代码来源:PolyRule.java

示例5: workspaceEventOccurred

import edu.mit.blocks.codeblocks.BlockLink; //导入依赖的package包/类
public void workspaceEventOccurred(WorkspaceEvent e) {
	BlockLink link = e.getSourceLink();
	if (e.getEventType() == WorkspaceEvent.BLOCKS_CONNECTED) {
		makeStack(getTopBlock(link.getSocketBlockID()));
	}
	else if (e.getEventType() == WorkspaceEvent.BLOCKS_DISCONNECTED) {
		makeStack(getTopBlock(link.getSocketBlockID()));
		makeStack(link.getPlugBlockID());
	}
}
 
开发者ID:heqichen,项目名称:openblocks,代码行数:11,代码来源:StackRule.java

示例6: 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));

    }
}
 
开发者ID:heqichen,项目名称:openblocks,代码行数:51,代码来源:BlockDropAnimator.java

示例7: 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();
}
 
开发者ID:heqichen,项目名称:openblocks,代码行数:72,代码来源:RenderableBlock.java

示例8: 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

示例9: procedureUpdateInfo

import edu.mit.blocks.codeblocks.BlockLink; //导入依赖的package包/类
/**
 * Similar to a WorkspaceListener, but not an actual listener because it is
 * never added to the list of listeners and can only be called after PolyRule.
 * This is because output is a poly block that needs to be handled before
 * attaching an output to a procedure can occur (if the output type is not
 * dealt with first, we can't use it to determine the procedure type).
 * 
 * @param event: WorkspaceEvent holds the information about the block that is
 * being dealt with (BlockID, Link, Widget, etc.)
 * TODO: Maybe we can abstract this even more from listener by only passing info
 * necessary for the update instead of a whole event, but the issue is that
 * I think the event is necessary to call the other listeners in the case that
 * outputs don't match and we have to disconnect blocks...
 */
public static void procedureUpdateInfo(WorkspaceEvent event) {
    Block b = getBlock(event.getSourceBlockID());
    BlockLink link = event.getSourceLink();
    
    switch (event.getEventType()) {
    case WorkspaceEvent.BLOCKS_CONNECTED:
        if (link != null) {
            blocksConnected(event.getSourceWidget(),
                            link.getSocketBlockID(), 
                            link.getPlugBlockID());
        }
        return;
        
    case WorkspaceEvent.BLOCKS_DISCONNECTED:
        if (link != null) {
            blocksDisconnected(event.getSourceWidget(),
                               link.getSocketBlockID(), 
                               link.getPlugBlockID());
        }
        return;
        
    case WorkspaceEvent.BLOCK_ADDED:
        if (b != null) {
            if (b.isProcedureDeclBlock()) {
                // Create a new entry for this proc 
                myProcInfo.put(b.getBlockID(), new OutputInfo());
            }
        }
        return;
        
    case WorkspaceEvent.BLOCK_REMOVED:
        if (b != null && b.isProcedureDeclBlock()) {
        	// System.out.println("procedure of type "+myProcInfo.get(b.getBlockID()).type+" removed.");
            // Remove our entry.
            myProcInfo.remove(b.getBlockID());
            if (link != null) {
            	blocksDisconnected(event.getSourceWidget(),
            			link.getSocketBlockID(),
            			link.getPlugBlockID());
            }
        }
        return;
    }
}
 
开发者ID:heqichen,项目名称:openblocks,代码行数:59,代码来源:ProcedureOutputManager.java

示例10: getSourceLink

import edu.mit.blocks.codeblocks.BlockLink; //导入依赖的package包/类
/**
 * Returns the BlockLink where this event originated, or null if the event type
 * of this is not block connected or disconnected.
 * @return the BlockLink where this event originated, or null if the event type
 * of this is not block connected or disconnected.
 */
public BlockLink getSourceLink() {
    return link;
}
 
开发者ID:heqichen,项目名称:openblocks,代码行数:10,代码来源:WorkspaceEvent.java

示例11: getNearbyLink

import edu.mit.blocks.codeblocks.BlockLink; //导入依赖的package包/类
/**
 * Looks for links between this RenderableBlock and others.
 * 
 * @return a BlockLink object with information on the closest possible
 *         linking between this RenderableBlock and another.
 */
public BlockLink getNearbyLink() {
	return BlockLinkChecker.getLink(workspace, this, workspace
			.getBlockCanvas().getBlocks());
}
 
开发者ID:heqichen,项目名称:openblocks,代码行数:11,代码来源:RenderableBlock.java


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