For every operation that leads to a modification of the bounding
box of a graphic object, you must use the applyToObject method of the
IlvManager
class. As this method notifies the manager of the modification of
the bounding box, you never directly call the
moveObject
and
reshapeObject
methods of
IlvGraphic
:
void moveObject(IlvGraphic obj, float x, float y, boolean redraw)
void reshapeObject(IlvGraphic obj, IlvRect newrect, boolean redraw)
For these basic operations, the manager has methods that call
applyToObject
for you:
Example: Moving an object
The following code gets a reference to an object named
test
from the manager. If the object exists, it is moved to the point
(10, 20) and redrawn (fourth parameter set to
true
).
IlvGraphic object = manager.getObject("test"); if (object != null) manager.moveObject(object, 10, 20, true);
The
moveObject
method is equivalent to the following code:
manager.applyToObject(object, new IlvApplyObject() { public void apply(IlvGraphic obj, Object arg){ IlvPoint p = (IlvPoint) arg; obj.move(p.x, p.y); } }, new IlvPoint(10,20), true);
This code calls the
applyToObject
method with
object
as a parameter and an anonymous class that implements the IlvApplyObject interface. The
arg
parameter is an
IlvPoint
object that gives the new location of the object.
The method
applyToObject
is defined in the IlvGraphicBag interface, so you may call
applyToObject
directly from a graphic object using:
obj.getGraphicBag().applyToObject(obj, ...);
Modifying multiple graphic objects
To apply an operation to many graphic
objects repeatedly, call:
void applyToObjects(IlvGraphicVector vector, IlvApplyObject f, Object arg, boolean redraw)
This applies the operation specified by the
IlvApplyObject f
to each graphic object contained in the input vector.
To apply complex operations that affect
the bounding box of many graphic objects to many objects once
only, call:
void applyToObjects(IlvGraphicVector vector, IlvApplyObjects f, Object arg, boolean redraw)
This applies the operation specified by the
IlvApplyObjects f
once only. This is useful for complex operations that affect the
bounding box of many objects.
Note
The
applyToObjects
method is overloaded. In the first example it takes an
IlvApplyObject
object as a parameter. In the second example it takes an
IlvApplyObjects
(plural) object as a parameter.