OS.java
上传用户:zhengdagz
上传日期:2014-03-06
资源大小:1956k
文件大小:3k
源码类别:

xml/soap/webservice

开发平台:

Java

  1. /*
  2.  * $Id: OS.java,v 1.2 2005/10/10 18:02:58 rbair Exp $
  3.  *
  4.  * Copyright 2004 Sun Microsystems, Inc., 4150 Network Circle,
  5.  * Santa Clara, California 95054, U.S.A. All rights reserved.
  6.  *
  7.  * This library is free software; you can redistribute it and/or
  8.  * modify it under the terms of the GNU Lesser General Public
  9.  * License as published by the Free Software Foundation; either
  10.  * version 2.1 of the License, or (at your option) any later version.
  11.  * 
  12.  * This library is distributed in the hope that it will be useful,
  13.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  15.  * Lesser General Public License for more details.
  16.  * 
  17.  * You should have received a copy of the GNU Lesser General Public
  18.  * License along with this library; if not, write to the Free Software
  19.  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
  20.  */
  21. package org.jdesktop.swingx.util;
  22. import java.awt.Toolkit;
  23. import javax.swing.UIManager;
  24. /**
  25.  * Provides methods related to the runtime environment.
  26.  */
  27. public class OS {
  28.   private static final boolean osIsMacOsX;
  29.   private static final boolean osIsWindows;
  30.   private static final boolean osIsWindowsXP;
  31.   private static final boolean osIsWindows2003;
  32.   static {
  33.     String os = System.getProperty("os.name").toLowerCase();
  34.     osIsMacOsX = "mac os x".equals(os);
  35.     osIsWindows = os.indexOf("windows") != -1;
  36.     osIsWindowsXP = "windows xp".equals(os);
  37.     osIsWindows2003 = "windows 2003".equals(os);
  38.   }
  39.   /**
  40.    * @return true if this VM is running on Mac OS X
  41.    */
  42.   public static boolean isMacOSX() {
  43.     return osIsMacOsX;
  44.   }
  45.   /**
  46.    * @return true if this VM is running on Windows
  47.    */
  48.   public static boolean isWindows() {
  49.     return osIsWindows;
  50.   }
  51.   /**
  52.    * @return true if this VM is running on Windows XP
  53.    */
  54.   public static boolean isWindowsXP() {
  55.     return osIsWindowsXP;
  56.   }
  57.   /**
  58.    * @return true if this VM is running on Windows 2003
  59.    */
  60.   public static boolean isWindows2003() {
  61.     return osIsWindows2003;
  62.   }
  63.   /**
  64.    * @return true if the VM is running Windows and the Java
  65.    *         application is rendered using XP Visual Styles.
  66.    */
  67.   public static boolean isUsingWindowsVisualStyles() {
  68.     if (!isWindows()) {
  69.       return false;
  70.     }
  71.     boolean xpthemeActive = Boolean.TRUE.equals(Toolkit.getDefaultToolkit()
  72.         .getDesktopProperty("win.xpstyle.themeActive"));
  73.     if (!xpthemeActive) {
  74.       return false;
  75.     } else {
  76.       try {
  77.         return System.getProperty("swing.noxp") == null;
  78.       } catch (RuntimeException e) {
  79.         return true;
  80.       }
  81.     }
  82.   }
  83.   /**
  84.    * Returns the name of the current Windows visual style.
  85.    * <ul>
  86.    * <li>it looks for a property name "win.xpstyle.name" in UIManager and if not found
  87.    * <li>it queries the win.xpstyle.colorName desktop property ({@link Toolkit#getDesktopProperty(java.lang.String)})
  88.    * </ul>
  89.    * 
  90.    * @return the name of the current Windows visual style if any. 
  91.    */
  92.   public static String getWindowsVisualStyle() {
  93.     String style = UIManager.getString("win.xpstyle.name");
  94.     if (style == null) {
  95.       // guess the name of the current XPStyle
  96.       // (win.xpstyle.colorName property found in awt_DesktopProperties.cpp in
  97.       // JDK source)
  98.       style = (String)Toolkit.getDefaultToolkit().getDesktopProperty(
  99.         "win.xpstyle.colorName");
  100.     }
  101.     return style;
  102.   }
  103.   
  104. }