QJCC homepage

biz.chitec.quarterback.swing
Class LocaleSelector

java.lang.Object
  extended byjava.awt.Component
      extended byjava.awt.Container
          extended byjavax.swing.JComponent
              extended byjavax.swing.JPanel
                  extended bybiz.chitec.quarterback.swing.LocaleSelector
All Implemented Interfaces:
javax.accessibility.Accessible, java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable

public class LocaleSelector
extends javax.swing.JPanel

Locale selection widget Shows available locales as buttons with name and flag (if available). Allows selection by button. Sends selection as property event. Contains static methods which show selection dialogs in a convenient way.

Version:
$Id: 8da267bf52d5da56c2b4ed05dfb5000582a244b0 $
Author:
chitec/Dirk Hillbrecht, 2003, cantamen/Dirk Hillbrecht 2003/2004 Distributed under the terms of the GNU LGPL.
See Also:
Serialized Form

Nested Class Summary
private static class LocaleSelector.LSButtonPanel
           
private static class LocaleSelector.LSComboBox
           
 
Nested classes inherited from class javax.swing.JPanel
javax.swing.JPanel.AccessibleJPanel
 
Nested classes inherited from class javax.swing.JComponent
javax.swing.JComponent.AccessibleJComponent
 
Nested classes inherited from class java.awt.Container
java.awt.Container.AccessibleAWTContainer
 
Nested classes inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
 
Fields inherited from class javax.swing.JPanel
 
Fields inherited from class javax.swing.JComponent
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
 
Fields inherited from class java.awt.Container
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
private LocaleSelector()
           
 
Method Summary
static java.util.List getAllLanguageLocalesList()
          Returns a sorted list of all known languages as list of locales
static javax.swing.JComboBox getComboBox(java.util.List locales)
          Creates a combo box widget which shows the given locales with name and flag.
static javax.swing.JComboBox getComboBox(java.util.List locales, int flagmode, int flagheight, boolean showisocode)
          Create a combo box which shows the given locales.
static javax.swing.JComboBox getComboBox(java.util.List locales, java.lang.String defaultlocale)
          Creates a combo box widget which shows the given locales with name and flag.
static javax.swing.JComboBox getComboBox(java.util.List locales, java.lang.String defaultlocale, int flagmode, int flagheight, boolean showisocode)
          Create a combo box which shows the given locales.
static java.lang.String getLocaleDescription(java.util.Locale locale, boolean showisocode)
          Return a textual description of the given locale The text contains language, country if given, variant if given, and ISO code if showisocode is true.
static java.util.List getSortedAvailableLocales()
          Return a sorted list of all known locales.
static void handleLocaleSelection(java.awt.Frame anchor, java.lang.String title, java.util.List availablelocales, java.util.Properties props, boolean warn)
          "All-inclusive" stand-alone dialog.
static java.util.Locale iDToLocale(java.lang.String id)
          Converts a locale ID to a locale instance.
static java.lang.String localeToID(java.util.Locale locale)
          Converts a locale instance into its id representation The returned id is given in the usual "_" notation.
static void showLocaleSelection(java.awt.Frame owner, java.lang.String title, java.util.List locales, java.lang.String currlocale, java.beans.PropertyChangeListener pcl)
          "Do-it-yourself" stand-alone dialog.
 
Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUI
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addPropertyChangeListener, addPropertyChangeListener, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBorder, getBounds, getClientProperty, getComponentGraphics, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getGraphics, getHeight, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPreferredSize, getPropertyChangeListeners, getPropertyChangeListeners, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isPreferredSizeSet, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFont, setForeground, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setFocusCycleRoot, setFocusTraversalKeys, setFocusTraversalPolicy, setLayout, transferFocusBackward, transferFocusDownCycle, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMouseWheelListeners, getName, getParent, getPeer, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

LocaleSelector

private LocaleSelector()
Method Detail

getAllLanguageLocalesList

public static java.util.List getAllLanguageLocalesList()
Returns a sorted list of all known languages as list of locales


getSortedAvailableLocales

public static java.util.List getSortedAvailableLocales()
Return a sorted list of all known locales.


getLocaleDescription

public static java.lang.String getLocaleDescription(java.util.Locale locale,
                                                    boolean showisocode)
Return a textual description of the given locale The text contains language, country if given, variant if given, and ISO code if showisocode is true.

Parameters:
locale - Locale to evaluate
showisocode - Flag whether the ISO code should be appended
Returns:
Textual description of given locale

getComboBox

public static javax.swing.JComboBox getComboBox(java.util.List locales,
                                                java.lang.String defaultlocale,
                                                int flagmode,
                                                int flagheight,
                                                boolean showisocode)
Create a combo box which shows the given locales.

Parameters:
locales - List of locales, either Locale objects or Stings in the lang_COUNTRY_VARIANT writing, e.g. "de_DE"
defaultlocale - default locale to be selected in the beginning. Null to ignore.
flagmode - Mode to show flags for the locales
flagheight - Height of the flags
showisocode - Flag whether the ISO codes of the locales should be shown additionally to the natural language name
Returns:
a nicely prepared JComboBox to show the locales

getComboBox

public static javax.swing.JComboBox getComboBox(java.util.List locales,
                                                int flagmode,
                                                int flagheight,
                                                boolean showisocode)
Create a combo box which shows the given locales.

Parameters:
locales - List of locales, either Locale objects or Stings in the lang_COUNTRY_VARIANT writing, e.g. "de_DE"
flagmode - Mode to show flags for the locales
flagheight - Height of the flags
showisocode - Flag whether the ISO codes of the locales should be shown additionally to the natural language name
Returns:
a nicely prepared JComboBox to show the locales

getComboBox

public static javax.swing.JComboBox getComboBox(java.util.List locales,
                                                java.lang.String defaultlocale)
Creates a combo box widget which shows the given locales with name and flag. The given default locale is selected at the beginning. Changes to the combo box can be passed and returned the usual way where the locale strings are used as indicators (e.g. in an ActionListener or as parameters to the setSelectedItem() method).

Parameters:
locales - List of locales, either Locale objects or Stings in the lang_COUNTRY_VARIANT writing, e.g. "de_DE"
defaultlocale - default locale to be selected in the beginning
Returns:
a nicely prepared JComboBox to show the locales

getComboBox

public static javax.swing.JComboBox getComboBox(java.util.List locales)
Creates a combo box widget which shows the given locales with name and flag. No default locale is set. This can be done later by passing the locale-describing String (e.g. "de_DE") to the standard "setSelectedItem()" method.

Parameters:
locales - List of locales, either Locale objects or Stings in the lang_COUNTRY_VARIANT writing, e.g. "de_DE"
Returns:
a nicely prepared JComboBox to show the locales

showLocaleSelection

public static void showLocaleSelection(java.awt.Frame owner,
                                       java.lang.String title,
                                       java.util.List locales,
                                       java.lang.String currlocale,
                                       java.beans.PropertyChangeListener pcl)
"Do-it-yourself" stand-alone dialog. Puts the LocaleSelector into a nice dialog and shows that on screen. The caller has to give a PropertyChangeListener which will get the newly selected locale (if anything was selected at all). The JDialog is modal and will block execution until something has been selected or the "Close" button has been pressed.

Parameters:
owner - The owner frame. Dialog will show itself relatively centered to that one
title - Title of the Frame. Should be locale-independant (e.g. program name)
locales - List of available locales. Those will be presented.
currlocale - Current locale. This will be preselected
pcl - PropertyChangeListener which gets the information that a new locale has been selected

handleLocaleSelection

public static void handleLocaleSelection(java.awt.Frame anchor,
                                         java.lang.String title,
                                         java.util.List availablelocales,
                                         java.util.Properties props,
                                         boolean warn)
"All-inclusive" stand-alone dialog. Wraps the stand-alone dialog with an already predefined property listener and writes the change directly into the given Properties. Does also read standard value from there. The default locale will be read from the Propertie's entries "user.language" and "user.region". The selection will be written back to those two entries. Furthermore, it is set as default Locale through Locale.setDefault().

Parameters:
anchor - The anchor frame. Dialog will show itself relatively centered to that one
title - Title of the Frame. Should be locale-independant (e.g. program name)
availablelocales - List of available locales. Those will be presented.
props - Properties bundle to real default from and write selection to.
warn - Flag to indicate that a warning message should be shown after the selection telling the user that for a complete takeover of the new locale selection, the program has to be restarted. The message will be printed in the just-selected locale.

iDToLocale

public static java.util.Locale iDToLocale(java.lang.String id)
Converts a locale ID to a locale instance. The locale id is given in the usual "_" notation.

Parameters:
id - Locale id
Returns:
Locale instance, null if given id is null or length is 0.

localeToID

public static java.lang.String localeToID(java.util.Locale locale)
Converts a locale instance into its id representation The returned id is given in the usual "_" notation.

Parameters:
locale - A locale instance
Returns:
ID of the given locale, empty string if locale is null.

QJCC homepage