OSDN Git Service

2003-06-19 Michael Koch <konqueror@gmx.de>
[pf3gnuchains/gcc-fork.git] / libjava / javax / swing / UIManager.java
1 /* UIManager.java -- 
2    Copyright (C) 2002 Free Software Foundation, Inc.
3
4 This file is part of GNU Classpath.
5
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.
10
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.
15
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.
20
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.
25
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. */
37
38
39 package javax.swing;
40
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;
50
51 public class UIManager implements Serializable
52 {
53   static final long serialVersionUID = -5547433830339189365L;
54
55     static class LookAndFeelInfo
56     {
57         String name, clazz;
58         
59         LookAndFeelInfo(String name, 
60                         String clazz)
61         {
62             this.name  = name;
63             this.clazz = clazz;
64         }
65         String getName()      { return name;  }
66         String getClassName() { return clazz; }
67     }
68
69     
70     static LookAndFeelInfo [] installed = {
71         new LookAndFeelInfo("Metal",
72                             "javax.swing.plaf.metal.MetalLookAndFeel")
73     };
74
75     
76     static LookAndFeel[] aux_installed;
77     
78     static LookAndFeel look_and_feel  = new MetalLookAndFeel();
79     
80
81     UIManager()
82     {
83     }
84
85     public static  void addPropertyChangeListener(PropertyChangeListener listener)
86     {
87         //      Add a PropertyChangeListener to the listener list. 
88     }
89
90     public static  void addAuxiliaryLookAndFeel(LookAndFeel l)
91     {
92         //          Add a LookAndFeel to the list of auxiliary look and feels. 
93         if (aux_installed == null)
94             {
95                 aux_installed = new LookAndFeel[1];
96                 aux_installed[0] = l;
97                 return;
98             }
99         
100         LookAndFeel[] T = new LookAndFeel[ aux_installed.length+1 ];
101         System.arraycopy(aux_installed, 0,
102                          T,             0,
103                          aux_installed.length);                  
104         aux_installed = T;
105         aux_installed[aux_installed.length-1] = l;
106     }
107     
108     public static  boolean removeAuxiliaryLookAndFeel(LookAndFeel laf)
109     {
110         if (aux_installed == null)
111             return false;
112
113         for (int i=0;i<aux_installed.length;i++)
114             {
115                 if (aux_installed[i] == laf)
116                     {
117                         aux_installed[ i ] = aux_installed[aux_installed.length-1];
118                         
119                         LookAndFeel[] T = new LookAndFeel[ aux_installed.length-1 ];
120                         System.arraycopy(aux_installed, 0,
121                                          T,             0,
122                                          aux_installed.length-1);                        
123                         aux_installed = T;
124                         return true;
125                     }           
126             }
127         return false;
128     }
129
130     public static  LookAndFeel[] getAuxiliaryLookAndFeels()
131     {   return aux_installed;    }
132
133
134     public static  Object get(Object key)
135     {   return getLookAndFeel().getDefaults().get(key);    }
136     
137     /**
138      * Returns a border from the defaults table. 
139      */
140     public static  Border getBorder(Object key)
141     {
142         return (Border) getLookAndFeel().getDefaults().get(key);
143     }
144     
145     /**
146      * Returns a drawing color from the defaults table. 
147      */
148     public static  Color getColor(Object key)
149     {
150         return (Color) getLookAndFeel().getDefaults().get(key);
151     }
152
153     /**
154      * this string can be passed to Class.forName()
155      */
156     public static  String getCrossPlatformLookAndFeelClassName()
157     {   
158         return "javax.swing.plaf.metal.MetalLookAndFeel";
159     }
160
161     /**
162      * Returns the default values for this look and feel. 
163      */
164     static  UIDefaults getDefaults()
165     {
166         return getLookAndFeel().getDefaults();
167     }
168
169     /**
170      * Returns a dimension from the defaults table. 
171      */
172     static  Dimension getDimension(Object key)
173     {
174         System.out.println("UIManager.getDim");
175         return new Dimension(200,100);
176     }
177
178
179   /**
180    * Retrieves a font from the defaults table of the current
181    * LookAndFeel.
182    *
183    * @param key an Object that specifies the font. Typically,
184    *        this is a String such as
185    *        <code>&quot;TitledBorder.font&quot;</code>.
186    */
187   public static Font getFont(Object key)
188   {
189     return (Font) getLookAndFeel().getDefaults().get(key);
190   }
191
192     static  Icon getIcon(Object key)
193     //      Returns an Icon from the defaults table. 
194     {
195         return (Icon) getLookAndFeel().getDefaults().get(key);
196     }
197     static  Insets getInsets(Object key)
198     //      Returns an Insets object from the defaults table. 
199     {
200         return (Insets) getLookAndFeel().getDefaults().getInsets(key);
201     }
202
203     static LookAndFeelInfo[] getInstalledLookAndFeels()
204     {
205         return installed;
206     }
207
208     static  int getInt(Object key)
209     {
210         Integer x = (Integer) getLookAndFeel().getDefaults().get(key);
211         if (x == null)
212             return 0;
213         return x.intValue();
214     }
215     static  LookAndFeel getLookAndFeel()
216     {
217         return look_and_feel;
218     }
219
220
221   /**
222    * Returns the <code>UIDefaults</code> table of the currently active
223    * look and feel.
224    */
225   public static UIDefaults getLookAndFeelDefaults()
226   {
227     return getLookAndFeel().getDefaults();
228   }
229
230
231     static  String getString(Object key)
232     //      Returns a string from the defaults table. 
233     {
234         return (String) getLookAndFeel().getDefaults().get(key);
235     }
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. 
238     {
239         return getCrossPlatformLookAndFeelClassName();
240     }
241
242
243     public static  ComponentUI getUI(JComponent target)
244     //      Returns the L&F object that renders the target component. 
245     {
246         ComponentUI ui = getDefaults().getUI(target);
247         //System.out.println("GET-UI-> " + ui + ", for " + target);
248         return ui;
249     }
250
251
252     public static  void installLookAndFeel(String name, String className)
253     //      Creates a new look and feel and adds it to the current array. 
254     {
255     }
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[]). 
258     {
259     }
260     public static  Object put(Object key, Object value)
261     //      Stores an object in the defaults table. 
262     {
263         return getLookAndFeel().getDefaults().put(key,value);
264     }
265     public static  void removePropertyChangeListener(PropertyChangeListener listener)
266     //      Remove a PropertyChangeListener from the listener list. 
267     {
268     }
269     public static  void setInstalledLookAndFeels(UIManager.LookAndFeelInfo[] infos)
270     //      Replaces the current array of installed LookAndFeelInfos. 
271     {
272     }
273     public static  void setLookAndFeel(LookAndFeel newLookAndFeel)
274     {
275         if (look_and_feel != null)
276             look_and_feel.uninitialize();
277
278         //      Set the current default look and feel using a LookAndFeel object. 
279         look_and_feel = newLookAndFeel;
280         look_and_feel.initialize();
281         
282         //      revalidate();
283         //      repaint();
284     }
285
286     public static  void setLookAndFeel(String className)
287         throws ClassNotFoundException, 
288                InstantiationException, 
289                IllegalAccessException,
290                UnsupportedLookAndFeelException
291     {
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
295         setLookAndFeel(a);
296     }
297
298
299 }