home *** CD-ROM | disk | FTP | other *** search
Java Source | 1998-05-08 | 3.8 KB | 110 lines |
- /*
- * Copyright (c) 1997-1998 Borland International, Inc. All Rights Reserved.
- *
- * This SOURCE CODE FILE, which has been provided by Borland as part
- * of a Borland product for use ONLY by licensed users of the product,
- * includes CONFIDENTIAL and PROPRIETARY information of Borland.
- *
- * USE OF THIS SOFTWARE IS GOVERNED BY THE TERMS AND CONDITIONS
- * OF THE LICENSE STATEMENT AND LIMITED WARRANTY FURNISHED WITH
- * THE PRODUCT.
- *
- * IN PARTICULAR, YOU WILL INDEMNIFY AND HOLD BORLAND, ITS RELATED
- * COMPANIES AND ITS SUPPLIERS, HARMLESS FROM AND AGAINST ANY CLAIMS
- * OR LIABILITIES ARISING OUT OF THE USE, REPRODUCTION, OR DISTRIBUTION
- * OF YOUR PROGRAMS, INCLUDING ANY CLAIMS OR LIABILITIES ARISING OUT OF
- * OR RESULTING FROM THE USE, MODIFICATION, OR DISTRIBUTION OF PROGRAMS
- * OR FILES CREATED FROM, BASED ON, AND/OR DERIVED FROM THIS SOURCE
- * CODE FILE.
- */
- package borland.samples.intl.beans;
-
- import java.awt.*;
- import java.util.*;
-
- import borland.samples.intl.beans.event.*;
-
- /**
- * LocaleChangeManager is a non-visual java bean which
- * notifies registered observers when a locale change occurs.
- * LocaleChangeManager itself must be registered with a
- * LocaleChangeEvent source, in this case LocaleChooser.
- * Using a LocaleChangeManager rather than having locale-aware components
- * register themselves directly with the user-interface for selecting
- * locales has two advantages:
- *<ol>
- *<li>Switching to a different locale chooser only requires changing
- * one hookup, the LocaleChangeManager to the locale chooser component.
- *<li>Locale-aware components don't need to have (global) access to
- * the locale chooser component.
- *</ol>
- *
- */
- public class LocaleChangeManager implements LocaleChangeListener {
- // holds the single instance of the LocaleChangeManager
- private static LocaleChangeManager localeChangeManager = null;
- // holds registered event listeners
- Vector localeChangeListeners = new Vector();
- private static Locale locale = Locale.getDefault();
-
- protected LocaleChangeManager() {
- }
-
- /**
- * Returns the single instance of the locale change manager.
- *
- * @return instance of locale change manager
- */
- public static LocaleChangeManager getLocaleChangeManager() {
- if (localeChangeManager == null) {
- localeChangeManager = new LocaleChangeManager();
- }
- return localeChangeManager;
- }
-
- /**
- * Returns the current locale according to the locale change manager
- * @return locale change manager's current locale
- */
- public static Locale getLocale() {
- return new Locale(locale.getLanguage(), locale.getCountry(), locale.getVariant());
- }
-
- /**
- * Registers a LocaleChangeListener to be notified on a locale change event.
- *
- * @param listener LocaleChangeListener to be added to notification list
- */
- public synchronized void addLocaleChangeListener(LocaleChangeListener listener) {
- localeChangeListeners.addElement(listener);
- }
-
- /**
- * Removes a LocaleChangeListener to be notified on a locale change event.
- *
- * @param listener LocaleChangeListener to be removed
- */
- public synchronized void removeLocaleChangeListener(LocaleChangeListener listener) {
- localeChangeListeners.removeElement(listener);
- }
-
- /**
- * Required for implementation of the LocaleChangeListener interface.
- * Notifies all registered listeners of a locale change
- *
- * @param e LocaleChangeEvent describing new locale
- */
- public void localeChanged(LocaleChangeEvent e) {
- Vector listeners;
-
- locale = e.getLocale();
-
- synchronized (this) {
- listeners = (Vector) localeChangeListeners.clone();
- }
- for (int i = 0; i < listeners.size(); i++) {
- ((LocaleChangeListener) listeners.elementAt(i)).localeChanged(e);
- }
- }
- }
-