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

The following examples show how to use java.awt.Rectangle#translate() . 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 File: XWM.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
static void setShellResizable(XDecoratedPeer window) {
    if (insLog.isLoggable(PlatformLogger.Level.FINE)) {
        insLog.fine("Setting shell resizable " + window);
    }
    XToolkit.awtLock();
    try {
        Rectangle shellBounds = window.getShellBounds();
        shellBounds.translate(-window.currentInsets.left, -window.currentInsets.top);
        window.updateSizeHints(window.getDimensions());
        requestWMExtents(window.getWindow());
        XlibWrapper.XMoveResizeWindow(XToolkit.getDisplay(), window.getShell(),
                                      shellBounds.x, shellBounds.y, shellBounds.width, shellBounds.height);
        /* REMINDER: will need to revisit when setExtendedStateBounds is added */
        //Fix for 4320050: Minimum size for java.awt.Frame is not being enforced.
        //We need to update frame's minimum size, not to reset it
        removeSizeHints(window, XUtilConstants.PMaxSize);
        window.updateMinimumSize();

        /* Restore decorations */
        setShellDecor(window);
    } finally {
        XToolkit.awtUnlock();
    }
}
 
Example 2
Source File: ElementOverlayPainter.java    From bboxdb with Apache License 2.0 6 votes vote down vote up
/**
 * Repaint the given area
 * @param mapViewer
 * @param bbox
 */
public boolean markRegionAsDirty(final OverlayElementGroup overlayElementGroup) {
	
	if(overlayElementGroup.getNumberOfOverlays() == 0) {
		return false;
	}
	
	final Rectangle bbox = new Rectangle(overlayElementGroup.getOverlay(0).getBBoxToDrawOnGui());
	
	for(final OverlayElement element : overlayElementGroup) {
		bbox.add(element.getDirtyPixel());
	}
	
	final Rectangle rect = mapViewer.getViewportBounds();
	
	bbox.translate((int) -rect.getX(), (int) -rect.getY());
	
	if(EventQueue.isDispatchThread()) {
		mapViewer.repaint(bbox);
	} else {
		SwingUtilities.invokeLater(() -> mapViewer.repaint(bbox));
	}

	return true;
}
 
Example 3
Source File: SunGraphics2D.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
protected static Shape transformShape(int tx, int ty, Shape s) {
    if (s == null) {
        return null;
    }

    if (s instanceof Rectangle) {
        Rectangle r = s.getBounds();
        r.translate(tx, ty);
        return r;
    }
    if (s instanceof Rectangle2D) {
        Rectangle2D rect = (Rectangle2D) s;
        return new Rectangle2D.Double(rect.getX() + tx,
                                      rect.getY() + ty,
                                      rect.getWidth(),
                                      rect.getHeight());
    }

    if (tx == 0 && ty == 0) {
        return cloneShape(s);
    }

    AffineTransform mat = AffineTransform.getTranslateInstance(tx, ty);
    return mat.createTransformedShape(s);
}
 
Example 4
Source File: AlternateChaser.java    From GVGAI_GYM with Apache License 2.0 6 votes vote down vote up
protected void movesToward(VGDLSprite target)
{
    double distance = this.physics.distance(rect, target.rect);
    for(Direction act : Types.DBASEDIRS)
    {
        //Calculate the distance if I'd apply this move.
        Rectangle r = new Rectangle(this.rect);
        r.translate((int)act.x(), (int)act.y());
        double newDist = this.physics.distance(r, target.rect);

        //depending on getting me closer/farther, if I'm fleeing/chasing, add move:
        if(fleeing && distance<newDist)
            actions.add(act);
        if(!fleeing && distance>newDist)
            actions.add(act);
    }
}
 
Example 5
Source File: ProfilerTableHover.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private void showPopup(Painter p, Rectangle rect) {
    mouse.deinstall();
    
    Point l = table.getLocationOnScreen();
    
    rect.translate(l.x, l.y);
    popupRect = rect;
    popupLocation = new Point(l.x + p.getX(), l.y + p.getY());
    
    PopupFactory popupFactory = PopupFactory.getSharedInstance();
    popup = popupFactory.getPopup(table, p, popupLocation.x, popupLocation.y);
    popup.show();
    
    paranoid = new Paranoid(p);
    paranoid.install();
    
    awt = new AWT();
    awt.install();
}
 
Example 6
Source File: XWM.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
static void setShellResizable(XDecoratedPeer window) {
    if (insLog.isLoggable(PlatformLogger.Level.FINE)) {
        insLog.fine("Setting shell resizable " + window);
    }
    XToolkit.awtLock();
    try {
        Rectangle shellBounds;
        if (getWMID() != UNITY_COMPIZ_WM) {
            shellBounds = window.getShellBounds();
            shellBounds.translate(-window.currentInsets.left,
                                  -window.currentInsets.top);
        } else {
            shellBounds = window.getDimensions().getScreenBounds();
        }
        window.updateSizeHints(window.getDimensions());
        requestWMExtents(window.getWindow());
        XlibWrapper.XMoveResizeWindow(XToolkit.getDisplay(),
                                      window.getShell(),
                                      window.scaleUp(shellBounds.x),
                                      window.scaleUp(shellBounds.y),
                                      window.scaleUp(shellBounds.width),
                                      window.scaleUp(shellBounds.height));
        /* REMINDER: will need to revisit when setExtendedStateBounds is added */
        //Fix for 4320050: Minimum size for java.awt.Frame is not being enforced.
        //We need to update frame's minimum size, not to reset it
        removeSizeHints(window, XUtilConstants.PMaxSize);
        window.updateMinimumSize();

        /* Restore decorations */
        setShellDecor(window);
    } finally {
        XToolkit.awtUnlock();
    }
}
 
Example 7
Source File: CustomComponent.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
public static Region getRegionOfInterest(SurfaceData src, SurfaceData dst,
                                         Region clip,
                                         int srcx, int srcy,
                                         int dstx, int dsty,
                                         int w, int h)
{
    /*
     * Intersect all of:
     *   - operation area (dstx, dsty, w, h)
     *   - destination bounds
     *   - (translated) src bounds
     *   - supplied clip (may be non-rectangular)
     * Intersect the rectangular regions first since those are
     * simpler operations.
     */
    Region ret = Region.getInstanceXYWH(dstx, dsty, w, h);
    ret = ret.getIntersection(dst.getBounds());
    Rectangle r = src.getBounds();
    // srcxy in src space maps to dstxy in dst space
    r.translate(dstx - srcx, dsty - srcy);
    ret = ret.getIntersection(r);
    if (clip != null) {
        // Intersect with clip last since it may be non-rectangular
        ret = ret.getIntersection(clip);
    }
    return ret;
}
 
Example 8
Source File: LWContainerPeer.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Paints all the child peers in the straight z-order, so the
 * bottom-most ones are painted first.
 */
private void repaintChildren(final Rectangle r) {
    final Rectangle content = getContentSize();
    for (final LWComponentPeer<?, ?> child : getChildren()) {
        final Rectangle childBounds = child.getBounds();
        Rectangle toPaint = r.intersection(childBounds);
        toPaint = toPaint.intersection(content);
        toPaint.translate(-childBounds.x, -childBounds.y);
        child.repaintPeer(toPaint);
    }
}
 
Example 9
Source File: ViewTooltips.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * Show popups for each rectangle, using the now configured painter.
 */
private void showPopups(Rectangle[] rects, Rectangle bds, Rectangle visible, JComponent comp, JScrollPane view) {
    boolean shown = false;
    for (int i=0; i < rects.length; i++) {
        Rectangle sect = rects[i];
        sect.translate (-bds.x, -bds.y);
        ImgComp part = painter.getPartial(sect, bds.x + rects[i].x < visible.x);
        Point pos = new Point (bds.x + rects[i].x, bds.y + rects[i].y);
        SwingUtilities.convertPointToScreen(pos, comp);
        if (comp instanceof JList) {
            //XXX off by one somewhere, only with JLists - where?
            pos.y--;
        }
        if (pos.x > 0) { //Mac OS will reposition off-screen popups to x=0,
            //so don't try to show them
            popups[i] = getPopupFactory().getPopup(view, 
                    part, pos.x, pos.y);
            popups[i].show();
            shown = true;
        }
    }
    if (shown) {
        setHideComponent (comp, view);
    } else {
        setHideComponent (null, null); //clear references
    }
}
 
Example 10
Source File: CustomComponent.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
public static Region getRegionOfInterest(SurfaceData src, SurfaceData dst,
                                         Region clip,
                                         int srcx, int srcy,
                                         int dstx, int dsty,
                                         int w, int h)
{
    /*
     * Intersect all of:
     *   - operation area (dstx, dsty, w, h)
     *   - destination bounds
     *   - (translated) src bounds
     *   - supplied clip (may be non-rectangular)
     * Intersect the rectangular regions first since those are
     * simpler operations.
     */
    Region ret = Region.getInstanceXYWH(dstx, dsty, w, h);
    ret = ret.getIntersection(dst.getBounds());
    Rectangle r = src.getBounds();
    // srcxy in src space maps to dstxy in dst space
    r.translate(dstx - srcx, dsty - srcy);
    ret = ret.getIntersection(r);
    if (clip != null) {
        // Intersect with clip last since it may be non-rectangular
        ret = ret.getIntersection(clip);
    }
    return ret;
}
 
Example 11
Source File: LWContainerPeer.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Paints all the child peers in the straight z-order, so the
 * bottom-most ones are painted first.
 */
private void repaintChildren(final Rectangle r) {
    final Rectangle content = getContentSize();
    for (final LWComponentPeer<?, ?> child : getChildren()) {
        final Rectangle childBounds = child.getBounds();
        Rectangle toPaint = r.intersection(childBounds);
        toPaint = toPaint.intersection(content);
        toPaint.translate(-childBounds.x, -childBounds.y);
        child.repaintPeer(toPaint);
    }
}
 
Example 12
Source File: CustomComponent.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
public static Region getRegionOfInterest(SurfaceData src, SurfaceData dst,
                                         Region clip,
                                         int srcx, int srcy,
                                         int dstx, int dsty,
                                         int w, int h)
{
    /*
     * Intersect all of:
     *   - operation area (dstx, dsty, w, h)
     *   - destination bounds
     *   - (translated) src bounds
     *   - supplied clip (may be non-rectangular)
     * Intersect the rectangular regions first since those are
     * simpler operations.
     */
    Region ret = Region.getInstanceXYWH(dstx, dsty, w, h);
    ret = ret.getIntersection(dst.getBounds());
    Rectangle r = src.getBounds();
    // srcxy in src space maps to dstxy in dst space
    r.translate(dstx - srcx, dsty - srcy);
    ret = ret.getIntersection(r);
    if (clip != null) {
        // Intersect with clip last since it may be non-rectangular
        ret = ret.getIntersection(clip);
    }
    return ret;
}
 
Example 13
Source File: SourceClippingBlitTest.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
public void runTests() {
        GraphicsConfiguration gc = getGraphicsConfiguration();
        for (Image srcIm :
            new Image[] {
                getBufferedImage(gc, IMAGEW, IMAGEH,
                        BufferedImage.TYPE_INT_RGB, true),
                getBufferedImage(gc, IMAGEW, IMAGEH,
                        BufferedImage.TYPE_INT_RGB, false),
                // commented out due to 6593406
//                getBMImage(gc, IMAGEW, IMAGEH),
//                getBufferedImage(gc, IMAGEW, IMAGEH,
//                        BufferedImage.TYPE_INT_ARGB, true),
//                getBufferedImage(gc, IMAGEW, IMAGEH,
//                        BufferedImage.TYPE_INT_ARGB, false),
                getVImage(gc, IMAGEW, IMAGEH),
            })
        {
            System.out.println("Testing source: " + srcIm);
            // wiggle the source and dest rectangles
            try {
                for (int locationVar = -10; locationVar < 20; locationVar += 10)
                {
                    for (int sizeVar = -10; sizeVar < 20; sizeVar += 10) {
                        Rectangle srcRect = (Rectangle)IMAGE_BOUNDS.clone();
                        srcRect.translate(locationVar, locationVar);
                        srcRect.grow(sizeVar, sizeVar);

                        Rectangle dstRect =
                                new Rectangle(sizeVar, sizeVar,
                                srcRect.width, srcRect.height);
                        System.out.println("testing blit rect src: " + srcRect);
                        System.out.println("                  dst: " + dstRect);
                        render(getGraphics(), srcIm, srcRect, dstRect);
                        test(srcRect, dstRect);
                    }
                }
                System.out.println("Test passed.");
            } finally {
                synchronized (lock) {
                    done = true;
                    lock.notifyAll();
                }
            }
        }
    }
 
Example 14
Source File: SourceClippingBlitTest.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
public void test(Rectangle srcRect, Rectangle dstRect) {
    int w = getWidth();
    int h = getHeight();
    Toolkit.getDefaultToolkit().sync();
    try {
        Thread.sleep(2000);
    } catch (InterruptedException ex) {}
    Point p = getLocationOnScreen();
    grabbedBI = robot.createScreenCapture(new Rectangle(p.x, p.y, w, h));

    // calculate the destination rectangle
    Rectangle srcBounds = srcRect.intersection(IMAGE_BOUNDS);
    int trX = dstRect.x - srcRect.x;
    int trY = dstRect.y - srcRect.y;
    Rectangle newDstRect = (Rectangle)dstRect.clone();
    newDstRect.translate(-trX, -trY);
    Rectangle.intersect(newDstRect, srcBounds, newDstRect);
    newDstRect.translate(trX, trY);
    Rectangle.intersect(newDstRect, new Rectangle(0, 0, w, h), newDstRect);

    System.out.println("calculated dest rect:" + newDstRect);

    // we do implicit clipping of the destination surface
    // by only checking pixels within its bounds
    for (int y = 0; y < h; y++) {
        for (int x = 0; x < w; x++) {
            int rgb = 0;
            if (newDstRect.contains(x, y)) {
                rgb = Color.red.getRGB();
            } else {
                rgb = Color.green.getRGB();
            }
            if (grabbedBI.getRGB(x, y) != rgb) {
                String msg1 = "Test failed at x="+x+" y="+y;
                System.out.println(msg1);
                System.out.println(" expected: "+Integer.toHexString(rgb)+
                        " got:"+Integer.toHexString(grabbedBI.getRGB(x, y)));
                throw new RuntimeException(msg1);
            }
        }
    }
    System.out.println("subtest passed");
}
 
Example 15
Source File: SourceClippingBlitTest.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
public void runTests() {
        GraphicsConfiguration gc = getGraphicsConfiguration();
        for (Image srcIm :
            new Image[] {
                getBufferedImage(gc, IMAGEW, IMAGEH,
                        BufferedImage.TYPE_INT_RGB, true),
                getBufferedImage(gc, IMAGEW, IMAGEH,
                        BufferedImage.TYPE_INT_RGB, false),
                // commented out due to 6593406
//                getBMImage(gc, IMAGEW, IMAGEH),
//                getBufferedImage(gc, IMAGEW, IMAGEH,
//                        BufferedImage.TYPE_INT_ARGB, true),
//                getBufferedImage(gc, IMAGEW, IMAGEH,
//                        BufferedImage.TYPE_INT_ARGB, false),
                getVImage(gc, IMAGEW, IMAGEH),
            })
        {
            System.out.println("Testing source: " + srcIm);
            // wiggle the source and dest rectangles
            try {
                for (int locationVar = -10; locationVar < 20; locationVar += 10)
                {
                    for (int sizeVar = -10; sizeVar < 20; sizeVar += 10) {
                        Rectangle srcRect = (Rectangle)IMAGE_BOUNDS.clone();
                        srcRect.translate(locationVar, locationVar);
                        srcRect.grow(sizeVar, sizeVar);

                        Rectangle dstRect =
                                new Rectangle(sizeVar, sizeVar,
                                srcRect.width, srcRect.height);
                        System.out.println("testing blit rect src: " + srcRect);
                        System.out.println("                  dst: " + dstRect);
                        render(getGraphics(), srcIm, srcRect, dstRect);
                        test(srcRect, dstRect);
                    }
                }
                System.out.println("Test passed.");
            } finally {
                synchronized (lock) {
                    done = true;
                    lock.notifyAll();
                }
            }
        }
    }
 
Example 16
Source File: SourceClippingBlitTest.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
public void runTests() {
        GraphicsConfiguration gc = getGraphicsConfiguration();
        for (Image srcIm :
            new Image[] {
                getBufferedImage(gc, IMAGEW, IMAGEH,
                        BufferedImage.TYPE_INT_RGB, true),
                getBufferedImage(gc, IMAGEW, IMAGEH,
                        BufferedImage.TYPE_INT_RGB, false),
                // commented out due to 6593406
//                getBMImage(gc, IMAGEW, IMAGEH),
//                getBufferedImage(gc, IMAGEW, IMAGEH,
//                        BufferedImage.TYPE_INT_ARGB, true),
//                getBufferedImage(gc, IMAGEW, IMAGEH,
//                        BufferedImage.TYPE_INT_ARGB, false),
                getVImage(gc, IMAGEW, IMAGEH),
            })
        {
            System.out.println("Testing source: " + srcIm);
            // wiggle the source and dest rectangles
            try {
                for (int locationVar = -10; locationVar < 20; locationVar += 10)
                {
                    for (int sizeVar = -10; sizeVar < 20; sizeVar += 10) {
                        Rectangle srcRect = (Rectangle)IMAGE_BOUNDS.clone();
                        srcRect.translate(locationVar, locationVar);
                        srcRect.grow(sizeVar, sizeVar);

                        Rectangle dstRect =
                                new Rectangle(sizeVar, sizeVar,
                                srcRect.width, srcRect.height);
                        System.out.println("testing blit rect src: " + srcRect);
                        System.out.println("                  dst: " + dstRect);
                        render(getGraphics(), srcIm, srcRect, dstRect);
                        test(srcRect, dstRect);
                    }
                }
                System.out.println("Test passed.");
            } finally {
                synchronized (lock) {
                    done = true;
                    lock.notifyAll();
                }
            }
        }
    }
 
Example 17
Source File: SourceClippingBlitTest.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
public void runTests() {
        GraphicsConfiguration gc = getGraphicsConfiguration();
        for (Image srcIm :
            new Image[] {
                getBufferedImage(gc, IMAGEW, IMAGEH,
                        BufferedImage.TYPE_INT_RGB, true),
                getBufferedImage(gc, IMAGEW, IMAGEH,
                        BufferedImage.TYPE_INT_RGB, false),
                // commented out due to 6593406
//                getBMImage(gc, IMAGEW, IMAGEH),
//                getBufferedImage(gc, IMAGEW, IMAGEH,
//                        BufferedImage.TYPE_INT_ARGB, true),
//                getBufferedImage(gc, IMAGEW, IMAGEH,
//                        BufferedImage.TYPE_INT_ARGB, false),
                getVImage(gc, IMAGEW, IMAGEH),
            })
        {
            System.out.println("Testing source: " + srcIm);
            // wiggle the source and dest rectangles
            try {
                for (int locationVar = -10; locationVar < 20; locationVar += 10)
                {
                    for (int sizeVar = -10; sizeVar < 20; sizeVar += 10) {
                        Rectangle srcRect = (Rectangle)IMAGE_BOUNDS.clone();
                        srcRect.translate(locationVar, locationVar);
                        srcRect.grow(sizeVar, sizeVar);

                        Rectangle dstRect =
                                new Rectangle(sizeVar, sizeVar,
                                srcRect.width, srcRect.height);
                        System.out.println("testing blit rect src: " + srcRect);
                        System.out.println("                  dst: " + dstRect);
                        render(getGraphics(), srcIm, srcRect, dstRect);
                        test(srcRect, dstRect);
                    }
                }
                System.out.println("Test passed.");
            } finally {
                synchronized (lock) {
                    done = true;
                    lock.notifyAll();
                }
            }
        }
    }
 
Example 18
Source File: InfoBoxOverlay.java    From runelite with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Override
public Dimension render(Graphics2D graphics)
{
	final List<InfoBox> infoBoxes = infoboxManager.getInfoBoxes();

	final boolean menuOpen = client.isMenuOpen();
	if (!menuOpen)
	{
		hoveredComponent = null;
	}

	if (infoBoxes.isEmpty())
	{
		return null;
	}

	// Set preferred size to the size of DEFAULT_WRAP_COUNT infoboxes, including the padding - which is applied
	// to the last infobox prior to wrapping too.
	panelComponent.setPreferredSize(new Dimension(DEFAULT_WRAP_COUNT * (config.infoBoxSize() + GAP), DEFAULT_WRAP_COUNT * (config.infoBoxSize() + GAP)));
	panelComponent.setOrientation(config.infoBoxVertical()
		? ComponentOrientation.VERTICAL
		: ComponentOrientation.HORIZONTAL);

	for (InfoBox box : infoBoxes)
	{
		if (!box.render())
		{
			continue;
		}

		final String text = box.getText();
		final Color color = box.getTextColor();

		final InfoBoxComponent infoBoxComponent = new InfoBoxComponent();
		infoBoxComponent.setText(text);
		if (color != null)
		{
			infoBoxComponent.setColor(color);
		}
		infoBoxComponent.setImage(box.getScaledImage());
		infoBoxComponent.setTooltip(box.getTooltip());
		infoBoxComponent.setPreferredSize(new Dimension(config.infoBoxSize(), config.infoBoxSize()));
		infoBoxComponent.setBackgroundColor(config.overlayBackgroundColor());
		infoBoxComponent.setInfoBox(box);
		panelComponent.getChildren().add(infoBoxComponent);
	}

	final Dimension dimension = super.render(graphics);

	// Handle tooltips
	final Point mouse = new Point(client.getMouseCanvasPosition().getX(), client.getMouseCanvasPosition().getY());

	for (final LayoutableRenderableEntity child : panelComponent.getChildren())
	{
		final InfoBoxComponent component = (InfoBoxComponent) child;

		// Create intersection rectangle
		final Rectangle intersectionRectangle = new Rectangle(component.getBounds());
		intersectionRectangle.translate(getBounds().x, getBounds().y);

		if (intersectionRectangle.contains(mouse))
		{
			final String tooltip = component.getTooltip();
			if (!Strings.isNullOrEmpty(tooltip))
			{
				tooltipManager.add(new Tooltip(tooltip));
			}

			if (!menuOpen)
			{
				hoveredComponent = component;
			}
			break;
		}
	}

	panelComponent.getChildren().clear();
	return dimension;
}
 
Example 19
Source File: CompositionArea.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
Rectangle getTextLocation(TextHitInfo offset) {
    Rectangle rectangle = getCaretRectangle(offset);
    Point location = getLocationOnScreen();
    rectangle.translate(location.x, location.y);
    return rectangle;
}
 
Example 20
Source File: CompositionArea.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
Rectangle getTextLocation(TextHitInfo offset) {
    Rectangle rectangle = getCaretRectangle(offset);
    Point location = getLocationOnScreen();
    rectangle.translate(location.x, location.y);
    return rectangle;
}