The layer container delegates the creation of layers to a layer factory, which needs to implement the ILayerFactory interface. A default factory (DefaultLayerFactory) is included and will be sufficient for most applications. However, there are reasons why an application might choose to provide its own factory: to have a single point in the application where layers get configured, to use subclasses of the built-in layers or to use custom layers. The following code shows the factory definition:
/**
* Layer factories are used by layer containers in order to create the actual
* user interface components for the various system layers, object layers,
* and custom layers.
*/
public interface ILayerFactory {
/**
* Creates a new system layer. The creation of all system layer types must
* be supported (all subclasses of AbstractSystemLayer).
*/
<T extends AbstractSystemLayer> T createSystemLayer(LayerContainer lc, Class<T> layerType); /**
* Creates a new timeline object layer to be used for rendering timeline
* objects.
*/
TimelineObjectLayer createTimelineLayer(LayerContainer lc, ILayer layer); /**
* Creates a new custom layer to be used for rendering custom information.
*/
AbstractCustomLayer createCustomLayer(LayerContainer lc, ILayer layer);
}
The method, which creates the system layers is rather restricted. The method has to guarantee that the layer created by it is of the type passed to it. The method is not allowed to return null. The method, which creates custom layers will only be called if ILayer.isCustomLayer() returns „true“. Applications that want to replace the default layer factory need to pass their own factory to the constructor of the Layer- Container class. The layer container itself gets created by the component factory of the Gantt chart, hence replacing the default layer factory also requires replacing the default component factory. The following code fragment shows a custom component factory using a custom layer factory:
public class CustomComponentFactory extends DefaultComponentFactory {
/**
* Creates a layer container that uses a custom layer factory.
*/
@Override
public LayerContainer createLayerContainer(AbstractGanttChart gc, TreeTable table, IGanttChartModel model) {
return new LayerContainer(gc, model, table, new CustomLayerFactory());
}
}
This custom component factory can then be passed to the constructor of the Gantt chart.
GanttChart gc = new GanttChart(new CustomComponentFactory());


