01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * 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;
22: import java.util.HashSet;
23: import java.util.Set;
24:
25: import javax.swing.SwingUtilities;
26: import javax.swing.UIManager;
27: import javax.swing.UnsupportedLookAndFeelException;
28:
29: import org.apache.jmeter.gui.GuiPackage;
30: import org.apache.jmeter.util.JMeterUtils;
31:
32: /**
33: * @author Brendan Burns
34: * @version $Revision: 493779 $
35: */
36: public class LookAndFeelCommand implements Command {
37:
38: private static Set commands = new HashSet();
39: static {
40: UIManager.LookAndFeelInfo[] lfs = UIManager
41: .getInstalledLookAndFeels();
42: for (int i = 0; i < lfs.length; i++) {
43: commands
44: .add(ActionNames.LAF_PREFIX + lfs[i].getClassName());
45: }
46:
47: try {
48: String defaultUI = JMeterUtils.getPropDefault("jmeter.laf",
49: UIManager.getCrossPlatformLookAndFeelClassName());
50: UIManager.setLookAndFeel(defaultUI);
51: } catch (IllegalAccessException e) {
52: } catch (ClassNotFoundException e) {
53: } catch (InstantiationException e) {
54: } catch (UnsupportedLookAndFeelException e) {
55: }
56: }
57:
58: public LookAndFeelCommand() {
59: }
60:
61: public void doAction(ActionEvent ev) {
62: try {
63: String className = ev.getActionCommand().substring(4)
64: .replace('/', '.');
65: UIManager.setLookAndFeel(className);
66: SwingUtilities.updateComponentTreeUI(GuiPackage
67: .getInstance().getMainFrame());
68: } catch (javax.swing.UnsupportedLookAndFeelException e) {
69: JMeterUtils.reportErrorToUser("Look and Feel unavailable:"
70: + e.toString());
71: } catch (InstantiationException e) {
72: JMeterUtils.reportErrorToUser("Look and Feel unavailable:"
73: + e.toString());
74: } catch (ClassNotFoundException e) {
75: JMeterUtils.reportErrorToUser("Look and Feel unavailable:"
76: + e.toString());
77: } catch (IllegalAccessException e) {
78: JMeterUtils.reportErrorToUser("Look and Feel unavailable:"
79: + e.toString());
80: }
81: }
82:
83: public Set getActionNames() {
84: return commands;
85: }
86: }
|