Java Code Examples for java.awt.Rectangle#setLocation()

The following examples show how to use java.awt.Rectangle#setLocation() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: ghidra   File: AbstractDockingTest.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Creates a png of the given component <b>by capturing a screenshot of the image</b>.  This
 * differs from creating the image by rendering it via a {@link Graphics} object.
 *
 * @param c the component
 * @return the new image
 * @throws AWTException if there is a problem creating the image
 */
public static Image createScreenImage(Component c) throws AWTException {

	yieldToSwing();

	Rectangle r = c.getBounds();
	Point p = r.getLocation();
	if (!(c instanceof Window)) {
		SwingUtilities.convertPointToScreen(p, c.getParent());
	}
	r.setLocation(p);
	Robot robot = new Robot();
	sleep(100);
	Image image = robot.createScreenCapture(r);
	sleep(100);
	return image;
}
 
Example 2
Source Project: GVGAI_GYM   File: VGDLSprite.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Overwritting intersects to check if we are on ground.
 * @return true if it directly intersects with sp (as in the normal case), but additionally checks for on_ground condition.
 */
public boolean groundIntersects (VGDLSprite sp)
{
    boolean normalIntersect = this.rect.intersects(sp.rect);

    boolean otherHigher = sp.lastrect.getMinY() > (this.lastrect.getMinY()+(this.rect.height/2));
    boolean goingDown = this.rect.getMinY() > this.lastrect.getMinY();

    if(!on_ground && sp.solid)
    {
        //No need to keep checking. Actually, we shouldn't (we won't intersect with all sprites!).
        Rectangle test_rect = new Rectangle(this.rect);
        test_rect.setLocation(this.rect.x,this.rect.y+3);

        this.on_ground = test_rect.intersects(sp.rect) && otherHigher && goingDown;
    }


    return normalIntersect;
}
 
Example 3
/**
 * Draw the entity.
 *
 * @param g2d
 *            The graphics to drawn on.
 */
@Override
public void draw(final Graphics2D g2d) {
	applyChanges();

	final Rectangle r = getDrawingArea();

	if (isContained()) {
		r.setLocation(0, 0);
	} else {
		if (!isOnScreen(g2d, r)) {
			return;
		}
	}

	final Composite oldComposite = g2d.getComposite();

	try {
		g2d.setComposite(entityComposite);
		draw(g2d, r.x, r.y, r.width, r.height);
	} finally {
		g2d.setComposite(oldComposite);
	}
}
 
Example 4
public WreckSprite(BoardView1 boardView1, final Entity entity, int secondaryPos) {
    super(boardView1);
    this.entity = entity;
    this.secondaryPos = secondaryPos;

    String shortName = entity.getShortName();

    Font font = new Font("SansSerif", Font.PLAIN, 10); //$NON-NLS-1$
    modelRect = new Rectangle(47, 55, bv.getFontMetrics(font).stringWidth(
            shortName) + 1, bv.getFontMetrics(font).getAscent());
    Rectangle tempBounds = new Rectangle(bv.hex_size).union(modelRect);
    if (secondaryPos == -1) {
        tempBounds.setLocation(bv.getHexLocation(entity.getPosition()));
    } else {
        tempBounds.setLocation(bv.getHexLocation(entity
                .getSecondaryPositions().get(secondaryPos)));
    }

    bounds = tempBounds;
    image = null;
}
 
Example 5
Source Project: netbeans   File: QuickSearchPopup.java    License: Apache License 2.0 6 votes vote down vote up
private void computePopupBounds (Rectangle result, JLayeredPane lPane, int modelSize) {
    Dimension cSize = comboBar.getSize();
    int width = getPopupWidth();
    Point location = new Point(cSize.width - width - 1, comboBar.getBottomLineY() - 1);
    if (SwingUtilities.getWindowAncestor(comboBar) != null) {
        location = SwingUtilities.convertPoint(comboBar, location, lPane);
    }
    result.setLocation(location);

    // hack to make jList.getpreferredSize work correctly
    // JList is listening on ResultsModel same as us and order of listeners
    // is undefined, so we have to force update of JList's layout data
    jList1.setFixedCellHeight(15);
    jList1.setFixedCellHeight(-1);
    // end of hack

    jList1.setVisibleRowCount(modelSize);
    Dimension preferredSize = jList1.getPreferredSize();

    preferredSize.width = width;
    preferredSize.height += statusPanel.getPreferredSize().height + 3;

    result.setSize(preferredSize);
}
 
Example 6
/**
 * Draw the top layer parts of an entity. This will be on down after all
 * other game layers are rendered.
 *
 * @param g2d
 *            The graphics to drawn on.
 */
@Override
public void drawTop(final Graphics2D g2d) {
	final Rectangle r = getArea();

	if (isContained()) {
		r.setLocation(0, 0);
	} else {
		if (!isOnScreen(g2d, r)) {
			return;
		}
	}

	final Composite oldComposite = g2d.getComposite();

	try {
		g2d.setComposite(entityComposite);
		drawTop(g2d, r.x, r.y, r.width, r.height);
	} finally {
		g2d.setComposite(oldComposite);
	}
}
 
Example 7
void setContentBounds(WindowDimensions dims) {
    XToolkit.awtLock();
    try {
        // Bounds of content window are of the same size as bounds of Java window and with
        // location as -(insets)
        Rectangle newBounds = dims.getBounds();
        Insets in = dims.getInsets();
        if (in != null) {
            newBounds.setLocation(-in.left, -in.top);
        }
        if (insLog.isLoggable(PlatformLogger.Level.FINE)) {
            insLog.fine("Setting content bounds {0}, old bounds {1}",
                        newBounds, getBounds());
        }
        // Fix for 5023533:
        // Change in the size of the content window means, well, change of the size
        // Change in the location of the content window means change in insets
        boolean needHandleResize = !(newBounds.equals(getBounds()));
        boolean needPaint = width <= 0 || height <= 0;
        reshape(newBounds);
        if (needHandleResize) {
            insLog.fine("Sending RESIZED");
            handleResize(newBounds);
        }
        if (needPaint) {
            postPaintEvent(target, 0, 0, newBounds.width, newBounds.height);
        }
    } finally {
        XToolkit.awtUnlock();
    }
}
 
Example 8
void setContentBounds(WindowDimensions dims) {
    XToolkit.awtLock();
    try {
        // Bounds of content window are of the same size as bounds of Java window and with
        // location as -(insets)
        Rectangle newBounds = dims.getBounds();
        Insets in = dims.getInsets();
        if (in != null) {
            newBounds.setLocation(-in.left, -in.top);
        }
        if (insLog.isLoggable(PlatformLogger.Level.FINE)) {
            insLog.fine("Setting content bounds {0}, old bounds {1}",
                        newBounds, getBounds());
        }
        // Fix for 5023533:
        // Change in the size of the content window means, well, change of the size
        // Change in the location of the content window means change in insets
        boolean needHandleResize = !(newBounds.equals(getBounds()));
        reshape(newBounds);
        if (needHandleResize) {
            insLog.fine("Sending RESIZED");
            handleResize(newBounds);
        }
    } finally {
        XToolkit.awtUnlock();
    }
    validateSurface();
}
 
Example 9
public void performSelection(Rectangle rectangle) {

        if (rectangle.width < 0) {
            rectangle.x += rectangle.width;
            rectangle.width *= -1;
        }

        if (rectangle.height < 0) {
            rectangle.y += rectangle.height;
            rectangle.height *= -1;
        }

        boolean changed = false;
        for (InputBlock b : this.getNodes()) {
            BlockWidget w = (BlockWidget) findWidget(b);
            Rectangle r = new Rectangle(w.getBounds());
            r.setLocation(w.getLocation());
            if (r.intersects(rectangle)) {
                if (!selection.contains(w)) {
                    changed = true;
                    selection.add(w);
                    w.setState(w.getState().deriveSelected(true));
                }
            } else {
                if (selection.contains(w)) {
                    changed = true;
                    selection.remove(w);
                    w.setState(w.getState().deriveSelected(false));
                }
            }
        }

        if (changed) {
            selectionChanged();
        }

    }
 
Example 10
public void performSelection(Rectangle rectangle) {

        if (rectangle.width < 0) {
            rectangle.x += rectangle.width;
            rectangle.width *= -1;
        }

        if (rectangle.height < 0) {
            rectangle.y += rectangle.height;
            rectangle.height *= -1;
        }

        boolean changed = false;
        for (InputBlock b : this.getNodes()) {
            BlockWidget w = (BlockWidget) findWidget(b);
            Rectangle r = new Rectangle(w.getBounds());
            r.setLocation(w.getLocation());
            if (r.intersects(rectangle)) {
                if (!selection.contains(w)) {
                    changed = true;
                    selection.add(w);
                    w.setState(w.getState().deriveSelected(true));
                }
            } else {
                if (selection.contains(w)) {
                    changed = true;
                    selection.remove(w);
                    w.setState(w.getState().deriveSelected(false));
                }
            }
        }

        if (changed) {
            selectionChanged();
        }

    }
 
Example 11
void setContentBounds(WindowDimensions dims) {
    XToolkit.awtLock();
    try {
        // Bounds of content window are of the same size as bounds of Java window and with
        // location as -(insets)
        Rectangle newBounds = dims.getBounds();
        Insets in = dims.getInsets();
        if (in != null) {
            newBounds.setLocation(-in.left, -in.top);
        }
        if (insLog.isLoggable(PlatformLogger.Level.FINE)) {
            insLog.fine("Setting content bounds {0}, old bounds {1}",
                        newBounds, getBounds());
        }
        // Fix for 5023533:
        // Change in the size of the content window means, well, change of the size
        // Change in the location of the content window means change in insets
        boolean needHandleResize = !(newBounds.equals(getBounds()));
        reshape(newBounds);
        if (needHandleResize) {
            insLog.fine("Sending RESIZED");
            handleResize(newBounds);
        }
    } finally {
        XToolkit.awtUnlock();
    }
    validateSurface();
}
 
Example 12
@Override
public Rectangle getBounds() {

    Dimension dim = new Dimension(bv.hex_size.width, 
            bv.hex_size.height);
    bounds = new Rectangle(dim);
    bounds.setLocation(this.bv.getHexLocation(flare.position));

    return bounds;
}
 
Example 13
public void performSelection(Rectangle rectangle) {

        if (rectangle.width < 0) {
            rectangle.x += rectangle.width;
            rectangle.width *= -1;
        }

        if (rectangle.height < 0) {
            rectangle.y += rectangle.height;
            rectangle.height *= -1;
        }

        boolean changed = false;
        for (InputBlock b : this.getNodes()) {
            BlockWidget w = (BlockWidget) findWidget(b);
            Rectangle r = new Rectangle(w.getBounds());
            r.setLocation(w.getLocation());
            if (r.intersects(rectangle)) {
                if (!selection.contains(w)) {
                    changed = true;
                    selection.add(w);
                    w.setState(w.getState().deriveSelected(true));
                }
            } else {
                if (selection.contains(w)) {
                    changed = true;
                    selection.remove(w);
                    w.setState(w.getState().deriveSelected(false));
                }
            }
        }

        if (changed) {
            selectionChanged();
        }

    }
 
Example 14
public GhostEntitySprite(BoardView1 boardView1, final Entity entity) {
    super(boardView1);
    this.entity = entity;

    String shortName = entity.getShortName();
    Font font = new Font("SansSerif", Font.PLAIN, 10); //$NON-NLS-1$
    modelRect = new Rectangle(47, 55, bv.getFontMetrics(font).stringWidth(
            shortName) + 1, bv.getFontMetrics(font).getAscent());
    Rectangle tempBounds = new Rectangle(bv.hex_size).union(modelRect);
    tempBounds.setLocation(bv.getHexLocation(entity.getPosition()));

    bounds = tempBounds;
    image = null;
}
 
Example 15
public void performSelection(Rectangle rectangle) {

        if (rectangle.width < 0) {
            rectangle.x += rectangle.width;
            rectangle.width *= -1;
        }

        if (rectangle.height < 0) {
            rectangle.y += rectangle.height;
            rectangle.height *= -1;
        }

        boolean changed = false;
        for (InputBlock b : this.getNodes()) {
            BlockWidget w = (BlockWidget) findWidget(b);
            Rectangle r = new Rectangle(w.getBounds());
            r.setLocation(w.getLocation());
            if (r.intersects(rectangle)) {
                if (!selection.contains(w)) {
                    changed = true;
                    selection.add(w);
                    w.setState(w.getState().deriveSelected(true));
                }
            } else {
                if (selection.contains(w)) {
                    changed = true;
                    selection.remove(w);
                    w.setState(w.getState().deriveSelected(false));
                }
            }
        }

        if (changed) {
            selectionChanged();
        }

    }
 
Example 16
public IsometricSprite(BoardView1 boardView1, Entity entity, int secondaryPos, Image radarBlipImage) {
    super(boardView1);
    this.entity = entity;
    this.radarBlipImage = radarBlipImage;
    this.secondaryPos = secondaryPos;
    String shortName = entity.getShortName();
    Font font = new Font("SansSerif", Font.PLAIN, 10); //$NON-NLS-1$
    modelRect = new Rectangle(47, 55, bv.getFontMetrics(font).stringWidth(
            shortName) + 1, bv.getFontMetrics(font).getAscent());

    int altAdjust = 0;
    if (bv.useIsometric()
            && (entity.isAirborne() || entity.isAirborneVTOLorWIGE())) {
        altAdjust = (int) (bv.DROPSHDW_DIST * bv.scale);
    } else if (bv.useIsometric() && (entity.getElevation() != 0)
            && !(entity instanceof GunEmplacement)) {
        altAdjust = (int) (entity.getElevation() * BoardView1.HEX_ELEV * bv.scale);
    }

    Dimension dim = new Dimension(bv.hex_size.width, bv.hex_size.height
            + altAdjust);
    Rectangle tempBounds = new Rectangle(dim).union(modelRect);

    if (secondaryPos == -1) {
        tempBounds.setLocation(bv.getHexLocation(entity.getPosition()));
    } else {
        tempBounds.setLocation(bv.getHexLocation(entity
                .getSecondaryPositions().get(secondaryPos)));
    }
    if (entity.getElevation() > 0) {
        tempBounds.y = tempBounds.y - altAdjust;
    }
    bounds = tempBounds;
    image = null;
}
 
Example 17
@Override
public Rectangle getBounds() {
    // Start with the hex and add the label
    bounds = new Rectangle(0,0,bv.hex_size.width, bv.hex_size.height);
    updateLabel();
    bounds.add(labelRect);
    // Add space for 4 little status boxes
    if (labelPos == Positioning.RIGHT) {
        bounds.add(-4*(labelRect.height+2)+labelRect.x, labelRect.y);
    } else {
        bounds.add(4*(labelRect.height+2)+labelRect.x+labelRect.width, labelRect.y);
    }

    // Move to board position, save this origin for correct drawing
    hexOrigin = bounds.getLocation();
    Point ePos;
    if (secondaryPos == -1) {
        ePos = bv.getHexLocation(entity.getPosition());
    } else {
        ePos = bv.getHexLocation(entity.getSecondaryPositions().get(secondaryPos));
    }
    bounds.setLocation(hexOrigin.x + ePos.x, hexOrigin.y + ePos.y);
    
    entityRect = new Rectangle(bounds.x + (int) (20 * bv.scale), bounds.y
            + (int) (14 * bv.scale), (int) (44 * bv.scale),
            (int) (44 * bv.scale));

    return bounds;
}
 
Example 18
Source Project: javamoney-examples   File: BoundsHelper.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * This method creates and returns bounds.
 *
 * @param width The width of the bounds.
 * @param height The height of the bounds.
 * @param area The area to center the bounds to.
 *
 * @return Bounds.
 */
public
static
Rectangle
createCenteredBounds(int width, int height, Rectangle area)
{
  Rectangle rectangle = new Rectangle(0, 0, width, height);
  int x = area.x + (area.width / 2);
  int y = area.y + (area.height / 2);

  rectangle.setLocation(x - (width / 2), y - (height / 2));

  return rectangle;
}
 
Example 19
Source Project: pdfxtk   File: Awt.java    License: Apache License 2.0 4 votes vote down vote up
public static Point place(Rectangle rectToPlace, int x, int y, Rectangle outerLimit) {
  rectToPlace.setLocation(x - rectToPlace.width / 2, y - rectToPlace.height / 2);
  return fitSmallerIntoBigger(rectToPlace.x, rectToPlace.y, rectToPlace.width, rectToPlace.height, outerLimit);
}
 
Example 20
/**
 * Calculate interpolated bounds based on the initial and final bounds,
 * and the state of progress.
 *
 * @param startBounds initial bounds
 * @param finalBounds final bounds
 * @param progress state of progress
 * @return interpolated bounds
 */
private Rectangle interpolate(Rectangle startBounds, Rectangle finalBounds, double progress) {
	Rectangle bounds = new Rectangle();
	bounds.setLocation(interpolate(startBounds.getLocation(), finalBounds.getLocation(), progress));
	bounds.setSize(interpolate(startBounds.getSize(), finalBounds.getSize(), progress));

	return bounds;
}