OS.java
资源名称:swingx.zip [点击查看]
上传用户:zhengdagz
上传日期:2014-03-06
资源大小:1956k
文件大小:3k
源码类别:
xml/soap/webservice
开发平台:
Java
- /*
- * $Id: OS.java,v 1.2 2005/10/10 18:02:58 rbair Exp $
- *
- * Copyright 2004 Sun Microsystems, Inc., 4150 Network Circle,
- * Santa Clara, California 95054, U.S.A. All rights reserved.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
- */
- package org.jdesktop.swingx.util;
- import java.awt.Toolkit;
- import javax.swing.UIManager;
- /**
- * Provides methods related to the runtime environment.
- */
- public class OS {
- private static final boolean osIsMacOsX;
- private static final boolean osIsWindows;
- private static final boolean osIsWindowsXP;
- private static final boolean osIsWindows2003;
- static {
- String os = System.getProperty("os.name").toLowerCase();
- osIsMacOsX = "mac os x".equals(os);
- osIsWindows = os.indexOf("windows") != -1;
- osIsWindowsXP = "windows xp".equals(os);
- osIsWindows2003 = "windows 2003".equals(os);
- }
- /**
- * @return true if this VM is running on Mac OS X
- */
- public static boolean isMacOSX() {
- return osIsMacOsX;
- }
- /**
- * @return true if this VM is running on Windows
- */
- public static boolean isWindows() {
- return osIsWindows;
- }
- /**
- * @return true if this VM is running on Windows XP
- */
- public static boolean isWindowsXP() {
- return osIsWindowsXP;
- }
- /**
- * @return true if this VM is running on Windows 2003
- */
- public static boolean isWindows2003() {
- return osIsWindows2003;
- }
- /**
- * @return true if the VM is running Windows and the Java
- * application is rendered using XP Visual Styles.
- */
- public static boolean isUsingWindowsVisualStyles() {
- if (!isWindows()) {
- return false;
- }
- boolean xpthemeActive = Boolean.TRUE.equals(Toolkit.getDefaultToolkit()
- .getDesktopProperty("win.xpstyle.themeActive"));
- if (!xpthemeActive) {
- return false;
- } else {
- try {
- return System.getProperty("swing.noxp") == null;
- } catch (RuntimeException e) {
- return true;
- }
- }
- }
- /**
- * Returns the name of the current Windows visual style.
- * <ul>
- * <li>it looks for a property name "win.xpstyle.name" in UIManager and if not found
- * <li>it queries the win.xpstyle.colorName desktop property ({@link Toolkit#getDesktopProperty(java.lang.String)})
- * </ul>
- *
- * @return the name of the current Windows visual style if any.
- */
- public static String getWindowsVisualStyle() {
- String style = UIManager.getString("win.xpstyle.name");
- if (style == null) {
- // guess the name of the current XPStyle
- // (win.xpstyle.colorName property found in awt_DesktopProperties.cpp in
- // JDK source)
- style = (String)Toolkit.getDefaultToolkit().getDesktopProperty(
- "win.xpstyle.colorName");
- }
- return style;
- }
- }