fixes for host gcc 4.6.1
[zpugcc/jano.git] / toolchain / gcc / libjava / javax / swing / UIManager.java
blob81e8ea54e5938fc135af14cff7e7d75d220437b7
1 /* UIManager.java --
2 Copyright (C) 2002, 2003 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 javax.swing.border.Border;
48 import javax.swing.plaf.ComponentUI;
49 import javax.swing.plaf.metal.MetalLookAndFeel;
51 public class UIManager implements Serializable
53 public static class LookAndFeelInfo
55 String name, clazz;
57 LookAndFeelInfo(String name,
58 String clazz)
60 this.name = name;
61 this.clazz = clazz;
64 String getName() { return name; }
65 String getClassName() { return clazz; }
68 private static final long serialVersionUID = -5547433830339189365L;
70 static LookAndFeelInfo [] installed = {
71 new LookAndFeelInfo ("Metal", "javax.swing.plaf.metal.MetalLookAndFeel")
74 static LookAndFeel[] aux_installed;
76 static LookAndFeel look_and_feel = new MetalLookAndFeel();
78 public UIManager()
80 // Do nothing here.
83 public static void addPropertyChangeListener (PropertyChangeListener listener)
85 // FIXME
88 public static void removePropertyChangeListener (PropertyChangeListener listener)
89 // Remove a PropertyChangeListener from the listener list.
91 // FIXME
94 /**
95 * @since 1.4
97 public static PropertyChangeListener[] getPropertyChangeListeners ()
99 // FIXME
100 throw new Error ("Not implemented");
103 public static void addAuxiliaryLookAndFeel (LookAndFeel l)
105 // Add a LookAndFeel to the list of auxiliary look and feels.
106 if (aux_installed == null)
108 aux_installed = new LookAndFeel[1];
109 aux_installed[0] = l;
110 return;
113 LookAndFeel[] T = new LookAndFeel[ aux_installed.length+1 ];
114 System.arraycopy(aux_installed, 0, T, 0, aux_installed.length);
115 aux_installed = T;
116 aux_installed[aux_installed.length-1] = l;
119 public static boolean removeAuxiliaryLookAndFeel(LookAndFeel laf)
121 if (aux_installed == null)
122 return false;
124 for (int i=0;i<aux_installed.length;i++)
126 if (aux_installed[i] == laf)
128 aux_installed[ i ] = aux_installed[aux_installed.length-1];
129 LookAndFeel[] T = new LookAndFeel[ aux_installed.length-1 ];
130 System.arraycopy (aux_installed, 0, T, 0, aux_installed.length-1);
131 aux_installed = T;
132 return true;
135 return false;
138 public static LookAndFeel[] getAuxiliaryLookAndFeels()
139 { return aux_installed; }
141 public static Object get(Object key)
142 { return getLookAndFeel().getDefaults().get(key); }
145 * Returns a border from the defaults table.
147 public static Border getBorder(Object key)
149 return (Border) getLookAndFeel().getDefaults().get(key);
153 * Returns a drawing color from the defaults table.
155 public static Color getColor(Object key)
157 return (Color) getLookAndFeel().getDefaults().get(key);
161 * this string can be passed to Class.forName()
163 public static String getCrossPlatformLookAndFeelClassName()
165 return "javax.swing.plaf.metal.MetalLookAndFeel";
169 * Returns the default values for this look and feel.
171 public static UIDefaults getDefaults()
173 return getLookAndFeel().getDefaults();
177 * Returns a dimension from the defaults table.
179 public static Dimension getDimension(Object key)
181 System.out.println("UIManager.getDim");
182 return new Dimension(200,100);
186 * Retrieves a font from the defaults table of the current
187 * LookAndFeel.
189 * @param key an Object that specifies the font. Typically,
190 * this is a String such as
191 * <code>&quot;TitledBorder.font&quot;</code>.
193 public static Font getFont(Object key)
195 return (Font) getLookAndFeel().getDefaults().get(key);
198 public static Icon getIcon(Object key)
199 // Returns an Icon from the defaults table.
201 return (Icon) getLookAndFeel().getDefaults().get(key);
204 public static Insets getInsets(Object key)
205 // Returns an Insets object from the defaults table.
207 return (Insets) getLookAndFeel().getDefaults().getInsets(key);
210 public static LookAndFeelInfo[] getInstalledLookAndFeels()
212 return installed;
215 public static int getInt(Object key)
217 Integer x = (Integer) getLookAndFeel().getDefaults().get(key);
218 if (x == null)
219 return 0;
220 return x.intValue();
223 public static LookAndFeel getLookAndFeel()
225 return look_and_feel;
229 * Returns the <code>UIDefaults</code> table of the currently active
230 * look and feel.
232 public static UIDefaults getLookAndFeelDefaults()
234 return getLookAndFeel().getDefaults();
237 public static String getString(Object key)
238 // Returns a string from the defaults table.
240 return (String) getLookAndFeel().getDefaults().get(key);
243 public static String getSystemLookAndFeelClassName()
244 // 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.
246 return getCrossPlatformLookAndFeelClassName();
249 public static ComponentUI getUI(JComponent target)
250 // Returns the L&F object that renders the target component.
252 ComponentUI ui = getDefaults().getUI(target);
253 //System.out.println("GET-UI-> " + ui + ", for " + target);
254 return ui;
257 public static void installLookAndFeel(String name, String className)
258 // Creates a new look and feel and adds it to the current array.
262 public static void installLookAndFeel(LookAndFeelInfo info)
263 // Adds the specified look and feel to the current array and then calls setInstalledLookAndFeels(javax.swing.UIManager.LookAndFeelInfo[]).
267 public static Object put(Object key, Object value)
268 // Stores an object in the defaults table.
270 return getLookAndFeel().getDefaults().put(key,value);
273 public static void setInstalledLookAndFeels(UIManager.LookAndFeelInfo[] infos)
274 // Replaces the current array of installed LookAndFeelInfos.
278 public static void setLookAndFeel(LookAndFeel newLookAndFeel)
280 if (look_and_feel != null)
281 look_and_feel.uninitialize();
283 // Set the current default look and feel using a LookAndFeel object.
284 look_and_feel = newLookAndFeel;
285 look_and_feel.initialize();
287 //revalidate();
288 //repaint();
291 public static void setLookAndFeel (String className)
292 throws ClassNotFoundException, InstantiationException, IllegalAccessException,
293 UnsupportedLookAndFeelException
295 // Set the current default look and feel using a class name.
296 Class c = Class.forName(className);
297 LookAndFeel a = (LookAndFeel) c.newInstance(); // throws class-cast-exception
298 setLookAndFeel(a);