ilog.views.graphlayout.labellayout
Class IlvLabelLayoutManagerProperty

java.lang.Object
  extended by ilog.views.IlvNamedProperty
      extended by ilog.views.graphlayout.labellayout.IlvLabelLayoutManagerProperty
All Implemented Interfaces:
IlvPersistentObject, Serializable
Direct Known Subclasses:
IlvAnnealingLabelLayoutManagerProperty, IlvRandomLabelLayoutManagerProperty

public class IlvLabelLayoutManagerProperty
extends IlvNamedProperty

The class IlvLabelLayoutManagerProperty allows you to store the global settings of an instance of IlvLabelLayout as a named property in the manager. This is used by IlvDefaultLabelingModel.saveParametersToNamedProperties(IlvLabelLayout, boolean) which is an auxiliary to be used before IlvManager.write(IlvOutputStream) if you want to store layout parameter settings in .ivl files.

If you create your own subclass of IlvLabelLayout and want to save the parameters of your subclass in .ivl files, you need to create a subclass of this class. The subclass must provide a constructor with your IlvLabelLayout subclass as input and transfer the layout parameters from the input layout to the property. It must also override the transfer method to transfer the layout parameters from the property back to the layout instance. Further information about subclassing can be found in the documentation of IlvNamedProperty.

As an example, assume that your subclass MyLayout of IlvLabelLayout has a string parameter that can be accessed by getMyParameter and set by setMyParameter. You can create a named property that can store this parameter in the following way:

 public class MyLayoutManagerProperty extends IlvLabelLayoutManagerProperty
 { 
  String myParameter;
 
  public MyLayoutManagerProperty(String name, MyLayout layout, boolean withDefaults)
  {
    super(name, layout, withDefaults);
    this.myParameter = layout.getMyParameter();
  }

  public MyLayoutManagerProperty(MyLayoutManagerProperty source)
  {
    super(source);
    this.myParameter = source.myParameter;
  }
 
  public MyLayoutManagerProperty(IlvInputStream stream)
    throws IOException, IlvReadFileException
  {
    super(stream);
    try {
      this.myParameter = stream.readString("myParameter");
    } catch (IlvFieldNotFoundException e) {
      this.myParameter = myParameterDefaultValue;
    }
  } 

  public IlvNamedProperty copy()
  {
    return new MyLayoutManagerProperty(this);
  }

  public void write(IlvOutputStream stream) throws IOException
  {
    super.write(stream);
    stream.write("myParameter", this.myParameter);
  }

  public void transfer(IlvLabelLayout layout)
  {
    super.transfer(layout);
    ((MyLayout)layout).setMyParameter(this.myParameter);
  }

  public boolean isPersistent()
  {
    // this will catch the case that omitDefaults is false
    if (super.isPersistent())
      return true;

    // in case omitDefaults is true:
    if (this.myParameter != myParameterDefaultValue)
      return true;
    return false;
  }
 }
 
Note that MyLayout must override IlvLabelLayout.createLayoutManagerProperty(String, boolean) to return an instance of your new class MyLayoutManagerProperty.

Since:
JViews 5.0
See Also:
IlvDefaultLabelingModel.saveParametersToNamedProperties(IlvLabelLayout, boolean), IlvDefaultLabelingModel.loadParametersFromNamedProperties(IlvLabelLayout), IlvDefaultLabelingModel.removeParametersFromNamedProperties(), Serialized Form

Constructor Summary
IlvLabelLayoutManagerProperty(IlvInputStream stream)
          Creates a new IlvLabelLayoutManagerProperty from an IlvInputStream.
IlvLabelLayoutManagerProperty(IlvLabelLayoutManagerProperty source)
          Creates a new IlvLabelLayoutManagerProperty by copying an existing one.
IlvLabelLayoutManagerProperty(String name, IlvLabelLayout layout, boolean withDefaults)
          Creates a new IlvLabelLayoutManagerProperty that stores layout parameter settings of the layout.
 
Method Summary
 IlvNamedProperty copy()
          Copies the named property.
 void dispose(IlvDefaultLabelingModel model)
          Disposes of the property and releases any resources that it is using.
protected  IlvLabelLayout getLayout()
          Returns the layout instance that created this property.
 boolean isPersistent()
          Returns true if the property must be saved to an .ivl file.
protected  boolean omitDefaults()
          Returns true if the layout property is not persistent when all stored parameter values are default values.
 void transfer(IlvLabelLayout layout)
          Transfers the layout parameter settings stored in this named property back to the input layout.
 void write(IlvOutputStream stream)
          Writes the property to the output stream.
 
Methods inherited from class ilog.views.IlvNamedProperty
getName
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

IlvLabelLayoutManagerProperty

public IlvLabelLayoutManagerProperty(String name,
                                     IlvLabelLayout layout,
                                     boolean withDefaults)
Creates a new IlvLabelLayoutManagerProperty that stores layout parameter settings of the layout.

Parameters:
name - The name of the property.
layout - The layout instance to be stored.
withDefaults - If true, the layout property is always persistent. If false, it is persistent only if nondefault parameter settings exist (that is, if the the property is saved to an .ivl file, the default parameter settings are not saved).

IlvLabelLayoutManagerProperty

public IlvLabelLayoutManagerProperty(IlvLabelLayoutManagerProperty source)
Creates a new IlvLabelLayoutManagerProperty by copying an existing one.

Parameters:
source - The origin of the copy.

IlvLabelLayoutManagerProperty

public IlvLabelLayoutManagerProperty(IlvInputStream stream)
                              throws IOException,
                                     IlvReadFileException
Creates a new IlvLabelLayoutManagerProperty from an IlvInputStream.

Parameters:
stream - The input stream from which the property must be read.
Throws:
IlvReadFileException - if an error occurs while reading.
IOException
Method Detail

getLayout

protected IlvLabelLayout getLayout()
Returns the layout instance that created this property. If the property was created by reading from IlvInputStream, it returns null.


omitDefaults

protected boolean omitDefaults()
Returns true if the layout property is not persistent when all stored parameter values are default values. Returns false if the layout property is persistent independent of default values. If the property was created by reading from IlvInputStream, it returns false.


copy

public IlvNamedProperty copy()
Copies the named property.

Specified by:
copy in class IlvNamedProperty

isPersistent

public boolean isPersistent()
Returns true if the property must be saved to an .ivl file.

Specified by:
isPersistent in class IlvNamedProperty

write

public void write(IlvOutputStream stream)
           throws IOException
Writes the property to the output stream.

Specified by:
write in interface IlvPersistentObject
Overrides:
write in class IlvNamedProperty
Parameters:
stream - The output stream.
Throws:
IOException - standard IO error.

transfer

public void transfer(IlvLabelLayout layout)
Transfers the layout parameter settings stored in this named property back to the input layout.

Parameters:
layout - The layout instance whose parameters are to be recovered from this instance.

dispose

public void dispose(IlvDefaultLabelingModel model)
Disposes of the property and releases any resources that it is using. This is called if the property was loaded and removed from the manager.

Parameters:
model - The labeling model.
See Also:
IlvDefaultLabelingModel.loadParametersFromNamedProperties(IlvLabelLayout), IlvDefaultLabelingModel.removeParametersFromNamedProperties()


Copyright © 1996-2007 ILOG S.A. All rights reserved.   Documentation homepage.