001: /**
002: * L2FProd.com Common Components 7.3 License.
003: *
004: * Copyright 2005-2007 L2FProd.com
005: *
006: * Licensed under the Apache License, Version 2.0 (the "License");
007: * you may not use this file except in compliance with the License.
008: * You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing, software
013: * distributed under the License is distributed on an "AS IS" BASIS,
014: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015: * See the License for the specific language governing permissions and
016: * limitations under the License.
017: */package com.l2fprod.common.util;
018:
019: import java.awt.Toolkit;
020:
021: import javax.swing.UIManager;
022:
023: /**
024: * Provides methods related to the runtime environment.
025: */
026: public class OS {
027:
028: private static final boolean osIsMacOsX;
029: private static final boolean osIsWindows;
030: private static final boolean osIsWindowsXP;
031: private static final boolean osIsWindows2003;
032: private static final boolean osIsWindowsVista;
033: private static final boolean osIsLinux;
034:
035: static {
036: String os = System.getProperty("os.name").toLowerCase();
037:
038: osIsMacOsX = "mac os x".equals(os);
039: osIsWindows = os.indexOf("windows") != -1;
040: osIsWindowsXP = "windows xp".equals(os);
041: osIsWindows2003 = "windows 2003".equals(os);
042: osIsWindowsVista = "windows vista".equals(os);
043: osIsLinux = os != null && os.indexOf("linux") != -1;
044: }
045:
046: /**
047: * @return true if this VM is running on Mac OS X
048: */
049: public static boolean isMacOSX() {
050: return osIsMacOsX;
051: }
052:
053: /**
054: * @return true if this VM is running on Windows
055: */
056: public static boolean isWindows() {
057: return osIsWindows;
058: }
059:
060: /**
061: * @return true if this VM is running on Windows XP
062: */
063: public static boolean isWindowsXP() {
064: return osIsWindowsXP;
065: }
066:
067: /**
068: * @return true if this VM is running on Windows 2003
069: */
070: public static boolean isWindows2003() {
071: return osIsWindows2003;
072: }
073:
074: /**
075: * @return true if this VM is running on Windows Vista
076: */
077: public static boolean isWindowsVista() {
078: return osIsWindowsVista;
079: }
080:
081: /**
082: * @return true if this VM is running on a Linux distribution
083: */
084: public static boolean isLinux() {
085: return osIsLinux;
086: }
087:
088: /**
089: * @return true if the VM is running Windows and the Java
090: * application is rendered using XP Visual Styles.
091: */
092: public static boolean isUsingWindowsVisualStyles() {
093: if (!isWindows()) {
094: return false;
095: }
096:
097: boolean xpthemeActive = Boolean.TRUE.equals(Toolkit
098: .getDefaultToolkit().getDesktopProperty(
099: "win.xpstyle.themeActive"));
100: if (!xpthemeActive) {
101: return false;
102: } else {
103: try {
104: return System.getProperty("swing.noxp") == null;
105: } catch (RuntimeException e) {
106: return true;
107: }
108: }
109: }
110:
111: /**
112: * Returns the name of the current Windows visual style.
113: * <ul>
114: * <li>it looks for a property name "win.xpstyle.name" in UIManager and if not found
115: * <li>it queries the win.xpstyle.colorName desktop property ({@link Toolkit#getDesktopProperty(java.lang.String)})
116: * </ul>
117: *
118: * @return the name of the current Windows visual style if any.
119: */
120: public static String getWindowsVisualStyle() {
121: String style = UIManager.getString("win.xpstyle.name");
122: if (style == null) {
123: // guess the name of the current XPStyle
124: // (win.xpstyle.colorName property found in awt_DesktopProperties.cpp in
125: // JDK source)
126: style = (String) Toolkit.getDefaultToolkit()
127: .getDesktopProperty("win.xpstyle.colorName");
128: }
129: return style;
130: }
131:
132: }
|