There are certain situations where you might want to save a
renderer. When you work in load-on-demand mode, for example, only
the parameters necessary for loading the graphic objects in the
layer are saved, not the objects themselves. Load-on-demand is
described in Using load-on-demand.
The complete source code of this example can
be found in the following file:
If the graphic objects are created using a specific renderer, you
must save that renderer to render the objects in the same way the
next time they are loaded. The class IlvSDOLayer, for example, lets you specify a
renderer ( setFeatureRenderer that will be saved with
the layer.
The
ColorLineRenderer
presented in the section Creating a colored line renderer derives from
the
IlvFeatureRenderer
interface, which extends
IlvPersistentObject
and can thus be saved.
/** * Writes this to specified stream. */ public void write(IlvOutputStream stream) throws java.io.IOException { stream.write("attributeName",myAttributeName); if (myColorModel instanceof IlvPersistentObject) stream.write("colorModel",(IlvPersistentObject)myColorModel); else System.err.println("Warning : colormodel not saved"); } public ColorLineRenderer(IlvInputStream stream) throws IlvReadFileException { myAttributeName = stream.readString("attributeName"); try { myColorModel = (ColorModel)stream.readPersistentObject("colorModel"); } catch (IlvFieldNotFoundException e) { // Get default colormodel myColorModel = IlvIntervalColorModel.MakeElevationColorModel(); } } }