QJCC homepage

biz.chitec.quarterback.swing
Class LocaleComboBoxModel

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

public class LocaleComboBoxModel
extends javax.swing.DefaultComboBoxModel

Special model to allow selection of a locale All installed locales are shown for selection. It is possible to have a special entry "not selected", which is selected if an empty locale is set (null or empty string).

In this model, locales can be handled and identified either by instances of the Locale class or by the usual Strings in underscore-notation.

Version:
$Id: b0ae372887cb21cad077d52cef96688bf4c8e64e $
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
LocaleComboBoxModel()
          Initializes the model with the list of locales without "not selected" entry
LocaleComboBoxModel(boolean withunselectedx)
           
LocaleComboBoxModel(boolean withunselectedx, java.util.List locales)
          Initializes the model either with or without the "unselected" entry.
 
Method Summary
 java.util.Locale indexToLocale(int index)
          Returns the locale at the given index.
 java.lang.String indexToLocaleID(int index)
          Returns the ID of the locale at the given index.
private  void initEntries(java.util.List locales)
          Initializes the list of locales.
 int localeIDToIndex(java.lang.String id)
          Returns the index of the locale with the given ID.
 int localeToIndex(java.util.Locale locale)
          Returns the index in the model of the given locale.
 
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

LocaleComboBoxModel

public LocaleComboBoxModel(boolean withunselectedx,
                           java.util.List locales)
Initializes the model either with or without the "unselected" entry.

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

LocaleComboBoxModel

public LocaleComboBoxModel(boolean withunselectedx)

LocaleComboBoxModel

public LocaleComboBoxModel()
Initializes the model with the list of locales without "not selected" entry

Method Detail

initEntries

private void initEntries(java.util.List locales)
Initializes the list of locales. According to the "withunselected" setting, the list begins with a special entry "unselected" or not. Otherwise, the content is sorted as given by Locale.getAvailableLocales().


localeToIndex

public int localeToIndex(java.util.Locale locale)
Returns the index in the model of the given locale. If the locale is null, the "unselected" index is returned. If the locale is not found, index 0 is returned. Internally, locales are found by their ID.

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

localeIDToIndex

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

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

indexToLocale

public java.util.Locale indexToLocale(int index)
Returns the locale at the given index. If the unselected index is given, null is returned.

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

indexToLocaleID

public java.lang.String indexToLocaleID(int index)
Returns the ID of the locale 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 locale ID to.
Returns:
ID of locale at given index, empty string if "unselected" is selected.

QJCC homepage