Search in sources :

Example 46 with Rectangle

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

the class Page method sendObjectBackward.

public void sendObjectBackward(MathObject mObj) {
    int index = objects.lastIndexOf(mObj);
    Rectangle objRect = new Rectangle(mObj.getxPos(), mObj.getyPos(), mObj.getWidth(), mObj.getHeight());
    MathObject mObj2;
    Rectangle objRect2;
    for (int i = index - 1; i >= 0; i--) {
        mObj2 = objects.get(i);
        objRect2 = new Rectangle(mObj2.getxPos(), mObj2.getyPos(), mObj2.getWidth(), mObj2.getHeight());
        if (objRect.intersects(objRect2)) {
            objects.remove(mObj);
            objects.add(i, mObj);
            break;
        }
    }
}
Also used : Rectangle(java.awt.Rectangle)

Example 47 with Rectangle

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

the class DocMouseListener method adjustTempGroupSelection.

/**
	 * Method to change the temporary group selection based on the current
	 * selection rectangle. Removes objects no longer contacted, and adds new
	 * objects that are not yet group members.
	 * 
	 * @return - whether or not a redraw event is needed
	 */
private boolean adjustTempGroupSelection() {
    // need to modify this code to take into account the current stacking of
    // the objects
    // large objects automatically cover up smaller ones using this system
    Rectangle selectRect = docPanel.getSelectionRect().getBounds();
    Grouping tempGroup = docPanel.getTempGroup();
    Vector<MathObject> pageObjects = docPanel.getSelectionRect().getParentPage().getObjects();
    // temporary storage of objects that collide with the selection
    // rectangle
    Vector<MathObject> collisionObjects = new Vector<>();
    for (MathObject mObj : pageObjects) {
        // selection rectangle
        if (selectRect.intersects(mObj.getBounds())) {
            collisionObjects.add(mObj);
        }
    }
    if (collisionObjects.isEmpty()) {
        // no objects were contacted
        docPanel.ungroupTempGroup();
        docPanel.setFocusedObject(null);
        return true;
    }
    if (collisionObjects.size() == 1) {
        // only one object was contacted
        MathObject contactedObj = collisionObjects.get(0);
        if (contactedObj.equals(docPanel.getFocusedObject())) {
            // do nothing
            ;
            if (contactedObj != tempGroup) {
                collisionObjects.remove(contactedObj);
                return true;
            }
        } else {
            docPanel.setFocusedObject(contactedObj);
            collisionObjects.remove(contactedObj);
            return true;
        }
    }
    if (collisionObjects.contains(tempGroup)) {
        MathObject mObj;
        // otherwise remove them
        for (int i = 0; i < tempGroup.getObjects().size(); i++) {
            mObj = tempGroup.getObjects().get(i);
            if (!selectRect.intersects(mObj.getBounds())) {
                tempGroup.removeObject(mObj);
                tempGroup.getParentContainer().addObject(mObj);
                mObj.setParentContainer(tempGroup.getParentContainer());
                i--;
            }
        }
        // remove the temporary group from the contacted list, it now
        // contains only elements that were
        // in it before and were contacted by the current selection
        // rectangle
        collisionObjects.remove(tempGroup);
    }
    if (!collisionObjects.isEmpty()) {
        tempGroup.setParentContainer(collisionObjects.get(0).getParentContainer());
        collisionObjects.get(0).getParentContainer().addObject(tempGroup);
        for (MathObject mObj : collisionObjects) {
            mObj.getParentContainer().removeObject(mObj);
            mObj.setParentContainer(null);
            tempGroup.addObjectFromPage(mObj);
            mObj.setParentContainer(tempGroup);
        }
        docPanel.getDoc().refactorPageNumbers();
        docPanel.setFocusedObject(tempGroup);
    }
    if (tempGroup.getParentContainer() != null) {
        if (tempGroup.getObjects().size() == 1) {
            // there is one one object
            // left in the temporary group
            docPanel.setFocusedObject(tempGroup.getObjects().get(0));
            docPanel.ungroupTempGroup();
        }
    }
    return false;
}
Also used : Rectangle(java.awt.Rectangle) Grouping(doc.mathobjects.Grouping) MathObject(doc.mathobjects.MathObject) Vector(java.util.Vector) Point(java.awt.Point)

Example 48 with Rectangle

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

the class DocPrinter method print.

public int print(Graphics g, PageFormat pf, int page) throws PrinterException {
    Page p;
    p = doc.getPage(page);
    if (p == null) {
        return NO_SUCH_PAGE;
    }
    PageGUI pageDrawer = new PageGUI();
    Graphics2D g2d = (Graphics2D) g;
    g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    pageDrawer.drawPage(g, p, new Point(0, 0), new Rectangle(p.getWidth(), p.getHeight()), 1);
    return PAGE_EXISTS;
}
Also used : Rectangle(java.awt.Rectangle) Page(doc.Page) Point(java.awt.Point) Graphics2D(java.awt.Graphics2D)

Example 49 with Rectangle

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

the class DocViewerPanel method makeDocPanel.

private JPanel makeDocPanel() {
    return new JPanel() {

        private static final long serialVersionUID = 1L;

        @Override
        public void paint(Graphics g) {
            // TODO - Stopwatch and logging
            //				System.out.println("painting doc:" + (new java.util.Date().getTime() - notebook.timeAtStart));
            //set the graphics object to render text and shapes with smooth lines
            Graphics2D g2d = (Graphics2D) g;
            if (!OpenNotebook.isMinimalGraphicsMode()) {
                g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
            }
            //pixels needed to render a page, and the minimum border space around it
            int pageXSize = (int) (getDoc().getWidth() * zoomLevel);
            int pageYSize = (int) (getDoc().getHeight() * zoomLevel);
            Rectangle viewPortRect = new Rectangle((int) docScrollPane.getViewport().getViewPosition().getX(), (int) docScrollPane.getViewport().getViewPosition().getY(), docScrollPane.getViewport().getWidth(), docScrollPane.getViewport().getHeight());
            //fill background with gray
            g.setColor(Color.GRAY.brighter());
            ((Graphics2D) g).fill(viewPortRect);
            Rectangle currPageRect;
            Point pageOrigin = null;
            //used to store origin of the part of the page that can be seen
            //and the sections overall width and height, both are in the user space at 72 dpi
            int xShowing, yShowing, xSizeShowing, ySizeShowing;
            for (int i = 0; i < doc.getNumPages(); i++) {
                //need to modify rectangle to properly calculate the portion of the page currently displayed
                //which will be given in the user space starting with the origin of the printable area at 0,0
                //and at 72 dpi
                pageOrigin = getPageOrigin(i);
                currPageRect = new Rectangle((int) pageOrigin.getX(), (int) pageOrigin.getY(), pageXSize, pageYSize);
                if (viewPortRect.intersects(currPageRect)) {
                    //render page only if it is in the current section of the document showing
                    if (viewPortRect.getX() < currPageRect.getX()) {
                        xShowing = 0;
                    } else {
                        xShowing = (int) ((viewPortRect.getX() - currPageRect.getX()) / zoomLevel);
                    }
                    if (viewPortRect.getY() < currPageRect.getY()) {
                        yShowing = 0;
                    } else {
                        yShowing = (int) ((viewPortRect.getY() - currPageRect.getY()) / zoomLevel);
                    }
                    pageGUI.drawPageWithDecorations(g, doc.getPage(i), new Point((int) pageOrigin.getX(), (int) pageOrigin.getY()), new Rectangle(xShowing, yShowing, 10, 0), zoomLevel);
                }
            }
            if (selectionRect != null) {
                pageGUI.polygonGUI.drawMathObject(selectionRect, g2d, getPageOrigin(selectionRect.getParentPage()), zoomLevel);
            }
            g.dispose();
        }
    };
}
Also used : Graphics(java.awt.Graphics) JPanel(javax.swing.JPanel) Rectangle(java.awt.Rectangle) Point(java.awt.Point) Point(java.awt.Point) Graphics2D(java.awt.Graphics2D)

Example 50 with Rectangle

use of java.awt.Rectangle in project jna by java-native-access.

the class AlphaMaskDemo method centerOnScreen.

/** Center the given {@link Window} on the default screen. */
private static void centerOnScreen(Window window) {
    Point center = GraphicsEnvironment.getLocalGraphicsEnvironment().getCenterPoint();
    Rectangle max = GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds();
    int x = Math.max(center.x - Math.round(window.getWidth() / 2f), max.x);
    int y = Math.max(center.y - Math.round(window.getHeight() / 2f), max.y);
    window.setLocation(new Point(x, y));
}
Also used : Rectangle(java.awt.Rectangle) Point(java.awt.Point) Point(java.awt.Point)

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