skip to main content
Defense > Programmer's documentation > Essential Features > Graphic objects > Named properties
 
Named properties
Another kind of user property, called named property, can also be set on a graphic object. A named property is an instance of the class IlvNamedProperty. This class is an abstract class; it must be subclassed for your own needs. The difference between a named property and a user property is mainly that this type of property is named and can be saved with the graphic object in an .ivl file when the graphic object is saved. Note that a named property can also be stored in the manager or in a layer object, which is described in Layers.
To store a named property in a graphic object, use:
 
void setNamedProperty(IlvNamedProperty)
To get a named property, use:
 
void getNamedProperty(String name)
The following example shows a named property.
 
import ilog.views.*;
import ilog.views.io.*;
 
public class MyNamedProperty extends IlvNamedProperty
{
  String value;
 
  public MyNamedProperty(IlvInputStream stream) throws IlvReadFileException
  {
    super(stream);
    this.value = stream.readString("value");
  }
 
  public MyNamedProperty(String name, String value)
  {
    super(name);
    this.value = value;
  }
 
  public MyNamedProperty(MyNamedProperty source)
  {
    super(source);
    this.value = source.value;
  }
 
  public IlvNamedProperty copy()
  {
    return new MyNamedProperty(this);
  }
 
  public boolean isPersistent()
  {
    return true;
  }
 
  public void write(IlvOutputStream stream) throws IOException
  {
    super.write(stream);
    stream.write("value", value);
  }
 
 }
This named property defines a member variable value of type String to store the value of the property.
Several methods have been created to allow the storage of the property in an .ivl file:
*The method isPersistent of the named property returns true.
*The method write is used to store the object in an .ivl file.
This method is overridden to store the string in the member variable value.Note that the super.write call is mandatory for a correct storage of the property.
*The class defines a public constructor with an IlvInputStream parameter.
This constructor is used to reload the property from the .ivl file.
NOTE  The complete name of the class (including the name of the package) will be stored in the .ivl file. Therefore, if you change the name of the class, the property can no longer be loaded. Also, the class must be a public class to be saved in an .ivl file. Otherwise, it is impossible for the .ivl file reader to instantiate the class.

Copyright © 2018, Rogue Wave Software, Inc. All Rights Reserved.