use of edu.mit.blocks.workspace.Page in project openblocks by mikaelhg.
the class BlockDropAnimator method dropBlock.
/**
* drops block by adding to widget and throwing workspace event
* @param block
*
* @requires block != null; block.blockID != null; block.blockID != Block.NULL
* workspace widget != null
*/
private static void dropBlock(RenderableBlock block) {
if (block == null) {
throw new RuntimeException("Invariant Violated: child block was null");
}
Workspace workspace = block.getWorkspace();
Page p = workspace.getCurrentPage(block);
if (p == null) {
throw new RuntimeException("Invariant Violated: child block was located on a null widget");
}
//add this block to that page.
p.blockDropped(block);
}
use of edu.mit.blocks.workspace.Page in project openblocks by mikaelhg.
the class FocusTraversalManager method workspaceEventOccurred.
///////////////////////////////
// WORKSPACE LISTENER METHOD //
///////////////////////////////
/**
* Subscription: BLOCK_ADDED events.
* Action: add this.mouselistener to the block referanced by event
* @requires block reference in event is not null
* @modifies this.blockFocusOwner && event.block
* @effects Add this.mouselistener to this.blockFocusOwner
* removes focus from this.blockFocusOwner
* adds focus to e.getSource iff e.getSource
* is instance of BlockCanvas and RenderableBlock
*/
public void workspaceEventOccurred(WorkspaceEvent event) {
switch(event.getEventType()) {
case WorkspaceEvent.BLOCK_ADDED:
//only add focus manager as listener to blocks added to pages
if (!(event.getSourceWidget() instanceof Page)) {
break;
}
RenderableBlock rb = workspace.getEnv().getRenderableBlock(event.getSourceBlockID());
if (rb == null) {
break;
}
//only add once
for (MouseListener l : rb.getMouseListeners()) {
if (l.equals(this)) {
return;
//TODO: this shouldn't return, it should break
//but you can't double break in java
}
}
rb.addMouseListener(this);
rb.addKeyListener(this);
setFocus(event.getSourceBlockID());
rb.grabFocus();
break;
}
}
Aggregations