use of edu.mit.blocks.renderable.RenderableBlock in project openblocks by mikaelhg.
the class FactoryManager method setupSubsets.
/**
* Sets up the subsets by clearing all subsets and installing
* the new collection of subsets. If "usingSys" is true,
* the the factory and myblocks drawers will be accessible.
* If "usingSubs" is true, then the subset drawers will
* be accessible.
* @param subsets - collection of subsets
* @param usingSys - true for factory and myblocks
* @param usingSubs - true for subsets
*/
public void setupSubsets(Collection<Subset> subsets, boolean usingSys, boolean usingSubs) {
if (usingSubs) {
this.subsetCanvases.clear();
for (Subset subset : subsets) {
FactoryCanvas canvas = new FactoryCanvas(subset.getName(), subset.getColor());
for (RenderableBlock frb : subset.getBlocks()) {
canvas.addBlock(frb);
workspace.notifyListeners(new WorkspaceEvent(workspace, this, frb.getBlockID(), WorkspaceEvent.BLOCK_ADDED));
}
canvas.layoutBlocks();
this.subsetCanvases.add(canvas);
}
this.navigator.setCanvas(this.subsetCanvases, SUBSETS_NAME);
if (usingSys) {
this.factorySwicther.removeAll();
this.factorySwicther.add(this.navigator.getSwitcher());
} else {
this.factorySwicther.removeAll();
this.factorySwicther.add(new CLabel(SUBSETS_NAME));
}
this.viewSubsetsDrawers();
} else if (usingSys) {
this.factorySwicther.removeAll();
final CBorderlessButton factoryButton = new CBorderlessButton(STATIC_NAME);
final CBorderlessButton myblocksButton = new CBorderlessButton(DYNAMIC_NAME);
ActionListener listener = new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (factoryButton.equals(e.getSource())) {
FactoryManager.this.viewStaticDrawers();
} else if (myblocksButton.equals(e.getSource())) {
FactoryManager.this.viewDynamicDrawers();
}
}
};
factoryButton.addActionListener(listener);
myblocksButton.addActionListener(listener);
this.factorySwicther.add(factoryButton, BorderLayout.WEST);
this.factorySwicther.add(myblocksButton, BorderLayout.EAST);
this.viewStaticDrawers();
}
this.factorySwicther.revalidate();
this.factorySwicther.repaint();
}
use of edu.mit.blocks.renderable.RenderableBlock in project openblocks by mikaelhg.
the class FactoryManager method workspaceEventOccurred.
public void workspaceEventOccurred(WorkspaceEvent event) {
// IT DOES SOME PREETY STRANGE THINGS
if (event.getEventType() == WorkspaceEvent.BLOCK_ADDED) {
if (event.getSourceWidget() instanceof Page) {
Page page = (Page) event.getSourceWidget();
Block block = workspace.getEnv().getBlock(event.getSourceBlockID());
// block may not be null if this is a block added event
if (block.hasStubs()) {
for (BlockStub stub : block.getFreshStubs()) {
this.addDynamicBlock(new FactoryRenderableBlock(event.getWorkspace(), this, stub.getBlockID()), page.getPageDrawer());
}
}
}
} else if (event.getEventType() == WorkspaceEvent.BLOCK_REMOVED) {
// may not be removing a null stanc eof block, so DO NOT check for it
Block block = workspace.getEnv().getBlock(event.getSourceBlockID());
if (block.hasStubs()) {
for (Long stub : BlockStub.getStubsOfParent(event.getWorkspace(), block)) {
RenderableBlock rb = workspace.getEnv().getRenderableBlock(stub);
if (rb != null && !rb.getBlockID().equals(Block.NULL) && rb.getParentWidget() != null && rb.getParentWidget().equals(this)) {
// rb.getParent() should not be null
rb.getParent().remove(rb);
rb.setParentWidget(null);
}
}
}
this.relayoutBlocks();
} else if (event.getEventType() == WorkspaceEvent.BLOCK_MOVED) {
Block block = workspace.getEnv().getBlock(event.getSourceBlockID());
if (block != null && block.hasStubs()) {
for (Long stub : BlockStub.getStubsOfParent(event.getWorkspace(), block)) {
RenderableBlock rb = workspace.getEnv().getRenderableBlock(stub);
if (rb != null && !rb.getBlockID().equals(Block.NULL) && rb.getParentWidget() != null && rb.getParentWidget().equals(this)) {
// rb.getParent() should not be null
rb.getParent().remove(rb);
rb.setParentWidget(null);
}
}
this.relayoutBlocks();
}
} else if (event.getEventType() == WorkspaceEvent.PAGE_RENAMED) {
// this.relayoutBlocks();
}
}
use of edu.mit.blocks.renderable.RenderableBlock in project openblocks by mikaelhg.
the class MiniMap method paint.
/**
* @modifies this.bounds && this.blockCanvas && this.blocks && this.comments
* @effects 1] Point this.blockCanvas to whatever current block
* canvas is in Workspace
* 2] Reset this.bounds to maintain aspect ratio and be
* 16 pixels away from upper-right edge corner &&
* 3] Rerender this.blocks and this.comment toreflect
* real-time relative positions and dimension
*/
public void paint(Graphics g) {
// should paint super first then reset canvas.
// using new canvas, find new height and ratio.
super.paint(g);
// draw shadow border
for (int i = 0; i < BORDER_WIDTH; i++) {
g.setColor(new Color(200, 200, 150, 50 * (i + 1)));
g.drawRect(i, i, this.getWidth() - 1 - 2 * i, this.getHeight() - 1 - 2 * i);
}
// Aspect-Ratio Logic
this.blockCanvas = workspace.getBlockCanvas();
// MUST CAST MAPHEIGHT TO DOUBLE!!
this.transformX = (double) (MAPWIDTH) / this.getCanvas().getWidth();
this.transformY = (double) (MAPHEIGHT) / this.getCanvas().getHeight();
g.translate(5, 5);
for (Page page : this.blockCanvas.getPages()) {
Color pageColor = page.getPageColor();
g.setColor(new Color(pageColor.getRed(), pageColor.getGreen(), pageColor.getBlue(), 200));
Rectangle pageRect = rescaleRect(page.getJComponent().getBounds());
g.fillRect(pageRect.x, pageRect.y, pageRect.width, pageRect.height);
g.setColor(Color.white);
g.clipRect(pageRect.x, pageRect.y, pageRect.width, pageRect.height);
g.drawString(page.getPageName(), pageRect.x + 1, pageRect.height - 3);
if (page.getIcon() != null && expand) {
g.drawImage(page.getIcon(), pageRect.x + 1, pageRect.height - 28, 15, 15, null);
}
g.setClip(null);
for (Component component : page.getJComponent().getComponents()) {
// re-render this.blocks and this.comments
if (component instanceof RenderableBlock && component != null && component.isVisible()) {
if (((RenderableBlock) component).isSearchResult()) {
g.setColor(Color.yellow);
} else {
g.setColor(((RenderableBlock) component).getBLockColor());
}
drawBoundingBox(g, component);
} else if (component instanceof Comment && component.isVisible()) {
g.setColor(Color.yellow);
drawBoundingBox(g, component);
}
}
}
for (Component component : this.getCanvas().getComponents()) {
if (component instanceof PageDivider) {
g.setColor(Color.GRAY);
Rectangle dividerRect = rescaleRect(component.getBounds());
g.fillRect(dividerRect.x, dividerRect.y, dividerRect.width + 1, dividerRect.height);
}
}
for (Component component : workspace.getComponentsInLayer(Workspace.DRAGGED_BLOCK_LAYER)) {
if (component instanceof RenderableBlock && component != null && component.isVisible()) {
g.setColor(((RenderableBlock) component).getBLockColor());
drawBoundingBox(g, component);
} else if (component instanceof Comment && component.isVisible()) {
g.setColor(Color.yellow);
drawBoundingBox(g, component);
}
}
g.setColor(Color.red);
g.drawRect(rescaleX(blockCanvas.getHorizontalModel().getValue()), rescaleY(blockCanvas.getVerticalModel().getValue()), rescaleX(blockCanvas.getWidth()), rescaleY(blockCanvas.getHeight()));
}
use of edu.mit.blocks.renderable.RenderableBlock in project openblocks by mikaelhg.
the class FocusTraversalManager method grabFocus.
// /////////////////
// MOUSE METHODS //
// /////////////////
/**
* Action: removes the focus current focused block
* and places new focus on e.getSource
* @requires e != null
* @modifies this.blockFocusOwner && e.getSource
* @effects removes focus from this.blockFocusOwner
* adds focus to e.getSource iff e.getSource
* is instance of BlockCanvas and RenderableBlock
*/
private void grabFocus(MouseEvent e) {
// System.out.println("FocusManager: Mouse Event at ("+ e.getX()+", "+e.getY()+") on "+e.getSource());
if (e.getSource() instanceof Canvas) {
// get canvas point
Point canvasPoint = e.getPoint();
/* SwingUtilities.convertPoint(
(BlockCanvas)e.getSource(),
e.getPoint(),
((BlockCanvas)e.getSource()).getCanvas());*/
setFocus(canvasPoint, Block.NULL);
((Canvas) e.getSource()).grabFocus();
} else if (e.getSource() instanceof RenderableBlock) {
setFocus(((RenderableBlock) e.getSource()).getBlockID());
((RenderableBlock) e.getSource()).grabFocus();
}
}
use of edu.mit.blocks.renderable.RenderableBlock in project openblocks by mikaelhg.
the class TypeBlockManager method addBlock.
/**
* @param block
*
* @requires block must be a valid block. That is, block may not be such that
* block == null || block.getBlockID() == null ||
* block.getBlockID() == Block.NULL || block.getBlockID() == -1 ||
* Block.getBlock(block.getBlockID()) == null ||
* Block.getBlock(block.getBlockID()).getGenusName() == null ||
* Block.getBlock(block.getBlockID()).getGenusName().length() == 0 ||
* Block.getBlock(block.getBlockID()).getBlockLabel() == null
* @modifies Objects modified by this method is undefined
* @effects The effects of this method is unknown
*/
private void addBlock(RenderableBlock block) {
// check invariant
if (block == null || block.getBlockID() == null || block.getBlockID().equals(Block.NULL) || workspace.getEnv().getBlock(block.getBlockID()) == null || workspace.getEnv().getBlock(block.getBlockID()).getGenusName() == null || workspace.getEnv().getBlock(block.getBlockID()).getGenusName().length() == 0 || workspace.getEnv().getBlock(block.getBlockID()).getBlockLabel() == null) {
throw new RuntimeException("Invariant Violated: may not pass an invalid instance of renderabel block");
}
// ignore default arguments
block.ignoreDefaultArguments();
this.blockCanvas.getCanvas().add(block, 0);
block.setLocation(0, 0);
Long parentBlockID = this.focusManager.getFocusBlockID();
if (invalidBlockID(parentBlockID)) {
new BlockDropAnimator(workspace, this.focusManager.getCanvasPoint(), block, workspace.getEnv().getRenderableBlock(parentBlockID));
} else {
RenderableBlock parentBlock = workspace.getEnv().getRenderableBlock(parentBlockID);
new BlockDropAnimator(workspace, SwingUtilities.convertPoint(parentBlock, this.focusManager.getBlockPoint(), this.blockCanvas.getCanvas()), block, workspace.getEnv().getRenderableBlock(parentBlockID));
}
this.focusManager.setFocus(block.getBlockID());
}
Aggregations