UIDefaults.java 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848
  1. /* UIDefaults.java -- database for all settings and interface bindings.
  2. Copyright (C) 2002, 2004, 2005 Free Software Foundation, Inc.
  3. This file is part of GNU Classpath.
  4. GNU Classpath is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2, or (at your option)
  7. any later version.
  8. GNU Classpath is distributed in the hope that it will be useful, but
  9. WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with GNU Classpath; see the file COPYING. If not, write to the
  14. Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  15. 02110-1301 USA.
  16. Linking this library statically or dynamically with other modules is
  17. making a combined work based on this library. Thus, the terms and
  18. conditions of the GNU General Public License cover the whole
  19. combination.
  20. As a special exception, the copyright holders of this library give you
  21. permission to link this library with independent modules to produce an
  22. executable, regardless of the license terms of these independent
  23. modules, and to copy and distribute the resulting executable under
  24. terms of your choice, provided that you also meet, for each linked
  25. independent module, the terms and conditions of the license of that
  26. module. An independent module is a module which is not derived from
  27. or based on this library. If you modify this library, you may extend
  28. this exception to your version of the library, but you are not
  29. obligated to do so. If you do not wish to do so, delete this
  30. exception statement from your version. */
  31. package javax.swing;
  32. import java.awt.Color;
  33. import java.awt.Dimension;
  34. import java.awt.Font;
  35. import java.awt.Insets;
  36. import java.beans.PropertyChangeListener;
  37. import java.beans.PropertyChangeSupport;
  38. import java.lang.reflect.Method;
  39. import java.util.Hashtable;
  40. import java.util.LinkedList;
  41. import java.util.ListIterator;
  42. import java.util.Locale;
  43. import java.util.MissingResourceException;
  44. import java.util.ResourceBundle;
  45. import javax.swing.border.Border;
  46. import javax.swing.plaf.ComponentUI;
  47. import javax.swing.plaf.InputMapUIResource;
  48. /**
  49. * UIDefaults is a database where all settings and interface bindings are
  50. * stored into. A PLAF implementation fills one of these (see for example
  51. * plaf/basic/BasicLookAndFeel.java) with "ButtonUI" -> new BasicButtonUI().
  52. *
  53. * @author Ronald Veldema (rveldema@cs.vu.nl)
  54. */
  55. public class UIDefaults extends Hashtable<Object, Object>
  56. {
  57. /** Our ResourceBundles. */
  58. private LinkedList bundles;
  59. /** The default locale. */
  60. private Locale defaultLocale;
  61. /** We use this for firing PropertyChangeEvents. */
  62. private PropertyChangeSupport propertyChangeSupport;
  63. /**
  64. * Used for lazy instantiation of UIDefaults values so that they are not
  65. * all loaded when a Swing application starts up, but only the values that
  66. * are really needed. An <code>ActiveValue</code> is newly instantiated
  67. * every time when the value is requested, as opposed to the normal
  68. * {@link LazyValue} that is only instantiated once.
  69. */
  70. public static interface ActiveValue
  71. {
  72. Object createValue(UIDefaults table);
  73. }
  74. public static class LazyInputMap implements LazyValue
  75. {
  76. Object[] bind;
  77. public LazyInputMap(Object[] bindings)
  78. {
  79. bind = bindings;
  80. }
  81. public Object createValue(UIDefaults table)
  82. {
  83. InputMapUIResource im = new InputMapUIResource();
  84. for (int i = 0; 2 * i + 1 < bind.length; ++i)
  85. {
  86. Object curr = bind[2 * i];
  87. if (curr instanceof KeyStroke)
  88. im.put((KeyStroke) curr, bind[2 * i + 1]);
  89. else
  90. im.put(KeyStroke.getKeyStroke((String) curr),
  91. bind[2 * i + 1]);
  92. }
  93. return im;
  94. }
  95. }
  96. /**
  97. * Used for lazy instantiation of UIDefaults values so that they are not
  98. * all loaded when a Swing application starts up, but only the values that
  99. * are really needed. A <code>LazyValue</code> is only instantiated once,
  100. * as opposed to the {@link ActiveValue} that is newly created every time
  101. * it is requested.
  102. */
  103. public static interface LazyValue
  104. {
  105. Object createValue(UIDefaults table);
  106. }
  107. public static class ProxyLazyValue implements LazyValue
  108. {
  109. LazyValue inner;
  110. public ProxyLazyValue(String s)
  111. {
  112. final String className = s;
  113. inner = new LazyValue()
  114. {
  115. public Object createValue(UIDefaults table)
  116. {
  117. try
  118. {
  119. return Class
  120. .forName(className)
  121. .getConstructor(new Class[] {})
  122. .newInstance(new Object[] {});
  123. }
  124. catch (Exception e)
  125. {
  126. return null;
  127. }
  128. }
  129. };
  130. }
  131. public ProxyLazyValue(String c, String m)
  132. {
  133. final String className = c;
  134. final String methodName = m;
  135. inner = new LazyValue()
  136. {
  137. public Object createValue(UIDefaults table)
  138. {
  139. try
  140. {
  141. return Class
  142. .forName(className)
  143. .getMethod(methodName, new Class[] {})
  144. .invoke(null, new Object[] {});
  145. }
  146. catch (Exception e)
  147. {
  148. return null;
  149. }
  150. }
  151. };
  152. }
  153. public ProxyLazyValue(String c, Object[] os)
  154. {
  155. final String className = c;
  156. final Object[] objs = os;
  157. final Class[] clss = new Class[objs.length];
  158. for (int i = 0; i < objs.length; ++i)
  159. {
  160. clss[i] = objs[i].getClass();
  161. }
  162. inner = new LazyValue()
  163. {
  164. public Object createValue(UIDefaults table)
  165. {
  166. try
  167. {
  168. return Class
  169. .forName(className)
  170. .getConstructor(clss)
  171. .newInstance(objs);
  172. }
  173. catch (Exception e)
  174. {
  175. return null;
  176. }
  177. }
  178. };
  179. }
  180. public ProxyLazyValue(String c, String m, Object[] os)
  181. {
  182. final String className = c;
  183. final String methodName = m;
  184. final Object[] objs = os;
  185. final Class[] clss = new Class[objs.length];
  186. for (int i = 0; i < objs.length; ++i)
  187. {
  188. clss[i] = objs[i].getClass();
  189. }
  190. inner = new LazyValue()
  191. {
  192. public Object createValue(UIDefaults table)
  193. {
  194. try
  195. {
  196. return Class
  197. .forName(className)
  198. .getMethod(methodName, clss)
  199. .invoke(null, objs);
  200. }
  201. catch (Exception e)
  202. {
  203. return null;
  204. }
  205. }
  206. };
  207. }
  208. public Object createValue(UIDefaults table)
  209. {
  210. return inner.createValue(table);
  211. }
  212. }
  213. /** Our serialVersionUID for serialization. */
  214. private static final long serialVersionUID = 7341222528856548117L;
  215. /**
  216. * Constructs a new empty UIDefaults instance.
  217. */
  218. public UIDefaults()
  219. {
  220. bundles = new LinkedList();
  221. defaultLocale = Locale.getDefault();
  222. propertyChangeSupport = new PropertyChangeSupport(this);
  223. }
  224. /**
  225. * Constructs a new UIDefaults instance and loads the specified entries.
  226. * The entries are expected to come in pairs, that means
  227. * <code>entries[0]</code> is a key, <code>entries[1]</code> is a value,
  228. * <code>entries[2]</code> a key and so forth.
  229. *
  230. * @param entries the entries to initialize the UIDefaults instance with
  231. */
  232. public UIDefaults(Object[] entries)
  233. {
  234. this();
  235. for (int i = 0; (2 * i + 1) < entries.length; ++i)
  236. put(entries[2 * i], entries[2 * i + 1]);
  237. }
  238. /**
  239. * Returns the entry for the specified <code>key</code> in the default
  240. * locale.
  241. *
  242. * @return the entry for the specified <code>key</code>
  243. */
  244. public Object get(Object key)
  245. {
  246. return this.get(key, getDefaultLocale());
  247. }
  248. /**
  249. * Returns the entry for the specified <code>key</code> in the Locale
  250. * <code>loc</code>.
  251. *
  252. * @param key the key for which we return the value
  253. * @param loc the locale
  254. */
  255. public Object get(Object key, Locale loc)
  256. {
  257. Object obj = null;
  258. if (super.containsKey(key))
  259. {
  260. obj = super.get(key);
  261. }
  262. else if (key instanceof String)
  263. {
  264. String keyString = (String) key;
  265. ListIterator i = bundles.listIterator(0);
  266. while (i.hasNext())
  267. {
  268. String bundle_name = (String) i.next();
  269. ResourceBundle res =
  270. ResourceBundle.getBundle(bundle_name, loc);
  271. if (res != null)
  272. {
  273. try
  274. {
  275. obj = res.getObject(keyString);
  276. break;
  277. }
  278. catch (MissingResourceException me)
  279. {
  280. // continue, this bundle has no such key
  281. }
  282. }
  283. }
  284. }
  285. // now we've found the object, resolve it.
  286. // nb: LazyValues aren't supported in resource bundles, so it's correct
  287. // to insert their results in the locale-less hashtable.
  288. if (obj == null)
  289. return null;
  290. if (obj instanceof LazyValue)
  291. {
  292. Object resolved = ((LazyValue) obj).createValue(this);
  293. super.remove(key);
  294. super.put(key, resolved);
  295. return resolved;
  296. }
  297. else if (obj instanceof ActiveValue)
  298. {
  299. return ((ActiveValue) obj).createValue(this);
  300. }
  301. return obj;
  302. }
  303. /**
  304. * Puts a key and value into this UIDefaults object.<br>
  305. * In contrast to
  306. * {@link java.util.Hashtable}s <code>null</code>-values are accepted
  307. * here and treated like #remove(key).
  308. * <br>
  309. * This fires a PropertyChangeEvent with key as name and the old and new
  310. * values.
  311. *
  312. * @param key the key to put into the map
  313. * @param value the value to put into the map
  314. *
  315. * @return the old value for key or <code>null</code> if <code>key</code>
  316. * had no value assigned
  317. */
  318. public Object put(Object key, Object value)
  319. {
  320. Object old = checkAndPut(key, value);
  321. if (key instanceof String && old != value)
  322. firePropertyChange((String) key, old, value);
  323. return old;
  324. }
  325. /**
  326. * Puts a set of key-value pairs into the map.
  327. * The entries are expected to come in pairs, that means
  328. * <code>entries[0]</code> is a key, <code>entries[1]</code> is a value,
  329. * <code>entries[2]</code> a key and so forth.
  330. * <br>
  331. * If a value is <code>null</code> it is treated like #remove(key).
  332. * <br>
  333. * This unconditionally fires a PropertyChangeEvent with
  334. * <code>&apos;UIDefaults&apos;</code> as name and <code>null</code> for
  335. * old and new value.
  336. *
  337. * @param entries the entries to be put into the map
  338. */
  339. public void putDefaults(Object[] entries)
  340. {
  341. for (int i = 0; (2 * i + 1) < entries.length; ++i)
  342. {
  343. checkAndPut(entries[2 * i], entries[2 * i + 1]);
  344. }
  345. firePropertyChange("UIDefaults", null, null);
  346. }
  347. /**
  348. * Checks the value for <code>null</code> and put it into the Hashtable, if
  349. * it is not <code>null</code>. If the value is <code>null</code> then
  350. * remove the corresponding key.
  351. *
  352. * @param key the key to put into this UIDefauls table
  353. * @param value the value to put into this UIDefaults table
  354. *
  355. * @return the old value for <code>key</code>
  356. */
  357. private Object checkAndPut(Object key, Object value)
  358. {
  359. Object old;
  360. if (value != null)
  361. old = super.put(key, value);
  362. else
  363. old = super.remove(key);
  364. return old;
  365. }
  366. /**
  367. * Returns a font entry for the default locale.
  368. *
  369. * @param key the key to the requested entry
  370. *
  371. * @return the font entry for <code>key</code> or null if no such entry
  372. * exists
  373. */
  374. public Font getFont(Object key)
  375. {
  376. Object o = get(key);
  377. return o instanceof Font ? (Font) o : null;
  378. }
  379. /**
  380. * Returns a font entry for a specic locale.
  381. *
  382. * @param key the key to the requested entry
  383. * @param locale the locale to the requested entry
  384. *
  385. * @return the font entry for <code>key</code> or null if no such entry
  386. * exists
  387. */
  388. public Font getFont(Object key, Locale locale)
  389. {
  390. Object o = get(key, locale);
  391. return o instanceof Font ? (Font) o : null;
  392. }
  393. /**
  394. * Returns a color entry for the default locale.
  395. *
  396. * @param key the key to the requested entry
  397. *
  398. * @return the color entry for <code>key</code> or null if no such entry
  399. * exists
  400. */
  401. public Color getColor(Object key)
  402. {
  403. Object o = get(key);
  404. return o instanceof Color ? (Color) o : null;
  405. }
  406. /**
  407. * Returns a color entry for a specic locale.
  408. *
  409. * @param key the key to the requested entry
  410. * @param locale the locale to the requested entry
  411. *
  412. * @return the color entry for <code>key</code> or null if no such entry
  413. * exists
  414. */
  415. public Color getColor(Object key, Locale locale)
  416. {
  417. Object o = get(key, locale);
  418. return o instanceof Color ? (Color) o : null;
  419. }
  420. /**
  421. * Returns an icon entry for the default locale.
  422. *
  423. * @param key the key to the requested entry
  424. *
  425. * @return the icon entry for <code>key</code> or null if no such entry
  426. * exists
  427. */
  428. public Icon getIcon(Object key)
  429. {
  430. Object o = get(key);
  431. return o instanceof Icon ? (Icon) o : null;
  432. }
  433. /**
  434. * Returns an icon entry for a specic locale.
  435. *
  436. * @param key the key to the requested entry
  437. * @param locale the locale to the requested entry
  438. *
  439. * @return the icon entry for <code>key</code> or null if no such entry
  440. * exists
  441. */
  442. public Icon getIcon(Object key, Locale locale)
  443. {
  444. Object o = get(key, locale);
  445. return o instanceof Icon ? (Icon) o : null;
  446. }
  447. /**
  448. * Returns a border entry for the default locale.
  449. *
  450. * @param key the key to the requested entry
  451. *
  452. * @return the border entry for <code>key</code> or null if no such entry
  453. * exists
  454. */
  455. public Border getBorder(Object key)
  456. {
  457. Object o = get(key);
  458. return o instanceof Border ? (Border) o : null;
  459. }
  460. /**
  461. * Returns a border entry for a specic locale.
  462. *
  463. * @param key the key to the requested entry
  464. * @param locale the locale to the requested entry
  465. *
  466. * @return the border entry for <code>key</code> or null if no such entry
  467. * exists
  468. */
  469. public Border getBorder(Object key, Locale locale)
  470. {
  471. Object o = get(key, locale);
  472. return o instanceof Border ? (Border) o : null;
  473. }
  474. /**
  475. * Returns a string entry for the default locale.
  476. *
  477. * @param key the key to the requested entry
  478. *
  479. * @return the string entry for <code>key</code> or null if no such entry
  480. * exists
  481. */
  482. public String getString(Object key)
  483. {
  484. Object o = get(key);
  485. return o instanceof String ? (String) o : null;
  486. }
  487. /**
  488. * Returns a string entry for a specic locale.
  489. *
  490. * @param key the key to the requested entry
  491. * @param locale the locale to the requested entry
  492. *
  493. * @return the string entry for <code>key</code> or null if no such entry
  494. * exists
  495. */
  496. public String getString(Object key, Locale locale)
  497. {
  498. Object o = get(key, locale);
  499. return o instanceof String ? (String) o : null;
  500. }
  501. /**
  502. * Returns an integer entry for the default locale.
  503. *
  504. * @param key the key to the requested entry
  505. *
  506. * @return the integer entry for <code>key</code> or null if no such entry
  507. * exists
  508. */
  509. public int getInt(Object key)
  510. {
  511. Object o = get(key);
  512. return o instanceof Integer ? ((Integer) o).intValue() : 0;
  513. }
  514. /**
  515. * Returns an integer entry for a specic locale.
  516. *
  517. * @param key the key to the requested entry
  518. * @param locale the locale to the requested entry
  519. *
  520. * @return the integer entry for <code>key</code> or null if no such entry
  521. * exists
  522. */
  523. public int getInt(Object key, Locale locale)
  524. {
  525. Object o = get(key, locale);
  526. return o instanceof Integer ? ((Integer) o).intValue() : 0;
  527. }
  528. /**
  529. * Returns a boolean entry for the default locale.
  530. *
  531. * @param key the key to the requested entry
  532. *
  533. * @return The boolean entry for <code>key</code> or <code>false</code> if no
  534. * such entry exists.
  535. */
  536. public boolean getBoolean(Object key)
  537. {
  538. return Boolean.TRUE.equals(get(key));
  539. }
  540. /**
  541. * Returns a boolean entry for a specic locale.
  542. *
  543. * @param key the key to the requested entry
  544. * @param locale the locale to the requested entry
  545. *
  546. * @return the boolean entry for <code>key</code> or null if no such entry
  547. * exists
  548. */
  549. public boolean getBoolean(Object key, Locale locale)
  550. {
  551. return Boolean.TRUE.equals(get(key, locale));
  552. }
  553. /**
  554. * Returns an insets entry for the default locale.
  555. *
  556. * @param key the key to the requested entry
  557. *
  558. * @return the insets entry for <code>key</code> or null if no such entry
  559. * exists
  560. */
  561. public Insets getInsets(Object key)
  562. {
  563. Object o = get(key);
  564. return o instanceof Insets ? (Insets) o : null;
  565. }
  566. /**
  567. * Returns an insets entry for a specic locale.
  568. *
  569. * @param key the key to the requested entry
  570. * @param locale the locale to the requested entry
  571. *
  572. * @return the boolean entry for <code>key</code> or null if no such entry
  573. * exists
  574. */
  575. public Insets getInsets(Object key, Locale locale)
  576. {
  577. Object o = get(key, locale);
  578. return o instanceof Insets ? (Insets) o : null;
  579. }
  580. /**
  581. * Returns a dimension entry for the default locale.
  582. *
  583. * @param key the key to the requested entry
  584. *
  585. * @return the dimension entry for <code>key</code> or null if no such entry
  586. * exists
  587. */
  588. public Dimension getDimension(Object key)
  589. {
  590. Object o = get(key);
  591. return o instanceof Dimension ? (Dimension) o : null;
  592. }
  593. /**
  594. * Returns a dimension entry for a specic locale.
  595. *
  596. * @param key the key to the requested entry
  597. * @param locale the locale to the requested entry
  598. *
  599. * @return the boolean entry for <code>key</code> or null if no such entry
  600. * exists
  601. */
  602. public Dimension getDimension(Object key, Locale locale)
  603. {
  604. Object o = get(key, locale);
  605. return o instanceof Dimension ? (Dimension) o : null;
  606. }
  607. /**
  608. * Returns the ComponentUI class that renders a component. <code>id</code>
  609. * is the ID for which the String value of the classname is stored in
  610. * this UIDefaults map.
  611. *
  612. * @param id the ID of the UI class
  613. * @param loader the ClassLoader to use
  614. *
  615. * @return the UI class for <code>id</code>
  616. */
  617. public Class<? extends ComponentUI> getUIClass(String id, ClassLoader loader)
  618. {
  619. String className = (String) get(id);
  620. if (className == null)
  621. return null;
  622. try
  623. {
  624. if (loader == null)
  625. loader = ClassLoader.getSystemClassLoader();
  626. return (Class<? extends ComponentUI>) loader.loadClass (className);
  627. }
  628. catch (Exception e)
  629. {
  630. return null;
  631. }
  632. }
  633. /**
  634. * Returns the ComponentUI class that renders a component. <code>id</code>
  635. * is the ID for which the String value of the classname is stored in
  636. * this UIDefaults map.
  637. *
  638. * @param id the ID of the UI class
  639. *
  640. * @return the UI class for <code>id</code>
  641. */
  642. public Class<? extends ComponentUI> getUIClass(String id)
  643. {
  644. return getUIClass (id, null);
  645. }
  646. /**
  647. * If a key is requested in #get(key) that has no value, this method
  648. * is called before returning <code>null</code>.
  649. *
  650. * @param msg the error message
  651. */
  652. protected void getUIError(String msg)
  653. {
  654. System.err.println ("UIDefaults.getUIError: " + msg);
  655. }
  656. /**
  657. * Returns the {@link ComponentUI} for the specified {@link JComponent}.
  658. *
  659. * @param target the component for which the ComponentUI is requested
  660. *
  661. * @return the {@link ComponentUI} for the specified {@link JComponent}
  662. */
  663. public ComponentUI getUI(JComponent target)
  664. {
  665. String classId = target.getUIClassID ();
  666. Class cls = getUIClass (classId);
  667. if (cls == null)
  668. {
  669. getUIError ("failed to locate UI class:" + classId);
  670. return null;
  671. }
  672. Method factory;
  673. try
  674. {
  675. factory = cls.getMethod ("createUI", new Class[] { JComponent.class } );
  676. }
  677. catch (NoSuchMethodException nme)
  678. {
  679. getUIError ("failed to locate createUI method on " + cls.toString ());
  680. return null;
  681. }
  682. try
  683. {
  684. return (ComponentUI) factory.invoke (null, new Object[] { target });
  685. }
  686. catch (java.lang.reflect.InvocationTargetException ite)
  687. {
  688. getUIError ("InvocationTargetException ("+ ite.getTargetException()
  689. +") calling createUI(...) on " + cls.toString ());
  690. return null;
  691. }
  692. catch (Exception e)
  693. {
  694. getUIError ("exception calling createUI(...) on " + cls.toString ());
  695. return null;
  696. }
  697. }
  698. /**
  699. * Adds a {@link PropertyChangeListener} to this UIDefaults map.
  700. * Registered PropertyChangeListener are notified when values
  701. * are beeing put into this UIDefaults map.
  702. *
  703. * @param listener the PropertyChangeListener to add
  704. */
  705. public void addPropertyChangeListener(PropertyChangeListener listener)
  706. {
  707. propertyChangeSupport.addPropertyChangeListener(listener);
  708. }
  709. /**
  710. * Removes a PropertyChangeListener from this UIDefaults map.
  711. *
  712. * @param listener the PropertyChangeListener to remove
  713. */
  714. public void removePropertyChangeListener(PropertyChangeListener listener)
  715. {
  716. propertyChangeSupport.removePropertyChangeListener(listener);
  717. }
  718. /**
  719. * Returns an array of all registered PropertyChangeListeners.
  720. *
  721. * @return all registered PropertyChangeListeners
  722. */
  723. public PropertyChangeListener[] getPropertyChangeListeners()
  724. {
  725. return propertyChangeSupport.getPropertyChangeListeners();
  726. }
  727. /**
  728. * Fires a PropertyChangeEvent.
  729. *
  730. * @param property the property name
  731. * @param oldValue the old value
  732. * @param newValue the new value
  733. */
  734. protected void firePropertyChange(String property,
  735. Object oldValue, Object newValue)
  736. {
  737. propertyChangeSupport.firePropertyChange(property, oldValue, newValue);
  738. }
  739. /**
  740. * Adds a ResourceBundle for localized values.
  741. *
  742. * @param name the name of the ResourceBundle to add
  743. */
  744. public void addResourceBundle(String name)
  745. {
  746. bundles.addFirst(name);
  747. }
  748. /**
  749. * Removes a ResourceBundle.
  750. *
  751. * @param name the name of the ResourceBundle to remove
  752. */
  753. public void removeResourceBundle(String name)
  754. {
  755. bundles.remove(name);
  756. }
  757. /**
  758. * Sets the current locale to <code>loc</code>.
  759. *
  760. * @param loc the Locale to be set
  761. */
  762. public void setDefaultLocale(Locale loc)
  763. {
  764. defaultLocale = loc;
  765. }
  766. /**
  767. * Returns the current default locale.
  768. *
  769. * @return the current default locale
  770. */
  771. public Locale getDefaultLocale()
  772. {
  773. return defaultLocale;
  774. }
  775. }