Class TimeTextField

All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible, Scrollable, SwingConstants

public class TimeTextField extends VTextField
Text field constrained to allow time intervals. The intervals can be SECONDS (including decimal values to millisecond precision), MINUTES:SECONDS and HOURS:MINUTES:SECONDS. In addition, the text field can be configures to accept a single-character input containing '?' to indicate that the application will interactively determine the time interval, and '*' to indicate that the time interval is indefinite (i.e., not specified by the user).
See Also:
  • Field Details

    • INDEFINITE

      public static final int INDEFINITE
      Indicate an indefinite interval. This value for the field indicates that the time interval is indefinite - until the application quits or stops the operation for which the time interval is used.
      See Also:
    • QUERY

      public static final int QUERY
      Indicate a queried time interval. This value for the field indicates that the caller is expected to determine the time interval by some interactive means.
      See Also:
  • Constructor Details

    • TimeTextField

      public TimeTextField()
      Class constructor.
    • TimeTextField

      public TimeTextField(Document doc, String text, int ncols)
      Class constructor for a document model, initial string and field size.
      Parameters:
      doc - the document model (must be an AbstractDocument)
      text - the initial text
      ncols - the number of columns in the text field.
    • TimeTextField

      public TimeTextField(int ncols)
      Class constructor specifying the field size..
      Parameters:
      ncols - the number of columns in the text field.
    • TimeTextField

      public TimeTextField(String text)
      Constructor giving an initial string.
      Parameters:
      text - the initial text
    • TimeTextField

      public TimeTextField(String text, int ncols)
      Constructor giving an initial string and field size.
      Parameters:
      text - the initial text
      ncols - the number of columns in the text field.
    • TimeTextField

      public TimeTextField(Document doc, String text, int ncols, TimeTextField.Mode mode)
      Constructor for a document model, initial string, field size, and mode.
      Parameters:
      doc - the document model (must be an AbstractDocument)
      text - the initial text
      ncols - the number of columns in the text field.
      mode - Mode.PLAIN, Mode.QUERY, Mode.INDEFINITE, or Mode.QUERY_AND_INDEFINITE to specify use of a single-character value
      See Also:
    • TimeTextField

      public TimeTextField(int ncols, TimeTextField.Mode mode)
      Constructor specifying the field size and mode.
      Parameters:
      ncols - the number of columns in the text field.
      mode - Mode.PLAIN, Mode.QUERY, Mode.INDEFINITE, or Mode.QUERY_AND_INDEFINITE to specify use of a single-character value
      See Also:
    • TimeTextField

      public TimeTextField(String text, TimeTextField.Mode mode)
      Constructor giving an initial string and mode.
      Parameters:
      text - the initial text
      mode - Mode.PLAIN, Mode.QUERY, Mode.INDEFINITE, or Mode.QUERY_AND_INDEFINITE to specify use of a single-character value
      See Also:
    • TimeTextField

      public TimeTextField(String text, int ncols, TimeTextField.Mode mode)
      Constructor giving an initial string, field size and mode.
      Parameters:
      text - the initial text
      ncols - the number of columns in the text field
      mode - Mode.PLAIN, Mode.QUERY, Mode.INDEFINITE, or Mode.QUERY_AND_INDEFINITE to specify use of a single-character value
      See Also:
  • Method Details

    • parseTime

      public static long parseTime(String value) throws Exception
      Parse a string representing the a time interval The format is [[DIGITS:]DIGITS:]DIGITS[.DIGITS] where DIGITS is a series of one or more digits. The optional part before and including the first colon represents hours, and the optional part before the second colon represents minutes. The next secion is a decimal number giving the time in seconds.
      Parameters:
      value - the string to parse
      Returns:
      the time in milliseconds
      Throws:
      Exception - an exception occurred
    • onAccepted

      protected void onAccepted() throws Exception
      Description copied from class: VTextField
      Accept input. This method will be called when input is accepted, either by terminating the input with the "Enter" or "Return" key, or by changing the focus to another component in this application. Note that selecting a window in a separate application may not trigger this method.

      The default method does nothing, but may be overridden to perform some operation when the value of the text field changes to a new accepted value. During error correction, this may happen multiple times. It can also happen if the method VTextField.setText(String) is called. While this method can throw an exception, it is called in such a way that the exception will normally be caught by this class' methods and processed silently if at all.

      When an instance of this class is constructed and the text field is empty, an initial call to this method is suppressed.

      Overrides:
      onAccepted in class VTextField
      Throws:
      Exception - an error occurred
    • setValue

      public void setValue(long value)
      Set the value of the text field.
      Parameters:
      value - the text-field's value (a non-negative integer, TimeTextField.QUERY, or TimeTextField.INDEFINITE)
      Throws:
      IllegalArgumentException - the argument is out of range
    • getValue

      public long getValue()
      Get the text field's value. The value will be in units of milliseconds, with -1 indicting that the value is indefinite and -2 indicating that the user is asking for a value. Values representing times are always positive.
      Returns:
      the value of the text field, or the default value when the text field is empty
    • setDefaultValue

      public void setDefaultValue(long value)
      Set the default value when the text-string is empty. The value may be any integer larger than -3, although values representing a time will always be non-negative. This allows getValue to return a negative value as an indication that the field is indefinite (-1), or that the user is asking for a value (-2).
      Parameters:
      value - the default value to use