org.apache.turbine.util
Class TimeSelector

java.lang.Object
  extended byorg.apache.turbine.util.TimeSelector

public class TimeSelector
extends java.lang.Object

TimeSelector is a utility class to handle the creation of a set of time drop-down menus. The code is broken into a set of static methods for quick and easy access to the individual select objects:

  ElementContainer ec timeSelect = new ElementContainer();
  String myName = "mytime";
  ec.addElement(TimeSelector.getHourSelector(myName));
  ec.addElement(TimeSelector.getMinuteSelector(myName));
  ec.addElement(TimeSelector.getAMPMSelector(myName));
  
There are also methods which will use attributes to build a complete time selector in the default 12hr format (eg HH:MM am/pm):
  TimeSelector ts = new TimeSelector(myName);
  timeSelect = ts.ecsOutput();
  
Minutes/Seconds are by default rounded to the nearest 5 units although this can be easily changed. 24hr TimeSelectors can also be produced. The following example creates a full precision TimeSelector (eg HH:MM:SS):
  TimeSelector ts = new TimeSelector(myName);
  ts.setTimeFormat(TimeSelector.TWENTY_FOUR_HOUR);
  ts.setMinuteInterval(1);
  ts.setSecondInterval(1);
  ts.setShowSeconds(true);
  timeSelect = ts.toString();
  

Version:
$Id: TimeSelector.java 534527 2007-05-02 16:10:59Z tv $
Author:
Jeffrey D. Brekke, Rich Aston

Field Summary
static java.lang.String AMPM_SUFFIX
          Suffix for am/pm parameter.
static java.lang.String DEFAULT_PREFIX
          Prefix for time names.
static java.lang.String HOUR_SUFFIX
          Suffix for hour parameter.
static java.lang.String MINUTE_SUFFIX
          Suffix for minute parameter.
static java.lang.String SECOND_SUFFIX
          Suffix for second parameter.
static int TWELVE_HOUR
          Constant for 12hr format
static int TWENTY_FOUR_HOUR
          Constant for 24hr format
 
Constructor Summary
TimeSelector()
          Constructor defaults to current date/time and uses the default prefix: TimeSelector.DEFAULT
TimeSelector(java.lang.String selName)
          Constructor defaults to current date/time.
TimeSelector(java.lang.String selName, java.util.Calendar useDate)
          Constructor, uses the date/time set in the calendar passed in (with the date/time set correctly).
 
Method Summary
 org.apache.ecs.ElementContainer ecsOutput()
          Return an ECS container with the select objects inside.
static org.apache.ecs.html.Select getAMPMSelector(java.lang.String name)
          Return an am/pm selector.
static org.apache.ecs.html.Select getAMPMSelector(java.lang.String name, java.util.Calendar now)
          Return an am/pm selector.
static org.apache.ecs.html.Select getHourSelector(java.lang.String name)
          Return an 12 hour selector.
static org.apache.ecs.html.Select getHourSelector(java.lang.String name, java.util.Calendar now)
          Return an 12 hour selector.
static org.apache.ecs.html.Select getHourSelector(java.lang.String name, java.util.Calendar now, int format)
          Return an hour selector (either 12hr or 24hr depending on format.
static org.apache.ecs.html.Select getMinuteSelector(java.lang.String name)
          Return a minute selector.
static org.apache.ecs.html.Select getMinuteSelector(java.lang.String name, java.util.Calendar now)
          Return a minute selector.
static org.apache.ecs.html.Select getMinuteSelector(java.lang.String name, java.util.Calendar now, int interval)
          Return a minute selector.
static org.apache.ecs.html.Select getSecondSelector(java.lang.String name)
          Return a second selector.
static org.apache.ecs.html.Select getSecondSelector(java.lang.String name, java.util.Calendar now)
          Return a second selector.
static org.apache.ecs.html.Select getSecondSelector(java.lang.String name, java.util.Calendar now, int interval)
          Return a second selector.
 java.lang.String getSelName()
          Get the selector name prefix.
 java.lang.String output()
          Used to build the popupmenu in HTML.
 TimeSelector setMinuteInterval(int minutes)
          Set the interval between options in the minute select box.
 TimeSelector setOnChange(java.lang.String onChange)
          Adds the onChange to all of <SELECT> tags.
 TimeSelector setSecondInterval(int seconds)
          Set the interval between options in the second select box.
 TimeSelector setSeconds(int seconds)
          Select the second to be selected if the showSeconds(false) behavior is used.
 void setSelName(java.lang.String selName)
          Set the selector name prefix.
 TimeSelector setShowSeconds(boolean show)
          Whether or not to show the seconds as a popup menu.
 TimeSelector setTimeFormat(int format)
          Set the time format to 12 or 24 hour.
 java.lang.String toString()
          Used to build the popupmenu in HTML.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

DEFAULT_PREFIX

public static final java.lang.String DEFAULT_PREFIX
Prefix for time names.

See Also:
Constant Field Values

HOUR_SUFFIX

public static final java.lang.String HOUR_SUFFIX
Suffix for hour parameter.

See Also:
Constant Field Values

MINUTE_SUFFIX

public static final java.lang.String MINUTE_SUFFIX
Suffix for minute parameter.

See Also:
Constant Field Values

SECOND_SUFFIX

public static final java.lang.String SECOND_SUFFIX
Suffix for second parameter.

See Also:
Constant Field Values

AMPM_SUFFIX

public static final java.lang.String AMPM_SUFFIX
Suffix for am/pm parameter.

See Also:
Constant Field Values

TWELVE_HOUR

public static final int TWELVE_HOUR
Constant for 12hr format

See Also:
Constant Field Values

TWENTY_FOUR_HOUR

public static final int TWENTY_FOUR_HOUR
Constant for 24hr format

See Also:
Constant Field Values
Constructor Detail

TimeSelector

public TimeSelector()
Constructor defaults to current date/time and uses the default prefix:
TimeSelector.DEFAULT


TimeSelector

public TimeSelector(java.lang.String selName,
                    java.util.Calendar useDate)
Constructor, uses the date/time set in the calendar passed in (with the date/time set correctly).

Parameters:
selName - A String with the selector name.
useDate - A Calendar with a date/time.

TimeSelector

public TimeSelector(java.lang.String selName)
Constructor defaults to current date/time.

Parameters:
selName - A String with the selector name.
Method Detail

setOnChange

public TimeSelector setOnChange(java.lang.String onChange)
Adds the onChange to all of <SELECT> tags. This is limited to one function for all three popups and is only used when the output() methods are used. Individual getHour, getMinute, getSecond, getAMPM static methods will not use this setting.

Parameters:
onChange - A String to use for onChange attribute. If null, then nothing will be set.
Returns:
A TimeSelector (self).

setSeconds

public TimeSelector setSeconds(int seconds)
Select the second to be selected if the showSeconds(false) behavior is used. Individual getHour, getMinute, getSecond, getAMPM static methods will not use this setting.

Parameters:
seconds - The second.
Returns:
A TimeSelector (self).

setMinuteInterval

public TimeSelector setMinuteInterval(int minutes)
Set the interval between options in the minute select box. Individual getHour, getMinute, getSecond, getAMPM static methods will not use this setting.

Parameters:
minutes - Interval in minutes.
Returns:
A TimeSelector (self).

setSecondInterval

public TimeSelector setSecondInterval(int seconds)
Set the interval between options in the second select box. Individual getHour, getMinute, getSecond, getAMPM static methods will not use this setting.

Parameters:
seconds - Interval in seconds.
Returns:
A TimeSelector (self).

setTimeFormat

public TimeSelector setTimeFormat(int format)
Set the time format to 12 or 24 hour. Individual getHour, getMinute, getSecond, getAMPM static methods will not use this setting.

Parameters:
format - Time format.
Returns:
A TimeSelector (self).

setShowSeconds

public TimeSelector setShowSeconds(boolean show)
Whether or not to show the seconds as a popup menu. The seconds will be a hidden parameter and the value set with setSeconds is used. Individual getHour, getMinute, getSecond, getAMPM static methods will not use this setting.

Parameters:
show - True if the second should be shown.
Returns:
A TimeSelector (self).

setSelName

public void setSelName(java.lang.String selName)
Set the selector name prefix. Individual getHour, getMinute, getSeconds, getAMPM static methods will not use this setting.


getSelName

public java.lang.String getSelName()
Get the selector name prefix.

Returns:
A String with the select name prefix.

getSecondSelector

public static org.apache.ecs.html.Select getSecondSelector(java.lang.String name)
Return a second selector.

Parameters:
name - The name to use for the selected second.
Returns:
A select object with second options.

getSecondSelector

public static org.apache.ecs.html.Select getSecondSelector(java.lang.String name,
                                                           java.util.Calendar now)
Return a second selector.

Parameters:
name - The name to use for the selected second.
now - Calendar to start with.
Returns:
A select object with second options.

getSecondSelector

public static org.apache.ecs.html.Select getSecondSelector(java.lang.String name,
                                                           java.util.Calendar now,
                                                           int interval)
Return a second selector.

Parameters:
name - The name to use for the selected second.
now - Calendar to start with.
interval - Interval between options.
Returns:
A select object with second options.

getMinuteSelector

public static org.apache.ecs.html.Select getMinuteSelector(java.lang.String name)
Return a minute selector.

Parameters:
name - The name to use for the selected minute.
Returns:
A select object with minute options.

getMinuteSelector

public static org.apache.ecs.html.Select getMinuteSelector(java.lang.String name,
                                                           java.util.Calendar now)
Return a minute selector.

Parameters:
name - The name to use for the selected minute.
Returns:
A select object with minute options.

getMinuteSelector

public static org.apache.ecs.html.Select getMinuteSelector(java.lang.String name,
                                                           java.util.Calendar now,
                                                           int interval)
Return a minute selector.

Parameters:
name - The name to use for the selected minute.
now - Calendar to start with.
interval - Interval between options.
Returns:
A select object with minute options.

getHourSelector

public static org.apache.ecs.html.Select getHourSelector(java.lang.String name)
Return an 12 hour selector.

Parameters:
name - The name to use for the selected hour.
Returns:
A select object with all the hours.

getHourSelector

public static org.apache.ecs.html.Select getHourSelector(java.lang.String name,
                                                         java.util.Calendar now)
Return an 12 hour selector.

Parameters:
name - The name to use for the selected hour.
now - Calendar to start with.
Returns:
A select object with all the hours.

getHourSelector

public static org.apache.ecs.html.Select getHourSelector(java.lang.String name,
                                                         java.util.Calendar now,
                                                         int format)
Return an hour selector (either 12hr or 24hr depending on format.

Parameters:
name - The name to use for the selected hour.
now - Calendar to start with.
format - Time format.
Returns:
A select object with all the hours.

getAMPMSelector

public static org.apache.ecs.html.Select getAMPMSelector(java.lang.String name)
Return an am/pm selector.

Parameters:
name - The name to use for the selected am/pm.
Returns:
A select object with am/pm

getAMPMSelector

public static org.apache.ecs.html.Select getAMPMSelector(java.lang.String name,
                                                         java.util.Calendar now)
Return an am/pm selector.

Parameters:
name - The name to use for the selected am/pm.
now - Calendar to start with.
Returns:
A select object with am/pm.

output

public java.lang.String output()
Used to build the popupmenu in HTML. The properties set in the object are used to generate the correct HTML. The selName attribute is used to seed the names of the select lists. The names will be generated as follows: If onChange was set it is also used in the generation of the output. The output HTML will list the select lists in the following order: hour minute ampm. If setShowSeconds(true) is used then an addition second select box is produced after the minute select box. If setTimeFormat(TimeSelector.TWENTY_FOUR_HOUR) is used then the ampm select box is omitted.

Returns:
A String with the correct HTML for the date selector.

toString

public java.lang.String toString()
Used to build the popupmenu in HTML. The properties set in the object are used to generate the correct HTML. The selName attribute is used to seed the names of the select lists. The names will be generated as follows: If onChange was set it is also used in the generation of the output. The output HTML will list the select lists in the following order: hour minute ampm. If setShowSeconds(true) is used then an addition second select box is produced after the minute select box. If setTimeFormat(TimeSelector.TWENTY_FOUR_HOUR) is used then the ampm select box is omitted.

Returns:
A String with the correct HTML for the date selector.

ecsOutput

public org.apache.ecs.ElementContainer ecsOutput()
Return an ECS container with the select objects inside.

Returns:
An ECS container.


Copyright © 2000-2008 Apache Software Foundation. All Rights Reserved.