FSF GCC merge 02/23/03
[official-gcc.git] / libjava / javax / swing / UIManager.java
blob18eebe358393a7f404f8b941d379ec8fafd3922f
1 /* UIManager.java --
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)
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. */
38 package javax.swing;
40 import java.io.*;
41 import java.awt.*;
43 import javax.swing.border.*;
44 import javax.swing.plaf.*;
45 import javax.swing.plaf.basic.*;
46 import javax.swing.plaf.metal.*;
49 import java.beans.*;
52 public class UIManager implements Serializable
54 static class LookAndFeelInfo
56 String name, clazz;
58 LookAndFeelInfo(String name,
59 String clazz)
61 this.name = name;
62 this.clazz = clazz;
64 String getName() { return name; }
65 String getClassName() { return clazz; }
69 static LookAndFeelInfo [] installed = {
70 new LookAndFeelInfo("Metal",
71 "javax.swing.plaf.metal.MetalLookAndFeel")
75 static LookAndFeel[] aux_installed;
77 static LookAndFeel look_and_feel = new MetalLookAndFeel();
80 UIManager()
84 public static void addPropertyChangeListener(PropertyChangeListener listener)
86 // Add a PropertyChangeListener to the listener list.
89 public static void addAuxiliaryLookAndFeel(LookAndFeel l)
91 // Add a LookAndFeel to the list of auxiliary look and feels.
92 if (aux_installed == null)
94 aux_installed = new LookAndFeel[1];
95 aux_installed[0] = l;
96 return;
99 LookAndFeel[] T = new LookAndFeel[ aux_installed.length+1 ];
100 System.arraycopy(aux_installed, 0,
101 T, 0,
102 aux_installed.length);
103 aux_installed = T;
104 aux_installed[aux_installed.length-1] = l;
107 public static boolean removeAuxiliaryLookAndFeel(LookAndFeel laf)
109 if (aux_installed == null)
110 return false;
112 for (int i=0;i<aux_installed.length;i++)
114 if (aux_installed[i] == laf)
116 aux_installed[ i ] = aux_installed[aux_installed.length-1];
118 LookAndFeel[] T = new LookAndFeel[ aux_installed.length-1 ];
119 System.arraycopy(aux_installed, 0,
120 T, 0,
121 aux_installed.length-1);
122 aux_installed = T;
123 return true;
126 return false;
129 public static LookAndFeel[] getAuxiliaryLookAndFeels()
130 { return aux_installed; }
133 public static Object get(Object key)
134 { return getLookAndFeel().getDefaults().get(key); }
137 * Returns a border from the defaults table.
139 public static Border getBorder(Object key)
141 return (Border) getLookAndFeel().getDefaults().get(key);
145 * Returns a drawing color from the defaults table.
147 public static Color getColor(Object key)
149 return (Color) getLookAndFeel().getDefaults().get(key);
153 * this string can be passed to Class.forName()
155 public static String getCrossPlatformLookAndFeelClassName()
157 return "javax.swing.plaf.metal.MetalLookAndFeel";
161 * Returns the default values for this look and feel.
163 static UIDefaults getDefaults()
165 return getLookAndFeel().getDefaults();
169 * Returns a dimension from the defaults table.
171 static Dimension getDimension(Object key)
173 System.out.println("UIManager.getDim");
174 return new Dimension(200,100);
176 static Font getFont(Object key)
177 // Returns a drawing font from the defaults table.
179 return (Font) getLookAndFeel().getDefaults().get(key);
181 static Icon getIcon(Object key)
182 // Returns an Icon from the defaults table.
184 return (Icon) getLookAndFeel().getDefaults().get(key);
186 static Insets getInsets(Object key)
187 // Returns an Insets object from the defaults table.
189 return (Insets) getLookAndFeel().getDefaults().getInsets(key);
192 static LookAndFeelInfo[] getInstalledLookAndFeels()
194 return installed;
197 static int getInt(Object key)
199 Integer x = (Integer) getLookAndFeel().getDefaults().get(key);
200 if (x == null)
201 return 0;
202 return x.intValue();
204 static LookAndFeel getLookAndFeel()
206 return look_and_feel;
209 static UIDefaults getLookAndFeelDefaults()
210 // Returns the default values for this look and feel.
212 return getLookAndFeel().getDefaults();
214 static String getString(Object key)
215 // Returns a string from the defaults table.
217 return (String) getLookAndFeel().getDefaults().get(key);
219 static String getSystemLookAndFeelClassName()
220 // 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.
222 return getCrossPlatformLookAndFeelClassName();
226 public static ComponentUI getUI(JComponent target)
227 // Returns the L&F object that renders the target component.
229 ComponentUI ui = getDefaults().getUI(target);
230 //System.out.println("GET-UI-> " + ui + ", for " + target);
231 return ui;
235 public static void installLookAndFeel(String name, String className)
236 // Creates a new look and feel and adds it to the current array.
239 public static void installLookAndFeel(LookAndFeelInfo info)
240 // Adds the specified look and feel to the current array and then calls setInstalledLookAndFeels(javax.swing.UIManager.LookAndFeelInfo[]).
243 public static Object put(Object key, Object value)
244 // Stores an object in the defaults table.
246 return getLookAndFeel().getDefaults().put(key,value);
248 public static void removePropertyChangeListener(PropertyChangeListener listener)
249 // Remove a PropertyChangeListener from the listener list.
252 public static void setInstalledLookAndFeels(UIManager.LookAndFeelInfo[] infos)
253 // Replaces the current array of installed LookAndFeelInfos.
256 public static void setLookAndFeel(LookAndFeel newLookAndFeel)
258 if (look_and_feel != null)
259 look_and_feel.uninitialize();
261 // Set the current default look and feel using a LookAndFeel object.
262 look_and_feel = newLookAndFeel;
263 look_and_feel.initialize();
265 // revalidate();
266 // repaint();
269 public static void setLookAndFeel(String className)
270 throws ClassNotFoundException,
271 InstantiationException,
272 IllegalAccessException,
273 UnsupportedLookAndFeelException
275 // Set the current default look and feel using a class name.
276 Class c = Class.forName(className);
277 LookAndFeel a = (LookAndFeel) c.newInstance(); // throws class-cast-exception
278 setLookAndFeel(a);