/[classpath]/classpath/javax/swing/UIDefaults.java
ViewVC logotype

Diff of /classpath/javax/swing/UIDefaults.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.18 by rabbit78, Wed Apr 6 20:45:12 2005 UTC revision 1.19 by rabbit78, Thu Apr 7 12:27:37 2005 UTC
# Line 64  import javax.swing.plaf.ComponentUI; Line 64  import javax.swing.plaf.ComponentUI;
64   */   */
65  public class UIDefaults extends Hashtable  public class UIDefaults extends Hashtable
66  {  {
67    
68      /** Our ResourceBundles. */
69    private LinkedList bundles;    private LinkedList bundles;
70    
71      /** The default locale. */
72    private Locale defaultLocale;    private Locale defaultLocale;
73    
74      /** We use this for firing PropertyChangeEvents. */
75    private PropertyChangeSupport propertyChangeSupport;    private PropertyChangeSupport propertyChangeSupport;
76    
77    public static interface ActiveValue    public static interface ActiveValue
# Line 208  public class UIDefaults extends Hashtabl Line 214  public class UIDefaults extends Hashtabl
214      }      }
215    }    }
216    
217      /** Our serialVersionUID for serialization. */
218    private static final long serialVersionUID = 7341222528856548117L;    private static final long serialVersionUID = 7341222528856548117L;
219    
220      /**
221       * Constructs a new empty UIDefaults instance.
222       */
223    public UIDefaults()    public UIDefaults()
224    {    {
225      bundles = new LinkedList();      bundles = new LinkedList();
# Line 217  public class UIDefaults extends Hashtabl Line 227  public class UIDefaults extends Hashtabl
227      propertyChangeSupport = new PropertyChangeSupport(this);      propertyChangeSupport = new PropertyChangeSupport(this);
228    }    }
229    
230      /**
231       * Constructs a new UIDefaults instance and loads the specified entries.
232       * The entries are expected to come in pairs, that means
233       * <code>entries[0]</code> is a key, <code>entries[1]</code> is a value,
234       * <code>entries[2]</code> a key and so forth.
235       *
236       * @param entries the entries to initialize the UIDefaults instance with
237       */
238    public UIDefaults(Object[] entries)    public UIDefaults(Object[] entries)
239    {    {
240      this();      this();
# Line 225  public class UIDefaults extends Hashtabl Line 243  public class UIDefaults extends Hashtabl
243        put(entries[2 * i], entries[2 * i + 1]);        put(entries[2 * i], entries[2 * i + 1]);
244    }    }
245    
246      /**
247       * Returns the entry for the specified <code>key</code> in the default
248       * locale.
249       *
250       * @return the entry for the specified <code>key</code>
251       */
252    public Object get(Object key)    public Object get(Object key)
253    {    {
254      return this.get(key, getDefaultLocale());      return this.get(key, getDefaultLocale());
255    }    }
256    
257      /**
258       * Returns the entry for the specified <code>key</code> in the Locale
259       * <code>loc</code>.
260       *
261       * @param key the key for which we return the value
262       * @param loc the locale
263       */
264    public Object get(Object key, Locale loc)    public Object get(Object key, Locale loc)
265    {    {
266      Object obj = null;      Object obj = null;
# Line 284  public class UIDefaults extends Hashtabl Line 315  public class UIDefaults extends Hashtabl
315      return obj;      return obj;
316    }    }
317    
318      /**
319       * Puts a key and value into this UIDefaults object.<br>
320       * In contrast to
321       * {@link java.util.Hashtable}s <code>null</code>-values are accepted
322       * here and treated like #remove(key).
323       * <br>
324       * This fires a PropertyChangeEvent with key as name and the old and new
325       * values.
326       *
327       * @param key the key to put into the map
328       * @param value the value to put into the map
329       *
330       * @return the old value for key or <code>null</code> if <code>key</code>
331       *     had no value assigned
332       */
333    public Object put(Object key, Object value)    public Object put(Object key, Object value)
334    {    {
335      Object old = checkAndPut(key, value);      Object old = checkAndPut(key, value);
# Line 293  public class UIDefaults extends Hashtabl Line 339  public class UIDefaults extends Hashtabl
339      return old;      return old;
340    }    }
341    
342      /**
343       * Puts a set of key-value pairs into the map.
344       * The entries are expected to come in pairs, that means
345       * <code>entries[0]</code> is a key, <code>entries[1]</code> is a value,
346       * <code>entries[2]</code> a key and so forth.
347       * <br>
348       * If a value is <code>null</code> it is treated like #remove(key).
349       * <br>
350       * This unconditionally fires a PropertyChangeEvent with
351       * <code>&apos;UIDefaults&apos;</code> as name and <code>null</code> for
352       * old and new value.
353       *
354       * @param entries the entries to be put into the map
355       */
356    public void putDefaults(Object[] entries)    public void putDefaults(Object[] entries)
357    {    {
358      for (int i = 0; (2 * i + 1) < entries.length; ++i)      for (int i = 0; (2 * i + 1) < entries.length; ++i)
# Line 324  public class UIDefaults extends Hashtabl Line 384  public class UIDefaults extends Hashtabl
384      return old;      return old;
385    }    }
386    
387      /**
388       * Returns a font entry for the default locale.
389       *
390       * @param key the key to the requested entry
391       *
392       * @return the font entry for <code>key</code> or null if no such entry
393       *     exists
394       */
395    public Font getFont(Object key)    public Font getFont(Object key)
396    {    {
397      Object o = get(key);      Object o = get(key);
398      return o instanceof Font ? (Font) o : null;      return o instanceof Font ? (Font) o : null;
399    }    }
400    
401      /**
402       * Returns a font entry for a specic locale.
403       *
404       * @param key the key to the requested entry
405       * @param locale the locale to the requested entry
406       *
407       * @return the font entry for <code>key</code> or null if no such entry
408       *     exists
409       */
410    public Font getFont(Object key, Locale l)    public Font getFont(Object key, Locale l)
411    {    {
412      Object o = get(key, l);      Object o = get(key, l);
413      return o instanceof Font ? (Font) o : null;      return o instanceof Font ? (Font) o : null;
414    }    }
415    
416      /**
417       * Returns a color entry for the default locale.
418       *
419       * @param key the key to the requested entry
420       *
421       * @return the color entry for <code>key</code> or null if no such entry
422       *     exists
423       */
424    public Color getColor(Object key)    public Color getColor(Object key)
425    {    {
426      Object o = get(key);      Object o = get(key);
427      return o instanceof Color ? (Color) o : null;      return o instanceof Color ? (Color) o : null;
428    }    }
429    
430      /**
431       * Returns a color entry for a specic locale.
432       *
433       * @param key the key to the requested entry
434       * @param locale the locale to the requested entry
435       *
436       * @return the color entry for <code>key</code> or null if no such entry
437       *     exists
438       */
439    public Color getColor(Object key, Locale l)    public Color getColor(Object key, Locale l)
440    {    {
441      Object o = get(key, l);      Object o = get(key, l);
442      return o instanceof Color ? (Color) o : null;      return o instanceof Color ? (Color) o : null;
443    }    }
444    
445      /**
446       * Returns an icon entry for the default locale.
447       *
448       * @param key the key to the requested entry
449       *
450       * @return the icon entry for <code>key</code> or null if no such entry
451       *     exists
452       */
453    public Icon getIcon(Object key)    public Icon getIcon(Object key)
454    {    {
455      Object o = get(key);      Object o = get(key);
456      return o instanceof Icon ? (Icon) o : null;      return o instanceof Icon ? (Icon) o : null;
457    }    }
458    
459      /**
460       * Returns an icon entry for a specic locale.
461       *
462       * @param key the key to the requested entry
463       * @param locale the locale to the requested entry
464       *
465       * @return the icon entry for <code>key</code> or null if no such entry
466       *     exists
467       */
468    public Icon getIcon(Object key, Locale l)    public Icon getIcon(Object key, Locale l)
469    {    {
470      Object o = get(key, l);      Object o = get(key, l);
471      return o instanceof Icon ? (Icon) o : null;      return o instanceof Icon ? (Icon) o : null;
472    }    }
473    
474      /**
475       * Returns a border entry for the default locale.
476       *
477       * @param key the key to the requested entry
478       *
479       * @return the border entry for <code>key</code> or null if no such entry
480       *     exists
481       */
482    public Border getBorder(Object key)    public Border getBorder(Object key)
483    {    {
484      Object o = get(key);      Object o = get(key);
485      return o instanceof Border ? (Border) o : null;      return o instanceof Border ? (Border) o : null;
486    }    }
487    
488      /**
489       * Returns a border entry for a specic locale.
490       *
491       * @param key the key to the requested entry
492       * @param locale the locale to the requested entry
493       *
494       * @return the border entry for <code>key</code> or null if no such entry
495       *     exists
496       */
497    public Border getBorder(Object key, Locale l)    public Border getBorder(Object key, Locale l)
498    {    {
499      Object o = get(key, l);      Object o = get(key, l);
500      return o instanceof Border ? (Border) o : null;      return o instanceof Border ? (Border) o : null;
501    }    }
502    
503      /**
504       * Returns a string entry for the default locale.
505       *
506       * @param key the key to the requested entry
507       *
508       * @return the string entry for <code>key</code> or null if no such entry
509       *     exists
510       */
511    public String getString(Object key)    public String getString(Object key)
512    {    {
513      Object o = get(key);      Object o = get(key);
514      return o instanceof String ? (String) o : null;      return o instanceof String ? (String) o : null;
515    }    }
516    
517      /**
518       * Returns a string entry for a specic locale.
519       *
520       * @param key the key to the requested entry
521       * @param locale the locale to the requested entry
522       *
523       * @return the string entry for <code>key</code> or null if no such entry
524       *     exists
525       */
526    public String getString(Object key, Locale l)    public String getString(Object key, Locale l)
527    {    {
528      Object o = get(key, l);      Object o = get(key, l);
529      return o instanceof String ? (String) o : null;      return o instanceof String ? (String) o : null;
530    }    }
531    
532      /**
533       * Returns an integer entry for the default locale.
534       *
535       * @param key the key to the requested entry
536       *
537       * @return the integer entry for <code>key</code> or null if no such entry
538       *     exists
539       */
540    public int getInt(Object key)    public int getInt(Object key)
541    {    {
542      Object o = get(key);      Object o = get(key);
543      return o instanceof Integer ? ((Integer) o).intValue() : 0;      return o instanceof Integer ? ((Integer) o).intValue() : 0;
544    }    }
545    
546      /**
547       * Returns an integer entry for a specic locale.
548       *
549       * @param key the key to the requested entry
550       * @param locale the locale to the requested entry
551       *
552       * @return the integer entry for <code>key</code> or null if no such entry
553       *     exists
554       */
555    public int getInt(Object key, Locale l)    public int getInt(Object key, Locale l)
556    {    {
557      Object o = get(key, l);      Object o = get(key, l);
558      return o instanceof Integer ? ((Integer) o).intValue() : 0;      return o instanceof Integer ? ((Integer) o).intValue() : 0;
559    }    }
560    
561      /**
562       * Returns a boolean entry for the default locale.
563       *
564       * @param key the key to the requested entry
565       *
566       * @return the boolean entry for <code>key</code> or null if no such entry
567       *     exists
568       */
569    public boolean getBoolean(Object key)    public boolean getBoolean(Object key)
570    {    {
571      return Boolean.TRUE.equals(get(key));      return Boolean.TRUE.equals(get(key));
572    }    }
573    
574      /**
575       * Returns a boolean entry for a specic locale.
576       *
577       * @param key the key to the requested entry
578       * @param locale the locale to the requested entry
579       *
580       * @return the boolean entry for <code>key</code> or null if no such entry
581       *     exists
582       */
583    public boolean getBoolean(Object key, Locale l)    public boolean getBoolean(Object key, Locale l)
584    {    {
585      return Boolean.TRUE.equals(get(key, l));      return Boolean.TRUE.equals(get(key, l));
586    }    }
587    
588      /**
589       * Returns an insets entry for the default locale.
590       *
591       * @param key the key to the requested entry
592       *
593       * @return the insets entry for <code>key</code> or null if no such entry
594       *     exists
595       */
596    public Insets getInsets(Object key)    public Insets getInsets(Object key)
597    {    {
598      Object o = get(key);      Object o = get(key);
599      return o instanceof Insets ? (Insets) o : null;      return o instanceof Insets ? (Insets) o : null;
600    }    }
601    
602      /**
603       * Returns an insets entry for a specic locale.
604       *
605       * @param key the key to the requested entry
606       * @param locale the locale to the requested entry
607       *
608       * @return the boolean entry for <code>key</code> or null if no such entry
609       *     exists
610       */
611    public Insets getInsets(Object key, Locale l)    public Insets getInsets(Object key, Locale l)
612    {    {
613      Object o = get(key, l);      Object o = get(key, l);
614      return o instanceof Insets ? (Insets) o : null;      return o instanceof Insets ? (Insets) o : null;
615    }    }
616    
617      /**
618       * Returns a dimension entry for the default locale.
619       *
620       * @param key the key to the requested entry
621       *
622       * @return the dimension entry for <code>key</code> or null if no such entry
623       *     exists
624       */
625    public Dimension getDimension(Object key)    public Dimension getDimension(Object key)
626    {    {
627      Object o = get(key);      Object o = get(key);
628      return o instanceof Dimension ? (Dimension) o : null;      return o instanceof Dimension ? (Dimension) o : null;
629    }    }
630    
631      /**
632       * Returns a dimension entry for a specic locale.
633       *
634       * @param key the key to the requested entry
635       * @param locale the locale to the requested entry
636       *
637       * @return the boolean entry for <code>key</code> or null if no such entry
638       *     exists
639       */
640    public Dimension getDimension(Object key, Locale l)    public Dimension getDimension(Object key, Locale l)
641    {    {
642      Object o = get(key, l);      Object o = get(key, l);
643      return o instanceof Dimension ? (Dimension) o : null;      return o instanceof Dimension ? (Dimension) o : null;
644    }    }
645    
646      /**
647       * Returns the ComponentUI class that renders a component. <code>id</code>
648       * is the ID for which the String value of the classname is stored in
649       * this UIDefaults map.
650       *
651       * @param id the ID of the UI class
652       * @param loader the ClassLoader to use
653       *
654       * @return the UI class for <code>id</code>
655       */
656    public Class getUIClass(String id, ClassLoader loader)    public Class getUIClass(String id, ClassLoader loader)
657    {    {
658      String className = (String) get (id);      String className = (String) get (id);
# Line 447  public class UIDefaults extends Hashtabl Line 670  public class UIDefaults extends Hashtabl
670        }        }
671    }    }
672    
673      /**
674       * Returns the ComponentUI class that renders a component. <code>id</code>
675       * is the ID for which the String value of the classname is stored in
676       * this UIDefaults map.
677       *
678       * @param id the ID of the UI class
679       *
680       * @return the UI class for <code>id</code>
681       */
682    public Class getUIClass(String id)    public Class getUIClass(String id)
683    {    {
684      return getUIClass (id, null);      return getUIClass (id, null);
685    }    }
686    
687      /**
688       * If a key is requested in #get(key) that has no value, this method
689       * is called before returning <code>null</code>.
690       *
691       * @param msg the error message
692       */
693    protected void getUIError(String msg)    protected void getUIError(String msg)
694    {    {
695      System.err.println ("UIDefaults.getUIError: " + msg);      System.err.println ("UIDefaults.getUIError: " + msg);
696    }    }
697    
698      /**
699       * Returns the {@link ComponentUI} for the specified {@link JComponent}.
700       *
701       * @param target the component for which the ComponentUI is requested
702       *
703       * @return the {@link ComponentUI} for the specified {@link JComponent}
704       */
705    public ComponentUI getUI(JComponent target)    public ComponentUI getUI(JComponent target)
706    {    {
707      String classId = target.getUIClassID ();      String classId = target.getUIClassID ();
# Line 496  public class UIDefaults extends Hashtabl Line 741  public class UIDefaults extends Hashtabl
741        }        }
742    }    }
743    
744      /**
745       * Adds a {@link PropertyChangeListener} to this UIDefaults map.
746       * Registered PropertyChangeListener are notified when values
747       * are beeing put into this UIDefaults map.
748       *
749       * @param listener the PropertyChangeListener to add
750       */
751    public void addPropertyChangeListener(PropertyChangeListener listener)    public void addPropertyChangeListener(PropertyChangeListener listener)
752    {    {
753      propertyChangeSupport.addPropertyChangeListener(listener);      propertyChangeSupport.addPropertyChangeListener(listener);
754    }    }
755    
756      /**
757       * Removes a PropertyChangeListener from this UIDefaults map.
758       *
759       * @param listener the PropertyChangeListener to remove
760       */
761    public void removePropertyChangeListener(PropertyChangeListener listener)    public void removePropertyChangeListener(PropertyChangeListener listener)
762    {    {
763      propertyChangeSupport.removePropertyChangeListener(listener);      propertyChangeSupport.removePropertyChangeListener(listener);
764    }    }
765    
766      /**
767       * Returns an array of all registered PropertyChangeListeners.
768       *
769       * @return all registered PropertyChangeListeners
770       */
771    public PropertyChangeListener[] getPropertyChangeListeners()    public PropertyChangeListener[] getPropertyChangeListeners()
772    {    {
773      return propertyChangeSupport.getPropertyChangeListeners();      return propertyChangeSupport.getPropertyChangeListeners();
774    }    }
775    
776      /**
777       * Fires a PropertyChangeEvent.
778       *
779       * @param property the property name
780       * @param oldValue the old value
781       * @param newValue the new value
782       */
783    protected void firePropertyChange(String property,    protected void firePropertyChange(String property,
784                                      Object oldValue, Object newValue)                                      Object oldValue, Object newValue)
785    {    {
786      propertyChangeSupport.firePropertyChange(property, oldValue, newValue);      propertyChangeSupport.firePropertyChange(property, oldValue, newValue);
787    }    }
788    
789      /**
790       * Adds a ResourceBundle for localized values.
791       *
792       * @param name the name of the ResourceBundle to add
793       */
794    public void addResourceBundle(String name)    public void addResourceBundle(String name)
795    {    {
796      bundles.addFirst(name);      bundles.addFirst(name);
797    }    }
798    
799      /**
800       * Removes a ResourceBundle.
801       *
802       * @param name the name of the ResourceBundle to remove
803       */
804    public void removeResourceBundle(String name)    public void removeResourceBundle(String name)
805    {    {
806      bundles.remove(name);      bundles.remove(name);
807    }    }
808    
809      /**
810       * Sets the current locale to <code>loc</code>.
811       *
812       * @param loc the Locale to be set
813       */
814    public void setDefaultLocale(Locale loc)    public void setDefaultLocale(Locale loc)
815    {    {
816      defaultLocale = loc;      defaultLocale = loc;
817    }    }
818    
819      /**
820       * Returns the current default locale.
821       *
822       * @return the current default locale
823       */
824    public Locale getDefaultLocale()    public Locale getDefaultLocale()
825    {    {
826      return defaultLocale;      return defaultLocale;

Legend:
Removed from v.1.18  
changed lines
  Added in v.1.19

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26