public class TLspLabelConflictChecker extends Object implements ILspLabelConflictChecker
ILcdLabelConflictChecker
by checking if
a given label placements overlaps with other placements, label obstacles or the view bounds by
calculating their intersection analytically.
This label conflict checker uses the bounds retrieved using
TLspLabelPlacement.getX()
,
TLspLabelPlacement.getY()
,
TLspLabelPlacement.getWidth()
,
TLspLabelPlacement.getHeight()
and
TLspLabelPlacement.getRotation()
.
ILspLabelConflictChecker.Conflict
Constructor and Description |
---|
TLspLabelConflictChecker() |
Modifier and Type | Method and Description |
---|---|
void |
addObstacle(TLspLabelObstacle aLabelObstacle)
Add the given obstacle to this conflict checker.
|
void |
addPlacement(TLspLabelPlacement aPlacement)
Add the given label placement to this conflict checker.
|
TLspLabelConflictChecker |
clone()
Makes
Object.clone() public. |
ILspLabelConflictChecker.Conflict |
getConflict(TLspLabelPlacement aPlacement)
Checks if the given placement is valid, that is if it does not overlap with already added
placements or obstacles.
|
List<TLspLabelObstacle> |
getObstacles()
Returns all obstacles that were added to (and not removed from) this conflict checker.
|
double |
getPadding()
Returns the padding around the label placements.
|
List<TLspLabelPlacement> |
getPlacements()
Returns all label placements that were added to (and not removed from) this conflict checker.
|
void |
removeObstacle(TLspLabelObstacle aLabelObstacle)
Removes the given obstacle from the conflict checker.
|
void |
removePlacement(TLspLabelPlacement aPlacement)
Removes the given label placement from the conflict checker.
|
void |
reset(Rectangle aViewBounds)
Resets the conflict checker.
|
void |
setPadding(double aPadding)
Sets the padding around the label placements.
|
public TLspLabelConflictChecker clone()
ILcdCloneable
Makes Object.clone()
public.
java.lang.Object
, it can be implemented like this:
public Object clone() {
try {
return super.clone();
} catch ( CloneNotSupportedException e ) {
// Cannot happen: extends from Object and implements Cloneable (see also Object.clone)
throw new RuntimeException( e );
}
}
clone
in interface ILcdCloneable
clone
in class Object
Object.clone()
public double getPadding()
setPadding(double)
public void setPadding(double aPadding)
Sets the padding around the label placements. This padding is added to the bounds of the placement, enlarging it. In practice this means that the bigger the padding, the more space each label occupies, and the less labels can be placed. Note that this setting only applies to label placements, and not to obstacles.
By default, this value is 0.0
.
Note that it is possible to change the padding at runtime. E.g. when setting the padding to a new value right
before calling addPlacement
of getConflict
, the new padding value is used for the newly added placement (but not for the placements that were
added before).
aPadding
- the padding.IllegalArgumentException
- when the given padding is smaller than 0
.getPadding()
public void reset(Rectangle aViewBounds)
ILspLabelConflictChecker
reset
in interface ILspLabelConflictChecker
aViewBounds
- the view bounds.public void addObstacle(TLspLabelObstacle aLabelObstacle)
ILspLabelConflictChecker
getConflict
method can use the given obstacle to detect conflicts.
After calling this method, it is possible that this bounds conflict checker keeps a reference to the given obstacle. By consequence, the given obstacle should not be changed outside this method. The given obstacle cannot be changed inside this method.
Adding the same obstacle instance twice should have the exact same effect as adding the obstacle instance only once.
addObstacle
in interface ILspLabelConflictChecker
aLabelObstacle
- an obstacle.public void removeObstacle(TLspLabelObstacle aLabelObstacle)
ILspLabelConflictChecker
addObstacle
.
After calling this method, it is possible that this bounds conflict checker keeps a reference to the given obstacle. By consequence, the given obstacle should never be changed outside this method. The given obstacle cannot be changed inside this method.
removeObstacle
in interface ILspLabelConflictChecker
aLabelObstacle
- an obstacle.public List<TLspLabelObstacle> getObstacles()
ILspLabelConflictChecker
getObstacles
in interface ILspLabelConflictChecker
public void addPlacement(TLspLabelPlacement aPlacement)
ILspLabelConflictChecker
getConflict
method can use the given placement to detect conflicts.
After calling this method, it is possible that this bounds conflict checker keeps a reference to the given label placement. By consequence, the bounds information in the given placement should not be changed outside this method. The given label placement cannot be changed inside this method.
Adding the same label placement instance twice should have the exact same effect as adding the label placement instance only once.
addPlacement
in interface ILspLabelConflictChecker
aPlacement
- a label placement.public void removePlacement(TLspLabelPlacement aPlacement)
ILspLabelConflictChecker
addPlacement
.
After calling this method, it is possible that this bounds conflict checker keeps a reference to the given label placement. By consequence, the bounds inside the given label placement should never be changed outside this method. The given bounds cannot be changed inside this method.
removePlacement
in interface ILspLabelConflictChecker
aPlacement
- a label placement.public List<TLspLabelPlacement> getPlacements()
ILspLabelConflictChecker
getPlacements
in interface ILspLabelConflictChecker
public ILspLabelConflictChecker.Conflict getConflict(TLspLabelPlacement aPlacement)
ILspLabelConflictChecker
When no conflict is found, the returned Conflict
should be null
.
getConflict
in interface ILspLabelConflictChecker
aPlacement
- a label placement.null
if no conflict was found.