PageRenderTime 9ms CodeModel.GetById 1ms app.highlight 5ms RepoModel.GetById 1ms app.codeStats 0ms

/jEdit/tags/jedit-4-1-pre5/org/gjt/sp/jedit/OperatingSystem.java

#
Java | 166 lines | 87 code | 16 blank | 63 comment | 28 complexity | 885b38215b495359f66895413945b6c9 MD5 | raw file
  1/*
  2 * OperatingSystem.java - OS detection
  3 * Copyright (C) 2002 Slava Pestov
  4 *
  5 * This program is free software; you can redistribute it and/or
  6 * modify it under the terms of the GNU General Public License
  7 * as published by the Free Software Foundation; either version 2
  8 * of the License, or any later version.
  9 *
 10 * This program is distributed in the hope that it will be useful,
 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 13 * GNU General Public License for more details.
 14 *
 15 * You should have received a copy of the GNU General Public License
 16 * along with this program; if not, write to the Free Software
 17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 18 */
 19
 20package org.gjt.sp.jedit;
 21
 22import javax.swing.UIManager;
 23import java.io.File;
 24import org.gjt.sp.util.Log;
 25
 26/**
 27 * Contains operating system detection routines.
 28 * @author Slava Pestov
 29 * @version $Id: OperatingSystem.java 4208 2002-05-29 11:19:57Z spestov $
 30 * @since jEdit 4.0pre4
 31 */
 32public class OperatingSystem
 33{
 34	//{{{ isDOSDerived() method
 35	/**
 36	 * Returns if we're running Windows 95/98/ME/NT/2000/XP, or OS/2.
 37	 */
 38	public static final boolean isDOSDerived()
 39	{
 40		return isWindows() || isOS2();
 41	} //}}}
 42
 43	//{{{ isWindows() method
 44	/**
 45	 * Returns if we're running Windows 95/98/ME/NT/2000/XP.
 46	 */
 47	public static final boolean isWindows()
 48	{
 49		return os == WINDOWS_9x || os == WINDOWS_NT;
 50	} //}}}
 51
 52	//{{{ isWindows9x() method
 53	/**
 54	 * Returns if we're running Windows 95/98/ME.
 55	 */
 56	public static final boolean isWindows9x()
 57	{
 58		return os == WINDOWS_9x;
 59	} //}}}
 60
 61	//{{{ isWindowsNT() method
 62	/**
 63	 * Returns if we're running Windows NT/2000/XP.
 64	 */
 65	public static final boolean isWindowsNT()
 66	{
 67		return os == WINDOWS_NT;
 68	} //}}}
 69
 70	//{{{ isOS2() method
 71	/**
 72	 * Returns if we're running OS/2.
 73	 */
 74	public static final boolean isOS2()
 75	{
 76		return os == OS2;
 77	} //}}}
 78
 79	//{{{ isUnix() method
 80	/**
 81	 * Returns if we're running Unix (this includes MacOS X).
 82	 */
 83	public static final boolean isUnix()
 84	{
 85		return os == UNIX || os == MAC_OS_X;
 86	} //}}}
 87
 88	//{{{ isMacOS() method
 89	/**
 90	 * Returns if we're running MacOS X.
 91	 */
 92	public static final boolean isMacOS()
 93	{
 94		return os == MAC_OS_X;
 95	} //}}}
 96
 97	//{{{ isMacOSLF() method
 98        /**
 99         * Returns if we're running MacOS X and using the native L&F.
100         */
101        public static final boolean isMacOSLF()
102        {
103                return (isMacOS() && UIManager.getLookAndFeel().isNativeLookAndFeel());
104        } //}}}
105
106	//{{{ isJava14() method
107	/**
108	 * Returns if Java 2 version 1.4 is in use.
109	 */
110	public static final boolean hasJava14()
111	{
112		return java14;
113	} //}}}
114
115	//{{{ Private members
116	private static final int UNIX = 0x31337;
117	private static final int WINDOWS_9x = 0x640;
118	private static final int WINDOWS_NT = 0x666;
119	private static final int OS2 = 0xDEAD;
120	private static final int MAC_OS_X = 0xABC;
121	private static final int UNKNOWN = 0xBAD;
122
123	private static int os;
124	private static boolean java14;
125
126	//{{{ Class initializer
127	static
128	{
129		if(System.getProperty("mrj.version") != null)
130		{
131			os = MAC_OS_X;
132		}
133		else
134		{
135			String osName = System.getProperty("os.name");
136			if(osName.indexOf("Windows 9") != -1
137				|| osName.indexOf("Windows ME") != -1)
138			{
139				os = WINDOWS_9x;
140			}
141			else if(osName.indexOf("Windows") != -1)
142			{
143				os = WINDOWS_NT;
144			}
145			else if(osName.indexOf("OS/2") != -1)
146			{
147				os = OS2;
148			}
149			else if(File.separatorChar == '/')
150			{
151				os = UNIX;
152			}
153			else
154			{
155				os = UNKNOWN;
156				Log.log(Log.WARNING,OperatingSystem.class,
157					"Unknown operating system: " + osName);
158			}
159		}
160
161		if(System.getProperty("java.version").compareTo("1.4") >= 0)
162			java14 = true;
163	} //}}}
164
165	//}}}
166}