KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > jmeter > gui > action > LookAndFeelCommand


1 // $Header: /home/cvs/jakarta-jmeter/src/core/org/apache/jmeter/gui/action/LookAndFeelCommand.java,v 1.5 2004/02/13 02:40:54 sebb Exp $
2
/*
3  * Copyright 2001-2004 The Apache Software Foundation.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17 */

18
19 package org.apache.jmeter.gui.action;
20
21 import java.awt.event.ActionEvent JavaDoc;
22 import java.util.HashSet JavaDoc;
23 import java.util.Set JavaDoc;
24
25 import javax.swing.SwingUtilities JavaDoc;
26 import javax.swing.UIManager JavaDoc;
27
28 import org.apache.jmeter.gui.GuiPackage;
29 import org.apache.jmeter.util.JMeterUtils;
30
31 /**
32  * @author Brendan Burns
33  * @version $Revision: 1.5 $
34  */

35 public class LookAndFeelCommand implements Command
36 {
37
38     private static Set JavaDoc commands = new HashSet JavaDoc();
39     static {
40         UIManager.LookAndFeelInfo JavaDoc[] lfs = UIManager.getInstalledLookAndFeels();
41         for (int i = 0; i < lfs.length; i++)
42         {
43             commands.add("laf:" + lfs[i].getClassName());
44         }
45
46         try
47         {
48             String JavaDoc defaultUI =
49                 JMeterUtils.getPropDefault(
50                     "jmeter.laf",
51                     UIManager.getCrossPlatformLookAndFeelClassName());
52             UIManager.setLookAndFeel(defaultUI);
53         }
54         catch (Exception JavaDoc e)
55         {
56         }
57     }
58
59     public LookAndFeelCommand()
60     {
61     }
62
63     public void doAction(ActionEvent JavaDoc ev)
64     {
65         try
66         {
67             String JavaDoc className =
68                 ev.getActionCommand().substring(4).replace('/', '.');
69             UIManager.setLookAndFeel(className);
70             SwingUtilities.updateComponentTreeUI(
71                 GuiPackage.getInstance().getMainFrame());
72         }
73         catch (javax.swing.UnsupportedLookAndFeelException JavaDoc e)
74         {
75             JMeterUtils.reportErrorToUser(
76                 "Look and Feel unavailable:" + e.toString());
77         }
78         catch (InstantiationException JavaDoc e)
79         {
80             JMeterUtils.reportErrorToUser(
81                 "Look and Feel unavailable:" + e.toString());
82         }
83         catch (ClassNotFoundException JavaDoc e)
84         {
85             JMeterUtils.reportErrorToUser(
86                 "Look and Feel unavailable:" + e.toString());
87         }
88         catch (IllegalAccessException JavaDoc e)
89         {
90             JMeterUtils.reportErrorToUser(
91                 "Look and Feel unavailable:" + e.toString());
92         }
93     }
94
95     public Set JavaDoc getActionNames()
96     {
97         return commands;
98     }
99 }
100
Popular Tags