1:
37:
38:
39: package ;
40:
41: import ;
42: import ;
43: import ;
44: import ;
45: import ;
46: import ;
47: import ;
48:
49: import ;
50: import ;
51: import ;
52:
53: public class UIManager implements Serializable
54: {
55: public static class LookAndFeelInfo
56: {
57: String name, clazz;
58:
59: public LookAndFeelInfo(String name,
60: String clazz)
61: {
62: this.name = name;
63: this.clazz = clazz;
64: }
65:
66: public String getName()
67: {
68: return name;
69: }
70:
71: public String getClassName()
72: {
73: return clazz;
74: }
75:
76:
81: public String toString()
82: {
83: StringBuffer s = new StringBuffer();
84: s.append(getClass().getName());
85: s.append('[');
86: s.append(getName());
87: s.append(' ');
88: s.append(getClassName());
89: s.append(']');
90: return s.toString();
91: }
92: }
93:
94: private static final long serialVersionUID = -5547433830339189365L;
95:
96: static LookAndFeelInfo [] installed = {
97: new LookAndFeelInfo ("Metal", "javax.swing.plaf.metal.MetalLookAndFeel")
98: };
99:
100: static LookAndFeel[] aux_installed;
101:
102: static LookAndFeel look_and_feel = new MetalLookAndFeel();
103:
104: static
105: {
106: String defaultlaf = System.getProperty("swing.defaultlaf");
107: try {
108: if (defaultlaf != null)
109: {
110: Class lafClass = Class.forName(defaultlaf);
111: LookAndFeel laf = (LookAndFeel) lafClass.newInstance();
112: setLookAndFeel(laf);
113: }
114: }
115: catch (Exception ex)
116: {
117: System.err.println("cannot initialize Look and Feel: " + defaultlaf);
118: System.err.println("errot: " + ex.getMessage());
119: System.err.println("falling back to Metal Look and Feel");
120: }
121: }
122:
123: public UIManager()
124: {
125:
126: }
127:
128:
133: public static void addPropertyChangeListener(PropertyChangeListener listener)
134: {
135:
136: }
137:
138:
143: public static void removePropertyChangeListener(PropertyChangeListener listener)
144: {
145:
146: }
147:
148:
155: public static PropertyChangeListener[] getPropertyChangeListeners()
156: {
157:
158: throw new Error ("Not implemented");
159: }
160:
161:
164: public static void addAuxiliaryLookAndFeel (LookAndFeel l)
165: {
166: if (aux_installed == null)
167: {
168: aux_installed = new LookAndFeel[1];
169: aux_installed[0] = l;
170: return;
171: }
172:
173: LookAndFeel[] T = new LookAndFeel[ aux_installed.length+1 ];
174: System.arraycopy(aux_installed, 0, T, 0, aux_installed.length);
175: aux_installed = T;
176: aux_installed[aux_installed.length-1] = l;
177: }
178:
179: public static boolean removeAuxiliaryLookAndFeel(LookAndFeel laf)
180: {
181: if (aux_installed == null)
182: return false;
183:
184: for (int i=0;i<aux_installed.length;i++)
185: {
186: if (aux_installed[i] == laf)
187: {
188: aux_installed[ i ] = aux_installed[aux_installed.length-1];
189: LookAndFeel[] T = new LookAndFeel[ aux_installed.length-1 ];
190: System.arraycopy (aux_installed, 0, T, 0, aux_installed.length-1);
191: aux_installed = T;
192: return true;
193: }
194: }
195: return false;
196: }
197:
198: public static LookAndFeel[] getAuxiliaryLookAndFeels()
199: {
200: return aux_installed;
201: }
202:
203: public static Object get(Object key)
204: {
205: return getLookAndFeel().getDefaults().get(key);
206: }
207:
208: public static Object get(Object key, Locale locale)
209: {
210: return getLookAndFeel().getDefaults().get(key ,locale);
211: }
212:
213:
219: public static boolean getBoolean(Object key)
220: {
221: Boolean value = (Boolean) getLookAndFeel().getDefaults().get(key);
222: return value != null ? value.booleanValue() : false;
223: }
224:
225:
231: public static boolean getBoolean(Object key, Locale locale)
232: {
233: Boolean value = (Boolean) getLookAndFeel().getDefaults().get(key, locale);
234: return value != null ? value.booleanValue() : false;
235: }
236:
237:
240: public static Border getBorder(Object key)
241: {
242: return (Border) getLookAndFeel().getDefaults().get(key);
243: }
244:
245:
250: public static Border getBorder(Object key, Locale locale)
251: {
252: return (Border) getLookAndFeel().getDefaults().get(key, locale);
253: }
254:
255:
258: public static Color getColor(Object key)
259: {
260: return (Color) getLookAndFeel().getDefaults().get(key);
261: }
262:
263:
266: public static Color getColor(Object key, Locale locale)
267: {
268: return (Color) getLookAndFeel().getDefaults().get(key);
269: }
270:
271:
274: public static String getCrossPlatformLookAndFeelClassName()
275: {
276: return "javax.swing.plaf.metal.MetalLookAndFeel";
277: }
278:
279:
282: public static UIDefaults getDefaults()
283: {
284: return getLookAndFeel().getDefaults();
285: }
286:
287:
290: public static Dimension getDimension(Object key)
291: {
292: return (Dimension) getLookAndFeel().getDefaults().get(key);
293: }
294:
295:
298: public static Dimension getDimension(Object key, Locale locale)
299: {
300: return (Dimension) getLookAndFeel().getDefaults().get(key, locale);
301: }
302:
303:
311: public static Font getFont(Object key)
312: {
313: return (Font) getLookAndFeel().getDefaults().get(key);
314: }
315:
316:
324: public static Font getFont(Object key, Locale locale)
325: {
326: return (Font) getLookAndFeel().getDefaults().get(key ,locale);
327: }
328:
329:
332: public static Icon getIcon(Object key)
333: {
334: return (Icon) getLookAndFeel().getDefaults().get(key);
335: }
336:
337:
340: public static Icon getIcon(Object key, Locale locale)
341: {
342: return (Icon) getLookAndFeel().getDefaults().get(key, locale);
343: }
344:
345:
348: public static Insets getInsets(Object key)
349: {
350: return (Insets) getLookAndFeel().getDefaults().getInsets(key);
351: }
352:
353:
356: public static Insets getInsets(Object key, Locale locale)
357: {
358: return (Insets) getLookAndFeel().getDefaults().getInsets(key, locale);
359: }
360:
361: public static LookAndFeelInfo[] getInstalledLookAndFeels()
362: {
363: return installed;
364: }
365:
366: public static int getInt(Object key)
367: {
368: Integer x = (Integer) getLookAndFeel().getDefaults().get(key);
369: if (x == null)
370: return 0;
371: return x.intValue();
372: }
373:
374: public static int getInt(Object key, Locale locale)
375: {
376: Integer x = (Integer) getLookAndFeel().getDefaults().get(key, locale);
377: if (x == null)
378: return 0;
379: return x.intValue();
380: }
381:
382: public static LookAndFeel getLookAndFeel()
383: {
384: return look_and_feel;
385: }
386:
387:
391: public static UIDefaults getLookAndFeelDefaults()
392: {
393: return getLookAndFeel().getDefaults();
394: }
395:
396:
399: public static String getString(Object key)
400: {
401: return (String) getLookAndFeel().getDefaults().get(key);
402: }
403:
404:
407: public static String getString(Object key, Locale locale)
408: {
409: return (String) getLookAndFeel().getDefaults().get(key, locale);
410: }
411:
412:
417: public static String getSystemLookAndFeelClassName()
418: {
419: return getCrossPlatformLookAndFeelClassName();
420: }
421:
422:
425: public static ComponentUI getUI(JComponent target)
426: {
427: return getDefaults().getUI(target);
428: }
429:
430:
433: public static void installLookAndFeel(String name, String className)
434: {
435: }
436:
437:
441: public static void installLookAndFeel(LookAndFeelInfo info)
442: {
443: }
444:
445:
448: public static Object put(Object key, Object value)
449: {
450: return getLookAndFeel().getDefaults().put(key,value);
451: }
452:
453:
456: public static void setInstalledLookAndFeels(UIManager.LookAndFeelInfo[] infos)
457: {
458: }
459:
460:
463: public static void setLookAndFeel(LookAndFeel newLookAndFeel)
464: throws UnsupportedLookAndFeelException
465: {
466: if (! newLookAndFeel.isSupportedLookAndFeel())
467: throw new UnsupportedLookAndFeelException(newLookAndFeel.getName());
468:
469: if (look_and_feel != null)
470: look_and_feel.uninitialize();
471:
472:
473: look_and_feel = newLookAndFeel;
474: look_and_feel.initialize();
475:
476:
477:
478: }
479:
480:
483: public static void setLookAndFeel (String className)
484: throws ClassNotFoundException, InstantiationException, IllegalAccessException,
485: UnsupportedLookAndFeelException
486: {
487: Class c = Class.forName(className);
488: LookAndFeel a = (LookAndFeel) c.newInstance();
489: setLookAndFeel(a);
490: }
491: }