Listener for the content of the manager

When the content of the manager changes, the manager will fire a ManagerContentChangedEvent event. Any class can listen for the modification of the content of the manager by implementing the ManagerContentChangedListener interface.
This interface contains only the contentsChanged method.
void contentsChanged(ManagerContentChangedEvent evt)  
This method is called when an object is added to or removed from the manager, or when the visibility, the bounding box, or the layer of a graphic object changes. A class that implements this interface will register itself by calling the addManagerContentChangedListener method of the manager.
A ManagerContentChangedEvent can be of several types depending on the type of modification in the manager. For each type, there is a corresponding subclass of the class ManagerContentChangedEvent . The type of the event can be retrieved with the getType method of the class. The list of these subclasses is indicated below along with the type of change in the manager that is responsible for it:
  • ObjectInsertedEvent ( type OBJECT_ADDED)
    A graphic object has been inserted. You can retrieve the graphic object that was inserted with the getGraphicObject method.
  • ObjectRemovedEvent ( type OBJECT_REMOVED)
    A graphic object has been removed. You can retrieve the graphic object that was removed with the getGraphicObject method.
  • ObjectBBoxChangedEvent (type OBJECT_BBOX_CHANGED )
    The bounding box of a graphic object has changed. You can retrieve the graphic object concerned using the getGraphicObject method and the old and new bounding box with the getOldBoundingBox and getNewBoundingBox methods.
  • ObjectLayerChangedEvent ( type OBJECT_LAYER_CHANGED)
    A graphic object has changed layers. You can retrieve the graphic object concerned using getGraphicObject and the old and new layer using the getOldLayer and getNewLayer methods.
  • ObjectVisibilityChangedEvent (type OBJECT_VISIBILITY_CHANGED)
    The visibility of a graphic object has changed. You can retrieve the graphic object concerned using getGraphicObject. The method isObjectVisible will tell you the new state of the object.
A listener will cast the event depending on the type:
public void contentsChanged(ManagerContentChangedEvent event)
{
  if (event.getType() == ManagerContentChangedEvent.OBJECT_ADDED) {
    ObjectInsertedEvent e = (ObjectInsertedEvent)event;
    IlvGraphic object = e.getGraphicObject();
    .... 
  }
}
As ManagerContentChangedEvent events can be sent very often (especially when numerous objects are being added as in the case of reading a file), the manager provides a way to notify the listeners that it is currently doing a series of modifications. In this case, the event will contain a flag telling the listener that the manager is currently performing several modifications. This flag can be tested using the isAdjusting method of the ManagerContentChangedEvent class. The manager will notify the listeners of the end of a series by sending a final ManagerContentsChangedEvent of type ADJUSTMENT_END .
Thus, a listener can decide to react to global modifications, but not to all individual modifications using the following code:
public class MyListener implements ManagerContentsChangedListener
{
  public void contentsChanged(ManagerContentChangedEvent event)
  {
     if (!event.isAdjusting()) {
        // do something
     }
  }
}
When making numerous modifications in a manager, you may want to be able to notify the listeners in the same way. To do so, you can use the setContentsAdjusting method of the manager in the following way:
manager.setContentsAdjusting(true);
try {
 //add a lot of objects
} finally {
  manager.setContentsAdjusting(false);
}
All operations done between the two calls to setContentsAdjusting will fire a ManagerContentChangedEvent event with the isAdjusting flag set to true . A call to the setContentsAdjusting method with the parameter set to false can send the file ADJUSTMENT_END event.
This mechanism can also help the internal listeners of Rogue Wave JViews to work in a more efficient way, so you are recommended to use it.

Events related to imminent content changes

Since JViews 8.1, IlvManager fires events when a graphic object is about to change or about to be deleted. These events are fired before the graphic objects are changed or deleted. To listen for these events, you need to implement the following interface.
public interface ManagerContentMonitor 
  extends ManagerContentChangedListener
{
  public void contentAboutToChange(ManagerContentAboutToChangeEvent event);
}
As this interface extends ManagerContentChangedListener , you can install a ManagerContentMonitor by calling addManagerContentChangedListener. IlvManager will call the method contentAboutToChange() that you have implemented when a graphic object is about to change or about to be deleted.