Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.apache.turbine.util
Class TimeSelector

    java.lang.Object
      org.apache.turbine.util.TimeSelector

    public class TimeSelector

extends 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 1078552 2011-03-06 19:58:46Z tv $
Author:
  Jeffrey D. Brekke, Rich Aston

Field Summary
`static String` | `AMPM_SUFFIX` Suffix for am/pm parameter.
`static String` | `DEFAULT_PREFIX` Prefix for time names.
`static String` | `HOUR_SUFFIX` Suffix for hour parameter.
`static String` | `MINUTE_SUFFIX` Suffix for minute parameter.
`static 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(String selName)` Constructor defaults to current date/time.
`TimeSelector(String selName, 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(String name)` Return an am/pm selector.
`static org.apache.ecs.html.Select` | `getAMPMSelector(String name, Calendar now)` Return an am/pm selector.
`static org.apache.ecs.html.Select` | `getHourSelector(String name)` Return an 12 hour selector.
`static org.apache.ecs.html.Select` | `getHourSelector(String name, Calendar now)` Return an 12 hour selector.
`static org.apache.ecs.html.Select` | `getHourSelector(String name, Calendar now, int format)` Return an hour selector (either 12hr or 24hr depending on `format`.
`static org.apache.ecs.html.Select` | `getMinuteSelector(String name)` Return a minute selector.
`static org.apache.ecs.html.Select` | `getMinuteSelector(String name, Calendar now)` Return a minute selector.
`static org.apache.ecs.html.Select` | `getMinuteSelector(String name, Calendar now, int interval)` Return a minute selector.
`static org.apache.ecs.html.Select` | `getSecondSelector(String name)` Return a second selector.
`static org.apache.ecs.html.Select` | `getSecondSelector(String name, Calendar now)` Return a second selector.
`static org.apache.ecs.html.Select` | `getSecondSelector(String name, Calendar now, int interval)` Return a second selector.
`String` | `getSelName()` Get the selector name prefix.
`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(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(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.
`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 String DEFAULT_PREFIX

  Prefix for time names.

  See Also:
    Constant Field Values

### HOUR_SUFFIX

    public static final String HOUR_SUFFIX

  Suffix for hour parameter.

  See Also:
    Constant Field Values

### MINUTE_SUFFIX

    public static final String MINUTE_SUFFIX

  Suffix for minute parameter.

  See Also:
    Constant Field Values

### SECOND_SUFFIX

    public static final String SECOND_SUFFIX

  Suffix for second parameter.

  See Also:
    Constant Field Values

### AMPM_SUFFIX

    public static final 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(String selName,
                        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(String selName)

  Constructor defaults to current date/time.

  Parameters:
    `selName` - A String with the selector name.

Method Detail

### setOnChange

    public TimeSelector setOnChange(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(String selName)

  Set the selector name prefix. Individual getHour, getMinute, getSeconds, getAMPM static methods will not use this setting.

  Parameters:
    `selname` - A String with the select name prefix.

### getSelName

    public String getSelName()

  Get the selector name prefix.

  Returns:
    A String with the select name prefix.

### getSecondSelector

    public static org.apache.ecs.html.Select getSecondSelector(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(String name,
                                                               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(String name,
                                                               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(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(String name,
                                                               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(String name,
                                                               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(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(String name,
                                                             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(String name,
                                                             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(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(String name,
                                                             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 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:
  - selName + "_hour"
  - selName + "_minute"
  - selName + "_ampm"
  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 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:
  - selName + "_hour"
  - selName + "_minute"
  - selName + "_ampm"
  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.

  Overrides:
    `toString` in class `Object`
  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.

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright © 2000-2011 The Apache Software Foundation. All Rights Reserved.