KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > util > Util


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.util;
21
22 import javax.swing.LookAndFeel JavaDoc;
23 import javax.swing.UIManager JavaDoc;
24
25 /**
26  * Provides utility methods
27  *
28  * @author Marek Slama
29  */

30
31 public class Util {
32
33     /** Creates a new instance of Utilities */
34     private Util() {
35     }
36
37     /** Tries to set default L&F according to platform.
38      * Uses:
39      * Metal L&F on Linux and Solaris
40      * Windows L&F on Windows
41      * Aqua L&F on Mac OS X
42      * System L&F on other OS
43      */

44     public static void setDefaultLookAndFeel () {
45         String JavaDoc uiClassName;
46         if (isWindowsOS()) {
47             uiClassName = "com.sun.java.swing.plaf.windows.WindowsLookAndFeel"; //NOI18N
48
} else if (isMacOSX()) {
49             uiClassName = "apple.laf.AquaLookAndFeel"; //NOI18N
50
} else if (isLinuxOS() || isSunOS()) {
51             uiClassName = "javax.swing.plaf.metal.MetalLookAndFeel"; //NOI18N
52
} else {
53             uiClassName = UIManager.getSystemLookAndFeelClassName();
54         }
55         if (uiClassName.equals(UIManager.getLookAndFeel().getClass().getName())) {
56             //Desired L&F is already set
57
return;
58         }
59         try {
60             UIManager.setLookAndFeel(uiClassName);
61         } catch (Exception JavaDoc ex) {
62             System.err.println("Cannot set L&F " + uiClassName); //NOI18N
63
System.err.println("Exception:" + ex.getMessage()); //NOI18N
64
ex.printStackTrace();
65         }
66     }
67     
68     private static boolean isWindowsOS() {
69         return System.getProperty("os.name").startsWith("Windows"); //NOI18N
70
}
71     
72     private static boolean isLinuxOS() {
73         return System.getProperty("os.name").startsWith("Lin"); //NOI18N
74
}
75     
76     private static boolean isSunOS() {
77         return System.getProperty("os.name").startsWith("Sun"); //NOI18N
78
}
79     
80     private static boolean isMacOSX() {
81         return System.getProperty("os.name").startsWith("Mac OS X"); //NOI18N
82
}
83     
84 }
85
86
Popular Tags