Search in sources :

Example 31 with Rectangle

use of java.awt.Rectangle in project darkFunction-Editor by darkFunction.

the class GraphicPanel method addGraphic.

public void addGraphic(GraphicObject aGraphic) {
    if (aGraphic.getAnchor() == GraphicObject.Anchor.CENTRE) {
        Rectangle r = aGraphic.getRect();
        r.x -= r.width / 2;
        r.y -= r.height / 2;
        aGraphic.saveRect();
    }
    // add to top
    _drawStack.add(0, aGraphic);
    aGraphic.setBounds(_graphicBounds);
    repaint();
    _lastAddedGraphic = aGraphic;
    for (int i = 0; i < _changeListeners.size(); ++i) {
        _changeListeners.get(i).graphicAdded(this, aGraphic);
    }
}
Also used : Rectangle(java.awt.Rectangle) Point(java.awt.Point)

Example 32 with Rectangle

use of java.awt.Rectangle in project darkFunction-Editor by darkFunction.

the class GridGraphicPanel method dropGraphic.

@Override
protected void dropGraphic(GraphicObject aGraphic, boolean aUndoable) {
    Rectangle bounds = this.getGraphicsBounds();
    if (bounds == null) {
        bounds = new Rectangle(0, 0, this.getSize().width, this.getSize().height);
    }
    Dimension padding = this.padding;
    if (padding == null)
        padding = new Dimension(0, 0);
    Rectangle r = aGraphic.getRect();
    if (this.tileSize != null) {
        Dimension total = new Dimension(tileSize.width + padding.width, tileSize.height + padding.height);
        Point currentCentre = new Point(r.x + r.width / 2, r.y + r.height / 2);
        Point closestPoint = new Point((currentCentre.x - (Math.abs(currentCentre.x) % total.width)) + (total.width / 2), (currentCentre.y - (Math.abs(currentCentre.y) % total.height)) + (total.height / 2));
        aGraphic.setRect(new Rectangle(closestPoint.x - r.width / 2, closestPoint.y - r.height / 2, r.width, r.height));
    }
    super.dropGraphic(aGraphic, aUndoable);
}
Also used : Rectangle(java.awt.Rectangle) Dimension(java.awt.Dimension) Point(java.awt.Point)

Example 33 with Rectangle

use of java.awt.Rectangle in project darkFunction-Editor by darkFunction.

the class GraphicPanel method mouseDragged.

public void mouseDragged(MouseEvent evt) {
    if (_lastClickPoint == null)
        return;
    Point p = evt.getPoint();
    Point dist = new Point(p.x - _lastClickPoint.x, p.y - _lastClickPoint.y);
    switch(_mouseButtonPressed) {
        case DRAG_BUTTON:
        case DRAG_BUTTON_2:
            {
                moveContent(dist, _lastOrigin);
            }
            break;
        case SELECT_BUTTON:
            {
                if (System.getProperty("os.name").startsWith("Mac OS X") && (evt.getModifiers() & ActionEvent.META_MASK) != 0) {
                    moveContent(dist, _lastOrigin);
                    break;
                }
                if (!_bAllowsEditing)
                    break;
                if (_resizingGraphic != null && _resizeDirection != Compass.NONE) {
                    Point resizeDist = MathUtil.dividePoint(dist, _zoom);
                    _resizingGraphic.resizeFromSavedPoint(resizeDist, _resizeDirection);
                } else if (_multiSelectRect != null) {
                    int topX = Math.min(p.x, _lastClickPoint.x);
                    int topY = Math.min(p.y, _lastClickPoint.y);
                    int bottomX = Math.max(p.x, _lastClickPoint.x);
                    int bottomY = Math.max(p.y, _lastClickPoint.y);
                    _multiSelectRect = new Rectangle(topX, topY, bottomX - topX, bottomY - topY);
                } else {
                    for (int i = 0; i < _drawStack.size(); ++i) {
                        GraphicObject graphic = _drawStack.get(i);
                        if (graphic.isSelected()) {
                            graphic.moveFromSavedPoint(MathUtil.dividePoint(dist, _zoom));
                        }
                    }
                }
            }
            break;
    }
    repaint();
}
Also used : Rectangle(java.awt.Rectangle) Point(java.awt.Point) Point(java.awt.Point)

Example 34 with Rectangle

use of java.awt.Rectangle in project darkFunction-Editor by darkFunction.

the class GraphicPanel method topGraphicAtPosition.

protected GraphicObject topGraphicAtPosition(Point aPoint) {
    for (int i = 0; i < _drawStack.size(); ++i) {
        GraphicObject graphic = _drawStack.get(i);
        Rectangle r = convertRectToViewRect(graphic.getRect());
        if (MathUtil.pointRectCollide(aPoint, r)) {
            return graphic;
        }
    }
    return null;
}
Also used : Rectangle(java.awt.Rectangle) Point(java.awt.Point)

Example 35 with Rectangle

use of java.awt.Rectangle in project darkFunction-Editor by darkFunction.

the class GraphicPanel method drawCheckerBoardBuffer.

protected void drawCheckerBoardBuffer(final Graphics g, final Rectangle aRect) {
    if (_checkerBoard == null)
        _checkerBoard = this.makeCheckerBoardBuffer(new Rectangle(0, 0, 256, 256));
    g.clipRect(aRect.x, aRect.y, aRect.width, aRect.height);
    for (int x = aRect.x; x < aRect.x + aRect.width; ++x) {
        for (int y = aRect.y; y < aRect.y + aRect.height; ++y) {
            g.drawImage(_checkerBoard, x, y, null);
            y += _checkerBoard.getHeight() - 1;
        }
        x += _checkerBoard.getWidth() - 1;
    }
    g.setClip(0, 0, this.getWidth(), this.getHeight());
}
Also used : Rectangle(java.awt.Rectangle) 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