de.jaret.util.ui.timebars.swt.renderer
Class DefaultTimeScaleRenderer

java.lang.Object
  extended by de.jaret.util.ui.timebars.swt.renderer.RendererBase
      extended by de.jaret.util.ui.timebars.swt.renderer.DefaultTimeScaleRenderer
All Implemented Interfaces:
ITickProvider, TimeScaleRenderer

public class DefaultTimeScaleRenderer
extends RendererBase
implements TimeScaleRenderer, ITickProvider

A default timescale renderer rendering a readable scale for ranges from years to milliseconds. A holiday enumerator is used to display special and holidays in the tooltip. Suports horizontal and vertical orientation.

Version:
$Id: DefaultTimeScaleRenderer.java 1086 2011-07-30 20:28:05Z kliem $
Author:
Peter Kliem

Field Summary
protected  java.util.List<de.jaret.util.date.iterator.DateIterator.Format> _formats
          format of the corresponding iterator label.
protected  de.jaret.util.date.holidayenumerator.HolidayEnumerator _holidayEnumerator
          holiday enumerator for tooltips.
protected  java.util.List<de.jaret.util.date.iterator.DateIterator> _iterators
          List of date iterators for the strips.
protected  de.jaret.util.date.iterator.DateIterator _lowerStrip
          iterator for the minor ticks.
protected  java.util.List<de.jaret.util.date.JaretDate> _majorTicks
          major ticks of the last rendering.
protected  de.jaret.util.date.iterator.DateIterator _midStrip
          iterator for the middle main strip.
protected  java.util.List<de.jaret.util.date.JaretDate> _minorTicks
          minor ticks of the last rendering.
protected  java.util.Map<de.jaret.util.date.iterator.DateIterator,de.jaret.util.date.iterator.DateIterator> _upperMap
          map defining upper iterators for middle iterators.
protected  de.jaret.util.date.iterator.DateIterator _upperStrip
          iterator for the upmost strip.
protected static int ADDITIONALGAP
          additional gap between end of label and next line (approx).
protected static int GAP
          gap between line and label.
protected static int MAJORLENGTH
          length of major ticks.
protected static int MINORLENGTH
          length of minor ticks.
protected static int PREFERREDHEIGHT
          preferred height.
protected static int SETBONUS
          Bonus rewarded when an Iterator is already enabled for a format.
 
Fields inherited from class de.jaret.util.ui.timebars.swt.renderer.RendererBase
_printer, _scaleX, _scaleY
 
Constructor Summary
DefaultTimeScaleRenderer()
          Default constructor.
DefaultTimeScaleRenderer(org.eclipse.swt.printing.Printer printer)
          Construct the renderer for a prinetr device.
 
Method Summary
 TimeScaleRenderer createPrintRenderer(org.eclipse.swt.printing.Printer printer)
          Create a timescale renderer setup for printing.
 void dispose()
          Dispose resources.
 void draw(org.eclipse.swt.graphics.GC gc, org.eclipse.swt.graphics.Rectangle drawingArea, TimeBarViewerDelegate delegate, boolean top, boolean printing)
          Draw the Timescale.
 int getHeight()
          Returns the prferred height for rendering.
 java.util.List<de.jaret.util.date.JaretDate> getMajorTicks(TimeBarViewerDelegate delegate)
          Provide a list of dates used as major ticks.
 java.util.List<de.jaret.util.date.JaretDate> getMinorTicks(TimeBarViewerDelegate delegate)
          Provide a list of dates used as minor ticks.
 java.lang.String getToolTipText(TimeBarViewer tbv, org.eclipse.swt.graphics.Rectangle drawingArea, int x, int y)
          Retrieve the tooltip text for a given locatin in the timescale.
protected  java.lang.String getToolTipTextForDate(de.jaret.util.date.JaretDate date, TickScaler.Range range)
          Convert date to string for tooltip display.
protected  void initIterators()
          Initialize all possible iterators (strips).
 void setCorrectDST(boolean correctDST)
          Setup the iterators to do a DST correction.
 void setHolidayEnumerator(de.jaret.util.date.holidayenumerator.HolidayEnumerator he)
          Set a holidayenumerator for diasplaying special days as tooltip.
 boolean supportsOptimizedScrolling()
          Report whether this renderer can be used with optimized scrolling.
 
Methods inherited from class de.jaret.util.ui.timebars.swt.renderer.RendererBase
drawFocus, getDefaultLineWidth, getPrinter, getScaleX, getScaleY, scaleX, scaleY
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PREFERREDHEIGHT

protected static final int PREFERREDHEIGHT
preferred height.

See Also:
Constant Field Values

MINORLENGTH

protected static final int MINORLENGTH
length of minor ticks.

See Also:
Constant Field Values

MAJORLENGTH

protected static final int MAJORLENGTH
length of major ticks.

See Also:
Constant Field Values

ADDITIONALGAP

protected static final int ADDITIONALGAP
additional gap between end of label and next line (approx).

See Also:
Constant Field Values

GAP

protected static final int GAP
gap between line and label.

See Also:
Constant Field Values

SETBONUS

protected static final int SETBONUS
Bonus rewarded when an Iterator is already enabled for a format.

See Also:
Constant Field Values

_majorTicks

protected java.util.List<de.jaret.util.date.JaretDate> _majorTicks
major ticks of the last rendering.


_minorTicks

protected java.util.List<de.jaret.util.date.JaretDate> _minorTicks
minor ticks of the last rendering.


_iterators

protected java.util.List<de.jaret.util.date.iterator.DateIterator> _iterators
List of date iterators for the strips.


_formats

protected java.util.List<de.jaret.util.date.iterator.DateIterator.Format> _formats
format of the corresponding iterator label.


_midStrip

protected de.jaret.util.date.iterator.DateIterator _midStrip
iterator for the middle main strip.


_upperStrip

protected de.jaret.util.date.iterator.DateIterator _upperStrip
iterator for the upmost strip.


_lowerStrip

protected de.jaret.util.date.iterator.DateIterator _lowerStrip
iterator for the minor ticks.


_upperMap

protected java.util.Map<de.jaret.util.date.iterator.DateIterator,de.jaret.util.date.iterator.DateIterator> _upperMap
map defining upper iterators for middle iterators.


_holidayEnumerator

protected de.jaret.util.date.holidayenumerator.HolidayEnumerator _holidayEnumerator
holiday enumerator for tooltips.

Constructor Detail

DefaultTimeScaleRenderer

public DefaultTimeScaleRenderer(org.eclipse.swt.printing.Printer printer)
Construct the renderer for a prinetr device.

Parameters:
printer - printer device

DefaultTimeScaleRenderer

public DefaultTimeScaleRenderer()
Default constructor.

Method Detail

initIterators

protected void initIterators()
Initialize all possible iterators (strips).


setHolidayEnumerator

public void setHolidayEnumerator(de.jaret.util.date.holidayenumerator.HolidayEnumerator he)
Set a holidayenumerator for diasplaying special days as tooltip.

Parameters:
he - holidayenumerator to use

draw

public void draw(org.eclipse.swt.graphics.GC gc,
                 org.eclipse.swt.graphics.Rectangle drawingArea,
                 TimeBarViewerDelegate delegate,
                 boolean top,
                 boolean printing)
Draw the Timescale.

Specified by:
draw in interface TimeScaleRenderer
Parameters:
gc - GraphicsContext to paint with.
drawingArea - Rectangel denoting the area to draw in. The gc is clipped to this area.
delegate - TimeBarViewerDelegate exposed for callbacks
top - if true the tmiescale is in position top, bottom otherwise
printing - flag to indicate printing.

getToolTipText

public java.lang.String getToolTipText(TimeBarViewer tbv,
                                       org.eclipse.swt.graphics.Rectangle drawingArea,
                                       int x,
                                       int y)
Retrieve the tooltip text for a given locatin in the timescale.

Specified by:
getToolTipText in interface TimeScaleRenderer
Parameters:
tbv - TimeBarViewer
drawingArea - area in that the timescale has been painted
x - x coordinate
y - y coordinate
Returns:
tooltip text or null

getToolTipTextForDate

protected java.lang.String getToolTipTextForDate(de.jaret.util.date.JaretDate date,
                                                 TickScaler.Range range)
Convert date to string for tooltip display.

Parameters:
date - date
range - last range
Returns:
string for displaying as tooltip

getHeight

public int getHeight()
Returns the prferred height for rendering.

Specified by:
getHeight in interface TimeScaleRenderer
Returns:
preferred height

dispose

public void dispose()
Dispose resources.

Specified by:
dispose in interface TimeScaleRenderer

createPrintRenderer

public TimeScaleRenderer createPrintRenderer(org.eclipse.swt.printing.Printer printer)
Create a timescale renderer setup for printing.

Specified by:
createPrintRenderer in interface TimeScaleRenderer
Parameters:
printer - Printer device taht will be used.
Returns:
timescale renderer setup for printing.

getMajorTicks

public java.util.List<de.jaret.util.date.JaretDate> getMajorTicks(TimeBarViewerDelegate delegate)
Provide a list of dates used as major ticks.

Specified by:
getMajorTicks in interface ITickProvider
Parameters:
delegate - the delegate the ticks are used with
Returns:
list of dates

getMinorTicks

public java.util.List<de.jaret.util.date.JaretDate> getMinorTicks(TimeBarViewerDelegate delegate)
Provide a list of dates used as minor ticks.

Specified by:
getMinorTicks in interface ITickProvider
Parameters:
delegate - the delegate the ticks are used with
Returns:
list of dates

setCorrectDST

public void setCorrectDST(boolean correctDST)
Setup the iterators to do a DST correction.

Parameters:
correctDST - true if a correction should be done.

supportsOptimizedScrolling

public boolean supportsOptimizedScrolling()
Report whether this renderer can be used with optimized scrolling. This will usually be the case if all elements drawn are positioned by the date.

Specified by:
supportsOptimizedScrolling in interface TimeScaleRenderer
Returns:
true if optimzed drawing can be used.


Copyright © 2012. All Rights Reserved.