com.dlsc.flexgantt.swing.timeline
Class SimpleGranularityDatelineModel

java.lang.Object
  extended by com.dlsc.flexgantt.model.dateline.AbstractDatelineModel<SimpleGranularity>
      extended by com.dlsc.flexgantt.swing.timeline.SimpleGranularityDatelineModel
All Implemented Interfaces:
IDatelineModel<SimpleGranularity>

public class SimpleGranularityDatelineModel
extends AbstractDatelineModel<SimpleGranularity>

A dateline model implementation based on the SimpleGranularity enumerator. The model returns major time points that are always ten times larger than the minor time points. So if the minor times are 1, 2, 3, ... then the major times are 10, 20, 30, 40, 50, ...

Since:
1.0
Author:
Dirk Lemmermann
See Also:
SimpleGranularity, SimpleGranularityDatelineRenderer, SimpleGranularityGridPolicy

Field Summary
 
Fields inherited from class com.dlsc.flexgantt.model.dateline.AbstractDatelineModel
datelineWidth, granularity, selectedTimeSpan, timeSpan, timeZone, zoom
 
Constructor Summary
SimpleGranularityDatelineModel(Dateline dateline)
          Constructs a new dateline model.
SimpleGranularityDatelineModel(Dateline dateline, ITimeSpan timeSpan, SimpleGranularity sg)
          Constructs a new dateline model.
SimpleGranularityDatelineModel(Dateline dateline, ITimeSpan timeSpan, SimpleGranularity sg, java.util.TimeZone timeZone)
          Constructs a new dateline model.
SimpleGranularityDatelineModel(Dateline dateline, SimpleGranularity sg)
          Constructs a new dateline model.
 
Method Summary
protected  void calculateDatelineWidth()
          Calculates the required width of the dateline based on the total time span and some additional information that needs to be provided by the subclasses.
 int getGap()
          The gap (in pixel) that will be added twice to each granularity width so that there will be some space between the text and the grid lines.
 java.util.List<GridLine> getGrid(int x1, int x2, boolean major)
          Returns a list of grid line coordinates for the given coordinate interval.
 java.lang.String getMajorDateString(SimpleGranularity granularity, long time)
          Returns a text representation for the given major time point and granularity.
 SimpleGranularity getMajorSimpleGranularity()
          Returns the currently shown major granularity, which gets determined by invoking SimpleGranularity.next() on the current granularity.
 java.lang.String getMinorDateString(SimpleGranularity granularity, long time)
          Returns a text representation for the given minor time point and granularity.
 long getTimeAt(int x)
          Returns the time for the given x-coordinate.
 int getTimeLocation(long time)
          Returns the location of the given time point.
 ITimeSpan getTimeSpanAt(int x, boolean major)
          Returns the time span that gets defined by the grid lines to the left and the right of the given x-coordinate.
 java.lang.String getTimeString(long time)
          Returns a textual representation for the givent time point.
 void requestVisibleTimeSpan(ITimeSpan span)
          A request that asks the model to change its settings in such a way that the requested time span will become visible in the viewport on the right-hand side of the Gantt chart.
 void setGap(int gap)
          Sets the gap (in pixel) that will be added twice to each granularity width so that there will be some space between the text and the grid lines.
 
Methods inherited from class com.dlsc.flexgantt.model.dateline.AbstractDatelineModel
addDatelineModelListener, fireDatelineModelChangeEvent, fireDatelineModelWillChangeEvent, getDatelineWidth, getGranularity, getSelectedTimeSpan, getTimeSpan, getTimeZone, getZoom, removeDatelineModelListener, setGranularity, setSelectedTimeSpan, setTimeSpan, setTimeZone, setZoom
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SimpleGranularityDatelineModel

public SimpleGranularityDatelineModel(Dateline dateline,
                                      ITimeSpan timeSpan,
                                      SimpleGranularity sg,
                                      java.util.TimeZone timeZone)
                               throws DatelineModelException
Constructs a new dateline model.

Parameters:
dateline - the dateline to which the model belongs
timeSpan - the total time span covered (the planning horizon)
sg - the initial simple granularity
timeZone - the time zone represented by the model
Throws:
DatelineModelException - if the requested time span can not be visualized with the requested granularity
Since:
1.0

SimpleGranularityDatelineModel

public SimpleGranularityDatelineModel(Dateline dateline,
                                      ITimeSpan timeSpan,
                                      SimpleGranularity sg)
                               throws DatelineModelException
Constructs a new dateline model. The time zone defaults to TimeZone.getDefault()

Parameters:
dateline - the dateline to which the model belongs
timeSpan - the total time span covered (the planning horizon)
sg - the initial simple granularity
Throws:
DatelineModelException - if the requested time span can not be visualized with the requested granularity
Since:
1.0

SimpleGranularityDatelineModel

public SimpleGranularityDatelineModel(Dateline dateline,
                                      SimpleGranularity sg)
                               throws DatelineModelException
Constructs a new dateline model. The initial time span is [0, 1000] and the time zone defaults to TimeZone.getDefault()

Parameters:
dateline - the dateline to which the model belongs
sg - the initial simple granularity
Throws:
DatelineModelException - if the requested time span can not be visualized with the requested granularity
Since:
1.0

SimpleGranularityDatelineModel

public SimpleGranularityDatelineModel(Dateline dateline)
                               throws DatelineModelException
Constructs a new dateline model. The initial time span is [0, 1000], the initial granularity is SimpleGranularity.ONE, and the time zone defaults to TimeZone.getDefault()

Parameters:
dateline - the dateline to which the model belongs
Throws:
DatelineModelException - if the requested time span can not be visualized with the requested granularity
Since:
1.0
Method Detail

getMajorSimpleGranularity

public SimpleGranularity getMajorSimpleGranularity()
Returns the currently shown major granularity, which gets determined by invoking SimpleGranularity.next() on the current granularity.

Returns:
the current major granularity
Since:
1.0

calculateDatelineWidth

protected void calculateDatelineWidth()
                               throws DatelineModelException
Description copied from class: AbstractDatelineModel
Calculates the required width of the dateline based on the total time span and some additional information that needs to be provided by the subclasses.

Specified by:
calculateDatelineWidth in class AbstractDatelineModel<SimpleGranularity>
Throws:
DatelineModelException - if the calculated width exceeds the maximum width that is equal to Integer.MAX_VALUE

getGrid

public java.util.List<GridLine> getGrid(int x1,
                                        int x2,
                                        boolean major)
Description copied from interface: IDatelineModel
Returns a list of grid line coordinates for the given coordinate interval. The same method gets invoked for major and minor grid lines.

Parameters:
x1 - the start coordinate
x2 - the end coordinate
major - if TRUE the method needs to return the major grid lines
Returns:
a list of x-coordinates where each coordinate represents one vertical grid line
See Also:
GridLayer

getTimeLocation

public int getTimeLocation(long time)
Description copied from interface: IDatelineModel
Returns the location of the given time point. The location is an x-coordinate within the dateline. Models that are continous will simply calculate the milliseconds per pixel (mpp) and base their calculations on that value (example mpp = 2000, time = 10000 -> x = 5). Discrete models might implement a more sophisticated algorithm to compute the coordinate. The method needs to work symetrically to the IDatelineModel.getTimeAt(int) method (example: x = getTimeLocation(getTimeAt(x))).

Parameters:
time - the time for which to return a coordinate
Returns:
the x-coordinate for the given time point
See Also:
IDatelineModel.getTimeAt(int)

getTimeAt

public long getTimeAt(int x)
Description copied from interface: IDatelineModel
Returns the time for the given x-coordinate.

Parameters:
x - the x-coordinate for which to return a time point
Returns:
the time at the given location
See Also:
IDatelineModel.getTimeLocation(long)

getTimeSpanAt

public ITimeSpan getTimeSpanAt(int x,
                               boolean major)
Description copied from interface: IDatelineModel
Returns the time span that gets defined by the grid lines to the left and the right of the given x-coordinate.

Parameters:
x - the location for which to return a time span
major - a flag controlling whether to return the time span of the major or the minor part of the dateline
Returns:
the time span at the given location

requestVisibleTimeSpan

public void requestVisibleTimeSpan(ITimeSpan span)
                            throws DatelineModelException
Description copied from interface: IDatelineModel
A request that asks the model to change its settings in such a way that the requested time span will become visible in the viewport on the right-hand side of the Gantt chart.

Parameters:
span - the requested time span
Throws:
DatelineModelException - if the model can not satisfy the request

getMajorDateString

public java.lang.String getMajorDateString(SimpleGranularity granularity,
                                           long time)
Returns a text representation for the given major time point and granularity.

Parameters:
granularity - the granularity in which the given time point will be displayed
time - the time point in need of a text representation
Returns:
a string describing the given time point
Since:
1.0

getMinorDateString

public java.lang.String getMinorDateString(SimpleGranularity granularity,
                                           long time)
Returns a text representation for the given minor time point and granularity.

Parameters:
granularity - the granularity in which the given time point will be displayed
time - the time point in need of a text representation
Returns:
a string describing the given time point
Since:
1.0

getGap

public int getGap()
The gap (in pixel) that will be added twice to each granularity width so that there will be some space between the text and the grid lines.

Returns:
the text gap in pixel
Since:
1.0

setGap

public void setGap(int gap)
Sets the gap (in pixel) that will be added twice to each granularity width so that there will be some space between the text and the grid lines.

Parameters:
gap - the text gap in pixel
Since:
1.0

getTimeString

public java.lang.String getTimeString(long time)
Description copied from interface: IDatelineModel
Returns a textual representation for the givent time point. If for example the given time is 0 then the text returned might be something like this: "Jan 1st, 1970".

Parameters:
time - the time for which to return a textual representation
Returns:
a textual representation of the given time point