public abstract class CTag extends Tag implements CElement
CTag
s are labels associated to canvas' shapes. The CTag
class has most of the methods of the CShape
class.
Calling one of these CTag
's methods calls the CShape
method that has the same name on every shape having this tag.
A tag is an object corresponding to a set of CShape
shapes that can be browsed (i.e. a collection
and an iterator on it).
One example is a CNamedTag
which is a set of shapes having a given label attached to them.
Another example is a CHierarchyTag(CShape s)
which is a set composed of s and every shape whose s is an ancestor.
Some tags, CExtensionalTag
tags, can be explicitely attached to and detached from a shape,
i.e. a shape can be added to or removed from the tag's collection,
while others can not. For example, a CNamedTag
can while a CHierarchyTag
can not (it is added by
setting the parent of a CShape
).
A tag can be attached to any number of shapes in the same canvas. A shape in the canvas can have any number of tags attached to it.
Tags are used for two main purposes : grouping and interaction.
ClickOnTag(BUTTON1, movable)
that will fire only when the user is clicking on an object with tag "movable".
class ColorTag extends CTag { Color color; ... }Then, in a state machine, one can use transitions like:
Transition onAnyColor = new PressOnTag(ColoredTag.class, BUTTON1) { public void action() { System.out.println("This object has a "+((ColoredTag)getTag()).color+" tag"); } };
Tag
Constructor and Description |
---|
CTag(Canvas c)
Builds a CTag that can tag the shapes displayed on the canvas c.
|
Modifier and Type | Method and Description |
---|---|
CElement |
above(CElement before)
Changes the display list order so that every CShape tagged by this tag is right above
the top most shape in another CElement.
|
CElement |
aboveAll()
Calls
aboveAll() for every CShape contained in this CElement . |
CTag |
action()
Calls
action(CShape s) for every CShape s that has this tag. |
void |
action(CShape s)
Method called by
action() . |
void |
addGhost()
Calls addGhost() on every CShape contained in this
CElement . |
CElement |
addTag(CExtensionalTag t)
Calls
addTag(Canvas.Tag t) for every CShape contained in this CElement . |
CElement |
addTag(java.lang.String t)
Calls
addTag(String t) for every CShape contained in this CElement . |
CTag |
and(CTag t)
Builds a tag corresponding to the set of shapes tagged by this tag and by t.
|
CTag |
and(java.lang.String t)
Builds a tag corresponding to the set of shapes tagged by this tag and by the
SMNamedTag t. |
CElement |
animate(Animation anim)
Calls
animate(Animation anim) for every CShape tagged by this CTag . |
void |
attachSM(CStateMachine sm,
boolean reset)
Attaches a state machine to this
CElement to describe its behavior. |
CElement |
below(CElement after)
Changes the display list order so that every CShape tagged by this tag is right below
the top least shape in another CElement.
|
CElement |
belowAll()
Calls
belowAll() for every CShape contained in this CElement . |
CShape |
contains(double x,
double y)
Returns the topmost CShape containing the point (x, y).
|
CShape |
contains(double x,
double y,
double w,
double h)
Returns the topmost CShape containing a given rectangle.
|
CShape |
contains(java.awt.geom.Point2D p)
Returns the topmost CShape containing the point p.
|
CShape |
contains(java.awt.Rectangle r)
Returns the topmost CShape containing a given rectangle.
|
void |
detachSM(CStateMachine sm)
Detaches a state machine from this
CElement . |
CShape |
firstShape()
Returns the first shape that has this tag.
|
CElement |
fixReferenceShapeToCurrent() |
java.util.LinkedList<CShape> |
getAntialiasedShapes()
Returns the list of CShape that have this tag and that are antialiased.
|
CRectangle |
getBoundingBox() |
Canvas |
getCanvas()
Returns the canvas in which this CElement is displayed.
|
double |
getCenterX() |
double |
getCenterY() |
java.util.LinkedList<CShape> |
getFilledShapes()
Returns the list of CShape that have this tag and that are filled.
|
CShape |
getFirstAntialiasedShape()
Returns the first antialiased CShape contained in this
CElement . |
CShape |
getFirstFilledShape()
Returns the first CShape contained in this
CElement and that is filled. |
CShape |
getFirstHavingTag(CTag t)
Returns the topmost CShape that has tag t.
|
CShape |
getFirstOutlinedShape()
Returns the first CShape contained in this
CElement and that is outlined. |
CPolyLine |
getIntersection(CShape s)
Tests whether a
CShape s intersects this CElement . |
double |
getMaxX() |
double |
getMaxY() |
double |
getMinX() |
double |
getMinY() |
java.util.LinkedList<CShape> |
getOutlinedShapes()
Returns the list of CShape that have this tag and that are outlined.
|
CShape |
getTopLeastShape() |
CShape |
getTopMostShape() |
boolean |
hasNext()
Tests if there is other objects tagged by this tag.
|
boolean |
hasTag(CTag t)
Returns true if every shape with this tag also has tag t.
|
boolean |
hasTag(java.lang.String t)
Returns true if every shape with this tag also has tag t.
|
CShape |
intersects(CShape s)
Returns the topmost
CShape that intersects the given CShape s. |
boolean |
isAntialiased()
Calls
isAntialiased() for every CShape that has this tag. |
boolean |
isDrawable()
Returns true if every shape that has this tag is drawable.
|
boolean |
isFilled()
Calls
isFilled() for every CShape contained in this CElement . |
CShape |
isOnOutline(java.awt.geom.Point2D p)
Returns the topmost CShape whose outline contains the point p.
|
boolean |
isOutlined()
Returns true if every shape that has this tag is outlined.
|
boolean |
isPickable()
Returns true if every shape that has this tag is pickable.
|
java.lang.Object |
next() |
CShape |
nextShape() |
CTag |
or(CTag t)
Builds a tag corresponding to the set of shapes tagged by this tag or by t.
|
CTag |
or(java.lang.String t)
Builds a tag corresponding to the set of shapes tagged by this tag or by the
SMNamedTag t. |
void |
removeGhost()
Calls removeGhost() on every CShape contained in this
CElement . |
CElement |
removeTag(CExtensionalTag t)
Calls
removeTag(Tag t) for every CShape contained in this CElement only if t is a SMExtensionalTag ,
does nothing otherwise. |
CElement |
removeTag(java.lang.String t)
Calls
removeTag(String t) for every CShape contained in this CElement . |
CElement |
rotateBy(double theta)
Calls
rotateBy(double theta) for every CShape contained in this CElement . |
CElement |
rotateTo(double theta)
Calls
rotateTo(double theta) for every CShape contained in this CElement . |
CElement |
scaleBy(double s)
Calls
scaleBy(double s) for every CShape contained in this CElement . |
CElement |
scaleBy(double sx,
double sy)
Calls
scale(double sx, double sy) for every CShape contained in this CElement . |
CElement |
scaleTo(double s)
Calls
scaleTo(double s) for every CShape contained in this CElement . |
CElement |
scaleTo(double sx,
double sy)
Calls
scaleTo(double sx, double sy) for every CShape contained in this CElement . |
CElement |
setAntialiased(boolean a)
Calls
setAntialiased(boolean) for every CShape contained in this CElement . |
CElement |
setClip(CShape clip)
Calls
setClip(CShape clip) for every CShape contained in this CElement . |
CElement |
setDrawable(boolean f)
Calls
setDrawable(boolean) for every CShape contained in this CElement . |
CElement |
setFilled(boolean f)
Calls
setFilled(boolean) for every CShape contained in this CElement . |
CElement |
setFillPaint(java.awt.Paint fp)
Calls
setFillPaint(Paint fp) for every CShape contained in this CElement . |
CElement |
setOutlined(boolean f)
Calls
setOutlined(boolean) for every CShape contained in this CElement . |
CElement |
setOutlinePaint(java.awt.Paint op)
Calls
setOutlinePaint(Paint op) for every CShape contained in this CElement . |
CElement |
setParent(CShape parent)
Calls
setParent(CShape parent) for every CShape contained in this CElement . |
CElement |
setPickable(boolean pick)
Calls
setPickable(boolean) for every CShape contained in this CElement . |
CElement |
setReferencePoint(double x,
double y)
Calls
setReferencePoint(double x, double y) for every CShape contained in this CElement . |
CElement |
setRenderingHint(java.awt.RenderingHints.Key hintKey,
java.lang.Object hintValue)
Calls
setRenderingHint(hintKey, hintValue) for every CShape contained in this CElement . |
CElement |
setShape(java.awt.Shape sh)
Calls
setShape(Shape sh) for every CShape contained in this CElement . |
CElement |
setStroke(java.awt.Stroke str)
Calls
setStroke(Shape sh) for every CShape contained in this CElement . |
CElement |
setTransformToIdentity()
Calls
setTransformToIdentity() for every CShape contained in this CElement . |
CElement |
setTransparencyFill(java.awt.AlphaComposite transparencyFill)
Calls
setTransparencyFill(AlphaComposite transparencyFill) for every CShape contained in this CElement . |
CElement |
setTransparencyFill(float alpha)
Calls
setTransparencyFill(float alpha) for every CShape contained in this CElement . |
CElement |
setTransparencyOutline(java.awt.AlphaComposite transparencyOutline)
Calls
setTransparencyOutline(AlphaComposite transparencyOutline) for every CShape contained in this CElement . |
CElement |
setTransparencyOutline(float alpha)
Calls
setTransparencyOutline(float alpha) for every CShape contained in this CElement . |
boolean |
tagsShape(CShape s)
Tests if the shape s is tagged by this tag.
|
CElement |
translateBy(double tx,
double ty)
Calls
translateBy(double tx, double ty) for every CShape contained in this CElement . |
CElement |
translateTo(double tx,
double ty)
Calls
translateTo(double tx, double ty) every CShape contained in this CElement . |
getCollection, remove, reset, size
public CTag(Canvas c)
c
- The canvas.public Canvas getCanvas()
public boolean hasNext()
public final java.lang.Object next()
public CShape nextShape()
CShape
.Iterator.next()
public boolean tagsShape(CShape s)
s
- The shapepublic CTag and(CTag t)
t
- The second tag.CAndTag
public CTag and(java.lang.String t)
SMNamedTag
t.public CTag or(CTag t)
t
- The second tag.COrTag
public CTag or(java.lang.String t)
SMNamedTag
t.public void action(CShape s)
action()
. This method does nothing.
Redefine it in a subclass to specify the effect of CTag#action()
s
- The CShape on which applying specific treatments.public final CTag action()
action(CShape s)
for every CShape s that has this tag.public CElement setShape(java.awt.Shape sh)
setShape(Shape sh)
for every CShape contained in this CElement
.setShape
in interface CElement
sh
- The shapeCElement
CShape.setShape(java.awt.Shape)
public CElement setParent(CShape parent)
setParent(CShape parent)
for every CShape contained in this CElement
.setParent
in interface CElement
parent
- The parent shapeCElement
CShape.setParent(CShape)
public CElement setStroke(java.awt.Stroke str)
setStroke(Shape sh)
for every CShape contained in this CElement
.setStroke
in interface CElement
str
- The strokeCElement
CShape.setStroke(java.awt.Stroke)
public CElement setTransparencyFill(java.awt.AlphaComposite transparencyFill)
setTransparencyFill(AlphaComposite transparencyFill)
for every CShape contained in this CElement
.setTransparencyFill
in interface CElement
transparencyFill
- The transparencyCElement
CShape.setTransparencyFill(AlphaComposite)
public CElement setTransparencyFill(float alpha)
setTransparencyFill(float alpha)
for every CShape contained in this CElement
.setTransparencyFill
in interface CElement
alpha
- The transparencyCElement
CShape.setTransparencyFill(float)
public CElement setTransparencyOutline(java.awt.AlphaComposite transparencyOutline)
setTransparencyOutline(AlphaComposite transparencyOutline)
for every CShape contained in this CElement
.setTransparencyOutline
in interface CElement
transparencyOutline
- The transparencyCElement
CShape.setTransparencyOutline(AlphaComposite)
public CElement setTransparencyOutline(float alpha)
setTransparencyOutline(float alpha)
for every CShape contained in this CElement
.setTransparencyOutline
in interface CElement
alpha
- The transparencyCElement
CShape.setTransparencyOutline(float)
public CElement setFillPaint(java.awt.Paint fp)
setFillPaint(Paint fp)
for every CShape contained in this CElement
.setFillPaint
in interface CElement
fp
- The paint valueCElement
CShape.setFillPaint(Paint)
public CElement setOutlinePaint(java.awt.Paint op)
setOutlinePaint(Paint op)
for every CShape contained in this CElement
.setOutlinePaint
in interface CElement
op
- The paint valueCElement
CShape.setOutlinePaint(Paint)
public boolean isAntialiased()
isAntialiased()
for every CShape that has this tag.isAntialiased
in interface CElement
CShape.isAntialiased()
public java.util.LinkedList<CShape> getAntialiasedShapes()
getAntialiasedShapes
in interface CElement
CShape.isAntialiased()
public CElement setRenderingHint(java.awt.RenderingHints.Key hintKey, java.lang.Object hintValue)
setRenderingHint(hintKey, hintValue)
for every CShape contained in this CElement
.
See java.awt.RenderingHints
for available hint keys and hint values.setRenderingHint
in interface CElement
hintKey
- The hint keyhintValue
- The hint valueCElement
.public CElement setAntialiased(boolean a)
setAntialiased(boolean)
for every CShape contained in this CElement
.setAntialiased
in interface CElement
a
- True to activate the antialiasing, false to deactivate it.CElement
CShape.setAntialiased(boolean)
public boolean isFilled()
isFilled()
for every CShape contained in this CElement
.isFilled
in interface CElement
CElement
is filled.CShape.isFilled()
public java.util.LinkedList<CShape> getFilledShapes()
getFilledShapes
in interface CElement
CShape.isFilled()
public CElement setFilled(boolean f)
setFilled(boolean)
for every CShape contained in this CElement
.setFilled
in interface CElement
f
- True if the shape must be filled, false otherwise.CElement
CShape.setFilled(boolean)
public boolean isOutlined()
isOutlined
in interface CElement
CShape.isOutlined()
public java.util.LinkedList<CShape> getOutlinedShapes()
CElement
getOutlinedShapes
in interface CElement
CShape.isOutlined()
public CElement setOutlined(boolean f)
setOutlined(boolean)
for every CShape contained in this CElement
.setOutlined
in interface CElement
f
- True if the shape must be outlined, false otherwise.CElement
CShape.setOutlined(boolean)
public boolean isDrawable()
isDrawable
in interface CElement
CShape.isDrawable()
public CElement setDrawable(boolean f)
setDrawable(boolean)
for every CShape contained in this CElement
.setDrawable
in interface CElement
f
- True if the shape must be drawn, false otherwise.CElement
CShape.setDrawable(boolean)
public boolean isPickable()
isPickable
in interface CElement
CShape.isPickable()
public CElement setPickable(boolean pick)
setPickable(boolean)
for every CShape contained in this CElement
.setPickable
in interface CElement
pick
- True if the shape must be pickable, false otherwise.CElement
CShape.setOutlined(boolean)
public CElement setReferencePoint(double x, double y)
setReferencePoint(double x, double y)
for every CShape contained in this CElement
.setReferencePoint
in interface CElement
x
- The x coordinate of the new reference point.y
- The y coordinate of the new reference point.CElement
CShape.setReferencePoint(double, double)
public CElement setTransformToIdentity()
setTransformToIdentity()
for every CShape contained in this CElement
.setTransformToIdentity
in interface CElement
CElement
CShape.setTransformToIdentity()
public CElement fixReferenceShapeToCurrent()
fixReferenceShapeToCurrent
in interface CElement
public CElement translateBy(double tx, double ty)
translateBy(double tx, double ty)
for every CShape contained in this CElement
.translateBy
in interface CElement
tx
- The x offsetty
- The y offsetCElement
CShape.translateBy(double, double)
public CElement translateTo(double tx, double ty)
translateTo(double tx, double ty)
every CShape contained in this CElement
.translateTo
in interface CElement
tx
- The x coordinatety
- The y coordinateCElement
CShape.translateTo(double, double)
public CElement scaleBy(double sx, double sy)
scale(double sx, double sy)
for every CShape contained in this CElement
.scaleBy
in interface CElement
sx
- The x scale factorsy
- The y scale factorCElement
CShape.scaleBy(double, double)
public CElement scaleBy(double s)
scaleBy(double s)
for every CShape contained in this CElement
.scaleBy
in interface CElement
s
- The scale factorCElement
CShape.scaleBy(double)
public CElement scaleTo(double sx, double sy)
scaleTo(double sx, double sy)
for every CShape contained in this CElement
.scaleTo
in interface CElement
sx
- The x scalesy
- The y scaleCElement
CShape.scaleTo(double, double)
public CElement scaleTo(double s)
scaleTo(double s)
for every CShape contained in this CElement
.scaleTo
in interface CElement
s
- The scale valueCElement
CShape.scaleTo(double)
public CElement rotateBy(double theta)
rotateBy(double theta)
for every CShape contained in this CElement
.rotateBy
in interface CElement
theta
- The angle offsetCElement
CShape.rotateBy(double)
public CElement rotateTo(double theta)
rotateTo(double theta)
for every CShape contained in this CElement
.rotateTo
in interface CElement
theta
- The angleCElement
CShape.rotateTo(double)
public CShape contains(double x, double y)
contains
in interface CElement
x
- The x-coordinate of the point to test.y
- The y-coordinate of the point to test.CShape.contains(double, double)
public CShape contains(java.awt.geom.Point2D p)
contains
in interface CElement
p
- The point to test.CShape.contains(Point2D)
public CShape contains(double x, double y, double w, double h)
contains
in interface CElement
x
- The x-coordinate of the left corner of the rectangle to test.y
- The y-coordinate of the left corner of the rectangle to test.w
- The width of the rectangle to test.h
- The height of the rectangle to test.CShape.contains(double, double, double, double)
public CShape contains(java.awt.Rectangle r)
contains
in interface CElement
r
- The rectangle to test.CShape.contains(Rectangle)
public CShape isOnOutline(java.awt.geom.Point2D p)
isOnOutline
in interface CElement
p
- The point to test.CShape.isOnOutline(Point2D)
public CShape intersects(CShape s)
CShape
that intersects the given CShape
s.intersects
in interface CElement
s
- The shapeCShape
that intersects the given CShape
, null if no CShape
intersects s.CShape.intersects(CShape)
public CPolyLine getIntersection(CShape s)
CShape
s intersects this CElement
.getIntersection
in interface CElement
s
- The shapeCPolyLine
if s intersects it, null otherwise.CShape.getIntersection(CShape)
public CShape getFirstHavingTag(CTag t)
getFirstHavingTag
in interface CElement
t
- The tag to test.CShape.hasTag(fr.lri.swingstates.canvas.CTag)
public boolean hasTag(java.lang.String t)
hasTag
in interface CElement
t
- The name of the tag to testCShape.hasTag(String)
public boolean hasTag(CTag t)
public CElement above(CElement before)
before
, this method does nothing.above
in interface CElement
before
- The shape that must be right below every shape contained in this CElement
in the display listCElement
CShape.below(CElement)
public CElement aboveAll()
aboveAll()
for every CShape contained in this CElement
.aboveAll
in interface CElement
CElement
CShape.aboveAll()
public CShape getTopMostShape()
public CShape getTopLeastShape()
public CElement below(CElement after)
after
, this method does nothing.below
in interface CElement
after
- The shape that must be right above every shape contained in this CElement
in the display listCShape.below(CElement)
public CElement belowAll()
belowAll()
for every CShape contained in this CElement
.belowAll
in interface CElement
CElement
CShape.belowAll()
public CElement setClip(CShape clip)
setClip(CShape clip)
for every CShape contained in this CElement
.setClip
in interface CElement
clip
- The clipping shape, or null to reset clipping of this shapeCElement
CShape.setClip(CShape)
public void addGhost()
CElement
.addGhost
in interface CElement
CShape.addGhost()
public void removeGhost()
CElement
.removeGhost
in interface CElement
CShape.removeGhost()
public CRectangle getBoundingBox()
getBoundingBox
in interface CElement
public double getMinX()
public double getMaxX()
public double getCenterX()
getCenterX
in interface CElement
public double getMinY()
public double getMaxY()
public double getCenterY()
getCenterY
in interface CElement
public CShape firstShape()
firstShape
in interface CElement
public CShape getFirstAntialiasedShape()
CElement
.getFirstAntialiasedShape
in interface CElement
CElement
, null if no CShape is antialiased.CShape.isAntialiased()
public CShape getFirstFilledShape()
CElement
and that is filled.getFirstFilledShape
in interface CElement
CElement
and that is filled, null if no CShape is filled.CShape.isFilled()
public final CShape getFirstOutlinedShape()
CElement
and that is outlined.getFirstOutlinedShape
in interface CElement
CElement
and that is outlined, null if no CShape is outlined.CShape.isOutlined()
public CElement addTag(CExtensionalTag t)
addTag(Canvas.Tag t)
for every CShape contained in this CElement
.public CElement addTag(java.lang.String t)
addTag(String t)
for every CShape contained in this CElement
.addTag
in interface CElement
t
- The name of the tagCElement
CShape.addTag(String)
public CElement removeTag(CExtensionalTag t)
removeTag(Tag t)
for every CShape contained in this CElement
only if t is a SMExtensionalTag
,
does nothing otherwise.removeTag
in interface CElement
t
- The tagCElement
CShape.removeTag(CExtensionalTag)
public CElement removeTag(java.lang.String t)
removeTag(String t)
for every CShape contained in this CElement
.removeTag
in interface CElement
t
- The name of the tagCElement
CShape.removeTag(String)
public void attachSM(CStateMachine sm, boolean reset)
CElement
to describe its behavior.public void detachSM(CStateMachine sm)
CElement
.public CElement animate(Animation anim)
animate(Animation anim)
for every CShape tagged by this CTag
.animate
in interface CElement
anim
- The animation to associate to each shape tagged by this CTag
.CTag
as a CElement
CShape.animate(Animation)