本文整理汇总了Java中edu.mit.blocks.codeblocks.BlockLinkChecker类的典型用法代码示例。如果您正苦于以下问题:Java BlockLinkChecker类的具体用法?Java BlockLinkChecker怎么用?Java BlockLinkChecker使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
BlockLinkChecker类属于edu.mit.blocks.codeblocks包,在下文中一共展示了BlockLinkChecker类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: loadBlockLanguage
import edu.mit.blocks.codeblocks.BlockLinkChecker; //导入依赖的package包/类
/**
* Loads all the block genuses, properties, and link rules of
* a language specified in the pre-defined language def file.
* @param root Loads the language specified in the Element root
*/
public void loadBlockLanguage(final Element root) {
/* MUST load shapes before genuses in order to initialize
connectors within each block correctly */
BlockConnectorShape.loadBlockConnectorShapes(root);
//load genuses
BlockGenus.loadBlockGenera(workspace, root);
//load rules
BlockLinkChecker.addRule(workspace, new CommandRule(workspace));
BlockLinkChecker.addRule(workspace, new SocketRule());
BlockLinkChecker.addRule(workspace, new PolyRule(workspace));
BlockLinkChecker.addRule(workspace, new StackRule(workspace));
BlockLinkChecker.addRule(workspace, new ParamRule());
//set the dirty flag for the language definition file
//to false now that the lang file has been loaded
langDefDirty = false;
}
示例2: removeBlock
import edu.mit.blocks.codeblocks.BlockLinkChecker; //导入依赖的package包/类
/**
*
* @param renderable
* @param widget
* @param container
*
* @requires renderable != null && renderable.blockID != null && renderable.blockID != Block.NULL
* && widget != null && container != null
* @modifies renderable && children blocks connected to renderable
* @effects removes renderable from container and widget and re-renders
* renderable block, widget, and container appropriately.
* Repeats for all of renderable's children.
*/
private void removeBlock(RenderableBlock renderable, WorkspaceWidget widget, Container container) {
widget.removeBlock(renderable);
container.remove(renderable);
container.validate();
container.repaint();
renderable.setParentWidget(null);
//Workspace.getInstance().notifyListeners(new WorkspaceEvent(widget, renderable.getBlockID(), WorkspaceEvent.BLOCK_REMOVED));
for (BlockConnector child : BlockLinkChecker.getSocketEquivalents(workspace.getEnv().getBlock(renderable.getBlockID()))) {
if (child == null || child.getBlockID().equals(Block.NULL)) {
continue;
}
RenderableBlock childRenderable = workspace.getEnv().getRenderableBlock(child.getBlockID());
if (childRenderable == null) {
continue;
}
removeBlock(childRenderable, widget, container);
}
if (renderable.hasComment()) {
renderable.removeComment();
}
workspace.notifyListeners(new WorkspaceEvent(workspace, widget, renderable.getBlockID(), WorkspaceEvent.BLOCK_REMOVED));
}
示例3: startDragging
import edu.mit.blocks.codeblocks.BlockLinkChecker; //导入依赖的package包/类
private void startDragging(RenderableBlock renderable,
WorkspaceWidget widget) {
renderable.pickedUp = true;
renderable.lastDragWidget = widget;
if (renderable.hasComment()) {
renderable.comment.setConstrainComment(false);
}
Component oldParent = renderable.getParent();
Workspace workspace = renderable.getWorkspace();
workspace.addToBlockLayer(renderable);
renderable.setLocation(SwingUtilities.convertPoint(oldParent,
renderable.getLocation(), workspace));
renderable.setHighlightParent(workspace);
for (BlockConnector socket : BlockLinkChecker
.getSocketEquivalents(workspace.getEnv().getBlock(
renderable.blockID))) {
if (socket.hasBlock()) {
startDragging(
workspace.getEnv().getRenderableBlock(
socket.getBlockID()), widget);
}
}
}
示例4: findStackType
import edu.mit.blocks.codeblocks.BlockLinkChecker; //导入依赖的package包/类
private String findStackType(Long topID, Long startID, String currentType) {
if (startID == Block.NULL)
return "";
topBlock.put(startID, topID);
Block b = workspace.getEnv().getBlock(startID);
String type = b.getProperty("stack-type");
if (type != null && type.length() > currentType.length())
currentType = type;
BlockConnector inlineSocket = getInlineStackSocket(b);
for (BlockConnector socket : BlockLinkChecker.getSocketEquivalents(b)) {
if (socket == inlineSocket && socket.hasBlock()) {
long blockID = socket.getBlockID();
stackType.put(blockID, findStackType(blockID, blockID, b.getProperty("inline-stack-type")));
}
else {
type = findStackType(topID, socket.getBlockID(), currentType);
if (type.length() > currentType.length())
currentType = type;
}
}
return currentType;
}
示例5: 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));
}
示例6: redrawFromTop
import edu.mit.blocks.codeblocks.BlockLinkChecker; //导入依赖的package包/类
/**
* Redraws this RenderableBlock along with the RenderableBlocks after it,
* which include after and socket blocks. In other words, this method
* redraws the stack of blocks that begin with this. NOTE: this is
* inefficient, should only use this if needed NOTE: Must call this after
* loading of blocks to update the socket dimensions of this and set the
* isLoading flag to false
*/
public void redrawFromTop() {
if (GraphicsEnvironment.isHeadless()) {
return;
}
isLoading = false;
for (BlockConnector socket : BlockLinkChecker
.getSocketEquivalents(getBlock())) {
if (socket.hasBlock()) {
// loop through all the afters of the connected block
long curBlockID = socket.getBlockID();
// TODO: this is a patch, but we need to fix the root of the
// problem!
if (workspace.getEnv().getRenderableBlock(curBlockID) == null) {
System.out.println("does not exist yet, block: "
+ curBlockID);
continue;
}
workspace.getEnv().getRenderableBlock(curBlockID)
.redrawFromTop();
// add dimension to the mapping
this.getConnectorTag(socket).setDimension(
calcDimensionOfSocket(socket));
} else {
this.getConnectorTag(socket).setDimension(null);
}
}
// reform shape with new socket dimension
reformBlockShape();
// next time, redraw with new positions and moving children blocks
clearBufferedImage();
}
示例7: stopDragging
import edu.mit.blocks.codeblocks.BlockLinkChecker; //导入依赖的package包/类
/**
* This method is called when this RenderableBlock is plugged into another
* RenderableBlock that has finished dragging.
*
* @param widget
* the WorkspaceWidget where this RenderableBlock is being
* dropped.
*/
public static void stopDragging(RenderableBlock renderable,
WorkspaceWidget widget) {
if (!renderable.dragging) {
throw new RuntimeException("dropping without prior dragging?");
}
// notify children
for (BlockConnector socket : BlockLinkChecker
.getSocketEquivalents(renderable.getBlock())) {
if (socket.hasBlock()) {
stopDragging(renderable.getWorkspace().getEnv()
.getRenderableBlock(socket.getBlockID()), widget);
}
}
// drop this block on its widget (if w is null it'll throw an exception)
widget.blockDropped(renderable);
// stop rendering as transparent
renderable.dragging = false;
// move comment
if (renderable.hasComment()) {
if (renderable.getParentWidget() != null) {
renderable.comment.setParent(renderable.getParentWidget()
.getJComponent(), 0);
} else {
renderable.comment.setParent(null, renderable.getBounds());
}
renderable.comment.setConstrainComment(true);
renderable.comment.setLocation(renderable.comment.getLocation());
renderable.comment.getArrow().updateArrow();
}
// When dragging, Child blocks can become mis-aligned to their Parent Block which is very annoying
// I can't stop this happening, nor work out why it happens.
// This is just a quick 'fix' to stop things looking too bad
renderable.moveConnectedBlocks();
}
示例8: drag
import edu.mit.blocks.codeblocks.BlockLinkChecker; //导入依赖的package包/类
private void drag(RenderableBlock renderable, int dx, int dy,
WorkspaceWidget widget, boolean isTopLevelBlock) {
if (!renderable.pickedUp) {
throw new RuntimeException("dragging without prior pickup");
}
// mark this as being dragged
renderable.dragging = true;
// move the block by drag amount
if (!isTopLevelBlock) {
renderable.setLocation(renderable.getX() + dx, renderable.getY()
+ dy);
}
// send blockEntered/blockExited/blogDragged as appropriate
if (widget != null) {
if (!widget.equals(renderable.lastDragWidget)) {
widget.blockEntered(renderable);
if (renderable.lastDragWidget != null) {
renderable.lastDragWidget.blockExited(renderable);
}
}
widget.blockDragged(renderable);
renderable.lastDragWidget = widget;
}
// translate highlight along with the block - this would happen
// automatically,
// but putting the call here takes out any lag.
renderable.highlighter.repaint();
// Propagate the drag event to anything plugged into this block
for (BlockConnector socket : BlockLinkChecker
.getSocketEquivalents(renderable.getBlock())) {
if (socket.hasBlock()) {
drag(workspace.getEnv().getRenderableBlock(socket.getBlockID()),
dx, dy, widget, false);
}
}
}
示例9: resetLanguage
import edu.mit.blocks.codeblocks.BlockLinkChecker; //导入依赖的package包/类
/**
* Resets the current language within the active
* Workspace.
*
*/
public void resetLanguage() {
BlockConnectorShape.resetConnectorShapeMappings();
getWorkspace().getEnv().resetAllGenuses();
BlockLinkChecker.reset();
}
示例10: 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;
}
示例11: 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);
}
}
示例12: moveConnectedBlocks
import edu.mit.blocks.codeblocks.BlockLinkChecker; //导入依赖的package包/类
/**
* Aligns all RenderableBlocks plugged into this one with the current
* location of this RenderableBlock. These RenderableBlocks to move include
* blocks connected at sockets and the after connector.
*/
public void moveConnectedBlocks() {
if (DEBUG) {
System.out.println("move connected blocks of this: " + this);
}
// if this hasn't been added anywhere, asking its location will break
// stuff
if (getParent() == null) {
return;
}
Block b = workspace.getEnv().getBlock(blockID);
Point socketLocation;
Point plugLocation;
RenderableBlock rb;
Point myScreenOffset = getLocation();
Point otherScreenOffset;
for (BlockConnector socket : BlockLinkChecker.getSocketEquivalents(b)) {
socketLocation = getSocketPixelPoint(socket);
if (socket.hasBlock()) {
rb = workspace.getEnv().getRenderableBlock(socket.getBlockID());
// TODO: djwendel - this is a patch, but the root of the problem
// needs to be found and fixed!!
if (rb == null) {
System.out.println("Block doesn't exist yet: "
+ socket.getBlockID());
continue;
}
plugLocation = rb.getSocketPixelPoint(BlockLinkChecker
.getPlugEquivalent(workspace.getEnv().getBlock(
socket.getBlockID())));
otherScreenOffset = SwingUtilities.convertPoint(rb.getParent(),
rb.getLocation(), getParent());
otherScreenOffset.translate(-rb.getX(), -rb.getY());
rb.setLocation(
(int) Math.round((float) myScreenOffset.getX()
+ socketLocation.getX()
- (float) otherScreenOffset.getX()
- plugLocation.getX()),
(int) Math.round((float) myScreenOffset.getY()
+ socketLocation.getY()
- (float) otherScreenOffset.getY()
- plugLocation.getY()));
rb.moveConnectedBlocks();
}
}
}
示例13: 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();
}
}
示例14: 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());
}