public class IlvDefaultLabelingModel extends IlvLabelingModel implements IlvLabelingModelWithRotation
IlvDefaultLabelingModel
provides a default labeling
model for an IlvManager
and provides a bridge between the API
of the IlvManager
and the API of the IlvLabelingModel
.
IlvDefaultLabelingModel
is a concrete subclass of
IlvLabelingModel
that allows IlvGraphic
objects of an IlvManager
to be labels or obstacles. It
handles objects of the following types as labels:
IlvLabel
(and subclasses of this).IlvZoomableLabel
(and subclasses of this).IlvText
(and subclasses of this).IlvLabelingModel
.
The default labeling model is optimized to handle polyline graphics
and polyline links efficiently. It can be used to place labels at
links of type IlvPolylineLinkImage
. However, it currently does
not handle splines very precisely, because this would be very costly.
It uses a rough approximation for splines.
If labels of any other subclass of IlvGraphic
should be
positioned, it is sufficient to override the method isDefaultLabelClass(java.lang.Object)
. If only a subset of IlvGraphic
objects should be obstacles, it is sufficient to override the method
isDefaultObstacleClass(java.lang.Object)
.
As an alternative to subclassing, the user can call the methods setLabel(java.lang.Object, boolean)
and setObstacle(java.lang.Object, boolean)
to redefine for individual objects
whether they are labels or obstacles.
If an application uses the class IlvManager
, the manager
can be attached directly to the layout instance, without explicitly
using a labeling model (see the method IlvLabelLayout.attach(IlvManager)
. In this case, an
IlvDefaultLabelingModel
will be internally created. This
default model can be retrieved using the method IlvLabelLayout.getLabelingModel()
, which will return an instance of
IlvDefaultLabelingModel
.
Note that you must call the method dispose()
after detaching
the label layouts when you no longer need the labeling model instance;
otherwise, some objects may not be garbage collected. This is
necessary only if the labeling model instance is directly created by
your code. Calling dispose()
is not necessary if the labeling
model instance is created internally by the JViews Graph Layout
library, for instance when attaching directly an
IlvManager
to a layout instance using IlvLabelLayout.attach(IlvManager)
.
Constructor and Description |
---|
IlvDefaultLabelingModel(IlvManager manager)
Creates a new labeling model for a given
IlvManager . |
Modifier and Type | Method and Description |
---|---|
void |
addLayer(IlvManagerLayer layer)
Adds a manager layer to the list of layers to be used during the label
layout.
|
void |
afterLayout(IlvLabelLayout layout,
IlvLabelLayoutReport layoutReport,
boolean redraw)
Notifies the labeling model that a layout session has finished.
|
void |
beforeLayout(IlvLabelLayout layout,
boolean redraw)
Notifies the labeling model that a layout session has been started.
|
IlvRect |
boundingBox(Object labelOrObstacle)
Returns the bounding rectangle of a label or obstacle.
|
IlvLabelingModel |
createLabelingModel(Object subgraph)
Creates a new
IlvDefaultLabelingModel for a subgraph. |
void |
dispose()
Disposes of this
IlvDefaultLabelingModel and releases any
resources that it is using. |
int |
getCoordinatesMode()
Returns the current coordinates mode.
|
double |
getLabelOverlap(Object label1,
IlvRect rect1,
double angle1,
Object label2,
IlvRect rect2,
double angle2,
double minDist)
Returns the overlap between two labels if you move the labels to the
positions specified by the passed rectangles and the rotation angle.
|
double |
getLabelOverlap(Object label1,
IlvRect bbox1,
Object label2,
IlvRect bbox2,
double minDist)
Returns the overlap between two labels, if the labels would be at the
given positions specified by the passed bounding boxes.
|
Enumeration |
getLabels()
Returns the enumeration of all labels.
|
Enumeration |
getLayers()
Returns an enumeration of the manager layers to be taken into account
during the label layout.
|
int |
getLayersCount()
Returns the number of manager layers to be taken into account during
the label layout.
|
IlvManager |
getManager()
Returns the
IlvManager that stores the labels and the
obstacles. |
double |
getObstacleOverlap(Object label,
IlvRect labelRect,
double angle,
Object obstacle,
IlvRect obstacleBBox,
double minDist)
Returns the overlap between the label and the obstacle if you move the
label to the position specified by the passed rectangle and the
rotation angle.
|
double |
getObstacleOverlap(Object label,
IlvRect labelBBox,
Object obstacle,
IlvRect obstacleBBox,
double minDist)
Returns the overlap between the label and the obstacle, if the label
would be at the given position specified by the passed bounding box.
|
Enumeration |
getObstacles()
Returns the enumeration of all obstacles.
|
double |
getPolylineObstacleOverlap(Object label,
IlvRect labelRect,
double angle,
Object polylineObstacle,
IlvPoint[] pts,
double lineWidth,
double minDist)
Returns the overlap between the label and the polyline obstacle if you
move the label to the position specified by the passed rectangle and
the rotation angle.
|
double |
getPolylineObstacleOverlap(Object label,
IlvRect labelBBox,
Object polylineObstacle,
IlvPoint[] pts,
double lineWidth,
double minDist)
Returns the overlap between the label and the polyline obstacle, if
the label would be at the given position specified by the passed
bounding box.
|
IlvPoint[] |
getPolylinePoints(Object polylineObstacle)
Returns the points that define the shape of a polyline obstacle.
|
double |
getPolylineWidth(Object polylineObstacle)
Returns the line width of a polyline obstacle.
|
Object |
getProperty(Object labelOrObstacle,
String key)
Returns the value of a property.
|
Object |
getProperty(String key)
Returns the value of a property of the labeling model.
|
IlvTransformer |
getReferenceTransformer()
Returns the transformer to be taken into account.
|
IlvManagerView |
getReferenceView()
Returns the specified reference view (if any) and
null
otherwise. |
double |
getRotation(Object label,
IlvRect rect)
Returns the rotation of the label if you move it to the position given
by the input rectangle
rect . |
boolean |
isBoundingBoxDependent()
Returns
true if two objects overlap only if their
bounding boxes overlap. |
protected boolean |
isDefaultLabelClass(Object obj)
Returns
true if the class of the object is the default
labeling class. |
protected boolean |
isDefaultObstacleClass(Object obj)
Returns
true if the class of the object is the default
obstacle class. |
boolean |
isFullLayerNotification()
Returns
true if adding or removing a layer sends a
separate event for each object contained in the layer. |
boolean |
isLabel(Object obj)
Returns
true if an object is a valid label and
false otherwise. |
boolean |
isLayerAdded(IlvManagerLayer layer)
Returns
true if the manager layer is one of the layers to
be taken into account during the layout. |
boolean |
isLayoutNeeded(IlvLabelLayout layout)
Returns
true if a given layout that has been already
applied to this manager is still valid. |
boolean |
isObstacle(Object obj)
Returns
true if an object is a valid obstacle and
false otherwise. |
boolean |
isPolylineObstacle(Object obj)
Returns
true if an object is a valid polyline obstacle
and false otherwise. |
boolean |
loadParametersFromNamedProperties(IlvLabelLayout layout)
Transfers the layout parameter settings from the named properties of
the manager back to the layout instance.
|
boolean |
loadParametersFromNamedProperties(IlvLabelLayout layout,
String propertyPrefix)
Transfers the layout parameter settings from the named properties of
the manager back to the layout instance.
|
IlvLabelLayout |
loadParametersFromNamedProperties(String propertyPrefix)
Transfers the layout parameter settings from the named properties of
the manager back to a new layout instance.
|
void |
moveLabel(Object label,
double x,
double y,
boolean redraw)
Changes the position of the specified label.
|
boolean |
removeAllLayers()
Removes all manager layers from the list of layers to be used during
the label layout.
|
boolean |
removeLayer(IlvManagerLayer layer)
Removes a manager layer from the list of layers to be used during the
label layout.
|
void |
removeParametersFromNamedProperties()
Removes all named properties that were used to store the label layout
parameter settings from the manager.
|
void |
removeParametersFromNamedProperties(Class layoutClass)
Removes the named properties that were used to store the label layout
parameter settings from the manager.
|
void |
removeParametersFromNamedProperties(String propertyPrefix)
Removes the named properties that were used to store the label layout
parameter settings from the manager.
|
String |
saveParametersToNamedProperties(IlvLabelLayout layout,
boolean withDefaults)
Transfers the layout parameter settings to named properties of the
manager.
|
String |
saveParametersToNamedProperties(IlvLabelLayout layout,
String propertyPrefix,
boolean withDefaults)
Transfers the layout parameter settings to named properties of the
manager.
|
void |
setCoordinatesMode(int mode)
Sets the coordinates mode to be used outside the layout.
|
void |
setFullLayerNotification(boolean flag)
Sets whether adding or removing a layer fires just one or many
labeling model events.
|
void |
setLabel(Object obj,
boolean isLabel)
Sets whether an object is a valid label.
|
void |
setObstacle(Object obj,
boolean isObstacle)
Sets whether an object is a valid obstacle.
|
void |
setProperty(Object labelOrObstacle,
String key,
Object value)
Sets the value of a property for a label or an obstacle.
|
void |
setProperty(String key,
Object value)
Sets the value of a property for the labeling model.
|
void |
setReferenceTransformer(IlvTransformer transformer)
Allows you to specify the reference transformer.
|
void |
setReferenceView(IlvManagerView view)
Allows you to specify the reference manager view.
|
void |
setRotation(Object label,
double angle)
Rotates the label around the center of its bounding box.
|
String |
toString()
Returns a string representation of the object.
|
addLabelingModelListener, adjustmentEnd, afterAttach, afterDetach, fireLabelingModelEvent, fireLabelingModelEvent, geometryChanged, getInstanceId, getLabelsCount, getObstaclesCount, removeLabelingModelListener, structureChanged
public IlvDefaultLabelingModel(IlvManager manager)
IlvManager
.manager
- The manager.public void dispose()
IlvDefaultLabelingModel
and releases any
resources that it is using. An IlvDefaultLabelingModel
object cannot be used after the dispose
method has been
called.
This method performs cleaning operations on the manager (for example, properties added to the manager are removed).
Note that the finalization process of the garbage collector also calls this method.
dispose
in class IlvLabelingModel
Object.finalize()
public IlvLabelingModel createLabelingModel(Object subgraph)
IlvDefaultLabelingModel
for a subgraph. The
method is used when performing a layout of nested graphs that contain
labels. It is called on the labeling model of a top-level graph that
contains the subgraph.createLabelingModel
in class IlvLabelingModel
subgraph
- The subgraph object. It must be an instance of
IlvManager
.null
public Enumeration getLabels()
getLabels
in class IlvLabelingModel
IlvLabelingModel.getLabelsCount()
protected boolean isDefaultLabelClass(Object obj)
true
if the class of the object is the default
labeling class. This implementation returns true
if the
object is an IlvLabel
, an IlvZoomableLabel
or an IlvText
.
You can override this method if you want to change the default behavior.
obj
- The object to test.true
if the class of the object is the default
labeling class.public boolean isLabel(Object obj)
true
if an object is a valid label and
false
otherwise. It returns true
if the
object was specified as a label via setLabel(java.lang.Object, boolean)
, and
false
if the object was explicitly specified not to be a
label. If nothing was specified via setLabel(java.lang.Object, boolean)
, this method
also returns true
if the object is an
IlvLabel
, an IlvZoomableLabel
or an
IlvText
.
If layers were selected for layout (see addLayer(ilog.views.IlvManagerLayer)
), then it
returns false
if the object is in a layer that is
currently not selected for layout, independent of its type.
If you want to change the default behavior to consider different
classes as labels, you should not override this method but rather
override isDefaultLabelClass(java.lang.Object)
.
isLabel
in class IlvLabelingModel
obj
- The object to test.true
if an object is a valid label.public void setLabel(Object obj, boolean isLabel)
IlvLabel
, IlvZoomableLabel
,
and IlvText
are considered to be labels. You can change
this default behavior by specifying explicitly with this method
whether the input object is a label or not.
Note that an object cannot be a label and an obstacle at the same time.
obj
- The object.isLabel
- true
if the object should be considered as
label.public void moveLabel(Object label, double x, double y, boolean redraw)
x
and
y
coordinates correspond to the top-left corner of the
rectangle that defines the label (see also the method boundingBox(Object)
). The coordinates are given with respect to the
current coordinates mode.moveLabel
in class IlvLabelingModel
label
- The label.x
- The new x-position of the label.y
- The new y-position of the label.redraw
- If true
, the label is redrawn.setCoordinatesMode(int)
public double getLabelOverlap(Object label1, IlvRect bbox1, Object label2, IlvRect bbox2, double minDist)
The default implementation compares the bounding boxes of both labels.
getLabelOverlap
in class IlvLabelingModel
label1
- The first label.bbox1
- The bounding box of the first label, translated to the
speculative position of the label.label2
- The second label.bbox2
- The bounding box of the second label, translated to the
speculative position of the label.minDist
- The desired minimum distance between labels.public Enumeration getObstacles()
getObstacles
in class IlvLabelingModel
IlvLabelingModel.getObstaclesCount()
protected boolean isDefaultObstacleClass(Object obj)
true
if the class of the object is the default
obstacle class. This implementation returns true
if the
object is an IlvGraphic
but neither an
IlvLabel
nor an IlvZoomableLabel
nor an
IlvText
.
You can override this method if you want to change the default behavior.
obj
- The object to test.true
if the class of the object is the default
obstacle class.public boolean isObstacle(Object obj)
true
if an object is a valid obstacle and
false
otherwise. It returns true
if the
object was specified as obstacle via setObstacle(java.lang.Object, boolean)
, and
false
if the object was explicitly specified to not be
an obstacle. If nothing was specified via setObstacle(java.lang.Object, boolean)
, this
method also returns true
if the object is not an
IlvLabel
or an IlvZoomableLabel
or an
IlvText
.
If layers were selected for layout (see addLayer(ilog.views.IlvManagerLayer)
), then it
returns false
if the object is in a layer that is
currently not selected for layout, independent of its type.
If you want to change the default behavior to consider different
classes as obstacles, you should not override this method but rather
override isDefaultObstacleClass(java.lang.Object)
.
isObstacle
in class IlvLabelingModel
obj
- The object to test.true
if an object is a valid obstacle.IlvLabelingModel.isPolylineObstacle(java.lang.Object)
public void setObstacle(Object obj, boolean isObstacle)
IlvLabel
, IlvZoomableLabel
,
and IlvText
are considered to be labels, and all other
objects are considered to be obstacles. You can change this default
behavior by specifying explicitly with this method whether the input
object is an obstacle or not.
Note that an object cannot be a label and an obstacle at the same time.
obj
- The object.isObstacle
- true
if the object should be considered
as an obstacle.public double getObstacleOverlap(Object label, IlvRect labelBBox, Object obstacle, IlvRect obstacleBBox, double minDist)
The default implementation compares the bounding boxes of the label with the bounding box of the obstacle.
getObstacleOverlap
in class IlvLabelingModel
label
- The label.labelBBox
- The bounding box of the label, translated to the
speculative position of the label.obstacle
- The obstacle.obstacleBBox
- The bounding box of the obstacle.minDist
- The desired minimum distance between label and obstacle.public boolean isPolylineObstacle(Object obj)
true
if an object is a valid polyline obstacle
and false
otherwise.
The default implementation returns true
if the object is
an obstacle of one of these types:
If layers were selected for layout (see addLayer(ilog.views.IlvManagerLayer)
), then it
returns false
if the object is in a layer that is
currently not selected for layout, independent of its type.
isPolylineObstacle
in class IlvLabelingModel
obj
- The object to test.true
if the object is a polyline obstacle.isObstacle(java.lang.Object)
public double getPolylineWidth(Object polylineObstacle)
IlvLabelLayout.MANAGER_COORDINATES
: returns the width of
the polyline obstacle in the coordinate space of the manager.IlvLabelLayout.VIEW_COORDINATES
: returns the width of the
polyline obstacle in the coordinate space of the view (see getReferenceTransformer()
).IlvLabelLayout.INVERSE_VIEW_COORDINATES
: returns the
width of the polyline obstacle by calculating the width in the
coordinate space of the view and applying the inverse transformation
(using the reference transformer) to obtain the corresponding value
in the coordinate space of the manager. This complex mechanism is
necessary if the obstacle is not fully zoomable.getPolylineWidth
in class IlvLabelingModel
polylineObstacle
- The polyline obstacle.isPolylineObstacle(java.lang.Object)
,
IlvGraphic.zoomable()
public IlvPoint[] getPolylinePoints(Object polylineObstacle)
IlvLabelLayout.MANAGER_COORDINATES
: returns the points in
the coordinate space of the manager.IlvLabelLayout.VIEW_COORDINATES
: returns the points in
the coordinate space of the view (see getReferenceTransformer()
).IlvLabelLayout.INVERSE_VIEW_COORDINATES
: returns the
points by calculating the points in the coordinate space of the view
and applying the inverse transformation to the points (using the
reference transformer) to obtain the corresponding points in the
coordinate space of the manager. This complex mechanism is necessary
if the obstacle is not fully zoomable.getPolylinePoints
in class IlvLabelingModel
polylineObstacle
- The polyline obstacle.null
if the points cannot be determined.isPolylineObstacle(java.lang.Object)
,
IlvGraphic.zoomable()
public double getPolylineObstacleOverlap(Object label, IlvRect labelBBox, Object polylineObstacle, IlvPoint[] pts, double lineWidth, double minDist)
The default implementation compares the bounding box of the label with the polypoint shape of the link.
getPolylineObstacleOverlap
in class IlvLabelingModel
label
- The label.labelBBox
- The bounding box of the label, translated to the
speculative position of the label.polylineObstacle
- The polyline obstacle.pts
- The points that define the shape of the polyline obstacle.lineWidth
- The line width of the polyline obstacle.minDist
- The desired minimum distance between label and obstacle.isPolylineObstacle(java.lang.Object)
public IlvManager getManager()
IlvManager
that stores the labels and the
obstacles.getManager
in class IlvLabelingModel
public IlvRect boundingBox(Object labelOrObstacle)
IlvLabelLayout.MANAGER_COORDINATES
: returns the bounding
box of the graphic object in the coordinate space of the manager,
that is, it calls IlvGraphic.boundingBox(IlvTransformer)
with a null
argument.IlvLabelLayout.VIEW_COORDINATES
: returns the bounding box
of the graphic object in the coordinate space of the view, that is,
it calls IlvGraphic.boundingBox(IlvTransformer)
with the
reference transformer as an argument (see getReferenceTransformer()
).IlvLabelLayout.INVERSE_VIEW_COORDINATES
: returns the
bounding box of the graphic object by calculating the bounding box in
the coordinate space of the view and applying to the rectangle the
inverse transformation (using the reference transformer) to obtain
the corresponding rectangle in the coordinate space of the manager.
This complex mechanism is necessary if the object is not fully
zoomable.boundingBox
in class IlvLabelingModel
labelOrObstacle
- The label or obstacle.public boolean isBoundingBoxDependent()
true
if two objects overlap only if their
bounding boxes overlap.
If you override the method getLabelOverlap
or getObstacleOverlap
, you may need to
override this method as well.
If the method getLabelOverlap
or getOsbatcleOverlap
always returns 0
if the bounding boxes of the objects do not overlap, then this method
may return true
. If the method getLabelOverlap
or getObstacleOverlap
may return a nonzero value even though the bounding boxes of the
objects do not overlap, then this method must return
false
.
isBoundingBoxDependent
in class IlvLabelingModel
true
.public boolean isLayoutNeeded(IlvLabelLayout layout)
true
if a given layout that has been already
applied to this manager is still valid. The method returns
true
if at least one of the following holds:
IlvLabelLayout.isParametersUpToDate()
called on
layout
returns false
.
IlvLabelLayout.isGeometryUpToDate()
called on
layout
returns false
.
IlvLabelLayout.isStructureUpToDate()
called on
layout
returns false
.
getReferenceTransformer()
returns a different
transformer than the one that had been used the last time the layout
was successfully performed on this manager unless the difference
between the two transformers is a pure translation).
getCoordinatesMode()
returns a different value
than the one used the last time the layout was successfully performed
on this manager.
false
.isLayoutNeeded
in class IlvLabelingModel
layout
- The layout.IlvLabelLayout.isLayoutNeeded()
,
IlvLabelLayout.isStructureUpToDate()
,
IlvLabelLayout.isGeometryUpToDate()
,
IlvLabelLayout.isParametersUpToDate()
public void beforeLayout(IlvLabelLayout layout, boolean redraw)
IlvLabelLayout.performLayout()
before the call to the method IlvLabelLayout.layout(boolean)
.
It calls IlvManager.setContentsAdjusting
to indicate the
start of a sequence of label movements. If the redraw
flag is true
, it additionally calls
IlvManager.initReDraws
to indicate the start of a
sequence of redraw operations.
You should not call this method directly.
beforeLayout
in class IlvLabelingModel
layout
- The layout instance that is the origin of the
notification.redraw
- If true
, the layout algorithm will ask the
labeling model to redraw the objects when the method
afterLayout
is called (that is, it will pass
true
for its redraw
argument).afterLayout(ilog.views.graphlayout.labellayout.IlvLabelLayout, ilog.views.graphlayout.labellayout.IlvLabelLayoutReport, boolean)
public void afterLayout(IlvLabelLayout layout, IlvLabelLayoutReport layoutReport, boolean redraw)
IlvLabelLayout.performLayout()
after
the method IlvLabelLayout.layout(boolean)
has finished, even if an
exception is thrown during the layout process.
Note that you can detect whether the layout was performed
successfully using the test layoutReport.getCode() ==
IlvLabelLayoutReport.LAYOUT_DONE
.
This method calls IlvManager.setContentsAdjusting
to
indicate the end of a sequence of label movements. If the
redraw
flag is true
, it additionally calls
IlvManager.reDrawViews
to indicate the end of a sequence
of redraw operations. This will redraw the views.
You should not call this method directly.
afterLayout
in class IlvLabelingModel
layout
- The layout instance that is the origin of the
notification.layoutReport
- The layout report.redraw
- If true
, the layout algorithm asks the
labeling model to redraw the graph.beforeLayout(ilog.views.graphlayout.labellayout.IlvLabelLayout, boolean)
public void setProperty(Object labelOrObstacle, String key, Object value)
value
is null
, the property is removed.
Otherwise, the property value is set to value
.setProperty
in class IlvLabelingModel
labelOrObstacle
- The label or obstacle for which the property is
to be set.key
- The key string for the property.value
- The new value of the property.getProperty(java.lang.Object, java.lang.String)
public Object getProperty(Object labelOrObstacle, String key)
null
if the property does not exist.getProperty
in class IlvLabelingModel
labelOrObstacle
- The label or obstacle for which the property is
to be retrieved.key
- The key string for the property.setProperty(java.lang.Object, java.lang.String, java.lang.Object)
public void setProperty(String key, Object value)
value
is null
, the property is removed.
Otherwise, the property value is set to value
.setProperty
in class IlvLabelingModel
key
- The key string for the property.value
- The new value of the property.getProperty(java.lang.Object, java.lang.String)
public Object getProperty(String key)
null
if the property does not exist.getProperty
in class IlvLabelingModel
key
- The key string for the property.setProperty(java.lang.Object, java.lang.String, java.lang.Object)
public void setCoordinatesMode(int mode)
IlvLabelLayout.MANAGER_COORDINATES
- Labels are placed
in the coordinate system of the manager, without applying any
transformation.
This mode should be used if you visualize objects at zoom level 1, or you do not visualize them at all, or the manager contains only fully zoomable objects. Indeed, in all these cases there is no need to take the transformer into account during the layout.
Note that in this mode the dimensional parameters of the layout algorithms are considered as being specified in manager coordinates.
IlvLabelLayout.VIEW_COORDINATES
- Labels are placed in
the coordinate system of the manager view. More exactly, all the
coordinates are transformed using the current reference transformer.
This mode should be used if you want the dimensional parameters of the layout algorithms to be considered as being specified in manager view coordinates.
IlvLabelLayout.INVERSE_VIEW_COORDINATES
- Labels are
placed in the coordinate system given by transforming view
coordinates back into the coordinate system of the manager. This mode
is equivalent to the "manager coordinates" mode if the geometry of
the graphic objects strictly obeys the transformer. (A small
difference may exist because of the limited precision of the
computations.)
On the contrary, if some graphic objects are either nonzoomable (see
IlvGraphic.zoomable()
) or semizoomable (for example, links with
a maximum line width), this mode gives different results than the
manager's coordinates mode. These results are optimal if the
manager is visualized using the same transformer as the one taken
into account during the layout.
Note that in this mode the dimensional parameters of the layout algorithms are considered as being specified in manager coordinates.
The default value is IlvLabelLayout.INVERSE_VIEW_COORDINATES
.
Note: This coordinates mode is used only when the layout is not
running. While the layout is running, the coordinates mode of the
layout instance is used (see IlvLabelLayout.setCoordinatesMode(int)
).
mode
- The mode.getCoordinatesMode()
,
IlvLabelLayout.setCoordinatesMode(int)
,
setReferenceTransformer(ilog.views.IlvTransformer)
,
setReferenceView(ilog.views.IlvManagerView)
public int getCoordinatesMode()
public void setReferenceTransformer(IlvTransformer transformer)
The reference transformer is the transformer (see the class IlvTransformer
) that is taken into account by the
IlvDefaultLabelingModel
when computing the geometry of
the manager if the coordinates mode is either IlvLabelLayout.VIEW_COORDINATES
or IlvLabelLayout.INVERSE_VIEW_COORDINATES
.
If the coordinates mode is IlvLabelLayout.MANAGER_COORDINATES
, the reference transformer is not
taken into account. In this mode, the layout computes the geometry of
the manager on the basis of the manager coordinates of objects,
without any transformation. If the encapsulated manager contains only
zoomable graphics (see IlvGraphic.zoomable()
), the geometry
will stay valid and optimal for any transformer.
If the encapsulated manager contains at least one nonzoomable object
(such as IlvLabel
), or objects that do not
strictly obey the transformer (such as a link with maximum line
width), the geometry becomes dependent on the transformer that is
used to draw the manager. Changing the transformer makes the layout
invalid so that a re-layout is necessary to again obtain the optimal
layout with respect to the new transformer. Calculating the layout in
manager coordinates may yield a nonoptimal result in a zoomed view.
In this case the layout must take the reference transformer into
account to obtain an optimal result.
If the coordinates mode is IlvLabelLayout.VIEW_COORDINATES
,
all coordinates are calculated and delivered to the layout algorithm
with respect to the reference transformer. In this mode, all
dimensional layout parameters must be specified in view coordinates
with respect to the reference transformer.
If the coordinates mode is IlvLabelLayout.INVERSE_VIEW_COORDINATES
, all coordinates are
calculated with respect to the reference transformer, but they are
delivered to the layout algorithm by transforming them back into
manager coordinates. This has the advantage that all dimensional
layout parameters can be specified in manager coordinates. If the
encapsulated manager contains only zoomable graphics, the result is
the same as when using manager coordinates. The layout is nearly
independent of the view. In a few rare cases, a slight shifting of
the coordinates may occur due to the coordinate optimization. If the
encapsulated manager contains nonzoomable objects, the calculation
with inverse view coordinates still produces an optimal result with
respect to the reference transformer. However, the layout is no
longer independent of the view, that is, it becomes nonoptimal when
the view transformer is changed.
In most cases it is not necessary to call this method because the
transformer to be taken into account is chosen using a set of default
rules (see getReferenceTransformer()
). If it is called, the
transformer specified using this method is returned by the method
getReferenceTransformer()
, overriding the default rules for
choosing the transformer.
If the IlvManager
contains nonzoomable objects, you may
need to call this method in the following cases:
If a manager containing nonzoomable objects is displayed
simultaneously in several views, you can use the method setReferenceView(ilog.views.IlvManagerView)
to indicate the view for which you want the layout
to correspond exactly to the geometry of the manager.
If you specified a transformer but want to reset this setting and go
back to the default behavior, call the method with a
null
argument.
Note that if this method is overridden, you must call
super.setReferenceTransformer(transformer)
to notify the
manager adapter that the reference transformer has changed.
Note also that a call to the method setReferenceView(ilog.views.IlvManagerView)
overrides the effect of a call to the method setReferenceTransformer(ilog.views.IlvTransformer)
. Similarly, a call to the method setReferenceTransformer(ilog.views.IlvTransformer)
overrides the effect of a call to the
method setReferenceView(ilog.views.IlvManagerView)
.
transformer
- The reference transformer.getReferenceTransformer()
,
setReferenceView(ilog.views.IlvManagerView)
,
setCoordinatesMode(int)
public IlvTransformer getReferenceTransformer()
This method returns the transformer specified using setReferenceTransformer(ilog.views.IlvTransformer)
if this transformer is not
null
. If no reference transformer is set, it returns the
current transformer of the manager view specified using setReferenceView(ilog.views.IlvManagerView)
(if any). If no reference view is set, it returns
the current transformer of the first manager view attached to the
manager (as returned by the method IlvManager.getViews()
). If
the manager is a subgrapher, that is, if it is used as a graphic
object contained in another IlvGrapher
, and the subgrapher
has no view directly attached, the first view of the closest parent
graph is used.
Otherwise, this method returns an identity transformer.
Note that you should not modify the transformer returned by this method.
public void setReferenceView(IlvManagerView view)
The reference view is the manager view (see the class IlvManagerView
) whose current transformer (see the method IlvManagerView.getTransformer()
) is used as a reference transformer
(see method getReferenceTransformer()
.
Usually, the view
argument is the manager view that is
used for displaying the manager, but this is not mandatory.
Call this method with a null
argument to reset the
setting.
Note that a call to the method setReferenceTransformer(ilog.views.IlvTransformer)
overrides the effect of a call to the method setReferenceView(ilog.views.IlvManagerView)
. Similarly, a call to the method setReferenceView(ilog.views.IlvManagerView)
overrides the effect of a call to the method
setReferenceTransformer(ilog.views.IlvTransformer)
.
public IlvManagerView getReferenceView()
null
otherwise.public final void addLayer(IlvManagerLayer layer)
getLayers()
returns null
.
An IllegalArgumentException
is thrown if the layer does
not belong to the encapsulated manager.
public final boolean removeLayer(IlvManagerLayer layer)
An IllegalArgumentException
is thrown if the layer does
not belong to the encapsulated manager.
true
if the layer is in the list of layers to be
used; false
if the layer is not in the list of layers
or if the list of layers is void.addLayer(ilog.views.IlvManagerLayer)
,
removeAllLayers()
,
getLayers()
public final boolean removeAllLayers()
false
if there are no layers to be removed and
true
otherwise.addLayer(ilog.views.IlvManagerLayer)
,
removeLayer(ilog.views.IlvManagerLayer)
,
getLayers()
public final Enumeration getLayers()
addLayer(IlvManagerLayer)
, all layers in the
encapsulated IlvManager
are used. In this case, this method
returns null
.IlvManagerLayer
instances) to be taken into account during the layout. Returns
null
if the list of layers to be used is empty.getLayersCount()
,
addLayer(ilog.views.IlvManagerLayer)
,
removeLayer(ilog.views.IlvManagerLayer)
,
removeAllLayers()
,
isLayerAdded(ilog.views.IlvManagerLayer)
public final int getLayersCount()
addLayer(IlvManagerLayer)
, all layers in the encapsulated
IlvManager
are used. In this case, this method returns
0
.IlvManagerLayer
instances)
to be taken into account during the layout. Returns 0
if the list of layers to be used is empty.addLayer(ilog.views.IlvManagerLayer)
,
getLayers()
,
isLayerAdded(ilog.views.IlvManagerLayer)
public final boolean isLayerAdded(IlvManagerLayer layer)
true
if the manager layer is one of the layers to
be taken into account during the layout. Otherwise, the method
returns false
. If you do not specify any layers using
the method addLayer(IlvManagerLayer)
, the method returns
false
for any argument.layer
- The layer to test.true
if the layer must be taken into account during
the layout.addLayer(ilog.views.IlvManagerLayer)
,
getLayers()
public void setFullLayerNotification(boolean flag)
true
is passed, adding or
removing a layer posts a separate event for each object contained in
the layer. If false
is passed, adding or removing a
layer posts only one event. This is more efficient. However some
layout classes listen to the events to cleanup memory, so if you
disable full layer notification, you are responsible to call IlvLabelLayout.cleanLabel(ilog.views.graphlayout.labellayout.IlvLabelingModel, java.lang.Object)
and IlvLabelLayout.cleanObstacle(ilog.views.graphlayout.labellayout.IlvLabelingModel, java.lang.Object)
yourself to cleanup the memory.
Full layer notification is enabled by default.
flag
- Set to true
for full layer notification, or
false
for a single layer notification.addLayer(ilog.views.IlvManagerLayer)
,
removeLayer(ilog.views.IlvManagerLayer)
,
isFullLayerNotification()
,
IlvLabelingModel.addLabelingModelListener(ilog.views.graphlayout.labellayout.LabelingModelListener)
public final boolean isFullLayerNotification()
true
if adding or removing a layer sends a
separate event for each object contained in the layer. Returns
false
if only one single event is fired in this case.setFullLayerNotification(boolean)
public String saveParametersToNamedProperties(IlvLabelLayout layout, boolean withDefaults)
If you want to store layout parameter settings into .ivl
files, this method should be called before IlvManager.write(ilog.views.io.IlvOutputStream)
.
It creates objects of class IlvLabelLayoutManagerProperty
and
IlvLabelLayoutLabelProperty
, stores the layout parameter
settings in these objects, and adds the objects as persistent named
properties with a unique property name to the manager.
The named properties contain a copy of the parameter settings. It is
possible to save the parameter settings, change the parameters
temporarily in the working instance of layout, and restore the saved
values later using the method loadParametersFromNamedProperties(ilog.views.graphlayout.labellayout.IlvLabelLayout)
. This can be nested, because the
last saved parameters are loaded first.
To avoid wasting memory, it is recommended that you remove the properties when they are no longer needed, for example, immediately after writing to a file or to an output stream. It is possible to transfer and store the parameter settings of multiple layouts at the same time. The typical calling sequence to save a manager with layout parameter settings for some attached layouts is:
if (layout1.supportsSaveParametersToNamedProperties()) defaultLabelingModel.saveParametersToNamedProperties(layout1, false); if (layout2.supportsSaveParametersToNamedProperties()) defaultLabelingModel.saveParametersToNamedProperties(layout2, false); if (layout3.supportsSaveParametersToNamedProperties()) defaultLabelingModel.saveParametersToNamedProperties(layout3, false); ... defaultLabelingModel.getManager().write("abcd.ivl"); defaultLabelingModel.removeParametersFromNamedProperties();
If false
is passed for the argument
withDefaults
, the layout properties are persistent only
if they contain parameters that are not default values. As a result,
the .ivl
files will be smaller. If true
is
passed for the argument withDefaults
, the layout
properties are always persistent, and the default values of the
layout parameter settings are also written to files by the next call
of IlvManager.write(ilog.views.io.IlvOutputStream)
.
If the input layout does not support saving parameters to named
properties, a RuntimeException
is thrown.
layout
- The layout instance to be saved. It should be attached to
this default labeling model.withDefaults
- If true
, the layout properties are
always persistent. If false
, they are persistent only
if nondefault parameter settings exist (that is, if the property is
saved to an .ivl
file, the default parameter settings
are not saved).loadParametersFromNamedProperties(ilog.views.graphlayout.labellayout.IlvLabelLayout)
,
removeParametersFromNamedProperties()
,
IlvLabelLayout.supportsSaveParametersToNamedProperties()
,
IlvNamedProperty
public String saveParametersToNamedProperties(IlvLabelLayout layout, String propertyPrefix, boolean withDefaults)
propertyPrefix
and the layout instance. This method is
used internally to recursively transfer the parameters of sublayout
instances of a parent layout to properties.
If the input layout does not support saving parameters to named
properties, a RuntimeException
is thrown.
layout
- The layout instance to be saved. It should be attached to
this default labeling model.propertyPrefix
- The prefix of the generated unique property name
that is used to store the layout properties.withDefaults
- If true
, the layout properties are
always persistent. If false
, they are 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).saveParametersToNamedProperties(IlvLabelLayout, boolean)
,
IlvLabelLayout.supportsSaveParametersToNamedProperties()
public boolean loadParametersFromNamedProperties(IlvLabelLayout layout)
If you stored layout parameter settings into .ivl
files
using the method saveParametersToNamedProperties(ilog.views.graphlayout.labellayout.IlvLabelLayout, boolean)
and want to
load them again, this method should be called after IlvManager.read(java.io.InputStream)
. It searches for a set of layout parameter
properties that matches the class of the input layout, transfers the
parameters to the layout instance, and removes this set of named
layout properties from the manager.
If multiple settings of parameters of different layout classes
were saved, it loads the setting that fits the input layout class
(for instance, it loads the tree layout settings if the input class
is IlvTreeLayout
). If multiple settings of parameters of
the same layout class were saved, it loads the setting that
was last saved by implementing the stack principle (the last-in,
first-out principle).
The typical calling sequence to read a manager with layout parameter settings for some attached layouts is:
defaultLabelingModel.getManager().read("abcd.ivl"); defaultLabelingModel.loadParametersFromNamedProperties(layout1); defaultLabelingModel.loadParametersFromNamedProperties(layout2); defaultLabelingModel.loadParametersFromNamedProperties(layout3); ... defaultLabelingModel.removeParametersFromNamedProperties();In this example, the final call of
removeParametersFromNamedProperties
is recommended to
avoid wasting memory when it is not known whether all layout
properties were loaded.layout
- The layout instance whose parameters are to be loaded. It
should be attached to this default labeling model.true
if layout parameters for the input layout were
stored in named properties of the manager, false
otherwise.saveParametersToNamedProperties(IlvLabelLayout, boolean)
,
removeParametersFromNamedProperties()
,
IlvLabelLayoutManagerProperty.transfer(ilog.views.graphlayout.labellayout.IlvLabelLayout)
,
IlvLabelLayoutLabelProperty.transfer(ilog.views.graphlayout.labellayout.IlvLabelLayout, ilog.views.IlvGraphic)
public boolean loadParametersFromNamedProperties(IlvLabelLayout layout, String propertyPrefix)
It searches for a set of layout parameter properties that has the property prefix string in the property name. It transfers the parameters to the layout instance and removes this set of named layout properties from the manager.
This method can also be used when the property prefix string is the full property name.
layout
- The layout instance whose parameters are to be loaded. It
should be attached to this default labeling model.propertyPrefix
- The prefix of the unique property name that was
used to store the layout properties.true
if layout parameters for the input layout were
stored in named properties of the manager, false
otherwise.saveParametersToNamedProperties(IlvLabelLayout, boolean)
,
loadParametersFromNamedProperties(IlvLabelLayout)
,
IlvLabelLayoutManagerProperty.transfer(ilog.views.graphlayout.labellayout.IlvLabelLayout)
,
IlvLabelLayoutLabelProperty.transfer(ilog.views.graphlayout.labellayout.IlvLabelLayout, ilog.views.IlvGraphic)
public IlvLabelLayout loadParametersFromNamedProperties(String propertyPrefix)
It searches for a set of layout parameter properties that has the property prefix string in the property name. If a corresponding set of properties is found, it creates a new layout instance that fits the layout properties, transfers the parameters to the new layout instance, and removes this set of named layout properties from the manager.
This method can be used when the property prefix string is the full
property name. However, it cannot be used if this labeling model was
internally created during IlvLabelLayout.attach(IlvManager)
.
It can only be used if this default labeling model was explicitly
allocated.
Note that the method throws a RuntimeException
in the
following cases:
IlvLabelLayout.attach(IlvManager)
.
propertyPrefix
- The prefix of the unique property name that was
used to store the layout properties.null
if the parameters are not
loaded.saveParametersToNamedProperties(IlvLabelLayout, boolean)
,
loadParametersFromNamedProperties(IlvLabelLayout)
,
IlvLabelLayoutManagerProperty.transfer(ilog.views.graphlayout.labellayout.IlvLabelLayout)
,
IlvLabelLayoutLabelProperty.transfer(ilog.views.graphlayout.labellayout.IlvLabelLayout, ilog.views.IlvGraphic)
public void removeParametersFromNamedProperties()
saveParametersToNamedProperties(IlvLabelLayout, boolean)
,
loadParametersFromNamedProperties(IlvLabelLayout)
,
IlvLabelLayoutManagerProperty.dispose(ilog.views.graphlayout.labellayout.IlvDefaultLabelingModel)
,
IlvLabelLayoutLabelProperty.dispose(ilog.views.graphlayout.labellayout.IlvDefaultLabelingModel)
public void removeParametersFromNamedProperties(String propertyPrefix)
This method can also be used when the property prefix string is the full property name.
propertyPrefix
- The prefix of the unique property name that was
used to store the layout properties.saveParametersToNamedProperties(IlvLabelLayout, boolean)
,
loadParametersFromNamedProperties(IlvLabelLayout)
,
IlvLabelLayoutManagerProperty.dispose(ilog.views.graphlayout.labellayout.IlvDefaultLabelingModel)
,
IlvLabelLayoutLabelProperty.dispose(ilog.views.graphlayout.labellayout.IlvDefaultLabelingModel)
public void removeParametersFromNamedProperties(Class layoutClass)
IlvTreeLayout
, it removes all layout
properties that are related to the Tree Layout.layoutClass
- The layout class.saveParametersToNamedProperties(IlvLabelLayout, boolean)
,
loadParametersFromNamedProperties(IlvLabelLayout)
,
IlvLabelLayoutManagerProperty.dispose(ilog.views.graphlayout.labellayout.IlvDefaultLabelingModel)
,
IlvLabelLayoutLabelProperty.dispose(ilog.views.graphlayout.labellayout.IlvDefaultLabelingModel)
public String toString()
IlvManager
, if any (see getManager()
).public double getLabelOverlap(Object label1, IlvRect rect1, double angle1, Object label2, IlvRect rect2, double angle2, double minDist)
The shape of label1
is considered to be the rectangle
rect1
rotated clockwise by angle1
around
the center of rect1
. The shape of label2
is
considered to be the rectangle rect2
rotated clockwise
by angle2
around the center of rect2
. The
angles are given in degrees.
The default implementation returns the approximate area of the intersection of both labels.
getLabelOverlap
in interface IlvLabelingModelWithRotation
label1
- The first label.rect1
- The unrotated bounding box of the first label, translated
to the proposed position for the label.angle1
- The rotation angle of the first label.label2
- The second label.rect2
- The unrotated bounding box of the second label, translated
to the proposed position for the label.angle2
- The rotation angle of the second label.minDist
- The minimum distance between labels.public double getObstacleOverlap(Object label, IlvRect labelRect, double angle, Object obstacle, IlvRect obstacleBBox, double minDist)
The shape of label
is considered to be the rectangle
labelRect
rotated clockwise by angle
around
the center of labelRect
. The angle is given in degrees.
The default implementation returns the approximate area of the intersection between the label and the obstacle bounding box.
getObstacleOverlap
in interface IlvLabelingModelWithRotation
label
- The label.labelRect
- The unrotated bounding box of the label, translated to
the proposed position for the label.angle
- The rotation angle of the label.obstacle
- The obstacle.obstacleBBox
- The bounding box of the obstacle.minDist
- The minimum distance between the label and the obstacle.public double getPolylineObstacleOverlap(Object label, IlvRect labelRect, double angle, Object polylineObstacle, IlvPoint[] pts, double lineWidth, double minDist)
The shape of label
is considered to be the rectangle
labelRect
rotated clockwise by angle
around
the center of labelRect
. The angle is given in degrees.
A return value of 0
indicates that there is no overlap
if the label is moved to the given position.
Call this method for polyline obstacles in label layout algorithms
instead of getObstacleOverlap(java.lang.Object, ilog.views.IlvRect, java.lang.Object, ilog.views.IlvRect, double)
, because it allows the
concrete labeling model to optimize the treatment of polyline
obstacles.
getPolylineObstacleOverlap
in interface IlvLabelingModelWithRotation
label
- The label.labelRect
- The unrotated bounding box of the label, translated to
the proposed position for the label.angle
- The rotation angle of the label.polylineObstacle
- The polyline obstacle.pts
- The points that define the shape of the polyline obstacle.lineWidth
- The line width of the polyline obstacle.minDist
- The minimum distance between the label and the obstacle.isPolylineObstacle(java.lang.Object)
public double getRotation(Object label, IlvRect rect)
rect
. You can use this method for
testing purposes even before the label is placed at this position.
The default implementation returns always 0,which indicates that the
label is not rotatable.
If you override this method to return a non-null rotation, then you
must also override the boundingBox(java.lang.Object)
method to return the
bounding box of the unrotated label.
getRotation
in interface IlvLabelingModelWithRotation
label
- The label.rect
- The proposed position for the label.public void setRotation(Object label, double angle)
setRotation
in interface IlvLabelingModelWithRotation
label
- The label.angle
- The rotation angle in degrees.© Copyright Rogue Wave Software, Inc. 1997, 2018. All Rights Reserved.