Search in sources :

Example 41 with Rectangle

use of java.awt.Rectangle in project openblocks by mikaelhg.

the class BlockStackSorterUtil method sortBlockStacks.

/**
     * This method serves to help clients sort blocks within a page
     * in some manner.
     *
     * @param page
     * @param topLevelBlocks
     *
     * @requires page != null && topLevelBlocks != null
     * @modifies the location of all topLevelBlocks
     * @effects sort the topLevelBlocks and move them to an order location on the page
     */
protected static void sortBlockStacks(Page page, Collection<RenderableBlock> topLevelBlocks) {
    blocksToArrange.clear();
    positioningBounds.setBounds(BUFFER_BETWEEN_BLOCKS, BUFFER_BETWEEN_BLOCKS, 0, BUFFER_BETWEEN_BLOCKS);
    //created an ordered list of blocks based on x-coordinate position
    blocksToArrange.addAll(topLevelBlocks);
    //Naively places blocks from top to bottom, left to right.
    for (RenderableBlock block : blocksToArrange) {
        Rectangle bounds = block.getStackBounds();
        if (positioningBounds.height + bounds.height > page.getJComponent().getHeight()) {
            //need to go to next column
            positioningBounds.x = positioningBounds.x + positioningBounds.width + BUFFER_BETWEEN_BLOCKS;
            positioningBounds.width = 0;
            positioningBounds.height = BUFFER_BETWEEN_BLOCKS;
        }
        block.setLocation(positioningBounds.x, positioningBounds.height);
        //sets the x and y position for when workspace is unzoomed
        block.setUnzoomedX(block.calculateUnzoomedX(positioningBounds.x));
        block.setUnzoomedY(block.calculateUnzoomedY(positioningBounds.height));
        block.moveConnectedBlocks();
        //update positioning bounds
        positioningBounds.width = Math.max(positioningBounds.width, bounds.width);
        positioningBounds.height = positioningBounds.height + bounds.height + BUFFER_BETWEEN_BLOCKS;
        if (positioningBounds.x + positioningBounds.width > page.getJComponent().getWidth()) {
            //resize page to the difference
            page.addPixelWidth(positioningBounds.x + positioningBounds.width - page.getJComponent().getWidth());
        }
    }
}
Also used : RenderableBlock(edu.mit.blocks.renderable.RenderableBlock) Rectangle(java.awt.Rectangle)

Example 42 with Rectangle

use of java.awt.Rectangle in project silk by jbee.

the class TestMockingBinds method bindsCanBeUsedToMockReturnValuesOfMockMethods.

@Test
public void bindsCanBeUsedToMockReturnValuesOfMockMethods() {
    Injector injector = Bootstrap.injector(TestMockingBindsModule.class);
    Shape shape = injector.resolve(dependency(Shape.class));
    Rectangle bounds = shape.getBounds();
    assertNotNull(bounds);
    assertTrue(shape instanceof Mock);
    Mock mock = (Mock) shape;
    assertEquals(1, mock.timesInvoked());
}
Also used : Shape(java.awt.Shape) Injector(se.jbee.inject.Injector) Rectangle(java.awt.Rectangle) Test(org.junit.Test)

Example 43 with Rectangle

use of java.awt.Rectangle in project Smack by igniterealtime.

the class WholeImageFilter method filter.

@Override
public BufferedImage filter(BufferedImage src, BufferedImage dst) {
    int width = src.getWidth();
    int height = src.getHeight();
    int type = src.getType();
    WritableRaster srcRaster = src.getRaster();
    originalSpace = new Rectangle(0, 0, width, height);
    transformedSpace = new Rectangle(0, 0, width, height);
    transformSpace(transformedSpace);
    if (dst == null) {
        ColorModel dstCM = src.getColorModel();
        dst = new BufferedImage(dstCM, dstCM.createCompatibleWritableRaster(transformedSpace.width, transformedSpace.height), dstCM.isAlphaPremultiplied(), null);
    }
    WritableRaster dstRaster = dst.getRaster();
    int[] inPixels = getRGB(src, 0, 0, width, height, null);
    inPixels = filterPixels(width, height, inPixels, transformedSpace);
    setRGB(dst, 0, 0, transformedSpace.width, transformedSpace.height, inPixels);
    return dst;
}
Also used : WritableRaster(java.awt.image.WritableRaster) ColorModel(java.awt.image.ColorModel) Rectangle(java.awt.Rectangle) BufferedImage(java.awt.image.BufferedImage)

Example 44 with Rectangle

use of java.awt.Rectangle in project OpenNotebook by jaltekruse.

the class DocMouseListener method mouseClicked.

public void mouseClicked(MouseEvent e) {
    docPanel.requestFocus();
    boolean clickHandled = false, requiresRedraw = false;
    if (selectionRectRequiresMouseDrag || selectionRectBeingResized) {
        selectionRectRequiresMouseDrag = false;
        selectionRectBeingResized = false;
        docPanel.setSelectionRect(null);
    }
    PointInDocument clickedPt = docPanel.panelPt2DocPt(e.getX(), e.getY());
    if (!clickedPt.isOutSidePage()) {
        Rectangle objRect;
        // gives extra space around object to allow selection,
        // most useful for when objects are very thin
        int clickBuffer = 3;
        Vector<MathObject> currPageObjects = docPanel.getDoc().getPage(clickedPt.getPage()).getObjects();
        MathObject mObj, oldFocused;
        oldFocused = docPanel.getFocusedObject();
        Page page = docPanel.getDoc().getPage(clickedPt.getPage());
        for (int i = (currPageObjects.size() - 1); i >= 0; i--) {
            // cycle through all of the objects belonging the page that was clicked on
            mObj = currPageObjects.get(i);
            objRect = mObj.getBounds();
            if (objRect.contains(new Point(clickedPt.getxPos(), clickedPt.getyPos())) && mObj != docPanel.getFocusedObject()) {
                // the click occurred within an object, that was already selected
                if (mObj instanceof Grouping && docPanel.isInStudentMode()) {
                    for (MathObject subObj : ((Grouping) mObj).getObjects()) {
                        objRect = subObj.getBounds();
                        if (objRect.contains(new Point(clickedPt.getxPos(), clickedPt.getyPos())) && mObj != docPanel.getFocusedObject()) {
                            docPanel.setFocusedObject(subObj);
                            docPanel.repaintDoc();
                            return;
                        }
                    }
                } else {
                    if (e.isShiftDown()) {
                        docPanel.addObjectToSelection(mObj);
                    } else {
                        docPanel.setFocusedObject(mObj);
                    }
                    docPanel.repaintDoc();
                    docPanel.updateObjectToolFrame();
                    return;
                }
            }
            // without ungrouping
            if (e.getClickCount() == 2 && objRect.contains(new Point(clickedPt.getxPos(), clickedPt.getyPos())) && mObj == docPanel.getFocusedObject() && docPanel.getFocusedObject() instanceof Grouping) {
                for (MathObject subObj : ((Grouping) mObj).getObjects()) {
                    objRect = new Rectangle(subObj.getxPos(), subObj.getyPos(), subObj.getWidth(), subObj.getHeight());
                    if (objRect.contains(new Point(clickedPt.getxPos(), clickedPt.getyPos()))) {
                        docPanel.setFocusedObject(subObj);
                        docPanel.repaintDoc();
                        return;
                    }
                }
            }
        }
        if (docPanel.getFocusedObject() == oldFocused) {
            if (oldFocused != null) {
                objRect = new Rectangle(oldFocused.getxPos() - clickBuffer, oldFocused.getyPos() - clickBuffer, oldFocused.getWidth() + 2 * clickBuffer, oldFocused.getHeight() + 2 * clickBuffer);
                if (!objRect.contains(new Point(clickedPt.getxPos(), clickedPt.getyPos()))) {
                    // send event to object
                    docPanel.setFocusedObject(null);
                    docPanel.repaintDoc();
                    return;
                }
            }
        }
    } else {
        // click was outside of page
        docPanel.setSelectedPage(null);
        docPanel.setFocusedObject(null);
        docPanel.repaintDoc();
        return;
    }
    // objects can be off of the page, so this check must happen out here
    if (docPanel.getFocusedObject() != null && !clickHandled) {
        Point objPos = null;
        objPos = docPanel.getObjectPos(docPanel.getFocusedObject());
        Rectangle focusedRect = new Rectangle(objPos.x, objPos.y, (int) (docPanel.getFocusedObject().getWidth() * docPanel.getZoomLevel()), (int) (docPanel.getFocusedObject().getHeight() * docPanel.getZoomLevel()));
        if (focusedRect.contains(new Point(e.getX(), e.getY()))) {
            // user clicked on the object that already had focus, send an event to the objet so it
            // can handle it for (for drag and drop, moving graphs etc.)
            docPanel.getPageGUI().handleMouseAction(docPanel.getFocusedObject(), (int) (e.getX() - objPos.getX()), (int) (e.getY() - objPos.getY()), PageGUI.MOUSE_LEFT_CLICK);
            clickHandled = true;
            requiresRedraw = true;
        }
    // throw click down to focused object
    }
    if (!clickHandled && !clickedPt.isOutSidePage()) {
        // the click hit a page, but missed all of its objects, select the
        // page
        docPanel.setSelectedPage(clickedPt.getPage());
        clickHandled = true;
        requiresRedraw = true;
    }
    if (!clickHandled) {
        // click occurred on a non-active part of screen,
        // unfocus current object
        docPanel.setFocusedObject(null);
        requiresRedraw = true;
    }
    if (requiresRedraw) {
        docPanel.repaintDoc();
    }
}
Also used : Rectangle(java.awt.Rectangle) Page(doc.Page) Grouping(doc.mathobjects.Grouping) Point(java.awt.Point) MathObject(doc.mathobjects.MathObject) Point(java.awt.Point) PointInDocument(doc.PointInDocument)

Example 45 with Rectangle

use of java.awt.Rectangle in project OpenNotebook by jaltekruse.

the class Page method addObject.

/**
	 * Add a MathObject to this page.
	 * @param mObj - object to add
	 * @return true if add was successful, if object did not fit in printable area it is not added
	 */
public boolean addObject(MathObject mObj) {
    // by removing this check broke creating a group by clicking and dragging.
    if (getObjects().contains(mObj)) {
        return true;
    }
    Rectangle printablePage = new Rectangle(0, 0, getWidth(), getHeight());
    while (getParentDoc().objectIDInUse(mObj.getObjectID())) {
        // randomly assign the object a new ID until it is unique within the document
        mObj.setObjectID(UUID.randomUUID());
    }
    if (!objects.contains(mObj)) {
        objects.add(mObj);
        mObj.setParentContainer(this);
        return true;
    }
    return false;
//throw error? the object would not fit within the printable page with the current position and dimensions
}
Also used : Rectangle(java.awt.Rectangle)

Aggregations

Rectangle (java.awt.Rectangle)809 Point (java.awt.Point)201 Dimension (java.awt.Dimension)81 BufferedImage (java.awt.image.BufferedImage)68 Graphics2D (java.awt.Graphics2D)65 Color (java.awt.Color)48 Insets (java.awt.Insets)47 ArrayList (java.util.ArrayList)37 Font (java.awt.Font)29 Test (org.junit.Test)28 IOException (java.io.IOException)27 GraphicsConfiguration (java.awt.GraphicsConfiguration)23 Paint (java.awt.Paint)23 GradientPaint (java.awt.GradientPaint)22 FontMetrics (java.awt.FontMetrics)21 Graphics (java.awt.Graphics)21 Rectangle2D (java.awt.geom.Rectangle2D)21 Robot (java.awt.Robot)19 File (java.io.File)19 PeakResult (gdsc.smlm.results.PeakResult)18