public class IlvLabelLayoutManagerProperty extends IlvNamedProperty
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
.
Constructor and Description |
---|
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 . |
Modifier and Type | Method and Description |
---|---|
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.
|
getName
public IlvLabelLayoutManagerProperty(String name, IlvLabelLayout layout, boolean withDefaults)
IlvLabelLayoutManagerProperty
that stores
layout parameter settings of the layout
.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).public IlvLabelLayoutManagerProperty(IlvLabelLayoutManagerProperty source)
IlvLabelLayoutManagerProperty
by copying an
existing one.source
- The origin of the copy.public IlvLabelLayoutManagerProperty(IlvInputStream stream) throws IOException, IlvReadFileException
IlvLabelLayoutManagerProperty
from an
IlvInputStream
.stream
- The input stream from which the property must be read.IlvReadFileException
- if an error occurs while reading.IOException
protected IlvLabelLayout 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
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(IlvLabelLayout layout)
layout
- The layout instance whose parameters are to be recovered
from this instance.public void dispose(IlvDefaultLabelingModel model)
model
- The labeling model.IlvDefaultLabelingModel.loadParametersFromNamedProperties(IlvLabelLayout)
,
IlvDefaultLabelingModel.removeParametersFromNamedProperties()
© Copyright 2024 Rogue Wave Software, Inc., a Perforce company.. All Rights Reserved.