/*
* Copyright (C) 1996-2007 by ILOG.
* All rights reserved.
*
* This source code is an addition to the ILOG JViews Reference Manual
* delivered with the JViews library.
* It is supplied as an example to show you how to code with JViews.
* Feel free to use, copy or modify it within the framework of your
* JViews license agreement.
*/
package decoration;
import ilog.tgo.composite.IltcCompositeGraphic;
import ilog.tgo.composite.IltcCompositeManager;
import ilog.tgo.composite.IltcLayer;
import ilog.tgo.graphic.IltCompositeGrapher;
import ilog.tgo.graphic.IltGraphicElementName;
/**
* This class implements a custom layer policy. In this layer
* policy, a new layer is created to store decorations that have
* the name set to <b>Comments</b>. This layer is placed on top
* of the System window layer.
*/
public class CustomLayerPolicy extends IltCompositeGrapher.LayerPolicy {
public static final String COMMENTS_DECORATION_NAME = "Comments";
protected IltcLayer commentsLayer;
/**
* Creates a new layer policy and allocates five special layers.
*/
public CustomLayerPolicy () {
super();
}
/**
* Returns the layer where the elements with the given name
* should be placed.
*/
public IltcLayer getElementLayer (IltcCompositeGraphic graphic, IltGraphicElementName elementName) {
if (elementName.getName().equals(COMMENTS_DECORATION_NAME)) {
return this.commentsLayer;
} else
return super.getElementLayer(graphic, elementName);
}
/**
* Indicates if the given layer can be removed or not.
*/
public boolean isRemovable (IltcLayer layer) {
return (layer == this.commentsLayer || super.isRemovable(layer));
}
/**
* Attaches the layer policy to the manager.
*/
public void attach(IltcCompositeManager manager) {
super.attach(manager);
this.commentsLayer = manager.addLayerOnTop(this.getSystemWindowLayer());
this.commentsLayer.setName("Comments");
}
/**
* Detaches the layer policy from the manager.
*
*/
public void detach(IltcCompositeManager manager) {
super.detach(manager);
manager.removeLayer(this.commentsLayer);
this.commentsLayer = null;
}
/**
* Returns the layer which holds the comments of all objects.
*/
public IltcLayer getCommentsLayer () {
return this.commentsLayer;
}
}