/** * @modifies this.miniPixelWidth * @effects sets the minimumPixelWidth such that the following condition holds: * DEFAULT_MINIMUMWIDTH < new minimumPixelWidth && for each block, b, in this page's set of * blocks { b.x+b.width < new minimumPixelWidth} */ public void reformMinimumPixelWidth() { minimumPixelWidth = 0; // reset min to 0 // loop through blocks, growing min to fit each block for (RenderableBlock b : this.getBlocks()) { if (b.getX() + b.getWidth() + b.getHighlightStrokeWidth() / 2 > minimumPixelWidth) { // increase min width to fit this block minimumPixelWidth = b.getX() + b.getWidth() + b.getHighlightStrokeWidth() / 2 + 1; } if (b.hasComment()) { if (b.getComment().getX() + b.getComment().getWidth() > minimumPixelWidth) { // increase min width to fit this block minimumPixelWidth = b.getComment().getX() + b.getComment().getWidth() + 1; } } } if (this.minimumPixelWidth < Page.DEFAULT_MINUMUM_WIDTH * zoom) { this.minimumPixelWidth = (int) (Page.DEFAULT_MINUMUM_WIDTH * zoom); } }
/** * @param block - the new block being added whose position must be revalidated * @requires block != null * @modifies block.location or this page's abstract width * @effects shifts this block into the page or increases the width of this page to fit the new * block. It must then notify listeners that the page's size may have changed */ public void reformBlockPosition(RenderableBlock block) { // move blocks in Point p = SwingUtilities.convertPoint(block.getParent(), block.getLocation(), this.pageJComponent); if (p.x < block.getHighlightStrokeWidth() / 2 + 1) { block.setLocation(block.getHighlightStrokeWidth() / 2 + 1, p.y); block.moveConnectedBlocks(); // the block has moved, so update p p = SwingUtilities.convertPoint(block.getParent(), block.getLocation(), this.pageJComponent); } else if (p.x + block.getWidth() + block.getHighlightStrokeWidth() / 2 + 1 > this.pageJComponent.getWidth()) { this.setPixelWidth(p.x + block.getWidth() + block.getHighlightStrokeWidth() / 2 + 1); } if (p.y < block.getHighlightStrokeWidth() / 2 + 1) { block.setLocation(p.x, block.getHighlightStrokeWidth() / 2 + 1); block.moveConnectedBlocks(); } else if (p.y + block.getStackBounds().height + block.getHighlightStrokeWidth() / 2 + 1 > this.pageJComponent.getHeight()) { block.setLocation( p.x, this.pageJComponent.getHeight() - block.getStackBounds().height - block.getHighlightStrokeWidth() / 2 + 1); block.moveConnectedBlocks(); } if (block.hasComment()) { // p = SwingUtilities.convertPoint(block.getComment().getParent(), // block.getComment().getLocation(), this.pageJComponent); p = block.getComment().getLocation(); if (p.x + block.getComment().getWidth() + 1 > this.pageJComponent.getWidth()) { this.setPixelWidth(p.x + block.getComment().getWidth() + 1); } } // repaint all pages PageChangeEventManager.notifyListeners(); }