lt.monarch.chart.chart2D.axis.layouters
Class MultiLevelLabelLayouter

java.lang.Object
  extended by lt.monarch.chart.chart2D.axis.layouters.SimpleLinearLabelLayouter
      extended by lt.monarch.chart.chart2D.axis.layouters.DefaultLinearLabelLayouter
          extended by lt.monarch.chart.chart2D.axis.layouters.MultiLevelLabelLayouter
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, LinearLabelLayouter

public class MultiLevelLabelLayouter
extends DefaultLinearLabelLayouter

This layouter is used to layout labels of multiple levels.

When mapper producing labels of multiple levels is used for axis, e.g. DateAxisMapper, this is situation where MultiLevelLabelLayouter could be applied. Layout constraints could be set for each level of labels indicating necessity to raise and possibly center labels of desired level (see API description of public constants - possible constraints values).

Raising constraint allows separate labels into rows. Layout algorithm traverses label levels from highest to lowest (from level of finest scale labels to level of start scale labels in case of DateAxisMapper) and, when it founds level with assigned constraint value indicating raising, the new label row is added. All labels of current and lower levels go into new row.
Labels are not rised if there are no visible labels of higher level.

Centering allows to have labels placed not at their axis ticks but rather center them between current label tick and next label tick; e.g. you can have months names placed at about 15th day of month rather than having them sticked on ticks at the beginning of the 1st day of month.
Centering in floating mode allows to have visible at least one label of scales of larger time units even when zooming in by large factors.

Limitation:
MultiLevelLabelLayouter can be used for Axis2DX and Axis2DY only.

Example:
Assume that DateAxisMapper is used for Axis2DX or Axis2DY and its starting scale units are set to Calendar.YEAR, finest - to Calendar.DAY_OF_MONTH (see DateAxisMapper#setStartingScaleUnits (int) and DateAxisMapper#setFinestScaleUnits (int)). So, we have labels of 3 levels. Year labels are the 1st level labels, month labels - the 2nd, and day labels - the 3th level. We want to have month labels to be moved to next row below day labels and center them at about 15th day of month. We use code:

((MultiLevelLabelLayouter) layouter).setLayoutConstraints (2, MultiLevelLabelLayouter.RAISE_AND_CENTER_FIXED_ON_RIGHT_RANGE);

Year labels will also go in the same row as month labels. If we want, we can move year labels further into next row using this line of code:

((MultiLevelLabelLayouter) layouter).setLayoutConstraints (1, MultiLevelLabelLayouter.RAISE);

Note that label level numbering in DateAxisMapper starts from labels of scale of starting (largest) time unit, i.e. if Calendar.MONTH is starting time unit then month labels are 1st level labels.

2007.02.21 Changes suggested by Robert Dunaj.

See Also:
Serialized Form

Field Summary
Modifier and Type Field and Description
 
Fields inherited from class lt.monarch.chart.chart2D.axis.layouters.SimpleLinearLabelLayouter
calculatePreferredDimensions, levels, prefferedHeight, prefferedWidth, sparseMode, start, stop, titleArea
 
Constructor Summary
Constructor and Description
MultiLevelLabelLayouter()
           
 
Method Summary
Modifier and Type Method and Description
protected  void eliminateOutbound(AbstractAxisLabel[] labels)
          Eliminates labels, falling outside the visible axis range.
 int getBottomPos(int level)
          Returns bottom position of labels of given level, if level is raised and -1 otherwise.
 boolean getDoWordWrap()
          Return weather word wrapping is enabled
 MultiLevelLabel getLayoutConstraints(int labelLevel)
          Returns layout constraints for given label level.
 double getMaxLevelLabelSize()
          Non-API method. Returns labels max level height for X axis and width for Y axis.
 double getRowSpacing()
          Number of pixels that separate rows of layouted labels.
 int getTopPos(int level)
          Returns top position of labels of given level, if level is raised and -1 otherwise.
 boolean isDynamicLabels()
          Reuse space of empty labels..
 boolean isEliminateOverlappingRowsLabels()
          Return is set eliminate lower low labels when exists upper row labels.
 void layout(AbstractAxisLabel[] labels)
          Layouts the specified labels.
 void prepare(AbstractAxisLabel[] labels)
          Non-API method. Calculates preferred size of all visible labels (maximum size of all labels).
protected  void rowLayout(AxisLabel[] rowLabels)
          Layout one rowLabels in multilevel layouter
protected  void rowPrepare(AxisLabel[] prepareLabels)
          Prepares one prepareLabels in multilevel layouter
 void setAxisParams(Alignment axisPosition, double maxLabelDimension)
          Deprecated. not usable changed to setAxisParams(Orientation, Alignment)
 void setAxisParams(boolean axisTopOrientated, double maxLabelHeigth)
          Deprecated. use setAxisParams(Alignment, double)
 void setAxisParams(Orientation axisOrientation, Alignment axisPosition)
          Sets axis parameters for level calculating.
 void setDoWordWrap(boolean doWordWrap)
          set word wrapping status
 void setDynamicLabels(boolean dynamicLabels)
          Sets capability reuse empty labels space.
 void setEliminateOverlappingRowsLabels(boolean eliminateOverlappingRowsLabels)
          Set eliminate lower low labels when exists upper row labels.
 void setLayoutConstraints(int labelLevel, MultiLevelLabel constraint)
          Sets layout constraints for desired label level.
 void setRowSpacing(int rowSpacing)
          Sets number of pixels that should separate rows of layouted labels.
 
Methods inherited from class lt.monarch.chart.chart2D.axis.layouters.DefaultLinearLabelLayouter
eliminateLevelsFrom, getMinimumLabelSpacing, setMinimumLabelSpacing
 
Methods inherited from class lt.monarch.chart.chart2D.axis.layouters.SimpleLinearLabelLayouter
clone, compareLabels, dispose, findMaxLevel, getMaxLevel, getPreferredHeight, getPreferredWidth, setSparseMode, setTitleArea, setVisibleRange, sort
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MultiLevelLabelLayouter

public MultiLevelLabelLayouter()
Method Detail

getDoWordWrap

public boolean getDoWordWrap()
Return weather word wrapping is enabled

Returns:
is word wrapping is enabled

setDoWordWrap

public void setDoWordWrap(boolean doWordWrap)
set word wrapping status

Parameters:
doWordWrap - is word wrapping enabled

layout

public void layout(AbstractAxisLabel[] labels)
Layouts the specified labels.

Specified by:
layout in interface LinearLabelLayouter
Overrides:
layout in class DefaultLinearLabelLayouter
Parameters:
labels - the labels to layout

rowLayout

protected void rowLayout(AxisLabel[] rowLabels)
Layout one rowLabels in multilevel layouter

Parameters:
rowLabels - row label array

eliminateOutbound

protected void eliminateOutbound(AbstractAxisLabel[] labels)
Description copied from class: SimpleLinearLabelLayouter
Eliminates labels, falling outside the visible axis range.

Overrides:
eliminateOutbound in class DefaultLinearLabelLayouter
Parameters:
labels - labels to layout

getTopPos

public int getTopPos(int level)
Returns top position of labels of given level, if level is raised and -1 otherwise. Value is valid after the layout(Label[]) method is already called.

Parameters:
level - label level
Returns:
minimum of top coordinates of labels of given level, or -1 if level is not raised or there was no labels of such level when layouting labels.

getBottomPos

public int getBottomPos(int level)
Returns bottom position of labels of given level, if level is raised and -1 otherwise. Value is valid after the layout(Label[]) method is already called.

Parameters:
level - label level
Returns:
maximum of top coordinates of labels of given level, or -1 if level is not raised or there was no labels of such level when layouting labels.

setLayoutConstraints

public void setLayoutConstraints(int labelLevel,
                                 MultiLevelLabel constraint)
Sets layout constraints for desired label level. See API descriptions of public constants - possible constraints values.

Parameters:
labelLevel - level of labels to which constraints should be applied. Level numbering starts at 1.
constraints - constraints to apply. Valid values are: MultiLevelLabelLayouter.NULL MultiLevelLabelLayouter.RAISE, MultiLevelLabelLayouter.RAISE_AND_CENTER_FIXED_ON_RIGHT_RANGE, MultiLevelLabelLayouter .RAISE_AND_CENTER_FLOATING_ON_RIGHT_RANGE.

getLayoutConstraints

public MultiLevelLabel getLayoutConstraints(int labelLevel)
Returns layout constraints for given label level. See API descriptions of public constants - possible constraints values.

Parameters:
labelLevel - label level which constraints should be returned. Level numbering starts at 1.
Returns:
layout constraints. Possible values are: MultiLevelLabelLayouter.NULL MultiLevelLabelLayouter.RAISE, MultiLevelLabelLayouter.RAISE_AND_CENTER_FIXED_ON_RIGHT_RANGE, MultiLevelLabelLayouter.RAISE_AND_CENTER_FLOATING_ON_RIGHT_RANGE.

setRowSpacing

public void setRowSpacing(int rowSpacing)
Sets number of pixels that should separate rows of layouted labels.

Parameters:
spacing - desired gap between two label rows in pixels

getRowSpacing

public double getRowSpacing()
Number of pixels that separate rows of layouted labels.

Returns:
gap between two label rows in pixels

setAxisParams

public void setAxisParams(boolean axisTopOrientated,
                          double maxLabelHeigth)
Deprecated. use setAxisParams(Alignment, double)

Sets axis parameters for level calculating.

Parameters:
axisTopOrientated - the axisTopOrientated to set
maxLabelHeigth - maximum label height

setAxisParams

public void setAxisParams(Alignment axisPosition,
                          double maxLabelDimension)
Deprecated. not usable changed to setAxisParams(Orientation, Alignment)

Sets axis parameters for level calculating.

Parameters:
axisPosition - the axisPosition to set
maxLabelDimension - maximum label height (if axis is oriented TOP or BOTTOM) or width (if axis is on the LEFT or RIGHT)

setAxisParams

public void setAxisParams(Orientation axisOrientation,
                          Alignment axisPosition)
Sets axis parameters for level calculating.

Parameters:
axisOrientation - the axisOrientation to set
axisPosition - the axisPosition to set

setDynamicLabels

public void setDynamicLabels(boolean dynamicLabels)
Sets capability reuse empty labels space.

Parameters:
dynamicLabels - the dynamicLabels to set

isDynamicLabels

public boolean isDynamicLabels()
Reuse space of empty labels..

Returns:
the dynamicLabels

setEliminateOverlappingRowsLabels

public void setEliminateOverlappingRowsLabels(boolean eliminateOverlappingRowsLabels)
Set eliminate lower low labels when exists upper row labels.

Parameters:
eliminateOverlappingRowsLabels - the eliminate overlapping rows labels to set

isEliminateOverlappingRowsLabels

public boolean isEliminateOverlappingRowsLabels()
Return is set eliminate lower low labels when exists upper row labels.

Returns:
the eliminate overlapping rows labels

prepare

public void prepare(AbstractAxisLabel[] labels)
Description copied from interface: LinearLabelLayouter
Non-API method. Calculates preferred size of all visible labels (maximum size of all labels).

Specified by:
prepare in interface LinearLabelLayouter
Overrides:
prepare in class DefaultLinearLabelLayouter
Parameters:
labels - label array

rowPrepare

protected void rowPrepare(AxisLabel[] prepareLabels)
Prepares one prepareLabels in multilevel layouter

Parameters:
prepareLabels - row label array

getMaxLevelLabelSize

public double getMaxLevelLabelSize()
Non-API method. Returns labels max level height for X axis and width for Y axis. Value is valid after the prepare(AbstractAxisLabel[] labels) or layout(AbstractAxisLabel[] labels) method is already called.

Returns:
maximum size of labels maximum level