public class IlvGraphLayoutNodeProperty extends IlvNamedProperty
IlvGraphLayoutNodeProperty
allows you to store
the settings of an instance of IlvGraphLayout
for an
individual node as a named property in the node. This is used by
IlvGrapherPropertyAdapter.saveParametersToNamedProperties(IlvGraphLayout,
boolean)
which is an auxiliary to be used before IlvGrapher.write(IlvOutputStream)
if you want to store layout
parameter settings in .ivl
files.
If you create your own subclass of IlvGraphLayout
and
want to save the layout parameters of your subclass for individual
nodes in .ivl
files, you need to create a subclass of
this class. The subclass must provide a constructor with your
IlvGraphLayout
subclass and the node as input, and
transfer the layout parameters of the node 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
IlvGraphLayout
has a string parameter for each node 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 MyLayoutNodeProperty extends IlvGraphLayoutNodeProperty { String myParameter; public MyLayoutNodeProperty( String name, MyLayout layout, IlvGraphic node, boolean withDefaults) { super(name, layout, node, withDefaults); this.myParameter = layout.getMyParameter(node); } public MyLayoutNodeProperty(MyLayoutNodeProperty source) { super(source); this.myParameter = source.myParameter; } public MyLayoutNodeProperty(IlvInputStream stream) throws IOException, IlvReadFileException { super(stream); try { this.myParameter = stream.readString("myParameter"); } catch (IlvFieldNotFoundException e) { this.myParameter = myParameterDefaultValue; } } public IlvNamedProperty copy() { return new MyLayoutNodeProperty(this); } public void write(IlvOutputStream stream) throws IOException { super.write(stream); stream.write("myParameter", this.myParameter); } public void transfer(IlvGraphLayout layout, IlvGraphic node) { super.transfer(layout, node); ((MyLayout)layout).setMyParameter(node, 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 IlvGraphLayout.createLayoutNodeProperty(String, IlvGraphic, boolean)
to return an instance of your new class
MyLayoutNodeProperty
.Modifier | Constructor and Description |
---|---|
|
IlvGraphLayoutNodeProperty(IlvGraphLayoutNodeProperty source)
Creates a new
IlvGraphLayoutNodeProperty by copying an
existing one. |
|
IlvGraphLayoutNodeProperty(IlvInputStream stream)
Creates a new
IlvGraphLayoutNodeProperty from an
IlvInputStream . |
protected |
IlvGraphLayoutNodeProperty(IlvInputStream stream,
boolean fromSubclass)
Creates a new
IlvGraphLayoutNodeProperty from an
IlvInputStream . |
|
IlvGraphLayoutNodeProperty(String name,
IlvGraphLayout layout,
IlvGraphic node,
boolean withDefaults)
Creates a new
IlvGraphLayoutNodeProperty that stores
layout parameter settings of the layout for the
node . |
Modifier and Type | Method and Description |
---|---|
IlvNamedProperty |
copy()
Copies the named property.
|
void |
dispose(IlvGrapherAdapter adapter)
Deprecated.
Since JViews 8.8, use
dispose(IlvGrapherPropertyAdapter) . |
void |
dispose(IlvGrapherPropertyAdapter adapter)
Disposes of the property and releases any resources that it is using.
|
protected IlvGraphLayout |
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 |
isWritten(IlvGraphic nodeOrLink)
Returns
true if the writing of the input node or link was
completed. |
protected boolean |
omitDefaults()
Returns
true if the layout property is not persistent
when all stored parameter values are default values. |
protected boolean |
readProperties(IlvInputStream stream)
Reads the properties from an
IlvInputStream . |
void |
transfer(IlvGraphLayout layout,
IlvGraphic node)
Transfers the layout parameter settings stored in this named property
back to the input layout for the input node.
|
void |
write(IlvOutputStream stream)
Writes the property to the output stream.
|
getName
public IlvGraphLayoutNodeProperty(String name, IlvGraphLayout layout, IlvGraphic node, boolean withDefaults)
IlvGraphLayoutNodeProperty
that stores
layout parameter settings of the layout
for the
node
.name
- The name of the property.layout
- The layout instance to be stored.node
- The node whose layout parameters are 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).public IlvGraphLayoutNodeProperty(IlvGraphLayoutNodeProperty source)
IlvGraphLayoutNodeProperty
by copying an
existing one.source
- The origin of the copy.public IlvGraphLayoutNodeProperty(IlvInputStream stream) throws IOException, IlvReadFileException
IlvGraphLayoutNodeProperty
from an
IlvInputStream
.stream
- The input stream from which the property must be read.IlvReadFileException
- if an error occurs while reading.IOException
protected IlvGraphLayoutNodeProperty(IlvInputStream stream, boolean fromSubclass) throws IOException, IlvReadFileException
IlvGraphLayoutNodeProperty
from an
IlvInputStream
. This method is for internal purpose.stream
- The input stream from which the property must be read.fromSubclass
- Whether this constructor is called from a subclass.IlvReadFileException
- if an error occurs while reading.IOException
protected boolean readProperties(IlvInputStream stream) throws IOException, IlvReadFileException
IlvInputStream
. This method
is for internal purpose.stream
- The input stream from which the property must be read.IlvReadFileException
- if an error occurs while reading.IOException
protected IlvGraphLayout getLayout()
IlvInputStream
, it
returns null
.protected boolean omitDefaults()
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
.public IlvNamedProperty copy()
copy
in class IlvNamedProperty
public boolean isPersistent()
true
if the property must be saved to an
.ivl
file.isPersistent
in class IlvNamedProperty
protected boolean isWritten(IlvGraphic nodeOrLink)
true
if the writing of the input node or link was
completed.
If customers need to subclass this class, this auxiliary can be used
inside the implementation of the write
method only. For
instance, it can be used if information must be written depending on
whether another node or another link has already been written.
nodeOrLink
- A node or link of the same grapher.true
if the node or link has been written before
this property.write(IlvOutputStream)
public void write(IlvOutputStream stream) throws IOException
write
in interface IlvPersistentObject
write
in class IlvNamedProperty
stream
- The output stream.IOException
- standard IO error.public void transfer(IlvGraphLayout layout, IlvGraphic node)
layout
- The layout instance whose parameters are to be recovered
from this named property.node
- The node whose layout parameters are to be recovered from
this named property.public void dispose(IlvGrapherPropertyAdapter adapter)
adapter
- The grapher property adapter.IlvGrapherPropertyAdapter.loadParametersFromNamedProperties(IlvGraphLayout)
,
IlvGrapherPropertyAdapter.removeParametersFromNamedProperties()
public void dispose(IlvGrapherAdapter adapter)
dispose(IlvGrapherPropertyAdapter)
.adapter
- The grapher adapter.© Copyright Rogue Wave Software, Inc. 1997, 2018. All Rights Reserved.