Java Code Examples for java.awt.Rectangle#clone()
The following examples show how to use
java.awt.Rectangle#clone() .
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: DisplayCanvas.java From TrakEM2 with GNU General Public License v3.0 | 5 votes |
/** Used for restoring properties from the database. */ public void setup(final double mag, final Rectangle srcRect) { this.magnification = mag; this.srcRect = (Rectangle)srcRect.clone(); // just in case super.setDrawingSize((int)Math.ceil(srcRect.width * mag), (int)Math.ceil(srcRect.height * mag)); setMagnification(mag); //no longer needed//display.pack(); // TODO should be run via invokeLater ... need to check many potential locks of invokeLater calling each other. }
Example 2
Source File: FGVertexRenderer.java From ghidra with Apache License 2.0 | 5 votes |
@Override protected void paintDropShadow(RenderContext<FGVertex, FGEdge> rc, GraphicsDecorator g, Shape shape, FGVertex vertex) { Rectangle bounds = shape.getBounds(); if (vertex instanceof GroupedFunctionGraphVertex) { // paint depth images offset from main vertex Rectangle originalBounds = bounds; Rectangle paintBounds = (Rectangle) originalBounds.clone(); Set<FGVertex> vertices = ((GroupedFunctionGraphVertex) vertex).getVertices(); int offset = 15; int size = vertices.size(); if (size > 3) { size = size / 3; // don't paint one-for-one, that's a bit much size = Math.max(size, 2); } int currentOffset = offset * size; for (int i = size - 1; i >= 0; i--) { paintBounds.x = originalBounds.x + currentOffset; paintBounds.y = originalBounds.y + currentOffset; currentOffset -= offset; super.paintDropShadow(rc, g, paintBounds); } } super.paintDropShadow(rc, g, bounds); }
Example 3
Source File: FGVertexRenderer.java From ghidra with Apache License 2.0 | 5 votes |
@Override protected void paintVertexOrVertexShape(RenderContext<FGVertex, FGEdge> rc, GraphicsDecorator g, Layout<FGVertex, FGEdge> layout, FGVertex vertex, Shape compactShape, Shape fullShape) { if (isScaledPastVertexPaintingThreshold(rc)) { paintScaledVertex(rc, vertex, g, compactShape); return; } if (vertex instanceof GroupedFunctionGraphVertex) { // paint depth images offset from main vertex Rectangle originalBounds = fullShape.getBounds(); Rectangle paintBounds = (Rectangle) originalBounds.clone(); Set<FGVertex> vertices = ((GroupedFunctionGraphVertex) vertex).getVertices(); int offset = 5; int size = vertices.size(); if (size > 3) { size = size / 3; // don't paint one-for-one, that's a bit much size = Math.max(size, 2); // we want at least 2, to give some depth } int currentOffset = offset * size; for (int i = size - 1; i >= 0; i--) { paintBounds.x = originalBounds.x + currentOffset; paintBounds.y = originalBounds.y + currentOffset; currentOffset -= offset; paintVertex(rc, g, vertex, paintBounds, layout); } } // paint one final time Rectangle bounds = fullShape.getBounds(); paintVertex(rc, g, vertex, bounds, layout); }
Example 4
Source File: Visual.java From SikuliX1 with MIT License | 5 votes |
public void setActualBounds(Rectangle actualBounds) { this.actualBounds = (Rectangle) actualBounds.clone(); Rectangle paintBounds = (Rectangle) actualBounds.clone(); if (hasShadow()) { paintBounds.x -= (shadowSize - shadowOffset); paintBounds.y -= (shadowSize - shadowOffset); paintBounds.width += (2 * shadowSize); paintBounds.height += (2 * shadowSize); } super.setBounds(paintBounds); updateAllFollowers(); }
Example 5
Source File: GraphEdge.java From pdfxtk with Apache License 2.0 | 5 votes |
public Rectangle getBounds() { Rectangle pbounds = polyline.getBounds(); if(polyRect != pbounds) { polyRect = pbounds; boundsCache = (Rectangle)pbounds.clone(); boundsCache.width++; boundsCache.height++; } return boundsCache; }
Example 6
Source File: MapLayoutUndoRedo.java From MeteoInfo with GNU Lesser General Public License v3.0 | 4 votes |
public ResizeElementEdit(MapLayout mapLayout, LayoutElement element, Rectangle newRect) { this.mapLayout = mapLayout; this.element = element; this.newRect = (Rectangle)newRect.clone(); this.oldRect = (Rectangle)element.getBounds().clone(); }
Example 7
Source File: SourceClippingBlitTest.java From jdk8u-jdk with GNU General Public License v2.0 | 4 votes |
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 8
Source File: CharacterFacadeImpl.java From pcgen with GNU Lesser General Public License v2.1 | 4 votes |
/** * Create a new reference based on the supplied rectangle. * @param rect */ public RectangleReference(Rectangle rect) { super(rect == null ? null : (Rectangle) rect.clone()); }
Example 9
Source File: SourceClippingBlitTest.java From openjdk-jdk8u with GNU General Public License v2.0 | 4 votes |
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 10
Source File: JFrame_Main.java From MobyDroid with Apache License 2.0 | 4 votes |
/** * Make a smaller Rectangle and use it to locate the cursor relative to * the Rectangle center. */ private int getOutcode(Point point, Rectangle rect) { Rectangle r = (Rectangle) rect.clone(); r.grow(-PROX_DIST, -PROX_DIST); return r.outcode(point.x, point.y); }
Example 11
Source File: SourceClippingBlitTest.java From jdk8u-jdk with GNU General Public License v2.0 | 4 votes |
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 12
Source File: SourceClippingBlitTest.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 4 votes |
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 13
Source File: SourceClippingBlitTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
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 14
Source File: SourceClippingBlitTest.java From jdk8u_jdk with GNU General Public License v2.0 | 4 votes |
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: IIOParam.java From JDKSourceCode1.8 with MIT License | 3 votes |
/** * Sets the source region of interest. The region of interest is * described as a rectangle, with the upper-left corner of the * source image as pixel (0, 0) and increasing values down and to * the right. The actual number of pixels used will depend on * the subsampling factors set by <code>setSourceSubsampling</code>. * If subsampling has been set such that this number is zero, * an <code>IllegalStateException</code> will be thrown. * * <p> The source region of interest specified by this method will * be clipped as needed to fit within the source bounds, as well * as the destination offsets, width, and height at the time of * actual I/O. * * <p> A value of <code>null</code> for <code>sourceRegion</code> * will remove any region specification, causing the entire image * to be used. * * @param sourceRegion a <code>Rectangle</code> specifying the * source region of interest, or <code>null</code>. * * @exception IllegalArgumentException if * <code>sourceRegion</code> is non-<code>null</code> and either * <code>sourceRegion.x</code> or <code>sourceRegion.y</code> is * negative. * @exception IllegalArgumentException if * <code>sourceRegion</code> is non-<code>null</code> and either * <code>sourceRegion.width</code> or * <code>sourceRegion.height</code> is negative or 0. * @exception IllegalStateException if subsampling is such that * this region will have a subsampled width or height of zero. * * @see #getSourceRegion * @see #setSourceSubsampling * @see ImageReadParam#setDestinationOffset * @see ImageReadParam#getDestinationOffset */ public void setSourceRegion(Rectangle sourceRegion) { if (sourceRegion == null) { this.sourceRegion = null; return; } if (sourceRegion.x < 0) { throw new IllegalArgumentException("sourceRegion.x < 0!"); } if (sourceRegion.y < 0){ throw new IllegalArgumentException("sourceRegion.y < 0!"); } if (sourceRegion.width <= 0) { throw new IllegalArgumentException("sourceRegion.width <= 0!"); } if (sourceRegion.height <= 0) { throw new IllegalArgumentException("sourceRegion.height <= 0!"); } // Throw an IllegalStateException if region falls between subsamples if (sourceRegion.width <= subsamplingXOffset) { throw new IllegalStateException ("sourceRegion.width <= subsamplingXOffset!"); } if (sourceRegion.height <= subsamplingYOffset) { throw new IllegalStateException ("sourceRegion.height <= subsamplingYOffset!"); } this.sourceRegion = (Rectangle)sourceRegion.clone(); }
Example 16
Source File: IIOParam.java From jdk8u-jdk with GNU General Public License v2.0 | 3 votes |
/** * Sets the source region of interest. The region of interest is * described as a rectangle, with the upper-left corner of the * source image as pixel (0, 0) and increasing values down and to * the right. The actual number of pixels used will depend on * the subsampling factors set by <code>setSourceSubsampling</code>. * If subsampling has been set such that this number is zero, * an <code>IllegalStateException</code> will be thrown. * * <p> The source region of interest specified by this method will * be clipped as needed to fit within the source bounds, as well * as the destination offsets, width, and height at the time of * actual I/O. * * <p> A value of <code>null</code> for <code>sourceRegion</code> * will remove any region specification, causing the entire image * to be used. * * @param sourceRegion a <code>Rectangle</code> specifying the * source region of interest, or <code>null</code>. * * @exception IllegalArgumentException if * <code>sourceRegion</code> is non-<code>null</code> and either * <code>sourceRegion.x</code> or <code>sourceRegion.y</code> is * negative. * @exception IllegalArgumentException if * <code>sourceRegion</code> is non-<code>null</code> and either * <code>sourceRegion.width</code> or * <code>sourceRegion.height</code> is negative or 0. * @exception IllegalStateException if subsampling is such that * this region will have a subsampled width or height of zero. * * @see #getSourceRegion * @see #setSourceSubsampling * @see ImageReadParam#setDestinationOffset * @see ImageReadParam#getDestinationOffset */ public void setSourceRegion(Rectangle sourceRegion) { if (sourceRegion == null) { this.sourceRegion = null; return; } if (sourceRegion.x < 0) { throw new IllegalArgumentException("sourceRegion.x < 0!"); } if (sourceRegion.y < 0){ throw new IllegalArgumentException("sourceRegion.y < 0!"); } if (sourceRegion.width <= 0) { throw new IllegalArgumentException("sourceRegion.width <= 0!"); } if (sourceRegion.height <= 0) { throw new IllegalArgumentException("sourceRegion.height <= 0!"); } // Throw an IllegalStateException if region falls between subsamples if (sourceRegion.width <= subsamplingXOffset) { throw new IllegalStateException ("sourceRegion.width <= subsamplingXOffset!"); } if (sourceRegion.height <= subsamplingYOffset) { throw new IllegalStateException ("sourceRegion.height <= subsamplingYOffset!"); } this.sourceRegion = (Rectangle)sourceRegion.clone(); }
Example 17
Source File: IIOParam.java From openjdk-jdk8u with GNU General Public License v2.0 | 3 votes |
/** * Sets the source region of interest. The region of interest is * described as a rectangle, with the upper-left corner of the * source image as pixel (0, 0) and increasing values down and to * the right. The actual number of pixels used will depend on * the subsampling factors set by <code>setSourceSubsampling</code>. * If subsampling has been set such that this number is zero, * an <code>IllegalStateException</code> will be thrown. * * <p> The source region of interest specified by this method will * be clipped as needed to fit within the source bounds, as well * as the destination offsets, width, and height at the time of * actual I/O. * * <p> A value of <code>null</code> for <code>sourceRegion</code> * will remove any region specification, causing the entire image * to be used. * * @param sourceRegion a <code>Rectangle</code> specifying the * source region of interest, or <code>null</code>. * * @exception IllegalArgumentException if * <code>sourceRegion</code> is non-<code>null</code> and either * <code>sourceRegion.x</code> or <code>sourceRegion.y</code> is * negative. * @exception IllegalArgumentException if * <code>sourceRegion</code> is non-<code>null</code> and either * <code>sourceRegion.width</code> or * <code>sourceRegion.height</code> is negative or 0. * @exception IllegalStateException if subsampling is such that * this region will have a subsampled width or height of zero. * * @see #getSourceRegion * @see #setSourceSubsampling * @see ImageReadParam#setDestinationOffset * @see ImageReadParam#getDestinationOffset */ public void setSourceRegion(Rectangle sourceRegion) { if (sourceRegion == null) { this.sourceRegion = null; return; } if (sourceRegion.x < 0) { throw new IllegalArgumentException("sourceRegion.x < 0!"); } if (sourceRegion.y < 0){ throw new IllegalArgumentException("sourceRegion.y < 0!"); } if (sourceRegion.width <= 0) { throw new IllegalArgumentException("sourceRegion.width <= 0!"); } if (sourceRegion.height <= 0) { throw new IllegalArgumentException("sourceRegion.height <= 0!"); } // Throw an IllegalStateException if region falls between subsamples if (sourceRegion.width <= subsamplingXOffset) { throw new IllegalStateException ("sourceRegion.width <= subsamplingXOffset!"); } if (sourceRegion.height <= subsamplingYOffset) { throw new IllegalStateException ("sourceRegion.height <= subsamplingYOffset!"); } this.sourceRegion = (Rectangle)sourceRegion.clone(); }
Example 18
Source File: IIOParam.java From hottub with GNU General Public License v2.0 | 3 votes |
/** * Sets the source region of interest. The region of interest is * described as a rectangle, with the upper-left corner of the * source image as pixel (0, 0) and increasing values down and to * the right. The actual number of pixels used will depend on * the subsampling factors set by <code>setSourceSubsampling</code>. * If subsampling has been set such that this number is zero, * an <code>IllegalStateException</code> will be thrown. * * <p> The source region of interest specified by this method will * be clipped as needed to fit within the source bounds, as well * as the destination offsets, width, and height at the time of * actual I/O. * * <p> A value of <code>null</code> for <code>sourceRegion</code> * will remove any region specification, causing the entire image * to be used. * * @param sourceRegion a <code>Rectangle</code> specifying the * source region of interest, or <code>null</code>. * * @exception IllegalArgumentException if * <code>sourceRegion</code> is non-<code>null</code> and either * <code>sourceRegion.x</code> or <code>sourceRegion.y</code> is * negative. * @exception IllegalArgumentException if * <code>sourceRegion</code> is non-<code>null</code> and either * <code>sourceRegion.width</code> or * <code>sourceRegion.height</code> is negative or 0. * @exception IllegalStateException if subsampling is such that * this region will have a subsampled width or height of zero. * * @see #getSourceRegion * @see #setSourceSubsampling * @see ImageReadParam#setDestinationOffset * @see ImageReadParam#getDestinationOffset */ public void setSourceRegion(Rectangle sourceRegion) { if (sourceRegion == null) { this.sourceRegion = null; return; } if (sourceRegion.x < 0) { throw new IllegalArgumentException("sourceRegion.x < 0!"); } if (sourceRegion.y < 0){ throw new IllegalArgumentException("sourceRegion.y < 0!"); } if (sourceRegion.width <= 0) { throw new IllegalArgumentException("sourceRegion.width <= 0!"); } if (sourceRegion.height <= 0) { throw new IllegalArgumentException("sourceRegion.height <= 0!"); } // Throw an IllegalStateException if region falls between subsamples if (sourceRegion.width <= subsamplingXOffset) { throw new IllegalStateException ("sourceRegion.width <= subsamplingXOffset!"); } if (sourceRegion.height <= subsamplingYOffset) { throw new IllegalStateException ("sourceRegion.height <= subsamplingYOffset!"); } this.sourceRegion = (Rectangle)sourceRegion.clone(); }
Example 19
Source File: IIOParam.java From Bytecoder with Apache License 2.0 | 3 votes |
/** * Sets the source region of interest. The region of interest is * described as a rectangle, with the upper-left corner of the * source image as pixel (0, 0) and increasing values down and to * the right. The actual number of pixels used will depend on * the subsampling factors set by {@code setSourceSubsampling}. * If subsampling has been set such that this number is zero, * an {@code IllegalStateException} will be thrown. * * <p> The source region of interest specified by this method will * be clipped as needed to fit within the source bounds, as well * as the destination offsets, width, and height at the time of * actual I/O. * * <p> A value of {@code null} for {@code sourceRegion} * will remove any region specification, causing the entire image * to be used. * * @param sourceRegion a {@code Rectangle} specifying the * source region of interest, or {@code null}. * * @exception IllegalArgumentException if * {@code sourceRegion} is non-{@code null} and either * {@code sourceRegion.x} or {@code sourceRegion.y} is * negative. * @exception IllegalArgumentException if * {@code sourceRegion} is non-{@code null} and either * {@code sourceRegion.width} or * {@code sourceRegion.height} is negative or 0. * @exception IllegalStateException if subsampling is such that * this region will have a subsampled width or height of zero. * * @see #getSourceRegion * @see #setSourceSubsampling * @see ImageReadParam#setDestinationOffset * @see ImageReadParam#getDestinationOffset */ public void setSourceRegion(Rectangle sourceRegion) { if (sourceRegion == null) { this.sourceRegion = null; return; } if (sourceRegion.x < 0) { throw new IllegalArgumentException("sourceRegion.x < 0!"); } if (sourceRegion.y < 0){ throw new IllegalArgumentException("sourceRegion.y < 0!"); } if (sourceRegion.width <= 0) { throw new IllegalArgumentException("sourceRegion.width <= 0!"); } if (sourceRegion.height <= 0) { throw new IllegalArgumentException("sourceRegion.height <= 0!"); } // Throw an IllegalStateException if region falls between subsamples if (sourceRegion.width <= subsamplingXOffset) { throw new IllegalStateException ("sourceRegion.width <= subsamplingXOffset!"); } if (sourceRegion.height <= subsamplingYOffset) { throw new IllegalStateException ("sourceRegion.height <= subsamplingYOffset!"); } this.sourceRegion = (Rectangle)sourceRegion.clone(); }
Example 20
Source File: IIOParam.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 3 votes |
/** * Sets the source region of interest. The region of interest is * described as a rectangle, with the upper-left corner of the * source image as pixel (0, 0) and increasing values down and to * the right. The actual number of pixels used will depend on * the subsampling factors set by <code>setSourceSubsampling</code>. * If subsampling has been set such that this number is zero, * an <code>IllegalStateException</code> will be thrown. * * <p> The source region of interest specified by this method will * be clipped as needed to fit within the source bounds, as well * as the destination offsets, width, and height at the time of * actual I/O. * * <p> A value of <code>null</code> for <code>sourceRegion</code> * will remove any region specification, causing the entire image * to be used. * * @param sourceRegion a <code>Rectangle</code> specifying the * source region of interest, or <code>null</code>. * * @exception IllegalArgumentException if * <code>sourceRegion</code> is non-<code>null</code> and either * <code>sourceRegion.x</code> or <code>sourceRegion.y</code> is * negative. * @exception IllegalArgumentException if * <code>sourceRegion</code> is non-<code>null</code> and either * <code>sourceRegion.width</code> or * <code>sourceRegion.height</code> is negative or 0. * @exception IllegalStateException if subsampling is such that * this region will have a subsampled width or height of zero. * * @see #getSourceRegion * @see #setSourceSubsampling * @see ImageReadParam#setDestinationOffset * @see ImageReadParam#getDestinationOffset */ public void setSourceRegion(Rectangle sourceRegion) { if (sourceRegion == null) { this.sourceRegion = null; return; } if (sourceRegion.x < 0) { throw new IllegalArgumentException("sourceRegion.x < 0!"); } if (sourceRegion.y < 0){ throw new IllegalArgumentException("sourceRegion.y < 0!"); } if (sourceRegion.width <= 0) { throw new IllegalArgumentException("sourceRegion.width <= 0!"); } if (sourceRegion.height <= 0) { throw new IllegalArgumentException("sourceRegion.height <= 0!"); } // Throw an IllegalStateException if region falls between subsamples if (sourceRegion.width <= subsamplingXOffset) { throw new IllegalStateException ("sourceRegion.width <= subsamplingXOffset!"); } if (sourceRegion.height <= subsamplingYOffset) { throw new IllegalStateException ("sourceRegion.height <= subsamplingYOffset!"); } this.sourceRegion = (Rectangle)sourceRegion.clone(); }