lt.monarch.chart.mapper
Class DateListAxisMapper

java.lang.Object
  extended by lt.monarch.chart.mapper.AbstractAxisMapper
      extended by lt.monarch.chart.mapper.CountableAxisMapper
          extended by lt.monarch.chart.mapper.DateListAxisMapper
All Implemented Interfaces:
java.io.Serializable, AxisMapper

public class DateListAxisMapper
extends CountableAxisMapper

Axis mapper which maps a date list. List may have date gaps. Gaps are ignored. All dates are mapped sequentially and spaced equally. Month edges are detected and marked on the scale. Note: KEY values in the data model must be sorted in ascending order.

See Also:
Serialized Form

Constructor Summary
Constructor and Description
DateListAxisMapper(java.util.Date[] dates)
          Constructs a new DateListAxisMapper with the specified array of dates.
DateListAxisMapper(java.util.Date[] dates, AxisMapperRange mapperRange)
          Constructs a new DateListAxisMapper with the specified array of dates with the specified axis mapper range.
 
Method Summary
Modifier and Type Method and Description
 void addDate(java.util.Date newDate)
          Adds single date point to the array of dates being mapped.
 java.lang.String formatKey(java.lang.Object key)
          Provides text representation of the specified Date value.
 java.util.Calendar getCalendar()
          Gets a calendar of the date axis mapper.
 java.text.DateFormat getDateFormat(int units)
          Gets the general date format of the date list axis mapper.
 java.util.Date[] getDates()
          Gets the list of dates.
 int getElementCount()
          Gets the number of elements in the list.
protected  java.text.Format[] getFormats()
          Gets all formats.
 int getLabelCount()
          Gets label count in the axis mapper.
 double getPreferredHeight(AbstractGraphics g, AbstractTextPainter textPainter)
          Gets preferred height.
 double getPreferredWidth(AbstractGraphics g, AbstractTextPainter textPainter)
          Gets preferred width.
 java.lang.Object[] getRegisteredKeys()
          Gets axis registered keys.
 AxisScale getScale()
          Returns a scale for this axis.
 AxisMapperRange getViewRange()
          Gets the visible range as AxisMapperRange object.
protected  double map(int i)
          Maps the i-th dates list element.
 double map(java.lang.Object key)
          Maps the specified Date value into the mapping range.
 java.lang.Object mapBack(double pos)
          Converts the position on the coordinate axis to the Date object.
 void setCalendar(java.util.Calendar calendar)
          Sets a Calendar for this date axis mapper.
 void setDateFormat(java.text.DateFormat dateFormat, int units)
          Sets the date format for specified scale units.
 void setDates(java.util.Date[] dates)
          Sets dates which will be mapped.
 void setFinestScaleUnits(int units)
          Sets the finest scale units.
 void setStartingScaleUnits(int units)
          Sets the biggest scale units.
 void setVisibleRange(java.util.Date start, java.util.Date end)
          Sets date view range for the axis.
 void showAllTicks(boolean show)
          Sets property, which defines if the finest scale ticks are shown.
 
Methods inherited from class lt.monarch.chart.mapper.CountableAxisMapper
getTextHeigh, getTextWidth
 
Methods inherited from class lt.monarch.chart.mapper.AbstractAxisMapper
addListener, fireMappingChanged, getProjectionRange, removeListener, setProjectionRange
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DateListAxisMapper

public DateListAxisMapper(java.util.Date[] dates)
Constructs a new DateListAxisMapper with the specified array of dates.

Parameters:
dates - the array of dates

DateListAxisMapper

public DateListAxisMapper(java.util.Date[] dates,
                          AxisMapperRange mapperRange)
Constructs a new DateListAxisMapper with the specified array of dates with the specified axis mapper range.

Parameters:
dates - the array of dates
mapperRange - the mapper range
Method Detail

setCalendar

public void setCalendar(java.util.Calendar calendar)
Sets a Calendar for this date axis mapper. The Calendar will be used to extract integer fields as YEAR, MONTH, DAY and so on from Date objects.

Parameters:
calendar - the calendar

setStartingScaleUnits

public void setStartingScaleUnits(int units)
Sets the biggest scale units. The scale starts with the units specified here.

Parameters:
units - Any of these values: Calendar.YEAR, Calendar.MONTH, Calendar.DAY_OF_MONTH

setFinestScaleUnits

public void setFinestScaleUnits(int units)
Sets the finest scale units. No units, smaller than specified by the finestScaleUnits property are drawn. Zooming can not be performed beyond this precision.

Parameters:
units - Any of these values: Calendar.YEAR, Calendar.MONTH, Calendar.DAY_OF_MONTH

setDateFormat

public void setDateFormat(java.text.DateFormat dateFormat,
                          int units)
Sets the date format for specified scale units. If parameter is not set the default DataFormat.SHORT format will be used for that scale unit.

Parameters:
dateFormat - : desired DateFormat,
units - Any of these values: Calendar.YEAR, Calendar.MONTH, Calendar.DAY_OF_MONTH

getCalendar

public java.util.Calendar getCalendar()
Gets a calendar of the date axis mapper.

Returns:
calendar of the date axis mapper
See Also:
setCalendar(java.util.Calendar)

getDateFormat

public java.text.DateFormat getDateFormat(int units)
Gets the general date format of the date list axis mapper.

Parameters:
units - time unit type, use Calendar variable list.
Returns:
general date format of the mapper

getViewRange

public AxisMapperRange getViewRange()
Gets the visible range as AxisMapperRange object.

Returns:
AxisMapperRange object representing visible mapper range

setDates

public void setDates(java.util.Date[] dates)
Sets dates which will be mapped.

Parameters:
dates - date list

addDate

public void addDate(java.util.Date newDate)
Adds single date point to the array of dates being mapped.

Parameters:
newDate - date to add

setVisibleRange

public void setVisibleRange(java.util.Date start,
                            java.util.Date end)
Sets date view range for the axis.

Parameters:
start - start date
end - end date

map

public double map(java.lang.Object key)
Maps the specified Date value into the mapping range.

Parameters:
key - the Date to map
Returns:
position of key in the date range; a value in range [0,1]

map

protected double map(int i)
Maps the i-th dates list element.

Parameters:
i - index of dates list element
Returns:
position of the dates list element in the mapping range

mapBack

public java.lang.Object mapBack(double pos)
Converts the position on the coordinate axis to the Date object.

Specified by:
mapBack in interface AxisMapper
Overrides:
mapBack in class AbstractAxisMapper
Parameters:
pos - the position on the coordinate axis
Returns:
Date object corresponding the specified position
See Also:
AxisMapper.mapBack(double)

getScale

public AxisScale getScale()
Returns a scale for this axis.

Returns:
a scale for this axis

getElementCount

public int getElementCount()
Gets the number of elements in the list.

Returns:
number of elements in the list

formatKey

public java.lang.String formatKey(java.lang.Object key)
Provides text representation of the specified Date value. Formats date according to the last set date format for any time unit.

Parameters:
key - the Date object to format
Returns:
text representation of the specified Date value

showAllTicks

public void showAllTicks(boolean show)
Sets property, which defines if the finest scale ticks are shown.

Parameters:
show - if true all ticks are shown.

getDates

public java.util.Date[] getDates()
Gets the list of dates.

Returns:
list of the dates

getRegisteredKeys

public java.lang.Object[] getRegisteredKeys()
Description copied from class: CountableAxisMapper
Gets axis registered keys.

Specified by:
getRegisteredKeys in class CountableAxisMapper
Returns:
axis registered keys

getLabelCount

public int getLabelCount()
Description copied from class: CountableAxisMapper
Gets label count in the axis mapper.

Specified by:
getLabelCount in class CountableAxisMapper
Returns:
returns label count in the axis mapper

getFormats

protected java.text.Format[] getFormats()
Gets all formats.

Returns:

getPreferredHeight

public double getPreferredHeight(AbstractGraphics g,
                                 AbstractTextPainter textPainter)
Description copied from interface: AxisMapper
Gets preferred height.

Parameters:
g - graphics context
textPainter - text painter mode
Returns:
preferred height

getPreferredWidth

public double getPreferredWidth(AbstractGraphics g,
                                AbstractTextPainter textPainter)
Description copied from interface: AxisMapper
Gets preferred width.

Parameters:
g - graphics context
textPainter - text painter mode
Returns:
preferred width