Rogue Wave® JViews のフォーマット済みファイルのオブジェクトの保存と読み込みを行うには、
write
メソッドと、IlvInputStream
パラメーターを取るコンストラクターを実装する必要があります。重要
IlvManager
オブジェクトをシリアライゼーションする推奨方法は IVL を介したシリアライゼーションで、Java™
によるシリアライゼーションではありません。シリアライゼーションは IlvIcon
やその他のクラスなどのグラフィック・オブジェクトを含むマネージャーに対しては機能しません。これらのクラスは、シリアライゼーションできない Java SE オブジェクトを内部管理するためです。write メソッド
write
メソッドは、オブジェクトの色、矩形寸法、影の太さを指定出力ストリームに書き込みます。/** * Writes the object to an output stream. */ public void write(IlvOutputStream stream) throws IOException { // Calls the super class method that will write // the fields specific to the super class. super.write(stream); // Writes the colors. stream.write("color", getColor()); stream.write("shadowColor", getShadowColor()); // Writes the thickness. stream.write("thickness", getThickness()); // Writes the definition rectangle. stream.write("rectangle", drawrect); }
write
メソッドでは、スーパークラスの write
メソッドを呼び出してスーパークラス専用の情報を保存します。これにより、クラス固有の情報を保存するために、クラス IlvOutputStream の write
メソッドが使用されます。read コンストラクター
ファイルからグラフィック・オブジェクトを読み込むには、
IlvInputStream
パラメーターで特定のコンストラクターを提供する必要があります。このコンストラクターはパブリックで、ファイル・リーダーによって呼び出す必要があります。また、コンストラクターでは write
メソッドで書き込まれたのと同じ情報を、同じ順序で読み込む必要があります。/** * Reads the object from an IlvInputStream * @param stream the input stream. * @exception IlvReadFileException an error occurs when reading. */ public ShadowEllipse(IlvInputStream stream) throws IlvReadFileException { // Calls the super class constructor that reads // the information for the super class in the file. super(stream); // Reads the color. setColor(stream.readColor("color")); // Reads the shadow color. setShadowColor(stream.readColor("shadowColor")); // Reads the thickness setThickness(stream.readInt("thickness")); // reads the definition rectangle. IlvRect rect = stream.readRect("rectangle"); drawrect.reshape(rect.x, rect.y, rect.width, rect.height); }
上記のコンストラクターは、ストリーム・オブジェクトからスーパークラス専用の情報を読み込むスーパークラスの読み込みコンストラクターを呼び出します。これで、サブクラスは独自に情報を読み込めるようになります。
コンストラクターは、クラス IlvInputStream内で定義された
read
メソッドを使用します。