|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectorg.ceryle.util.timeline.TimeLine
public class TimeLine
A utility for the processing of time strings and generation of timelines.
This class generates a time line from a Start and End time, or a Start time
and Duration. This timeline is then used to generate the time extents and
populate an org.ceryle.util.timeline.TimeScale for application to
an extension of a TouchGraph Node, a topic node or TNode (see
TNode). This may also be used as a utility class
for processing date and time information.
Includes validation (parsing) methods for both date-time and duration strings, trying each of the four Date parsing formats successively until one works:
Durations are input as a comma-delimited list of values, each a number followed by a calendar field string. TimeLine's field strings vary from that of java.util.Calendar with the addition of three new fields: centuries, decades, and weeks. While these can be input as part of a duration, note that weeks are not included on output scales. Entry order is not significant, and the parser is case insensitive (though this may not hold true on non-English localizations due to case folding rules).
Acceptable singular and plural field strings (which can be localized to
other languages, see the Messages class), are
shown below, each followed by its enumerated Clock constant:
Clock.FIELD_CENTURYClock.FIELD_DECADEClock.FIELD_YEARClock.FIELD_MONTHClock.FIELD_WEEKClock.FIELD_DAYClock.FIELD_HOURClock.FIELD_MINUTEClock.FIELD_SECOND.
TimeExtentDialog,
TimeExtentPanel| Field Summary | |
|---|---|
protected String[] |
FIELD_NAME
Date field names (in singular and plural, 9 elements between) as Strings. |
static long[] |
SEC_PER_FIELD
Constants for calculating elapsed times. |
static Date |
TIME_NOT_SET
A Date constant indicating a time not yet initialized/set (uses TIME_NOT_SET_MS). |
static long |
TIME_NOT_SET_MS
A long constant indicating a time not yet initialized/set (the default is -7, indicating 7 milliseconds before midnight of 1 Jan 1970). |
| Constructor Summary | |
|---|---|
TimeLine(Services services)
Constructor with a reference to the application Services services. |
|
| Method Summary | |
|---|---|
static GregorianCalendar |
addDuration(GregorianCalendar gc,
int[] dur)
Add the provided duration array to the GregorianCalendar gc, returning the modified calendar. |
void |
calculateResolution()
Display the field counts between the start and end extents of this TimeLine. |
void |
displayElapsed()
Display the elapsed time between the start and end extents of this TimeLine. |
TimeScale |
generateScale(long count,
int minorScaleIndex)
Generate a scale, provided count as the number of minor ticks, minorScaleIndex is field index of the minor tick field, and variance is how far from perfect. |
String |
getDateAsString(Date date)
Returns the provided Date date as a String, formatted to DateFormat.MEDIUM, the String "not set" if null. |
int[] |
getDuration()
Returns the duration of this TimeLine as an array of field values representing a duration. |
String |
getDurationAsString(int[] duration,
boolean includeTime)
Return the provided array of long integers representing a duration, as a String. |
int[] |
getDurationFromDates(Date startDate,
Date endDate)
Return the elapsed time as an int[] array between the start and end extents of this TimeLine. |
Date |
getEnd()
Returns the end of this TimeLine as a Date, null if this has not been set. |
GregorianCalendar |
getEndAsGregorianCalendar()
Returns the end of this TimeLine as a GregorianCalendar, null if this has not been set. |
long |
getEndInMillis()
Returns the end of this TimeLine as a long, the constant TIME_NOT_SET_MS if this has not been set. |
Date |
getStart()
Returns the start of this TimeLine as a Date, null if this has not been set. |
GregorianCalendar |
getStartAsGregorianCalendar()
Returns the start of this TimeLine as GregorianCalendar, null if this has not been set. |
long |
getStartInMillis()
Returns the start of this TimeLine as a long, the constant TIME_NOT_SET_MS if this has not been set. |
TimeScale |
getTimeScale()
Returns the TimeScale established by this TimeLine, null if not set. |
GregorianCalendar |
parseDateTime(String dt)
Parses the provided String dt to a GregorianCalendar date, returning the result. |
long[] |
parseDuration(String duration)
Parses the String duration representing a time duration, whose format is a comma-separated list of values, eg., "1 century, 6 decades, 3 years, 4 months, 2 weeks, 7 days, 4 hours, 23 minutes, 56 seconds", returning an array of long ints. |
void |
setDuration(int[] duration)
Sets the duration of this TimeLine provided with an array of int values representing a duration. |
void |
setEnd(GregorianCalendar end)
Sets the end of this TimeLine provided with an ending date as the GregorianCalendar end. |
void |
setPixelsPerTick(int pixelsPerTick)
Sets the minimum pixels/tick, used to establish scale resolution. |
void |
setStart(GregorianCalendar start)
Sets the start of this TimeLine provided with a starting date as a GregorianCalendar start. |
GregorianCalendar |
setStartAndDuration(GregorianCalendar start,
int[] duration)
Sets the dateTime extent of this TimeLine provided with starting date as a GregorianCalendar start and a String duration representing the duration (for the format of this String, see TimeLine). |
int[] |
setStartAndEnd(GregorianCalendar start,
GregorianCalendar end)
Sets the time extent of this TimeLine provided with starting and ending times as the GregorianCalendars start and end. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
protected String[] FIELD_NAME
public static final Date TIME_NOT_SET
public static final long TIME_NOT_SET_MS
public static final long[] SEC_PER_FIELD
| Constructor Detail |
|---|
public TimeLine(Services services)
| Method Detail |
|---|
public void setPixelsPerTick(int pixelsPerTick)
public TimeScale getTimeScale()
public void setStart(GregorianCalendar start)
public Date getStart()
public long getStartInMillis()
public GregorianCalendar getStartAsGregorianCalendar()
public void setDuration(int[] duration)
public int[] getDuration()
public void setEnd(GregorianCalendar end)
public Date getEnd()
public long getEndInMillis()
public GregorianCalendar getEndAsGregorianCalendar()
public int[] setStartAndEnd(GregorianCalendar start,
GregorianCalendar end)
public GregorianCalendar setStartAndDuration(GregorianCalendar start,
int[] duration)
TimeLine).
The difference between calling setStart() and
setDuration() separately is that this method will
calculate the End date, returning its value as a GregorianCalendar.
public static GregorianCalendar addDuration(GregorianCalendar gc,
int[] dur)
public GregorianCalendar parseDateTime(String dt)
public long[] parseDuration(String duration)
throws ProcessException
The calendar field names are internationalized in both singular and
plural (via the Messages class), and are parsed
case insensitively (insofar as string matching following lowercase
wrapping functions in each localization). Field names are padded
with spaces so that string matches won't accidentally match a
singular where a plural is intended (eg., the algorithm searches
for " year " and " years ", not "year" and "years").
Note that any portion of the duration can be negative, though this might be rather confusing if not managed correctly (eg., a duration of "6 years, -23 weeks, -4 days" is difficult to understand even when correctly added to the start date). Also, if a field redundancy occurs (eg., "2 weeks, 4 weeks"), only the last value is used.
If a parsing error occurs, generates an error message to the MessageHandler and returns null.
duration - a comma-delimited String of duration values
ProcessExceptionpublic String getDateAsString(Date date)
public String getDurationAsString(int[] duration,
boolean includeTime)
public int[] getDurationFromDates(Date startDate,
Date endDate)
public void calculateResolution()
throws ProcessException
ProcessException
public TimeScale generateScale(long count,
int minorScaleIndex)
throws ProcessException
ProcessExceptionpublic void displayElapsed()
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||