The following code example creates a new graphic subclass MyMarker
that has a special selection object MyMarkerSelection
. If the marker is selected, the object
interactor MyMarkerEdition
becomes active.
Each click in the marker selection changes the type (and therefore
also the shape) of the marker.
public class MyMarker extends IlvMarker
{
...
public IlvSelection makeSelection()
{
return new MyMarkerSelection(this);
}
}
public class MyMarkerSelection extends IlvUnresizeableDrawSelection
{
...
public String getDefaultInteractor()
{
return MyMarkerEdition.class.getName();
}
}
public class MyMarkerEdition extends IlvReshapeSelection
{
public MyMarkerEdition()
{
super();
}
protected boolean handleButtonDown(IlvDrawSelection sel, MouseEvent event,
IlvObjectInteractorContext context)
{
// each click with the left mouse button into the selection object
// changes the type of the selected object
if ((event.getModifiers() & InputEvent.BUTTON2_MASK) != 0 ||
(event.getModifiers() & InputEvent.BUTTON3_MASK) != 0)
return true;
MyMarkerSelection msel = (MyMarkerSelection)sel;
MyMarker marker = (MyMarker)msel.getObject();
// even though the object interactor is on the selection, it
// modifies the selected object, not the selection
final int tp = (marker.getType() >= 512 ? 1 : marker.getType() * 2);
IlvGraphicBag bag = marker.getGraphicBag();
if (bag == null)
marker.setType(tp);
else
bag.applyToObject(marker, new IlvApplyObject() {
public void apply(IlvGraphic g, Object arg) {
((MyMarker)g).setType(tp);
}
}, null, true);
return true;
}
}