Using Graph Layout Algorithms > Automatic Label Placement > Using Label Layout in Java > Layout Events and Listeners

The label layout framework provides the same event mechanism as the graph layout framework. The following events may occur:

Label Layout Events

The class LabelLayoutEvent corresponds to the class GraphLayoutEvent (see Graph Layout Event Listeners). You can install a listener for these events at the layout instance by using the method:

labelLayout.addLabelLayoutEventListener(listener);

The listener must implement the LabelLayoutEventListener interface and receives events while the layout is running. A typical example is to check how much of the layout has already completed:

class MyLabelLayoutListener
  implements LabelLayoutEventListener 
{ 
  public void layoutStepPerformed(LabelLayoutEvent event)
  { 
    IlvLabelLayoutReport layoutReport = event.getLayoutReport(); 
    System.out.println("percentage of completion: " + 
                       layoutReport.getPercentageComplete()); 
  }
}

Label Layout Parameter Events

The class LabelLayoutParameterEvent corresponds to the class GraphLayoutParameterEvent (see Parameter Event Listeners). You can install a listener to these events at the layout instance by

labelLayout.addLabelLayoutParameterEventListener(listener);

The listener must implement the LabelLayoutParameterEventListener interface and receives events when layout parameters change. It also receives a special event at the end of a successful layout. For example:

class MyLabelLayoutParameterListener 
  implements LabelLayoutParameterEventListener 
{ 
  public void parametersUpToDate(LabelLayoutParameterEvent event)
  { 
    if (!event.isParametersUpToDate())
      System.out.println("Any label layout parameter has changed.");
  } 
}