public class EditableRectangle extends Rectangle2D.Double implements EditableShape, Cloneable
Rectangle2D.Double, Rectangle2D.Float
Modifier and Type | Field and Description |
---|---|
protected int |
border |
protected Point2D |
lastP1 |
protected Point2D |
lastP2 |
protected Point2D |
p1 |
protected Point2D |
p2 |
protected Point2D |
p3 |
protected Point2D |
p4 |
protected boolean |
selected |
height, width, x, y
OUT_BOTTOM, OUT_LEFT, OUT_RIGHT, OUT_TOP
Constructor and Description |
---|
EditableRectangle(int x,
int y,
int width,
int height) |
EditableRectangle(Point2D ini,
Point2D end)
Creates new EditableRectangle
|
Modifier and Type | Method and Description |
---|---|
void |
aproximateNearestBorder(double x,
double y)
Moves towards a specific point the side of the shape that is located nearest it.
.
|
void |
changeBorder(double x,
double y)
Changes the co-ordinates of the previously marked corner to (x, y)
|
Object |
clone()
Makes a copy of the shape.
|
void |
deselectBorder()
Unselects the selected border of the shape, if any.
|
double |
distanceTo(double x,
double y)
Computes the distance between a supplied point and the nearest limit of the shape.
|
EditableShape[] |
divide(double x,
double y)
Divides the shape taking (x,y) as the "significant" point of the division.
|
EditableShape[] |
divide(double x,
double y,
boolean newPoint) |
void |
drawBorders(Graphics g)
Draws the shape with dragable sides
|
Point2D[] |
getBorders()
Gets an array with all the corners and other special points of the shape.
|
Point2D |
getEndPoint()
Gets the point of the shape that is considered as "ending" point.
|
Point2D |
getInitialPoint()
Returns the point of the shape that acts as "starting" point.
|
Point2D |
getLocation() |
Point2D |
getNearestBorder(double x,
double y)
Rerturns the starting point of the side of the shape nearest to a specific point.
|
Point2D |
getNotSelectedBorder()
Gets the starting point of the first non-selected side of the shape
|
boolean |
hasClickedBorder(double x,
double y,
boolean needSelected)
Checks if the specified point lies within a side of the shape
|
boolean |
hasSelectedBorder()
Checks if the shape currently has a selected side.
|
boolean |
isAdjacentTo(Point2D p)
Checks if the shape is adjacent to a specific point.
|
boolean |
isInto(Rectangle2D r)
Checks if the shape is into the limits of a specific
Rectangle . |
boolean |
isSelected()
Checks if the shape is selected
|
void |
paint(Graphics g,
int drawingMode)
Draws the shape with the default colour
|
void |
paintSelection(Graphics g)
Draws squares in black and the remainder objects in the selection color
(EditableShapeConstants.selectedColor)
|
void |
paintWithColor(Graphics g,
int drawingMode,
Color c)
Draws the shape with the indicated color.
|
void |
selectBorder(double x,
double y)
Selects the side of the shape that lies with the specified point (if any).
|
void |
setLimits(int x,
int y,
int width,
int height) |
void |
setLimits(Point2D ini,
Point2D end) |
void |
setSelected(boolean b)
Selects/unselects the shape
|
void |
transform(AffineTransform aTransf)
Applies an affine transformation (rotation, trnaslation, scale...) to the shape
|
createIntersection, createUnion, getBounds2D, getHeight, getWidth, getX, getY, isEmpty, outcode, setRect, setRect, toString
add, add, add, contains, contains, equals, getPathIterator, getPathIterator, hashCode, intersect, intersects, intersectsLine, intersectsLine, outcode, setFrame, union
contains, contains, getBounds, getCenterX, getCenterY, getFrame, getMaxX, getMaxY, getMinX, getMinY, intersects, setFrame, setFrame, setFrameFromCenter, setFrameFromCenter, setFrameFromDiagonal, setFrameFromDiagonal
finalize, getClass, notify, notifyAll, wait, wait, wait
contains, contains, contains, contains, getBounds, getBounds2D, getPathIterator, getPathIterator, intersects, intersects
protected boolean selected
protected int border
protected Point2D p1
protected Point2D p2
protected Point2D p3
protected Point2D p4
protected Point2D lastP1
protected Point2D lastP2
public void setLimits(int x, int y, int width, int height)
public EditableShape[] divide(double x, double y)
EditableShape
divide
in interface EditableShape
x
- The horizontal co-ordinate of the pointy
- The vertical co-ordinate of the pointpublic EditableShape[] divide(double x, double y, boolean newPoint)
public void setSelected(boolean b)
EditableShape
setSelected
in interface EditableShape
b
- The state (selected/unselected) of the shapepublic double distanceTo(double x, double y)
EditableShape
distanceTo
in interface EditableShape
x
- The horizontal co-ordinate of the pointy
- The vertical co-ordinate of the pointpublic boolean hasClickedBorder(double x, double y, boolean needSelected)
EditableShape
hasClickedBorder
in interface EditableShape
x
- The horizontal co-ordinate of the point to checky
- The vertical co-ordinate of the point to checkneedSelected
- When the value of this param is true
, the side must be selected.true
when a side of the shape is near the point defined by x and y.public void paintSelection(Graphics g)
EditableShape
paintSelection
in interface EditableShape
g
- The graphic environment where to draw the shapepublic boolean isSelected()
EditableShape
isSelected
in interface EditableShape
true
if the shape is selected, false
otherwise.public void aproximateNearestBorder(double x, double y)
EditableShape
aproximateNearestBorder
in interface EditableShape
x
- The horizontal co-ordinate of the pointy
- The vertival co-ordinate of the pointpublic void paintWithColor(Graphics g, int drawingMode, Color c)
EditableShape
paintWithColor
in interface EditableShape
g
- The graphic environment where to draw the shapedrawingMode
- The drawing mode. Squares are drawed in red when this value is
ShapeGenPanel.NEW_POINTc
- The color to be used to draw the shapepublic void transform(AffineTransform aTransf)
EditableShape
transform
in interface EditableShape
aTransf
- The affine transformation to be appliedpublic boolean isAdjacentTo(Point2D p)
EditableShape
isAdjacentTo
in interface EditableShape
p
- The point to be checkedtrue
if the shape is adjacent to the point, false
otherwisepublic boolean isInto(Rectangle2D r)
EditableShape
Rectangle
.isInto
in interface EditableShape
r
- The rectangle to be checkedtrue
if the shape intersects with the rectangle, false
otherwise.public Point2D getEndPoint()
EditableShape
getEndPoint
in interface EditableShape
public void changeBorder(double x, double y)
EditableShape
changeBorder
in interface EditableShape
x
- The horizontal co-ordinate of the pointy
- The vertical co-ordinate of the pointpublic void drawBorders(Graphics g)
EditableShape
drawBorders
in interface EditableShape
g
- The graphic environment where to draw the shapepublic Point2D getInitialPoint()
EditableShape
getInitialPoint
in interface EditableShape
public void paint(Graphics g, int drawingMode)
EditableShape
paint
in interface EditableShape
g
- The graphic environment where to draw the shapedrawingMode
- The drawing mode. Squares are drawed in red when this value is ShapeGenPanel.NEW_POINTpublic Point2D getNearestBorder(double x, double y)
EditableShape
getNearestBorder
in interface EditableShape
x
- The horizontal co-ordinate of the pointy
- The vertical co-ordinate of the pointpublic Point2D getLocation()
public Object clone()
EditableShape
clone
in interface EditableShape
clone
in class RectangularShape
public Point2D[] getBorders()
EditableShape
getBorders
in interface EditableShape
public void selectBorder(double x, double y)
EditableShape
selectBorder
in interface EditableShape
x
- The horizontal co-ordinate of the point to checky
- The vertical co-ordinate of the point to checkpublic void deselectBorder()
EditableShape
deselectBorder
in interface EditableShape
public boolean hasSelectedBorder()
EditableShape
hasSelectedBorder
in interface EditableShape
true
if the shape has a selected side, false
otherwise.public Point2D getNotSelectedBorder()
EditableShape
getNotSelectedBorder
in interface EditableShape
Copyright © 2004-15 Francesc Busquets (fbusquets@xtec.cat) & Departament d'Educació de la Generalitat de Catalunya (info@xtec.cat)
Licensed under the terms of the GNU General Public License.