Most editors provide a snapping grid that forces the
objects to be located at specified locations. The coordinates where
the user can move the objects are called
grid
points. The class
IlvGrid provides
this functionality.
An instance of the class IlvGrid
can
be installed on each manager view. The view provides methods to set
or retrieve the grid:
public void setGrid(IlvGrid grid)
public IlvGrid getGrid()
The following code installs a grid on a view with a vertical
and horizontal grid point spacing of 10. The last two parameters are
set to true
to specify that the grid is
visible and active:
mgrview.setGrid(new IlvGrid(Color.black, new IlvPoint(), 10f, 10f, true, true));
When a grid is installed on a view, the standard Rogue Wave JViews editing interactors, such as those
for creating, moving, or editing an object, snap objects to the grid
automatically.
These operations are not performed by the manager, but
by the interactor itself. If you want to implement this mechanism
in a new interactor you create, use the following method of the IlvManagerView
class
in the code of your new interactor:
public final void snapToGrid(IlvPoint point)
This method moves the IlvPoint
argument
to the closest point on the grid if a grid is installed and active.
Otherwise, it does nothing.