Search in sources :

Example 1 with Page

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);
}
Also used : Page(edu.mit.blocks.workspace.Page) Workspace(edu.mit.blocks.workspace.Workspace)

Example 2 with Page

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;
    }
}
Also used : MouseListener(java.awt.event.MouseListener) RenderableBlock(edu.mit.blocks.renderable.RenderableBlock) Page(edu.mit.blocks.workspace.Page)

Aggregations

Page (edu.mit.blocks.workspace.Page)2 RenderableBlock (edu.mit.blocks.renderable.RenderableBlock)1 Workspace (edu.mit.blocks.workspace.Workspace)1 MouseListener (java.awt.event.MouseListener)1