01: /*
02: * Copyright 2005-2008 Kirill Grouchnikov, based on work by
03: * Sun Microsystems, Inc. All rights reserved.
04: *
05: * This library is free software; you can redistribute it and/or
06: * modify it under the terms of the GNU Lesser General Public
07: * License as published by the Free Software Foundation; either
08: * version 2.1 of the License, or (at your option) any later version.
09: *
10: * This library is distributed in the hope that it will be useful,
11: * but WITHOUT ANY WARRANTY; without even the implied warranty of
12: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13: * Lesser General Public License for more details.
14: *
15: * You should have received a copy of the GNU Lesser General Public
16: * License along with this library; if not, write to the Free Software
17: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18: */
19: package test;
20:
21: import java.awt.event.ActionEvent;
22: import java.awt.event.ActionListener;
23:
24: import javax.swing.*;
25:
26: public class LafChanger implements ActionListener {
27: private JFrame frame;
28:
29: private String lafClassName;
30:
31: public static JMenuItem getMenuItem(JFrame frame, String lafName,
32: String lafClassName) {
33: JMenuItem result = new JMenuItem(lafName);
34: result.addActionListener(new LafChanger(frame, lafClassName));
35: return result;
36: }
37:
38: public LafChanger(JFrame frame, String lafClassName) {
39: super ();
40: this .frame = frame;
41: this .lafClassName = lafClassName;
42: }
43:
44: public void actionPerformed(ActionEvent e) {
45: SwingUtilities.invokeLater(new Runnable() {
46: public void run() {
47: boolean was_wm_decorated = !frame.isUndecorated();
48:
49: try {
50: UIManager.setLookAndFeel(lafClassName);
51: SwingUtilities.updateComponentTreeUI(frame);
52: } catch (ClassNotFoundException cnfe) {
53: out("LAF main class '" + lafClassName
54: + "' not found");
55: } catch (Exception exc) {
56: exc.printStackTrace();
57: }
58:
59: if (JFrame.isDefaultLookAndFeelDecorated()) {
60: boolean is_wm_decorated = !UIManager
61: .getLookAndFeel()
62: .getSupportsWindowDecorations();
63: if (is_wm_decorated != was_wm_decorated) {
64: out("Changing decoration policy\n");
65: frame.setVisible(false);
66: frame.dispose();
67: frame.setUndecorated(!is_wm_decorated);
68: frame.pack();
69: frame.setVisible(true);
70: was_wm_decorated = !frame.isUndecorated();
71: }
72: }
73: }
74: });
75: }
76:
77: public static void out(Object obj) {
78: try {
79: System.out.println(obj);
80: } catch (Exception exc) {
81: // ignore - is thrown on Mac in WebStart (security access)
82: }
83: }
84: }
|