use of edu.mit.blocks.workspace.WorkspaceEvent in project openblocks by mikaelhg.
the class RenderableBlock method mouseDragged.
public void mouseDragged(MouseEvent e) {
if (SwingUtilities.isLeftMouseButton(e)) {
if (pickedUp) {
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();
}
}
}
use of edu.mit.blocks.workspace.WorkspaceEvent in project openblocks by mikaelhg.
the class BlockLabel method textChanged.
protected void textChanged(String text) {
if ((this.labelType.equals(BlockLabel.Type.NAME_LABEL) || this.labelType.equals(BlockLabel.Type.PORT_LABEL)) && workspace.getEnv().getBlock(blockID).isLabelEditable()) {
if (this.labelType.equals(BlockLabel.Type.NAME_LABEL)) {
workspace.getEnv().getBlock(blockID).setBlockLabel(text);
}
BlockConnector plug = workspace.getEnv().getBlock(blockID).getPlug();
// has stubs, update them.
if (plug != null && plug.getBlockID() != Block.NULL) {
if (workspace.getEnv().getBlock(plug.getBlockID()) != null) {
if (workspace.getEnv().getBlock(plug.getBlockID()).isProcedureDeclBlock() && workspace.getEnv().getBlock(plug.getBlockID()).hasStubs()) {
// nor desired to call the connectors changed event again.
if (workspace.getEnv().getRenderableBlock(plug.getBlockID()).isLoading()) {
BlockStub.parentConnectorsChanged(workspace, plug.getBlockID());
}
}
}
}
RenderableBlock rb = workspace.getEnv().getRenderableBlock(blockID);
if (rb != null) {
workspace.notifyListeners(new WorkspaceEvent(workspace, rb.getParentWidget(), blockID, WorkspaceEvent.BLOCK_RENAMED));
}
}
}
use of edu.mit.blocks.workspace.WorkspaceEvent in project openblocks by mikaelhg.
the class BlockUtilities method deleteBlock.
public static void deleteBlock(RenderableBlock block) {
block.setLocation(0, 0);
WorkspaceWidget widget = block.getParentWidget();
if (widget != null) {
widget.removeBlock(block);
}
Container parent = block.getParent();
if (parent != null) {
parent.remove(block);
parent.validate();
}
block.setParentWidget(null);
Workspace workspace = block.getWorkspace();
workspace.notifyListeners(new WorkspaceEvent(workspace, widget, block.getBlockID(), WorkspaceEvent.BLOCK_REMOVED));
}
use of edu.mit.blocks.workspace.WorkspaceEvent in project openblocks by mikaelhg.
the class BlockUtilities method makeRenderable.
public static RenderableBlock makeRenderable(Workspace workspace, BlockNode node, WorkspaceWidget widget) {
// genusName may not be null
String genusName = node.getGenusName();
RenderableBlock renderable = BlockUtilities.getBlock(workspace, genusName, node.getLabel());
if (renderable == null) {
throw new RuntimeException("No children block exists for this genus: " + genusName);
}
// assume not null
Block block = workspace.getEnv().getBlock(renderable.getBlockID());
widget.blockDropped(renderable);
for (int i = 0; i < node.getChildren().size(); i++) {
BlockConnector socket = block.getSocketAt(i);
BlockNode child = node.getChildren().get(i);
RenderableBlock childRenderable = makeRenderable(workspace, child, widget);
Block childBlock = workspace.getEnv().getBlock(childRenderable.getBlockID());
// link blocks
BlockLink link;
if (childBlock.hasPlug()) {
link = BlockLinkChecker.canLink(workspace, block, childBlock, socket, childBlock.getPlug());
} else if (childBlock.hasBeforeConnector()) {
link = BlockLinkChecker.canLink(workspace, block, childBlock, socket, childBlock.getBeforeConnector());
} else {
link = null;
}
// assume link is not null
link.connect();
workspace.notifyListeners(new WorkspaceEvent(workspace, workspace.getEnv().getRenderableBlock(link.getPlugBlockID()).getParentWidget(), link, WorkspaceEvent.BLOCKS_CONNECTED));
}
if (node.getAfterNode() != null) {
// assume has after connector
BlockConnector socket = block.getAfterConnector();
BlockNode child = node.getAfterNode();
RenderableBlock childRenderable = makeRenderable(workspace, child, widget);
Block childBlock = workspace.getEnv().getBlock(childRenderable.getBlockID());
// link blocks
BlockLink link;
if (childBlock.hasPlug()) {
link = BlockLinkChecker.canLink(workspace, block, childBlock, socket, childBlock.getPlug());
} else if (childBlock.hasBeforeConnector()) {
link = BlockLinkChecker.canLink(workspace, block, childBlock, socket, childBlock.getBeforeConnector());
} else {
link = null;
}
// assume link is not null
link.connect();
workspace.notifyListeners(new WorkspaceEvent(workspace, workspace.getEnv().getRenderableBlock(link.getPlugBlockID()).getParentWidget(), link, WorkspaceEvent.BLOCKS_CONNECTED));
}
return renderable;
}
use of edu.mit.blocks.workspace.WorkspaceEvent in project openblocks by mikaelhg.
the class CommentLabel method mouseClicked.
/**
* Implement MouseListener interface
* toggle collapse state of block if button pressed
*/
@Override
public void mouseClicked(MouseEvent e) {
toggle();
RenderableBlock rb = workspace.getEnv().getRenderableBlock(getBlockID());
rb.getComment().setVisible(isActive());
workspace.notifyListeners(new WorkspaceEvent(workspace, rb.getComment().getCommentSource().getParentWidget(), WorkspaceEvent.BLOCK_COMMENT_VISBILITY_CHANGE));
update();
rb.revalidate();
rb.repaint();
workspace.getMiniMap().repaint();
}
Aggregations