| The Essential JViews Framework > Graphic Objects > Input/Output Operations |
Input/Output Operations |
INDEX
PREVIOUS
NEXT
|
The ILOG JViews library provides the following two classes for saving graphic objects to, and loading graphic objects from, a stream:
IlvOutputStream, used by the class IlvManager to save all the graphic objects that it contains
IlvInputStream, allowing a file generated by IlvOutputStream to be read into an IlvManager
Graphic objects can always be written into an IlvOutputStream because they inherit the write method of the IlvGraphic class:
public void write(IlvOutputStream stream) throws IOException
To save the information contained in your class, you can override this method and use the methods of the class IlvOutputStream. When overriding this method, you must not forget to call the write method of the superclass to save the information related to the superclass. You will obtain something that resembles the following example:
To read your graphic object from an IlvInputStream, you must create a constructor with an IlvInputStream. This constructor is mandatory even if you have not overridden the write method. The corresponding constructor in the class IlvGraphic is:
public IlvGraphic(IlvInputStream stream) throws IlvReadFileException
Assuming that MyClass is the name of your class, your new constructor will look like this:
public MyClass(IlvInputStream stream) throws IlvReadFileException
In the body of this constructor, you first call the corresponding constructor in the superclass, then you read the information you have saved in the write method. In the above example, the corresponding constructor is:
public MyClass(IlvInputStream stream) throws IlvReadFileException { super(stream); setColor(stream.readColor("color")); setThickness(stream.readInt("thickness")); ... } |
| Copyright © 1987-2007 ILOG S.A. All rights reserved. Documentation homepage. Legal terms. | PREVIOUS NEXT |