Creating your own selection object

The selection object depends on the graphic object. In fact, the manager creates the selection object using the following method of the graphic object:
IlvSelection makeSelection()   
You can override this method to return your own instance of the selection object. Another possibility is to set an IlvSelectionFactory on the manager and let this factory decide which subclass of IlvSelection should be instantiated depending on the graphic object. The following is an example which creates a new selection object (a white border) around the selected object.
class mySelection extends IlvSelection 
{
  static final int thickness = 3;
  mySelection(IlvGraphic obj)
  { 
    super(obj); 
  }
 
  public void draw(Graphics g, IlvTransformer t)
  { 
    g.setColor(Color.white); 
    IlvRect rect = boundingBox(t);
    for (int i = 0; i < thickness; i++) {
      if ((int)Math.floor(rect.width) > 
           2*i && (int)Math.floor(rect.height) > 2*i) 
         g.drawRect((int)Math.floor(rect.x)+i, 
                    (int)Math.floor(rect.y)+i, 
                    (int)Math.floor(rect.width)-2*i-1,
                    (int)Math.floor(rect.height)-2*i-1); 
    } 
  }
  
  public IlvRect boundingBox(IlvTransformer t) 
  {
    // get the bounding rectangle of the selected object
    IlvRect bbox = getObject().boundingBox(t); 
    bbox.x-= thickness; 
    bbox.y-= thickness;
    bbox.width+= 2*thickness; 
    bbox.height+= 2*thickness;
    return bbox;
  }
 
  public boolean contains(IlvPoint p, IlvPoint tp, IlvTransformer t)
  { 
    return false;
  }
}
You can see that the selection object is defined in the same way as a graphic object. The constructor of a selection object always takes the selected object as a parameter. Note that the boundingBox method of the selection object uses the boundingBox method of the selected object so that the selection object (in this case, the white border) is always around the selected object, whatever the transformer is.