de.sciss.gui
Class TimeFormat

java.lang.Object
  extended by java.text.Format
      extended by java.text.MessageFormat
          extended by de.sciss.gui.TimeFormat
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable

public class TimeFormat
extends java.text.MessageFormat

A MessageFormat subclass for displaying time values in minutes and seconds.

Version:
0.3, 03-Dec-05
Author:
Hanns Holger Rutz
See Also:
NumberField.HHMMSS, Serialized Form
Todo:
this might be buggy (in apple's VM). the transport position label used to feed a time format which caused StackOverflow errors are a while. those errors disappeared when we programmed a custom label. however the bug might also come from JLabel. it should be checked if high frequency updates in the SimpleTransmitterEditor's setCursorInfo call -- which still use a TimeFormat -- provoke those StackOverflowErrors.

Nested Class Summary
 
Nested classes/interfaces inherited from class java.text.MessageFormat
java.text.MessageFormat.Field
 
Constructor Summary
TimeFormat(int flags, java.lang.String prefix, java.lang.String suffix, int numDecimals, java.util.Locale locale)
          Constructs a new TimeFormat with automatically created pattern.
 
Method Summary
 java.lang.String formatTime(java.lang.Number seconds)
          Creates a formatted string using a parameter for seconds
 java.lang.Number parseTime(java.lang.String str)
          Tries to parse a formatted time string (as produced by formatTime).
 
Methods inherited from class java.text.MessageFormat
applyPattern, clone, equals, format, format, format, formatToCharacterIterator, getFormats, getFormatsByArgumentIndex, getLocale, hashCode, parse, parse, parseObject, setFormat, setFormatByArgumentIndex, setFormats, setFormatsByArgumentIndex, setLocale, toPattern
 
Methods inherited from class java.text.Format
format, parseObject
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TimeFormat

public TimeFormat(int flags,
                  java.lang.String prefix,
                  java.lang.String suffix,
                  int numDecimals,
                  java.util.Locale locale)
Constructs a new TimeFormat with automatically created pattern.

Parameters:
flags - 0 at the moment
prefix - a string to prepend to the formatted string, or null
suffix - a string to append to the formatted string, or null
numDecimals - number of decimals, e.g. 3 for millisecs, 0 for secs
locale - Locale to choose for number formatting
Method Detail

formatTime

public java.lang.String formatTime(java.lang.Number seconds)
Creates a formatted string using a parameter for seconds

Parameters:
seconds - the time in seconds which will be formatted using an MM:SS.millis pattern
Returns:
the formatted string ready for display
Synchronization:
when called concurrently, explicit synchronization must be enforced

parseTime

public java.lang.Number parseTime(java.lang.String str)
                           throws java.text.ParseException
Tries to parse a formatted time string (as produced by formatTime).

Parameters:
str - a formatted string such as "12:33.456"
Returns:
the number found by parsing the string. Either a Long, if the seconds are integer, otherwise a Double containing decimals for milliseconds.
Throws:
java.text.ParseException - if the string cannot be parsed