2002-08-09 12:26:17 +08:00
|
|
|
/* RectangularShape.java -- a rectangular frame for several generic shapes
|
|
|
|
Copyright (C) 2000, 2002 Free Software Foundation
|
2000-07-23 08:24:14 +08:00
|
|
|
|
Start of AWT merge with Classpath:
* Makefile.in: Rebuilt.
* Makefile.am (awt_java_source_files): Reference files in
gnu/java/awt, not gnu/gcj/awt.
* java/awt/image/BufferedImage.java: Updated copyright.
* java/awt/image/ComponentColorModel.java: Updated copyright.
* java/awt/image/ComponentSampleModel.java: Updated copyright.
* java/awt/image/DataBuffer.java: Updated copyright.
* java/awt/image/DataBufferByte.java: Updated copyright.
* java/awt/image/DataBufferInt.java: Updated copyright.
* java/awt/image/DataBufferUShort.java: Updated copyright.
* java/awt/image/IndexColorModel.java: Updated copyright.
* java/awt/image/PackedColorModel.java: Updated copyright.
* java/awt/image/Raster.java: Updated copyright.
* java/awt/image/RasterOp.java: Updated copyright.
* java/awt/image/SampleModel.java: Updated copyright.
* java/awt/image/SinglePixelPackedSampleModel.java: Updated copyright.
* java/awt/image/WritableRaster.java: Updated copyright.
* java/awt/color/ColorSpace.java: Updated copyright.
* java/awt/color/ICC_ColorSpace.java: Updated copyright
* java/awt/color/ICC_Profile.java: Updated copyright.
* java/awt/event/HierarchyBoundsAdapter.java: Updated copyright.
* java/awt/event/HierarchyBoundsListener.java: Updated copyright.
* java/awt/event/HierarchyEvent.java: Updated copyright.
* java/awt/event/HierarchyListener.java: Updated copyright.
* java/awt/geom/AffineTransform.java: Updated copyright.
* java/awt/geom/Dimension2D.java: Updated copyright.
* java/awt/geom/Ellipse2D.java: Updated copyright.
* java/awt/geom/IllegalPathStateException.java: Updated copyright.
* java/awt/geom/Line2D.java: Updated copyright.
* java/awt/geom/NoninvertibleTransformException.java: Updated
copyright.
* java/awt/geom/PathIterator.java: Updated copyright.
* java/awt/geom/Point2D.java: Updated copyright.
* java/awt/geom/Rectangle2D.java: Updated copyright.
* java/awt/geom/RectangularShape.java: Updated copyright.
* java/awt/geom/RoundRectangle2D.java: Updated copyright.
* java/awt/Toolkit.java: Updated import for file moves.
* java/awt/Rectangle.java: Updated copyright; added javadoc from
Classpath.
(hashCode): New method from Classpath.
* java/awt/Graphics2D.java: Updated copyright.
* java/awt/Transparency.java: Updated copyright.
* java/awt/Paint.java: Updated copyright.
* java/awt/Graphics.java: New version from Classpath.
* java/awt/EventDispatchThread.java: Updated copyright.
* java/awt/CardLayout.java (layoutContainer): Don't skip invisible
children.
(gotoComponent): Wrap around on next/previous.
* gnu/gcj/awt/BitMaskExtent.java: Removed.
* gnu/gcj/awt/Buffers.java: Removed.
* gnu/gcj/awt/ComponentDataBlitOp.java: Removed.
* gnu/gcj/awt/GLightweightPeer.java: Removed.
* gnu/java/awt/BitMaskExtent.java: Added.
* gnu/java/awt/Buffers.java: Added.
* gnu/java/awt/ComponentDataBlitOp.java: Added.
* gnu/java/awt/GLightweightPeer.java: Added.
* java/awt/geom/Line2D.java (clone): Ignore
CloneNotSupportedException.
* gnu/gcj/awt/GLightweightPeer.java (getColorModel): New method.
* java/awt/Frame.java: Merged with Classpath.
* java/awt/RenderingHints.java: Copyright update.
* java/awt/Paint.java: Copyright update.
* java/awt/image/DirectColorModel.java: Merged with Classpath.
* java/awt/image/ColorModel.java: Merged with Classpath.
* java/awt/Window.java (show): New Implementation from Classpath.
(isShowing): Use super.isShowing().
* java/awt/EventQueue.java: Merged with Classpath.
* java/awt/AWTEventMulticaster.java (save): Throw
RuntimeException.
(saveInternal): Likewise.
* java/awt/AWTEvent.java: Now implements Serializable.
* java/awt/Event.java: Copyright update.
* java/awt/peer/ComponentPeer.java: Merged with Classpath.
* java/awt/image/BufferedImage.java: Copyright update.
* java/awt/GraphicsConfiguration.java: Copyright update.
* java/awt/Component.java: (addNotify): Don't call
addNotifyContainerChildren().
(addNotifyContainerChildren): Removed.
(setPeer): New method from Classpath.
(setTreeLock): Likewise.
(setVisible): Rewrote.
(show): Use it.
(hide): Likewise.
(validate): Set `valid'.
(checkImage(Image,ImageObserver)): Implementation from Classpath.
(createImage(ImageProducer)): Likewise.
(prepareImage): Likewise.
* java/awt/Container.java (addImpl): Handle case where constraint
is not a String. Post event via system event queue.
(remove): Post event via system event queue.
(validateTree): Only validate child if it is invalid.
(getAlignmentX): Call super method as default.
(getAlignmentY): Likewise.
(addContainerListener): Now synchronized.
(removeContainerListener): Likewise.
(addNotifyContainerChildren): Now private.
* java/awt/ComponentOrientation.java: Updated copyright. Added
@author.
* java/awt/FlowLayout.java (serialVersionUID): New field.
(setAlignment): Better exception message.
(layoutContainer): Don't compute component's preferred size unless
we're going to use it.
* java/awt/BorderLayout.java (AFTER_LAST_LINE, AFTER_LINE_ENDS,
BEFORE_FIRST_LINE, BEFORE_LINE_BEGINS): New constants.
(firstLine, lastLine, firstItem, lastItem): New fields.
(addLayoutComponent): Handle case where constraints is null.
Also, handle relative locations.
(removeLayoutComponent): Handle relative locations.
(MIN, MAX, PREF): New constants.
(calcCompSize): New method.
(calcSize): New method.
(minimumLayoutSize): Use it.
(preferredLayoutSize): Likewise.
(maximumLayoutSize): Likewise.
(toString): Include more information.
(setBounds): New method.
(layoutContainer): Use libgcj implementation; extended to handle
relative locations.
From-SVN: r48896
2002-01-16 12:21:35 +08:00
|
|
|
This file is part of GNU Classpath.
|
2000-07-23 08:24:14 +08:00
|
|
|
|
Start of AWT merge with Classpath:
* Makefile.in: Rebuilt.
* Makefile.am (awt_java_source_files): Reference files in
gnu/java/awt, not gnu/gcj/awt.
* java/awt/image/BufferedImage.java: Updated copyright.
* java/awt/image/ComponentColorModel.java: Updated copyright.
* java/awt/image/ComponentSampleModel.java: Updated copyright.
* java/awt/image/DataBuffer.java: Updated copyright.
* java/awt/image/DataBufferByte.java: Updated copyright.
* java/awt/image/DataBufferInt.java: Updated copyright.
* java/awt/image/DataBufferUShort.java: Updated copyright.
* java/awt/image/IndexColorModel.java: Updated copyright.
* java/awt/image/PackedColorModel.java: Updated copyright.
* java/awt/image/Raster.java: Updated copyright.
* java/awt/image/RasterOp.java: Updated copyright.
* java/awt/image/SampleModel.java: Updated copyright.
* java/awt/image/SinglePixelPackedSampleModel.java: Updated copyright.
* java/awt/image/WritableRaster.java: Updated copyright.
* java/awt/color/ColorSpace.java: Updated copyright.
* java/awt/color/ICC_ColorSpace.java: Updated copyright
* java/awt/color/ICC_Profile.java: Updated copyright.
* java/awt/event/HierarchyBoundsAdapter.java: Updated copyright.
* java/awt/event/HierarchyBoundsListener.java: Updated copyright.
* java/awt/event/HierarchyEvent.java: Updated copyright.
* java/awt/event/HierarchyListener.java: Updated copyright.
* java/awt/geom/AffineTransform.java: Updated copyright.
* java/awt/geom/Dimension2D.java: Updated copyright.
* java/awt/geom/Ellipse2D.java: Updated copyright.
* java/awt/geom/IllegalPathStateException.java: Updated copyright.
* java/awt/geom/Line2D.java: Updated copyright.
* java/awt/geom/NoninvertibleTransformException.java: Updated
copyright.
* java/awt/geom/PathIterator.java: Updated copyright.
* java/awt/geom/Point2D.java: Updated copyright.
* java/awt/geom/Rectangle2D.java: Updated copyright.
* java/awt/geom/RectangularShape.java: Updated copyright.
* java/awt/geom/RoundRectangle2D.java: Updated copyright.
* java/awt/Toolkit.java: Updated import for file moves.
* java/awt/Rectangle.java: Updated copyright; added javadoc from
Classpath.
(hashCode): New method from Classpath.
* java/awt/Graphics2D.java: Updated copyright.
* java/awt/Transparency.java: Updated copyright.
* java/awt/Paint.java: Updated copyright.
* java/awt/Graphics.java: New version from Classpath.
* java/awt/EventDispatchThread.java: Updated copyright.
* java/awt/CardLayout.java (layoutContainer): Don't skip invisible
children.
(gotoComponent): Wrap around on next/previous.
* gnu/gcj/awt/BitMaskExtent.java: Removed.
* gnu/gcj/awt/Buffers.java: Removed.
* gnu/gcj/awt/ComponentDataBlitOp.java: Removed.
* gnu/gcj/awt/GLightweightPeer.java: Removed.
* gnu/java/awt/BitMaskExtent.java: Added.
* gnu/java/awt/Buffers.java: Added.
* gnu/java/awt/ComponentDataBlitOp.java: Added.
* gnu/java/awt/GLightweightPeer.java: Added.
* java/awt/geom/Line2D.java (clone): Ignore
CloneNotSupportedException.
* gnu/gcj/awt/GLightweightPeer.java (getColorModel): New method.
* java/awt/Frame.java: Merged with Classpath.
* java/awt/RenderingHints.java: Copyright update.
* java/awt/Paint.java: Copyright update.
* java/awt/image/DirectColorModel.java: Merged with Classpath.
* java/awt/image/ColorModel.java: Merged with Classpath.
* java/awt/Window.java (show): New Implementation from Classpath.
(isShowing): Use super.isShowing().
* java/awt/EventQueue.java: Merged with Classpath.
* java/awt/AWTEventMulticaster.java (save): Throw
RuntimeException.
(saveInternal): Likewise.
* java/awt/AWTEvent.java: Now implements Serializable.
* java/awt/Event.java: Copyright update.
* java/awt/peer/ComponentPeer.java: Merged with Classpath.
* java/awt/image/BufferedImage.java: Copyright update.
* java/awt/GraphicsConfiguration.java: Copyright update.
* java/awt/Component.java: (addNotify): Don't call
addNotifyContainerChildren().
(addNotifyContainerChildren): Removed.
(setPeer): New method from Classpath.
(setTreeLock): Likewise.
(setVisible): Rewrote.
(show): Use it.
(hide): Likewise.
(validate): Set `valid'.
(checkImage(Image,ImageObserver)): Implementation from Classpath.
(createImage(ImageProducer)): Likewise.
(prepareImage): Likewise.
* java/awt/Container.java (addImpl): Handle case where constraint
is not a String. Post event via system event queue.
(remove): Post event via system event queue.
(validateTree): Only validate child if it is invalid.
(getAlignmentX): Call super method as default.
(getAlignmentY): Likewise.
(addContainerListener): Now synchronized.
(removeContainerListener): Likewise.
(addNotifyContainerChildren): Now private.
* java/awt/ComponentOrientation.java: Updated copyright. Added
@author.
* java/awt/FlowLayout.java (serialVersionUID): New field.
(setAlignment): Better exception message.
(layoutContainer): Don't compute component's preferred size unless
we're going to use it.
* java/awt/BorderLayout.java (AFTER_LAST_LINE, AFTER_LINE_ENDS,
BEFORE_FIRST_LINE, BEFORE_LINE_BEGINS): New constants.
(firstLine, lastLine, firstItem, lastItem): New fields.
(addLayoutComponent): Handle case where constraints is null.
Also, handle relative locations.
(removeLayoutComponent): Handle relative locations.
(MIN, MAX, PREF): New constants.
(calcCompSize): New method.
(calcSize): New method.
(minimumLayoutSize): Use it.
(preferredLayoutSize): Likewise.
(maximumLayoutSize): Likewise.
(toString): Include more information.
(setBounds): New method.
(layoutContainer): Use libgcj implementation; extended to handle
relative locations.
From-SVN: r48896
2002-01-16 12:21:35 +08:00
|
|
|
GNU Classpath is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2, or (at your option)
|
|
|
|
any later version.
|
|
|
|
|
|
|
|
GNU Classpath is distributed in the hope that it will be useful, but
|
|
|
|
WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with GNU Classpath; see the file COPYING. If not, write to the
|
|
|
|
Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
|
|
|
02111-1307 USA.
|
|
|
|
|
2002-01-23 06:40:42 +08:00
|
|
|
Linking this library statically or dynamically with other modules is
|
|
|
|
making a combined work based on this library. Thus, the terms and
|
|
|
|
conditions of the GNU General Public License cover the whole
|
|
|
|
combination.
|
|
|
|
|
|
|
|
As a special exception, the copyright holders of this library give you
|
|
|
|
permission to link this library with independent modules to produce an
|
|
|
|
executable, regardless of the license terms of these independent
|
|
|
|
modules, and to copy and distribute the resulting executable under
|
|
|
|
terms of your choice, provided that you also meet, for each linked
|
|
|
|
independent module, the terms and conditions of the license of that
|
|
|
|
module. An independent module is a module which is not derived from
|
|
|
|
or based on this library. If you modify this library, you may extend
|
|
|
|
this exception to your version of the library, but you are not
|
|
|
|
obligated to do so. If you do not wish to do so, delete this
|
|
|
|
exception statement from your version. */
|
2000-07-23 08:24:14 +08:00
|
|
|
|
2002-08-09 12:26:17 +08:00
|
|
|
|
2000-07-23 08:24:14 +08:00
|
|
|
package java.awt.geom;
|
2002-08-09 12:26:17 +08:00
|
|
|
|
|
|
|
import java.awt.Rectangle;
|
|
|
|
import java.awt.Shape;
|
2000-07-23 08:24:14 +08:00
|
|
|
|
|
|
|
/**
|
2002-08-09 12:26:17 +08:00
|
|
|
* This class provides a generic framework, and several helper methods, for
|
|
|
|
* subclasses which represent geometric objects inside a rectangular frame.
|
|
|
|
* This does not specify any geometry except for the bounding box.
|
|
|
|
*
|
2000-07-23 08:24:14 +08:00
|
|
|
* @author Tom Tromey <tromey@cygnus.com>
|
2002-08-09 12:26:17 +08:00
|
|
|
* @author Eric Blake <ebb9@email.byu.edu>
|
|
|
|
* @since 1.2
|
|
|
|
* @see Arc2D
|
|
|
|
* @see Ellipse2D
|
|
|
|
* @see Rectangle2D
|
|
|
|
* @see RoundRectangle2D
|
|
|
|
* @status updated to 1.4
|
2000-07-23 08:24:14 +08:00
|
|
|
*/
|
|
|
|
public abstract class RectangularShape implements Shape, Cloneable
|
|
|
|
{
|
2002-08-09 12:26:17 +08:00
|
|
|
/**
|
|
|
|
* Default constructor.
|
|
|
|
*/
|
|
|
|
protected RectangularShape()
|
2000-07-23 08:24:14 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2002-08-09 12:26:17 +08:00
|
|
|
/**
|
|
|
|
* Get the x coordinate of the upper-left corner of the framing rectangle.
|
|
|
|
*
|
|
|
|
* @return the x coordinate
|
|
|
|
*/
|
|
|
|
public abstract double getX();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the y coordinate of the upper-left corner of the framing rectangle.
|
|
|
|
*
|
|
|
|
* @return the y coordinate
|
|
|
|
*/
|
|
|
|
public abstract double getY();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the width of the framing rectangle.
|
|
|
|
*
|
|
|
|
* @return the width
|
|
|
|
*/
|
|
|
|
public abstract double getWidth();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the height of the framing rectangle.
|
|
|
|
*
|
|
|
|
* @return the height
|
|
|
|
*/
|
|
|
|
public abstract double getHeight();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the minimum x coordinate in the frame. This is misnamed, or else
|
|
|
|
* Sun has a bug, because the implementation returns getX() even when
|
|
|
|
* getWidth() is negative.
|
|
|
|
*
|
|
|
|
* @return the minimum x coordinate
|
|
|
|
*/
|
|
|
|
public double getMinX()
|
|
|
|
{
|
|
|
|
return getX();
|
2000-07-23 08:24:14 +08:00
|
|
|
}
|
|
|
|
|
2002-08-09 12:26:17 +08:00
|
|
|
/**
|
|
|
|
* Get the minimum y coordinate in the frame. This is misnamed, or else
|
|
|
|
* Sun has a bug, because the implementation returns getY() even when
|
|
|
|
* getHeight() is negative.
|
|
|
|
*
|
|
|
|
* @return the minimum y coordinate
|
|
|
|
*/
|
|
|
|
public double getMinY()
|
2000-07-23 08:24:14 +08:00
|
|
|
{
|
2002-08-09 12:26:17 +08:00
|
|
|
return getY();
|
2000-07-23 08:24:14 +08:00
|
|
|
}
|
|
|
|
|
2002-08-09 12:26:17 +08:00
|
|
|
/**
|
|
|
|
* Get the maximum x coordinate in the frame. This is misnamed, or else
|
|
|
|
* Sun has a bug, because the implementation returns getX()+getWidth() even
|
|
|
|
* when getWidth() is negative.
|
|
|
|
*
|
|
|
|
* @return the maximum x coordinate
|
|
|
|
*/
|
|
|
|
public double getMaxX()
|
|
|
|
{
|
|
|
|
return getX() + getWidth();
|
2000-07-23 08:24:14 +08:00
|
|
|
}
|
|
|
|
|
2002-08-09 12:26:17 +08:00
|
|
|
/**
|
|
|
|
* Get the maximum y coordinate in the frame. This is misnamed, or else
|
|
|
|
* Sun has a bug, because the implementation returns getY()+getHeight() even
|
|
|
|
* when getHeight() is negative.
|
|
|
|
*
|
|
|
|
* @return the maximum y coordinate
|
|
|
|
*/
|
|
|
|
public double getMaxY()
|
2000-07-23 08:24:14 +08:00
|
|
|
{
|
2002-08-09 12:26:17 +08:00
|
|
|
return getY() + getHeight();
|
2000-07-23 08:24:14 +08:00
|
|
|
}
|
|
|
|
|
2002-08-09 12:26:17 +08:00
|
|
|
/**
|
|
|
|
* Return the x coordinate of the center point of the framing rectangle.
|
|
|
|
*
|
|
|
|
* @return the central x coordinate
|
|
|
|
*/
|
|
|
|
public double getCenterX()
|
2000-07-23 08:24:14 +08:00
|
|
|
{
|
2002-08-09 12:26:17 +08:00
|
|
|
return getX() + getWidth() / 2;
|
2000-07-23 08:24:14 +08:00
|
|
|
}
|
|
|
|
|
2002-08-09 12:26:17 +08:00
|
|
|
/**
|
|
|
|
* Return the y coordinate of the center point of the framing rectangle.
|
|
|
|
*
|
|
|
|
* @return the central y coordinate
|
|
|
|
*/
|
|
|
|
public double getCenterY()
|
2000-07-23 08:24:14 +08:00
|
|
|
{
|
2002-08-09 12:26:17 +08:00
|
|
|
return getY() + getHeight() / 2;
|
2000-07-23 08:24:14 +08:00
|
|
|
}
|
|
|
|
|
2002-08-09 12:26:17 +08:00
|
|
|
/**
|
|
|
|
* Return the frame around this object. Note that this may be a looser
|
|
|
|
* bounding box than getBounds2D.
|
|
|
|
*
|
|
|
|
* @return the frame, in double precision
|
|
|
|
* @see #setFrame(double, double, double, double)
|
|
|
|
*/
|
|
|
|
public Rectangle2D getFrame()
|
2000-07-23 08:24:14 +08:00
|
|
|
{
|
2002-08-09 12:26:17 +08:00
|
|
|
return new Rectangle2D.Double(getX(), getY(), getWidth(), getHeight());
|
2000-07-23 08:24:14 +08:00
|
|
|
}
|
|
|
|
|
2002-08-09 12:26:17 +08:00
|
|
|
/**
|
|
|
|
* Test if the shape is empty, meaning that no points are inside it.
|
|
|
|
*
|
|
|
|
* @return true if the shape is empty
|
|
|
|
*/
|
|
|
|
public abstract boolean isEmpty();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the framing rectangle of this shape to the given coordinate and size.
|
|
|
|
*
|
|
|
|
* @param x the new x coordinate
|
|
|
|
* @param y the new y coordinate
|
|
|
|
* @param w the new width
|
|
|
|
* @param h the new height
|
|
|
|
* @see #getFrame()
|
|
|
|
*/
|
|
|
|
public abstract void setFrame(double x, double y, double w, double h);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the framing rectangle of this shape to the given coordinate and size.
|
|
|
|
*
|
|
|
|
* @param p the new point
|
|
|
|
* @param d the new dimension
|
|
|
|
* @throws NullPointerException if p or d is null
|
|
|
|
* @see #getFrame()
|
|
|
|
*/
|
|
|
|
public void setFrame(Point2D p, Dimension2D d)
|
2000-07-23 08:24:14 +08:00
|
|
|
{
|
2002-08-09 12:26:17 +08:00
|
|
|
setFrame(p.getX(), p.getY(), d.getWidth(), d.getHeight());
|
2000-07-23 08:24:14 +08:00
|
|
|
}
|
|
|
|
|
2002-08-09 12:26:17 +08:00
|
|
|
/**
|
|
|
|
* Set the framing rectangle of this shape to the given rectangle.
|
|
|
|
*
|
|
|
|
* @param r the new framing rectangle
|
|
|
|
* @throws NullPointerException if r is null
|
|
|
|
* @see #getFrame()
|
|
|
|
*/
|
|
|
|
public void setFrame(Rectangle2D r)
|
2000-07-23 08:24:14 +08:00
|
|
|
{
|
2002-08-09 12:26:17 +08:00
|
|
|
setFrame(r.getX(), r.getY(), r.getWidth(), r.getHeight());
|
2000-07-23 08:24:14 +08:00
|
|
|
}
|
|
|
|
|
2002-08-09 12:26:17 +08:00
|
|
|
/**
|
|
|
|
* Set the framing rectangle of this shape using two points on a diagonal.
|
|
|
|
* The area will be positive.
|
|
|
|
*
|
|
|
|
* @param x1 the first x coordinate
|
|
|
|
* @param y1 the first y coordinate
|
|
|
|
* @param x2 the second x coordinate
|
|
|
|
* @param y2 the second y coordinate
|
|
|
|
*/
|
|
|
|
public void setFrameFromDiagonal(double x1, double y1, double x2, double y2)
|
2000-07-23 08:24:14 +08:00
|
|
|
{
|
|
|
|
if (x1 > x2)
|
|
|
|
{
|
|
|
|
double t = x2;
|
|
|
|
x2 = x1;
|
|
|
|
x1 = t;
|
|
|
|
}
|
|
|
|
if (y1 > y2)
|
|
|
|
{
|
|
|
|
double t = y2;
|
|
|
|
y2 = y1;
|
|
|
|
y1 = t;
|
|
|
|
}
|
2002-08-09 12:26:17 +08:00
|
|
|
setFrame(x1, y1, x2 - x1, y2 - y1);
|
2000-07-23 08:24:14 +08:00
|
|
|
}
|
|
|
|
|
2002-08-09 12:26:17 +08:00
|
|
|
/**
|
|
|
|
* Set the framing rectangle of this shape using two points on a diagonal.
|
|
|
|
* The area will be positive.
|
|
|
|
*
|
|
|
|
* @param p1 the first point
|
|
|
|
* @param p2 the second point
|
|
|
|
* @throws NullPointerException if either point is null
|
|
|
|
*/
|
|
|
|
public void setFrameFromDiagonal(Point2D p1, Point2D p2)
|
2000-07-23 08:24:14 +08:00
|
|
|
{
|
2002-08-09 12:26:17 +08:00
|
|
|
setFrameFromDiagonal(p1.getX(), p1.getY(), p2.getX(), p2.getY());
|
2000-07-23 08:24:14 +08:00
|
|
|
}
|
|
|
|
|
2002-08-09 12:26:17 +08:00
|
|
|
/**
|
|
|
|
* Set the framing rectangle of this shape using the center of the frame,
|
|
|
|
* and one of the four corners. The area will be positive.
|
|
|
|
*
|
|
|
|
* @param centerX the x coordinate at the center
|
|
|
|
* @param centerY the y coordinate at the center
|
|
|
|
* @param cornerX the x coordinate at a corner
|
|
|
|
* @param cornerY the y coordinate at a corner
|
|
|
|
*/
|
|
|
|
public void setFrameFromCenter(double centerX, double centerY,
|
|
|
|
double cornerX, double cornerY)
|
2000-07-23 08:24:14 +08:00
|
|
|
{
|
2002-08-09 12:26:17 +08:00
|
|
|
double halfw = Math.abs(cornerX - centerX);
|
|
|
|
double halfh = Math.abs(cornerY - centerY);
|
|
|
|
setFrame(centerX - halfw, centerY - halfh, halfw + halfw, halfh + halfh);
|
2000-07-23 08:24:14 +08:00
|
|
|
}
|
|
|
|
|
2002-08-09 12:26:17 +08:00
|
|
|
/**
|
|
|
|
* Set the framing rectangle of this shape using the center of the frame,
|
|
|
|
* and one of the four corners. The area will be positive.
|
|
|
|
*
|
|
|
|
* @param center the center point
|
|
|
|
* @param corner a corner point
|
|
|
|
* @throws NullPointerException if either point is null
|
|
|
|
*/
|
|
|
|
public void setFrameFromCenter(Point2D center, Point2D corner)
|
2000-07-23 08:24:14 +08:00
|
|
|
{
|
2002-08-09 12:26:17 +08:00
|
|
|
setFrameFromCenter(center.getX(), center.getY(),
|
|
|
|
corner.getX(), corner.getY());
|
2000-07-23 08:24:14 +08:00
|
|
|
}
|
|
|
|
|
2002-08-09 12:26:17 +08:00
|
|
|
/**
|
|
|
|
* Tests if a point is inside the boundary of the shape.
|
|
|
|
*
|
|
|
|
* @param p the point to test
|
|
|
|
* @return true if the point is inside the shape
|
|
|
|
* @throws NullPointerException if p is null
|
|
|
|
* @see #contains(double, double)
|
|
|
|
*/
|
|
|
|
public boolean contains(Point2D p)
|
2000-07-23 08:24:14 +08:00
|
|
|
{
|
2002-08-09 12:26:17 +08:00
|
|
|
return contains(p.getX(), p.getY());
|
2000-07-23 08:24:14 +08:00
|
|
|
}
|
|
|
|
|
2002-08-09 12:26:17 +08:00
|
|
|
/**
|
|
|
|
* Tests if a rectangle and this shape share common internal points.
|
|
|
|
*
|
|
|
|
* @param r the rectangle to test
|
|
|
|
* @return true if the rectangle intersects this shpae
|
|
|
|
* @throws NullPointerException if r is null
|
|
|
|
* @see #intersects(double, double, double, double)
|
|
|
|
*/
|
|
|
|
public boolean intersects(Rectangle2D r)
|
2000-07-23 08:24:14 +08:00
|
|
|
{
|
2002-08-09 12:26:17 +08:00
|
|
|
return intersects(r.getX(), r.getY(), r.getWidth(), r.getHeight());
|
2000-07-23 08:24:14 +08:00
|
|
|
}
|
|
|
|
|
2002-08-09 12:26:17 +08:00
|
|
|
/**
|
|
|
|
* Tests if the shape completely contains the given rectangle.
|
|
|
|
*
|
|
|
|
* @param r the rectangle to test
|
|
|
|
* @return true if r is contained in this shape
|
|
|
|
* @throws NullPointerException if r is null
|
|
|
|
* @see #contains(double, double, double, double)
|
|
|
|
*/
|
|
|
|
public boolean contains(Rectangle2D r)
|
2000-07-23 08:24:14 +08:00
|
|
|
{
|
2002-08-09 12:26:17 +08:00
|
|
|
return contains(r.getX(), r.getY(), r.getWidth(), r.getHeight());
|
2000-07-23 08:24:14 +08:00
|
|
|
}
|
|
|
|
|
2002-08-09 12:26:17 +08:00
|
|
|
/**
|
|
|
|
* Returns a bounding box for this shape, in integer format. Notice that you
|
|
|
|
* may get a tighter bound with getBounds2D. If the frame is empty, the
|
|
|
|
* box is the default empty box at the origin.
|
|
|
|
*
|
|
|
|
* @return a bounding box
|
|
|
|
*/
|
|
|
|
public Rectangle getBounds()
|
2000-07-23 08:24:14 +08:00
|
|
|
{
|
2002-08-09 12:26:17 +08:00
|
|
|
if (isEmpty())
|
|
|
|
return new Rectangle();
|
|
|
|
double x = getX();
|
|
|
|
double y = getY();
|
|
|
|
double maxx = Math.ceil(x + getWidth());
|
|
|
|
double maxy = Math.ceil(y + getHeight());
|
|
|
|
x = Math.floor(x);
|
|
|
|
y = Math.floor(y);
|
|
|
|
return new Rectangle((int) x, (int) y, (int) (maxx - x), (int) (maxy - y));
|
2000-07-23 08:24:14 +08:00
|
|
|
}
|
|
|
|
|
2002-08-09 12:26:17 +08:00
|
|
|
/**
|
|
|
|
* Return an iterator along the shape boundary. If the optional transform
|
|
|
|
* is provided, the iterator is transformed accordingly. The path is
|
|
|
|
* flattened until all segments differ from the curve by at most the value
|
|
|
|
* of the flatness parameter, within the limits of the default interpolation
|
|
|
|
* recursion limit of 1024 segments between actual points. Each call
|
|
|
|
* returns a new object, independent from others in use. The result is
|
|
|
|
* threadsafe if and only if the iterator returned by
|
|
|
|
* {@link #getPathIterator(AffineTransform)} is as well.
|
|
|
|
*
|
|
|
|
* @param transform an optional transform to apply to the iterator
|
|
|
|
* @param flatness the desired flatness
|
|
|
|
* @return a new iterator over the boundary
|
|
|
|
* @throws IllegalArgumentException if flatness is invalid
|
|
|
|
* @since 1.2
|
|
|
|
*/
|
|
|
|
public PathIterator getPathIterator(AffineTransform at, double flatness)
|
2000-07-23 08:24:14 +08:00
|
|
|
{
|
2002-08-09 12:26:17 +08:00
|
|
|
return new FlatteningPathIterator(getPathIterator(at), flatness);
|
2000-07-23 08:24:14 +08:00
|
|
|
}
|
|
|
|
|
2002-08-09 12:26:17 +08:00
|
|
|
/**
|
|
|
|
* Create a new shape of the same run-time type with the same contents as
|
|
|
|
* this one.
|
|
|
|
*
|
|
|
|
* @return the clone
|
|
|
|
*/
|
|
|
|
public Object clone()
|
2000-07-23 08:24:14 +08:00
|
|
|
{
|
2000-08-09 21:01:44 +08:00
|
|
|
try
|
2002-08-09 12:26:17 +08:00
|
|
|
{
|
|
|
|
return super.clone();
|
|
|
|
}
|
|
|
|
catch (CloneNotSupportedException e)
|
|
|
|
{
|
|
|
|
throw (Error) new InternalError().initCause(e); // Impossible
|
|
|
|
}
|
2000-07-23 08:24:14 +08:00
|
|
|
}
|
2002-08-09 12:26:17 +08:00
|
|
|
} // class RectangularShape
|