Customize the look of a selection

Article ID: 2338
Last updated: 29 May, 2018
Article ID: 2338
Last updated: 29 May, 2018
Revision: 3
Views: 440
Posted: 26 Jul, 2007
by Dean J.
Updated: 29 May, 2018
by Gargani A.

Question

How to customize the look of a selection?

Answer

If you want to change the look of an object when it is selected, you can implement your own IlvSelection object.

The selection object is placed in the selection manager layer, which is always the highest layer (in fact, one layer higher than the highest normal manager layer). When using IlvSelection, you have no choice, it will be placed in the highest manager layer. To install a new selection, you need to:

1) Create a subclass of IlvSelection (or a subclass of a class that inherits from IlvSelection such as IlvHandlesSelection and IlvDrawSelection) and override the IlvSelection draw method. This draw method can call the draw method of the selected object. For example, the template method below has a similar effect as if the selection object would be drawn below the selected object:

public class IlvMySelection extends IlvSelection {
...
  public void draw(Graphics dst,IlvTransformer t)
  {
  // first draw the additional selection decorations that should look
  // like being behind the graphic object
  super.draw(dst, t);
  // then draw the selected object
  if (getObject() != null) getObject().draw(dst, t);
  //... then draw the additional selection decorations that should look
  // like being in front of the graphic object
  }
}

2.a) Create a subclass of IlvGraphic (or a subclass of a class that inherits from [IlvGraphic]) and override makeSelection().

public IlvSelection makeSelection()
{
  return new IlvMySelection(this);
}

For these subclasses of IlvGraphic, IlvMySelection is now used.

2.b) Another way to install a new selection is to create a selection factory. In this case, you do not need to subclass IlvGraphic objects. See IlvSelectionFactory. Here is a sample:

private class MySelectionFactory implements IlvSelectionFactory
{
  public IlvSelection makeSelection(IlvGraphic obj)
  {
    return new IlvMySelection(obj);
  }
}

Install this selection factory at the IlvManager:

manager.setSelectionFactory(new MySelectionFactory());

Note that if you have nested graphers, you need to install the factory at all submanagers as well. If you are using SDM and the Diagrammer API, SDM does not use additional selection objects. Instead, it rerenders the original object when selected, and you have full freedom to specify how it should look like when selected. You can even replace the unselected graphic object by a different graphic object when selected. Please refer to the IlvSDMEngine class documentation page and in particular to the IlvSDMEngine.setSelectionPseudoClass() method for more information about this feature.

This article was:   Helpful | Not helpful
Report an issue
Article ID: 2338
Last updated: 29 May, 2018
Revision: 3
Views: 440
Posted: 26 Jul, 2007 by Dean J.
Updated: 29 May, 2018 by Gargani A.
Also listed in


Others in this category