2 Copyright (C) 2002 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)
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
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
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. */
41 import java.awt.Color;
42 import java.awt.Dimension;
44 import java.awt.Insets;
45 import java.beans.PropertyChangeListener;
46 import java.io.Serializable;
47 import javax.swing.border.Border;
48 import javax.swing.plaf.ComponentUI;
49 import javax.swing.plaf.metal.MetalLookAndFeel;
51 public class UIManager implements Serializable
53 static final long serialVersionUID = -5547433830339189365L;
55 static class LookAndFeelInfo
59 LookAndFeelInfo(String name,
65 String getName() { return name; }
66 String getClassName() { return clazz; }
70 static LookAndFeelInfo [] installed = {
71 new LookAndFeelInfo("Metal",
72 "javax.swing.plaf.metal.MetalLookAndFeel")
76 static LookAndFeel[] aux_installed;
78 static LookAndFeel look_and_feel = new MetalLookAndFeel();
85 public static void addPropertyChangeListener(PropertyChangeListener listener)
87 // Add a PropertyChangeListener to the listener list.
90 public static void addAuxiliaryLookAndFeel(LookAndFeel l)
92 // Add a LookAndFeel to the list of auxiliary look and feels.
93 if (aux_installed == null)
95 aux_installed = new LookAndFeel[1];
100 LookAndFeel[] T = new LookAndFeel[ aux_installed.length+1 ];
101 System.arraycopy(aux_installed, 0,
103 aux_installed.length);
105 aux_installed[aux_installed.length-1] = l;
108 public static boolean removeAuxiliaryLookAndFeel(LookAndFeel laf)
110 if (aux_installed == null)
113 for (int i=0;i<aux_installed.length;i++)
115 if (aux_installed[i] == laf)
117 aux_installed[ i ] = aux_installed[aux_installed.length-1];
119 LookAndFeel[] T = new LookAndFeel[ aux_installed.length-1 ];
120 System.arraycopy(aux_installed, 0,
122 aux_installed.length-1);
130 public static LookAndFeel[] getAuxiliaryLookAndFeels()
131 { return aux_installed; }
134 public static Object get(Object key)
135 { return getLookAndFeel().getDefaults().get(key); }
138 * Returns a border from the defaults table.
140 public static Border getBorder(Object key)
142 return (Border) getLookAndFeel().getDefaults().get(key);
146 * Returns a drawing color from the defaults table.
148 public static Color getColor(Object key)
150 return (Color) getLookAndFeel().getDefaults().get(key);
154 * this string can be passed to Class.forName()
156 public static String getCrossPlatformLookAndFeelClassName()
158 return "javax.swing.plaf.metal.MetalLookAndFeel";
162 * Returns the default values for this look and feel.
164 static UIDefaults getDefaults()
166 return getLookAndFeel().getDefaults();
170 * Returns a dimension from the defaults table.
172 static Dimension getDimension(Object key)
174 System.out.println("UIManager.getDim");
175 return new Dimension(200,100);
180 * Retrieves a font from the defaults table of the current
183 * @param key an Object that specifies the font. Typically,
184 * this is a String such as
185 * <code>"TitledBorder.font"</code>.
187 public static Font getFont(Object key)
189 return (Font) getLookAndFeel().getDefaults().get(key);
192 static Icon getIcon(Object key)
193 // Returns an Icon from the defaults table.
195 return (Icon) getLookAndFeel().getDefaults().get(key);
197 static Insets getInsets(Object key)
198 // Returns an Insets object from the defaults table.
200 return (Insets) getLookAndFeel().getDefaults().getInsets(key);
203 static LookAndFeelInfo[] getInstalledLookAndFeels()
208 static int getInt(Object key)
210 Integer x = (Integer) getLookAndFeel().getDefaults().get(key);
215 static LookAndFeel getLookAndFeel()
217 return look_and_feel;
222 * Returns the <code>UIDefaults</code> table of the currently active
225 public static UIDefaults getLookAndFeelDefaults()
227 return getLookAndFeel().getDefaults();
231 static String getString(Object key)
232 // Returns a string from the defaults table.
234 return (String) getLookAndFeel().getDefaults().get(key);
236 static String getSystemLookAndFeelClassName()
237 // Returns the name of the LookAndFeel class that implements the native systems look and feel if there is one, otherwise the name of the default cross platform LookAndFeel class.
239 return getCrossPlatformLookAndFeelClassName();
243 public static ComponentUI getUI(JComponent target)
244 // Returns the L&F object that renders the target component.
246 ComponentUI ui = getDefaults().getUI(target);
247 //System.out.println("GET-UI-> " + ui + ", for " + target);
252 public static void installLookAndFeel(String name, String className)
253 // Creates a new look and feel and adds it to the current array.
256 public static void installLookAndFeel(LookAndFeelInfo info)
257 // Adds the specified look and feel to the current array and then calls setInstalledLookAndFeels(javax.swing.UIManager.LookAndFeelInfo[]).
260 public static Object put(Object key, Object value)
261 // Stores an object in the defaults table.
263 return getLookAndFeel().getDefaults().put(key,value);
265 public static void removePropertyChangeListener(PropertyChangeListener listener)
266 // Remove a PropertyChangeListener from the listener list.
269 public static void setInstalledLookAndFeels(UIManager.LookAndFeelInfo[] infos)
270 // Replaces the current array of installed LookAndFeelInfos.
273 public static void setLookAndFeel(LookAndFeel newLookAndFeel)
275 if (look_and_feel != null)
276 look_and_feel.uninitialize();
278 // Set the current default look and feel using a LookAndFeel object.
279 look_and_feel = newLookAndFeel;
280 look_and_feel.initialize();
286 public static void setLookAndFeel(String className)
287 throws ClassNotFoundException,
288 InstantiationException,
289 IllegalAccessException,
290 UnsupportedLookAndFeelException
292 // Set the current default look and feel using a class name.
293 Class c = Class.forName(className);
294 LookAndFeel a = (LookAndFeel) c.newInstance(); // throws class-cast-exception