下面列出了java.awt.Rectangle#clone ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@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);
}
@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);
}
public Rectangle getBounds() {
Rectangle pbounds = polyline.getBounds();
if(polyRect != pbounds) {
polyRect = pbounds;
boundsCache = (Rectangle)pbounds.clone();
boundsCache.width++;
boundsCache.height++;
}
return boundsCache;
}
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();
}
/** 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.
}
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();
}
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");
}
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");
}
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");
}
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");
}
/**
* 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);
}
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");
}
/**
* Create a new reference based on the supplied rectangle.
* @param rect
*/
public RectangleReference(Rectangle rect)
{
super(rect == null ? null : (Rectangle) rect.clone());
}
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");
}
/**
* 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();
}
/**
* 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();
}
/**
* 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();
}
/**
* 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();
}
/**
* 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();
}
/**
* 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();
}