QJCC homepage

biz.chitec.quarterback.swing
Class TimeZoneComboBoxModel

java.lang.Object
  extended byjavax.swing.AbstractListModel
      extended byjavax.swing.DefaultComboBoxModel
          extended bybiz.chitec.quarterback.swing.TimeZoneComboBoxModel
All Implemented Interfaces:
javax.swing.ComboBoxModel, javax.swing.ListModel, javax.swing.MutableComboBoxModel, java.io.Serializable

public class TimeZoneComboBoxModel
extends javax.swing.DefaultComboBoxModel

Special model to allow selection of a TimeZone The timezones are shown in alphabetical order. It is possible to have a special entry "not selected", which is selected if an empty timezone is set (null or empty string). Timezones can be selected either by their id or by giving a complete TimeZone instance

Version:
$Id: 210da1606791cdd94ca1513ac368b52ff9c90757 $
Author:
cantamen/Dirk Hillbrecht 2005
See Also:
Serialized Form

Field Summary
private  java.util.ResourceBundle rb
           
private  boolean withunselected
           
 
Fields inherited from class javax.swing.DefaultComboBoxModel
 
Fields inherited from class javax.swing.AbstractListModel
listenerList
 
Constructor Summary
TimeZoneComboBoxModel()
          Initializes the model with the list of timezones without "not selected" entry
TimeZoneComboBoxModel(boolean withunselectedx)
          Initializes the model either with or without the "unselected" entry.
 
Method Summary
 java.util.TimeZone indexToTimeZone(int index)
          Returns the TimeZone at the given index.
 java.lang.String indexToTimeZoneID(int index)
          Returns the ID of the timezone at the given index.
private  void initEntries()
          Initializes the list of timezones.
 int timeZoneIDToIndex(java.lang.String id)
          Returns the index of the timezone with the given ID.
 int timeZoneToIndex(java.util.TimeZone tz)
          Returns the index in the model of the given timezone.
 
Methods inherited from class javax.swing.DefaultComboBoxModel
addElement, getElementAt, getIndexOf, getSelectedItem, getSize, insertElementAt, removeAllElements, removeElement, removeElementAt, setSelectedItem
 
Methods inherited from class javax.swing.AbstractListModel
addListDataListener, fireContentsChanged, fireIntervalAdded, fireIntervalRemoved, getListDataListeners, getListeners, removeListDataListener
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface javax.swing.ListModel
addListDataListener, removeListDataListener
 

Field Detail

rb

private java.util.ResourceBundle rb

withunselected

private boolean withunselected
Constructor Detail

TimeZoneComboBoxModel

public TimeZoneComboBoxModel(boolean withunselectedx)
Initializes the model either with or without the "unselected" entry.

Parameters:
withunselectedx - Flag whether the list should contain an "unselected" entry.

TimeZoneComboBoxModel

public TimeZoneComboBoxModel()
Initializes the model with the list of timezones without "not selected" entry

Method Detail

initEntries

private void initEntries()
Initializes the list of timezones. According to the "withunselected" setting, the list begins with a special entry "unselected" or not. Otherwise, the content is sorted alphabetically.


timeZoneToIndex

public int timeZoneToIndex(java.util.TimeZone tz)
Returns the index in the model of the given timezone. If the time zone is null, the "unselected" index is returned. If the timezone is not found, index 0 is returned. Internally, timezones are found by their ID.

Parameters:
tz - Timezone to find, null to find "unselected"
Returns:
Index of the given timezone in the list, 0 if unselected or unknown.

timeZoneIDToIndex

public int timeZoneIDToIndex(java.lang.String id)
Returns the index of the timezone with the given ID. If the ID is null or empty, the "unselected" index is returned. If the timezone is not found, index 0 is returned.

Parameters:
id - ID of the timezone to find.
Returns:
Index of the timezone in question, 0 if unselected or unknown.

indexToTimeZone

public java.util.TimeZone indexToTimeZone(int index)
Returns the TimeZone at the given index. If the unselected index is given, null is returned.

Parameters:
index - Index to give TimeZone to.
Returns:
Selected TimeZone, null if "unselected" is selected.

indexToTimeZoneID

public java.lang.String indexToTimeZoneID(int index)
Returns the ID of the timezone at the given index. If the unselected index is given, the empty string is returned. This method does never return null.

Parameters:
index - Index to give timezone ID to.
Returns:
ID of timezone at given index, empty string if "unselected" is selected.

QJCC homepage