source: trunk/gcc/libjava/javax/swing/UIManager.java

Last change on this file was 1389, checked in by bird, 21 years ago

Initial revision

  • Property cvs2svn:cvs-rev set to 1.1
  • Property svn:eol-style set to native
  • Property svn:executable set to *
File size: 8.0 KB
Line 
1/* UIManager.java --
2 Copyright (C) 2002 Free Software Foundation, Inc.
3
4This file is part of GNU Classpath.
5
6GNU Classpath is free software; you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published by
8the Free Software Foundation; either version 2, or (at your option)
9any later version.
10
11GNU Classpath is distributed in the hope that it will be useful, but
12WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with GNU Classpath; see the file COPYING. If not, write to the
18Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
1902111-1307 USA.
20
21Linking this library statically or dynamically with other modules is
22making a combined work based on this library. Thus, the terms and
23conditions of the GNU General Public License cover the whole
24combination.
25
26As a special exception, the copyright holders of this library give you
27permission to link this library with independent modules to produce an
28executable, regardless of the license terms of these independent
29modules, and to copy and distribute the resulting executable under
30terms of your choice, provided that you also meet, for each linked
31independent module, the terms and conditions of the license of that
32module. An independent module is a module which is not derived from
33or based on this library. If you modify this library, you may extend
34this exception to your version of the library, but you are not
35obligated to do so. If you do not wish to do so, delete this
36exception statement from your version. */
37
38package javax.swing;
39
40import java.io.*;
41import java.awt.*;
42
43import javax.swing.border.*;
44import javax.swing.plaf.*;
45import javax.swing.plaf.basic.*;
46import javax.swing.plaf.metal.*;
47
48
49import java.beans.*;
50
51
52public class UIManager implements Serializable
53{
54 static class LookAndFeelInfo
55 {
56 String name, clazz;
57
58 LookAndFeelInfo(String name,
59 String clazz)
60 {
61 this.name = name;
62 this.clazz = clazz;
63 }
64 String getName() { return name; }
65 String getClassName() { return clazz; }
66 }
67
68
69 static LookAndFeelInfo [] installed = {
70 new LookAndFeelInfo("Metal",
71 "javax.swing.plaf.metal.MetalLookAndFeel")
72 };
73
74
75 static LookAndFeel[] aux_installed;
76
77 static LookAndFeel look_and_feel = new MetalLookAndFeel();
78
79
80 UIManager()
81 {
82 }
83
84 public static void addPropertyChangeListener(PropertyChangeListener listener)
85 {
86 // Add a PropertyChangeListener to the listener list.
87 }
88
89 public static void addAuxiliaryLookAndFeel(LookAndFeel l)
90 {
91 // Add a LookAndFeel to the list of auxiliary look and feels.
92 if (aux_installed == null)
93 {
94 aux_installed = new LookAndFeel[1];
95 aux_installed[0] = l;
96 return;
97 }
98
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;
105 }
106
107 public static boolean removeAuxiliaryLookAndFeel(LookAndFeel laf)
108 {
109 if (aux_installed == null)
110 return false;
111
112 for (int i=0;i<aux_installed.length;i++)
113 {
114 if (aux_installed[i] == laf)
115 {
116 aux_installed[ i ] = aux_installed[aux_installed.length-1];
117
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;
124 }
125 }
126 return false;
127 }
128
129 public static LookAndFeel[] getAuxiliaryLookAndFeels()
130 { return aux_installed; }
131
132
133 public static Object get(Object key)
134 { return getLookAndFeel().getDefaults().get(key); }
135
136 /**
137 * Returns a border from the defaults table.
138 */
139 public static Border getBorder(Object key)
140 {
141 return (Border) getLookAndFeel().getDefaults().get(key);
142 }
143
144 /**
145 * Returns a drawing color from the defaults table.
146 */
147 public static Color getColor(Object key)
148 {
149 return (Color) getLookAndFeel().getDefaults().get(key);
150 }
151
152 /**
153 * this string can be passed to Class.forName()
154 */
155 public static String getCrossPlatformLookAndFeelClassName()
156 {
157 return "javax.swing.plaf.metal.MetalLookAndFeel";
158 }
159
160 /**
161 * Returns the default values for this look and feel.
162 */
163 static UIDefaults getDefaults()
164 {
165 return getLookAndFeel().getDefaults();
166 }
167
168 /**
169 * Returns a dimension from the defaults table.
170 */
171 static Dimension getDimension(Object key)
172 {
173 System.out.println("UIManager.getDim");
174 return new Dimension(200,100);
175 }
176 static Font getFont(Object key)
177 // Returns a drawing font from the defaults table.
178 {
179 return (Font) getLookAndFeel().getDefaults().get(key);
180 }
181 static Icon getIcon(Object key)
182 // Returns an Icon from the defaults table.
183 {
184 return (Icon) getLookAndFeel().getDefaults().get(key);
185 }
186 static Insets getInsets(Object key)
187 // Returns an Insets object from the defaults table.
188 {
189 return (Insets) getLookAndFeel().getDefaults().getInsets(key);
190 }
191
192 static LookAndFeelInfo[] getInstalledLookAndFeels()
193 {
194 return installed;
195 }
196
197 static int getInt(Object key)
198 {
199 Integer x = (Integer) getLookAndFeel().getDefaults().get(key);
200 if (x == null)
201 return 0;
202 return x.intValue();
203 }
204 static LookAndFeel getLookAndFeel()
205 {
206 return look_and_feel;
207 }
208
209 static UIDefaults getLookAndFeelDefaults()
210 // Returns the default values for this look and feel.
211 {
212 return getLookAndFeel().getDefaults();
213 }
214 static String getString(Object key)
215 // Returns a string from the defaults table.
216 {
217 return (String) getLookAndFeel().getDefaults().get(key);
218 }
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.
221 {
222 return getCrossPlatformLookAndFeelClassName();
223 }
224
225
226 public static ComponentUI getUI(JComponent target)
227 // Returns the L&F object that renders the target component.
228 {
229 ComponentUI ui = getDefaults().getUI(target);
230 //System.out.println("GET-UI-> " + ui + ", for " + target);
231 return ui;
232 }
233
234
235 public static void installLookAndFeel(String name, String className)
236 // Creates a new look and feel and adds it to the current array.
237 {
238 }
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[]).
241 {
242 }
243 public static Object put(Object key, Object value)
244 // Stores an object in the defaults table.
245 {
246 return getLookAndFeel().getDefaults().put(key,value);
247 }
248 public static void removePropertyChangeListener(PropertyChangeListener listener)
249 // Remove a PropertyChangeListener from the listener list.
250 {
251 }
252 public static void setInstalledLookAndFeels(UIManager.LookAndFeelInfo[] infos)
253 // Replaces the current array of installed LookAndFeelInfos.
254 {
255 }
256 public static void setLookAndFeel(LookAndFeel newLookAndFeel)
257 {
258 if (look_and_feel != null)
259 look_and_feel.uninitialize();
260
261 // Set the current default look and feel using a LookAndFeel object.
262 look_and_feel = newLookAndFeel;
263 look_and_feel.initialize();
264
265 // revalidate();
266 // repaint();
267 }
268
269 public static void setLookAndFeel(String className)
270 throws ClassNotFoundException,
271 InstantiationException,
272 IllegalAccessException,
273 UnsupportedLookAndFeelException
274 {
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);
279 }
280
281
282}
Note: See TracBrowser for help on using the repository browser.