Merge from the pain train
[official-gcc.git] / libjava / javax / swing / UIManager.java
blobdfc6a82ac463b5a26d1a9f6e8dd14cbd05a0a4f1
1 /* UIManager.java --
2 Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc.
4 This file is part of GNU Classpath.
6 GNU Classpath is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
11 GNU Classpath is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Classpath; see the file COPYING. If not, write to the
18 Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
19 02111-1307 USA.
21 Linking this library statically or dynamically with other modules is
22 making a combined work based on this library. Thus, the terms and
23 conditions of the GNU General Public License cover the whole
24 combination.
26 As a special exception, the copyright holders of this library give you
27 permission to link this library with independent modules to produce an
28 executable, regardless of the license terms of these independent
29 modules, and to copy and distribute the resulting executable under
30 terms of your choice, provided that you also meet, for each linked
31 independent module, the terms and conditions of the license of that
32 module. An independent module is a module which is not derived from
33 or based on this library. If you modify this library, you may extend
34 this exception to your version of the library, but you are not
35 obligated to do so. If you do not wish to do so, delete this
36 exception statement from your version. */
39 package javax.swing;
41 import java.awt.Color;
42 import java.awt.Dimension;
43 import java.awt.Font;
44 import java.awt.Insets;
45 import java.beans.PropertyChangeListener;
46 import java.io.Serializable;
47 import java.util.Locale;
49 import javax.swing.border.Border;
50 import javax.swing.plaf.ComponentUI;
51 import javax.swing.plaf.metal.MetalLookAndFeel;
53 public class UIManager implements Serializable
55 public static class LookAndFeelInfo
57 String name, clazz;
59 public LookAndFeelInfo(String name,
60 String clazz)
62 this.name = name;
63 this.clazz = clazz;
66 public String getName()
68 return name;
71 public String getClassName()
73 return clazz;
77 private static final long serialVersionUID = -5547433830339189365L;
79 static LookAndFeelInfo [] installed = {
80 new LookAndFeelInfo ("Metal", "javax.swing.plaf.metal.MetalLookAndFeel")
83 static LookAndFeel[] aux_installed;
85 static LookAndFeel look_and_feel = new MetalLookAndFeel();
87 public UIManager()
89 // Do nothing here.
92 /**
93 * Add a <code>PropertyChangeListener</code> to the listener list.
95 * @param listener the listener to add
97 public static void addPropertyChangeListener(PropertyChangeListener listener)
99 // FIXME
103 * Remove a <code>PropertyChangeListener</code> from the listener list.
105 * @param listener the listener to remove
107 public static void removePropertyChangeListener(PropertyChangeListener listener)
109 // FIXME
113 * Returns an array of all added <code>PropertyChangeListener</code> objects.
115 * @return an array of listeners
117 * @since 1.4
119 public static PropertyChangeListener[] getPropertyChangeListeners()
121 // FIXME
122 throw new Error ("Not implemented");
126 * Add a LookAndFeel to the list of auxiliary look and feels.
128 public static void addAuxiliaryLookAndFeel (LookAndFeel l)
130 if (aux_installed == null)
132 aux_installed = new LookAndFeel[1];
133 aux_installed[0] = l;
134 return;
137 LookAndFeel[] T = new LookAndFeel[ aux_installed.length+1 ];
138 System.arraycopy(aux_installed, 0, T, 0, aux_installed.length);
139 aux_installed = T;
140 aux_installed[aux_installed.length-1] = l;
143 public static boolean removeAuxiliaryLookAndFeel(LookAndFeel laf)
145 if (aux_installed == null)
146 return false;
148 for (int i=0;i<aux_installed.length;i++)
150 if (aux_installed[i] == laf)
152 aux_installed[ i ] = aux_installed[aux_installed.length-1];
153 LookAndFeel[] T = new LookAndFeel[ aux_installed.length-1 ];
154 System.arraycopy (aux_installed, 0, T, 0, aux_installed.length-1);
155 aux_installed = T;
156 return true;
159 return false;
162 public static LookAndFeel[] getAuxiliaryLookAndFeels()
164 return aux_installed;
167 public static Object get(Object key)
169 return getLookAndFeel().getDefaults().get(key);
172 public static Object get(Object key, Locale locale)
174 return getLookAndFeel().getDefaults().get(key ,locale);
178 * Returns a boolean value from the defaults table,
179 * <code>false</code> if key is not present.
181 * @since 1.4
183 public static boolean getBoolean(Object key)
185 Boolean value = (Boolean) getLookAndFeel().getDefaults().get(key);
186 return value != null ? value.booleanValue() : false;
190 * Returns a boolean value from the defaults table,
191 * <code>false</code> if key is not present.
193 * @since 1.4
195 public static boolean getBoolean(Object key, Locale locale)
197 Boolean value = (Boolean) getLookAndFeel().getDefaults().get(key, locale);
198 return value != null ? value.booleanValue() : false;
202 * Returns a border from the defaults table.
204 public static Border getBorder(Object key)
206 return (Border) getLookAndFeel().getDefaults().get(key);
210 * Returns a border from the defaults table.
212 * @since 1.4
214 public static Border getBorder(Object key, Locale locale)
216 return (Border) getLookAndFeel().getDefaults().get(key, locale);
220 * Returns a drawing color from the defaults table.
222 public static Color getColor(Object key)
224 return (Color) getLookAndFeel().getDefaults().get(key);
228 * Returns a drawing color from the defaults table.
230 public static Color getColor(Object key, Locale locale)
232 return (Color) getLookAndFeel().getDefaults().get(key);
236 * this string can be passed to Class.forName()
238 public static String getCrossPlatformLookAndFeelClassName()
240 return "javax.swing.plaf.metal.MetalLookAndFeel";
244 * Returns the default values for this look and feel.
246 public static UIDefaults getDefaults()
248 return getLookAndFeel().getDefaults();
252 * Returns a dimension from the defaults table.
254 public static Dimension getDimension(Object key)
256 return (Dimension) getLookAndFeel().getDefaults().get(key);
260 * Returns a dimension from the defaults table.
262 public static Dimension getDimension(Object key, Locale locale)
264 return (Dimension) getLookAndFeel().getDefaults().get(key, locale);
268 * Retrieves a font from the defaults table of the current
269 * LookAndFeel.
271 * @param key an Object that specifies the font. Typically,
272 * this is a String such as
273 * <code>TitledBorder.font</code>.
275 public static Font getFont(Object key)
277 return (Font) getLookAndFeel().getDefaults().get(key);
281 * Retrieves a font from the defaults table of the current
282 * LookAndFeel.
284 * @param key an Object that specifies the font. Typically,
285 * this is a String such as
286 * <code>TitledBorder.font</code>.
288 public static Font getFont(Object key, Locale locale)
290 return (Font) getLookAndFeel().getDefaults().get(key ,locale);
294 * Returns an Icon from the defaults table.
296 public static Icon getIcon(Object key)
298 return (Icon) getLookAndFeel().getDefaults().get(key);
302 * Returns an Icon from the defaults table.
304 public static Icon getIcon(Object key, Locale locale)
306 return (Icon) getLookAndFeel().getDefaults().get(key, locale);
310 * Returns an Insets object from the defaults table.
312 public static Insets getInsets(Object key)
314 return (Insets) getLookAndFeel().getDefaults().getInsets(key);
318 * Returns an Insets object from the defaults table.
320 public static Insets getInsets(Object key, Locale locale)
322 return (Insets) getLookAndFeel().getDefaults().getInsets(key, locale);
325 public static LookAndFeelInfo[] getInstalledLookAndFeels()
327 return installed;
330 public static int getInt(Object key)
332 Integer x = (Integer) getLookAndFeel().getDefaults().get(key);
333 if (x == null)
334 return 0;
335 return x.intValue();
338 public static int getInt(Object key, Locale locale)
340 Integer x = (Integer) getLookAndFeel().getDefaults().get(key, locale);
341 if (x == null)
342 return 0;
343 return x.intValue();
346 public static LookAndFeel getLookAndFeel()
348 return look_and_feel;
352 * Returns the <code>UIDefaults</code> table of the currently active
353 * look and feel.
355 public static UIDefaults getLookAndFeelDefaults()
357 return getLookAndFeel().getDefaults();
361 * Returns a string from the defaults table.
363 public static String getString(Object key)
365 return (String) getLookAndFeel().getDefaults().get(key);
369 * Returns a string from the defaults table.
371 public static String getString(Object key, Locale locale)
373 return (String) getLookAndFeel().getDefaults().get(key, locale);
377 * Returns the name of the LookAndFeel class that implements the
378 * native systems look and feel if there is one, otherwise the name
379 * of the default cross platform LookAndFeel class.
381 public static String getSystemLookAndFeelClassName()
383 return getCrossPlatformLookAndFeelClassName();
387 * Returns the Look and Feel object that renders the target component.
389 public static ComponentUI getUI(JComponent target)
391 return getDefaults().getUI(target);
395 * Creates a new look and feel and adds it to the current array.
397 public static void installLookAndFeel(String name, String className)
402 * Adds the specified look and feel to the current array and then calls
403 * setInstalledLookAndFeels(javax.swing.UIManager.LookAndFeelInfo[]).
405 public static void installLookAndFeel(LookAndFeelInfo info)
410 * Stores an object in the defaults table.
412 public static Object put(Object key, Object value)
414 return getLookAndFeel().getDefaults().put(key,value);
418 * Replaces the current array of installed LookAndFeelInfos.
420 public static void setInstalledLookAndFeels(UIManager.LookAndFeelInfo[] infos)
425 * Set the current default look.
427 public static void setLookAndFeel(LookAndFeel newLookAndFeel)
428 throws UnsupportedLookAndFeelException
430 if (! newLookAndFeel.isSupportedLookAndFeel())
431 throw new UnsupportedLookAndFeelException(newLookAndFeel.getName());
433 if (look_and_feel != null)
434 look_and_feel.uninitialize();
436 // Set the current default look and feel using a LookAndFeel object.
437 look_and_feel = newLookAndFeel;
438 look_and_feel.initialize();
440 //revalidate();
441 //repaint();
445 * Set the current default look and feel using a class name.
447 public static void setLookAndFeel (String className)
448 throws ClassNotFoundException, InstantiationException, IllegalAccessException,
449 UnsupportedLookAndFeelException
451 Class c = Class.forName(className);
452 LookAndFeel a = (LookAndFeel) c.newInstance(); // throws class-cast-exception
453 setLookAndFeel(a);