001 /* 002 * $Id: OS.java,v 1.2 2005/10/10 18:02:58 rbair Exp $ 003 * 004 * Copyright 2004 Sun Microsystems, Inc., 4150 Network Circle, 005 * Santa Clara, California 95054, U.S.A. All rights reserved. 006 * 007 * This library is free software; you can redistribute it and/or 008 * modify it under the terms of the GNU Lesser General Public 009 * License as published by the Free Software Foundation; either 010 * version 2.1 of the License, or (at your option) any later version. 011 * 012 * This library is distributed in the hope that it will be useful, 013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 015 * Lesser General Public License for more details. 016 * 017 * You should have received a copy of the GNU Lesser General Public 018 * License along with this library; if not, write to the Free Software 019 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 020 */ 021 package org.jdesktop.swingx.util; 022 023 import java.awt.Toolkit; 024 025 import javax.swing.UIManager; 026 027 /** 028 * Provides methods related to the runtime environment. 029 */ 030 public class OS { 031 032 private static final boolean osIsMacOsX; 033 private static final boolean osIsWindows; 034 private static final boolean osIsWindowsXP; 035 private static final boolean osIsWindows2003; 036 037 static { 038 String os = System.getProperty("os.name").toLowerCase(); 039 040 osIsMacOsX = "mac os x".equals(os); 041 osIsWindows = os.indexOf("windows") != -1; 042 osIsWindowsXP = "windows xp".equals(os); 043 osIsWindows2003 = "windows 2003".equals(os); 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 the VM is running Windows and the Java 076 * application is rendered using XP Visual Styles. 077 */ 078 public static boolean isUsingWindowsVisualStyles() { 079 if (!isWindows()) { 080 return false; 081 } 082 083 boolean xpthemeActive = Boolean.TRUE.equals(Toolkit.getDefaultToolkit() 084 .getDesktopProperty("win.xpstyle.themeActive")); 085 if (!xpthemeActive) { 086 return false; 087 } else { 088 try { 089 return System.getProperty("swing.noxp") == null; 090 } catch (RuntimeException e) { 091 return true; 092 } 093 } 094 } 095 096 /** 097 * Returns the name of the current Windows visual style. 098 * <ul> 099 * <li>it looks for a property name "win.xpstyle.name" in UIManager and if not found 100 * <li>it queries the win.xpstyle.colorName desktop property ({@link Toolkit#getDesktopProperty(java.lang.String)}) 101 * </ul> 102 * 103 * @return the name of the current Windows visual style if any. 104 */ 105 public static String getWindowsVisualStyle() { 106 String style = UIManager.getString("win.xpstyle.name"); 107 if (style == null) { 108 // guess the name of the current XPStyle 109 // (win.xpstyle.colorName property found in awt_DesktopProperties.cpp in 110 // JDK source) 111 style = (String)Toolkit.getDefaultToolkit().getDesktopProperty( 112 "win.xpstyle.colorName"); 113 } 114 return style; 115 } 116 117 }