選択オブジェクトはグラフィック・オブジェクトによって異なります。マネージャーは次のグラフィック・オブジェクトのメソッドで選択オブジェクトを作成します。
IlvSelection makeSelection()
このメソッドをオーバーライドして、選択オブジェクトの独自のインスタンスを返すこともできます。マネージャーで IlvSelectionFactory を設定し、グラフィック・オブジェクトに応じて、このファクトリーに
IlvSelection
のどのサブクラスをインスタンス化するのかを判定させることもできます。次に、指定オブジェクトの周囲に新規の選択オブジェクト (白枠) を作成する例を示します。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; } }
選択オブジェクトがグラフィック・オブジェクトと同じように定義されていることがわかります。選択オブジェクトのコンストラクターは、パラメーターとして常に指定オブジェクトを取ります。選択オブジェクトの
boundingBox
メソッドは選択されたオブジェクトの boundingBox
メソッドを使用して、選択オブジェクト (この場合は、白枠) がトランスフォーマーのいかんにかかわらず、常に指定オブジェクトの周囲にくるようにします。