|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectsm.SMShape
A shape to be added to an SMCanvas
.
The shape is defined by a geometry and some grahical attributes, and it can have tags.
A shape can be marked as drawable or not, and pickable or not.
When a shape is not drawable, it is not displayed by the enclosing canvas.
When a shape is not pickable, it is ignored by the enclosing canvas for pick operations.
The geometry of a shape is defined by an arbitrary Java2D Shape
.
Subclasses of SMShape
define specific geometries, namely rectangle, ellipse, polyline, text, and image.
The geometry of a shape is transformed by an affine transformation that
combines a scale, a rotation and a translation. The default transformation is the identity.
The rotation, scale and translateTo operations occur around the shape's reference point, which by default is at the center of the shape's bounding box.
The reference point can be changed. It is defined relatively to the shape's bounding box, i.e
(0, 0) means the top left corner of the shape, (1,1) the bottom right corner, (0.5, 0.5) the center, etc.
By default, the geometry of the shape is relative to the enclosing canvas's coordinate system. However a shape can have a parent, which is another shape in the canvas. In this case the shape's coordinates are relative to the transformation of its parent. This means that changing the transform of the parent shape will affect its children. A shape can be the parent of an arbitrary number of shapes, and can itself have a parent.
The last element that affects the shape's geometry is the clipping shape. A shape can be clipped by another shape of the canvas. The clipped shape is only visible within the interior of the clipping shape.
The graphical attributes of a shape consists of a fill paint,
an outline paint and a stroke style. The fill paint is used if the shape is filled
to paint the interior of the shape. The outline paint and stroke style are used
if the shape is outlined to paint the border of the shape. Paints and stroke styles
can be any Java2D objects that implement the Paint
and Stroke
interfaces respectively. Graphical attributes affect picking. For example, if a shape is not filled,
only the border stroke is taken into account for picking.
Tags can be attached to a shape. See SMTag
for details.
It is important to remember that tags cannot be added to a shape until the shape is added to a canvas.
This is because each canvas manages its own set of tags.
SMCanvas
,
SMTag
Field Summary | |
static int |
cptId
|
Constructor Summary | |
SMShape()
|
|
SMShape(java.awt.Shape s)
Builds an SMShape from a Java2D shape. |
|
SMShape(java.awt.Shape s,
java.awt.Paint p)
Builds an SMShape from a Java2D shape and a fill paint. |
|
SMShape(java.awt.Shape s,
java.awt.Paint p,
java.awt.Paint o)
Builds an SMShape from a Java2D shape, a fill paint and an outline paint. |
|
SMShape(java.awt.Shape s,
java.awt.Paint p,
java.awt.Paint o,
java.awt.Stroke str)
Builds an SMShape from a Java2D shape, a fill paint, an outline paint and a stroke style. |
|
SMShape(java.awt.Shape s,
java.awt.Paint p,
java.awt.Stroke str)
Builds an SMShape from a Java2D shape, a fill paint and a stroke style. |
|
SMShape(java.awt.Shape s,
java.awt.Stroke str)
Builds an SMShape from a Java2D shape and a stroke style. |
Method Summary | |
SMShape |
above(SMShape before)
Moves this shape in the canvas's display list so that it is right above a given shape in the display list. |
SMShape |
aboveAll()
Moves this shape in the canvas's display list so that it is above all other shapes. |
SMShape |
addChild(SMShape c)
Adds a child to this shape. |
SMShape |
addGhost()
Builds the 'ghost' of this shape. |
SMShape |
addTag(SMExtensionalTag t)
Adds a tag to this shape. |
SMShape |
addTag(SMTag t)
Adds a tag to this shape only if the tag is a SMVolatileTag , does anything otherwise. |
SMShape |
addTag(java.lang.String t)
Adds a SMNamedTag tag to this shape. |
SMShape |
addTo(SMCanvas c)
Adds this shape to a canvas. |
SMEllipse |
asEllipse()
Returns this shape if it is an ellipse, null otherwise |
SMImage |
asImage()
Returns this shape if it is an image, null otherwise |
SMPolyLine |
asPolyLine()
Returns this shape if it is a polyline, null otherwise |
SMRectangle |
asRectangle()
Returns this shape if it is a rectangle, null otherwise |
SMRectangularShape |
asRectangularShape()
Returns this shape if it is a rectangularShape, null otherwise |
SMText |
asText()
Returns this shape if it is a text, null otherwise |
void |
attachSM(StateMachine sm,
boolean reset)
Attaches a state machine to this interactive object to describe its behavior. |
SMShape |
below(SMShape after)
Moves this shape in the canvas's display list so that it is right below a given shape in the display list. |
SMShape |
belowAll()
Moves this shape in the canvas's display list so that it is below all other shapes. |
java.awt.geom.Point2D |
canvasToShape(java.awt.geom.Point2D p)
Converts a point relative to the canvas into a point relative to the shape |
java.lang.Object |
clone()
|
boolean |
contains(double x,
double y)
Tests whether a point (x, y) is inside this shape. |
boolean |
contains(double x,
double y,
double w,
double h)
Tests whether a rectangle R is inside this shape. |
boolean |
contains(java.awt.geom.Point2D p)
Tests whether a point p is inside this shape. |
boolean |
contains(java.awt.geom.Rectangle2D r)
Tests whether a rectangle R is inside this shape. |
boolean |
containsPoint(double x,
double y)
Tests if a point is in this interactive object. |
boolean |
containsPoint(java.awt.geom.Point2D point)
Tests if a point is in this interactive object. |
SMShape |
copyTo(SMShape sms)
Copies this shape into a destination shape. |
void |
detachSM(StateMachine sm)
Detaches a state machine from this interactive object. |
SMShape |
duplicate()
Creates a new copy of this shape and returns it. |
boolean |
equals(java.lang.Object o)
|
java.awt.Shape |
getAbsShape()
Returns the shape in the absolute coordinate system of the canvas |
java.awt.geom.AffineTransform |
getAbsTransform()
Returns the absolute affine transformation that is applied to the shape. |
SMRectangle |
getBoundingBox()
|
SMCanvas |
getCanvas()
Return the canvas this shape belongs to, if any. |
double |
getCenterX()
|
double |
getCenterY()
|
java.util.LinkedList |
getChildren()
Returns the children of this shape as a linked list. |
SMShape |
getClip()
Returns the shape that clips this shape, if any. |
java.awt.Paint |
getFillPaint()
Returns the fill Paint, which is used to display the interior of the shape when it is filled. |
double |
getHeight()
|
SMHierarchy |
getHierarchy()
Returns the hierarchy of this shape. |
int |
getID()
|
double |
getMaxX()
|
double |
getMaxY()
|
double |
getMinX()
|
double |
getMinY()
|
java.awt.Paint |
getOutlinePaint()
Returns the outline Paint, which is used to display the boundary of the shape when it is outlined. |
SMShape |
getParent()
Returns the parent of this shape, if any. |
double |
getReferenceX()
Returns the x coordinate of this shape's reference point. |
double |
getReferenceY()
Returns the y coordinate of this shape's reference point. |
double |
getRotation()
Returns this shape's rotation angle |
double |
getScaleX()
Returns the x scale value. |
double |
getScaleY()
Returns the y scale value. |
java.awt.Shape |
getShape()
Returns the shape. |
java.awt.Stroke |
getStroke()
Returns the stroke style, which specifies the shape of the boundary of the shape when it is outlined (thickness, dash pattern, etc.). |
java.awt.geom.AffineTransform |
getTransform()
Returns the affine transformation that is applied to the shape. |
double |
getTranslateX()
Returns the x coordinate of this shape. |
double |
getTranslateY()
Returns the y coordinate of this shape. |
float |
getTransparency()
Returns the transparency, which applies to the whole shape (boundary and interior). |
double |
getWidth()
|
boolean |
hasTag(SMTag t)
Tests whether this shape has a given tag. |
boolean |
hasTag(java.lang.String t)
Tests whether this shape has a given SMNamedTag tag. |
boolean |
intersects(double x,
double y,
double w,
double h)
Tests whether a rectangle R intersects this shape. |
boolean |
intersects(java.awt.geom.Rectangle2D r)
Tests whether a rectangle r intersects this shape. |
boolean |
isAbove(SMShape before)
Tests if this shape is above another shape in the display list. |
boolean |
isAntialiased()
Returns true if this shape is antialiased. |
boolean |
isBelow(SMShape after)
Tests if this shape is before another shape in the display list. |
boolean |
isDrawable()
Returns true if this shape is to be displayed. |
boolean |
isEmpty()
Determines whether or not the bounding box of this shape is empty. |
boolean |
isFilled()
Returns true if this shape is filled. |
boolean |
isOnOutline(java.awt.geom.Point2D p)
Tests whether a point p is on this shape's outline. |
boolean |
isOutlined()
Returns true if this shape is outlined. |
boolean |
isPickable()
Returns true if the shape can be picked. |
void |
paint(java.awt.Graphics g)
Paints the shape. |
SMShape |
remove()
Removes this shape from its canvas. |
SMShape |
removeChild(SMShape s)
Removes a child from this shape. |
void |
removeGhost()
Removes the 'ghost' of this shape from the canvas. |
SMShape |
removeTag(SMTag t)
Removes a tag from this shape only if the tag is a SMVolatileTag . |
SMShape |
removeTag(java.lang.String t)
Removes a tag from this shape. |
SMShape |
rotateBy(double dt)
Rotates this shape by dt |
SMShape |
rotateTo(double t)
Rotates this shape to angle t |
SMShape |
scaleBy(double ds)
Scales this shape by s horizontally and vertically. |
SMShape |
scaleBy(double x,
double y)
Scales this shape by x horizontally and y vertically. |
SMShape |
scaleTo(double s)
Sets this shape's scale to s horizontally and vertically. |
SMShape |
scaleTo(double x,
double y)
Sets the scale of this shape to x horizontally and y vertically. |
SMShape |
setAntialiased(boolean a)
Specifies whether this shape is antialiased. |
SMShape |
setClip(SMShape clip)
Sets the clipping shape of this shape. |
SMShape |
setDrawable(boolean d)
Specifies whether this shape is to be displayed. |
SMShape |
setFilled(boolean isFilled)
Sets the filled property of this shape. |
SMShape |
setFillPaint(java.awt.Paint fp)
Sets the fill Paint, which is used to display the interior of the shape when it is filled. |
SMShape |
setOutlined(boolean o)
Sets the outlined property of this shape. |
SMShape |
setOutlinePaint(java.awt.Paint op)
Sets the outline Paint, which is used to display the boundary of the shape when it is outlined. |
SMShape |
setParent(SMShape p)
Sets the parent of this shape (only if the parent and this ahape are in the same canvas). |
SMShape |
setPickable(boolean pick)
Specifies whether this shape can be picked. |
SMShape |
setReferencePoint(double x,
double y)
Set this shape's reference point. |
SMShape |
setShape(java.awt.Shape s)
Sets the shape. |
SMShape |
setStroke(java.awt.Stroke str)
Sets the stroke style, which specifies the shape of the boundary of the shape when it is outlined (thickness, dash pattern, etc.). |
SMShape |
setTransparency(float alpha)
Sets the transparency of this shape, which applies both to the boundary and interior. |
java.awt.geom.Point2D |
shapeToCanvas(java.awt.geom.Point2D p)
Converts a point relative to the shape into a point relative to the canvas |
SMShape |
translateBy(double dx,
double dy)
Translates this shape by dx, dy. |
SMShape |
translateTo(double x,
double y)
Translates this shape to x, y (the point of reference of this shape will be exactly at (x, y)). |
Methods inherited from class java.lang.Object |
getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static int cptId
Constructor Detail |
public SMShape()
public SMShape(java.awt.Shape s)
s
- The java2D shapepublic SMShape(java.awt.Shape s, java.awt.Stroke str)
s
- The java2D shapestr
- The stroke stylepublic SMShape(java.awt.Shape s, java.awt.Paint p)
s
- The java2D shapep
- The fill paintpublic SMShape(java.awt.Shape s, java.awt.Paint p, java.awt.Paint o)
s
- The java2D shapep
- The fill painto
- The outline paintpublic SMShape(java.awt.Shape s, java.awt.Paint p, java.awt.Paint o, java.awt.Stroke str)
s
- The java2D shapep
- The fill painto
- The outlinestr
- The stroke stylepublic SMShape(java.awt.Shape s, java.awt.Paint p, java.awt.Stroke str)
s
- The java2D shapep
- The fill paintstr
- The stroke styleMethod Detail |
public int getID()
public boolean equals(java.lang.Object o)
public SMCanvas getCanvas()
getCanvas
in interface InteractiveObject
public java.awt.Shape getShape()
public SMShape setShape(java.awt.Shape s)
s
- The new Java2D shape.
public SMShape addTo(SMCanvas c)
c
- The canvas.
public SMShape remove()
public void paint(java.awt.Graphics g)
g
- The graphics with which the shape must be painted.public boolean isDrawable()
public SMShape setDrawable(boolean d)
d
- True if the shape is to be displayed, false otherwise.
public float getTransparency()
public SMShape setTransparency(float alpha)
alpha
- The transparency level (0.0 = transparent, 1.0 = opaque).
public boolean isFilled()
public SMShape setFilled(boolean isFilled)
isFilled
- True if the shape is filled.
public java.awt.Paint getFillPaint()
public SMShape setFillPaint(java.awt.Paint fp)
fp
- The fill Paint.
public boolean isOutlined()
public SMShape setOutlined(boolean o)
o
- True if the shape is outlined.
public java.awt.Stroke getStroke()
public SMShape setStroke(java.awt.Stroke str)
str
- The stroke style.
public java.awt.Paint getOutlinePaint()
public SMShape setOutlinePaint(java.awt.Paint op)
op
- The outline Paint.
public SMShape getClip()
public SMShape setClip(SMShape clip)
clip
- The clipping shape, or null to reset clipping of this shape.
public boolean isAntialiased()
public SMShape setAntialiased(boolean a)
a
- True if this shape is to be antialiased.
public SMHierarchy getHierarchy()
public SMShape getParent()
public java.util.LinkedList getChildren()
public SMShape setParent(SMShape p)
p
- The new parent, or null if the shape is to have no parent.
public SMShape addChild(SMShape c)
c
- The child shape
public SMShape removeChild(SMShape s) throws ImpossibleOperationOnDifferentCanvasException
s
- The child shape to remove
ImpossibleOperationOnDifferentCanvasException
ImpossibleOperationOnDifferentCanvasException
public java.awt.geom.AffineTransform getTransform()
public java.awt.geom.AffineTransform getAbsTransform()
public java.awt.Shape getAbsShape()
public double getReferenceX()
public double getReferenceY()
public SMShape setReferencePoint(double x, double y)
x
- The x coordinate of the new reference point.y
- The y coordinate of the new reference point.
public SMShape translateBy(double dx, double dy)
dx
- The x offsetdy
- The y offset
public SMShape translateTo(double x, double y)
x
- The x coordinatey
- The y coordinate
public double getTranslateX()
public double getTranslateY()
public SMShape rotateBy(double dt)
dt
- The angle offset
public SMShape rotateTo(double t)
t
- The angle
public double getRotation()
public SMShape scaleBy(double x, double y)
x
- The x scale factory
- The y scale factor
public SMShape scaleTo(double x, double y)
x
- The x scaley
- The y scale
public SMShape scaleBy(double ds)
ds
- The scale factor
public SMShape scaleTo(double s)
s
- The scale value
public double getScaleX()
public double getScaleY()
public java.awt.geom.Point2D shapeToCanvas(java.awt.geom.Point2D p)
p
- - The point to be converted
public java.awt.geom.Point2D canvasToShape(java.awt.geom.Point2D p)
p
- - The point to be converted
public SMRectangle getBoundingBox()
public double getHeight()
public double getWidth()
public double getMinX()
public double getMinY()
public double getMaxX()
public double getMaxY()
public double getCenterX()
public double getCenterY()
public boolean isEmpty()
public boolean isPickable()
pick, pickAll
) and by the state machines.
public SMShape setPickable(boolean pick)
pick, pickAll
) and by the state machines.
pick
- True if this shape can be picked, false otherwise.
public boolean contains(double x, double y)
x
- The x coordinatey
- The y coordinate
Shape.contains(double, double)
public boolean contains(java.awt.geom.Point2D p)
p
- The point
Shape.contains(Point2D)
public boolean contains(double x, double y, double w, double h)
x
- The x coordinate of the upper left corner of Ry
- The y coordinate of the upper left corner of Rw
- The width of Rh
- The height of R
Shape.contains(double, double, double, double)
public boolean contains(java.awt.geom.Rectangle2D r)
r
- The rectangle
Shape.contains(Rectangle2D)
public boolean isOnOutline(java.awt.geom.Point2D p)
p
- The point
public boolean intersects(double x, double y, double w, double h)
x
- The x coordinate of the upper left corner of Ry
- The y coordinate of the upper left corner of Rw
- The width of Rh
- The height of R
public boolean intersects(java.awt.geom.Rectangle2D r)
r
- The rectangle
public boolean isAbove(SMShape before)
before
- The shape.
before
(false if this shape or the the shape before
are not attached to a canvas).public SMShape above(SMShape before)
before
- The shape that must be right below this shape in the display list
public SMShape aboveAll()
public boolean isBelow(SMShape after)
after
- The shape.
after
(false if this shape or the the shape after
are not attached to a canvas).public SMShape below(SMShape after)
after
- The shape that must be right above this shape in the display list
public SMShape belowAll()
public SMShape addTag(SMTag t)
SMVolatileTag
, does anything otherwise.
t
- The tag to be added
public SMShape addTag(SMExtensionalTag t)
t
- The tag to be added
public SMShape addTag(java.lang.String t)
SMNamedTag
tag to this shape.
t
- The name of the tag to be added
public boolean hasTag(SMTag t)
t
- The tag to be tested
public boolean hasTag(java.lang.String t)
SMNamedTag
tag.
t
- The name of the tag to be tested
public SMShape removeTag(SMTag t)
SMVolatileTag
.
t
- The tag to remove
public SMShape removeTag(java.lang.String t)
t
- The name of the SMNamedTag
tag to remove
public java.lang.Object clone() throws java.lang.CloneNotSupportedException
java.lang.CloneNotSupportedException
public SMShape copyTo(SMShape sms)
sms
- The destination shape
public SMShape duplicate()
public SMRectangle asRectangle()
public SMEllipse asEllipse()
public SMPolyLine asPolyLine()
public SMRectangularShape asRectangularShape()
public SMText asText()
public SMImage asImage()
public SMShape addGhost()
public void removeGhost()
public void attachSM(StateMachine sm, boolean reset)
InteractiveObject
attachSM
in interface InteractiveObject
sm
- The State machine that describes the behavior of this interactive object.reset
- True if the machine must be reset, false otherwise.public void detachSM(StateMachine sm)
InteractiveObject
detachSM
in interface InteractiveObject
sm
- The State machine to detach.public boolean containsPoint(java.awt.geom.Point2D point)
InteractiveObject
containsPoint
in interface InteractiveObject
point
- The point to test.
public boolean containsPoint(double x, double y)
InteractiveObject
containsPoint
in interface InteractiveObject
x
- The x-coordinate of the point to test.y
- The y-coordinate of the point to test.
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |