PageRenderTime 78ms CodeModel.GetById 29ms RepoModel.GetById 0ms app.codeStats 0ms

/jEdit/tags/jedit-4-0-final/org/gjt/sp/jedit/OperatingSystem.java

#
Java | 153 lines | 79 code | 15 blank | 59 comment | 28 complexity | 6f8168d85ecf4d0d5cfc5f9b6d58eeb2 MD5 | raw file
Possible License(s): BSD-3-Clause, AGPL-1.0, Apache-2.0, LGPL-2.0, LGPL-3.0, GPL-2.0, CC-BY-SA-3.0, LGPL-2.1, GPL-3.0, MPL-2.0-no-copyleft-exception, IPL-1.0
  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. package org.gjt.sp.jedit;
  20. import java.io.File;
  21. import org.gjt.sp.util.Log;
  22. /**
  23. * Contains operating system detection routines.
  24. * @author Slava Pestov
  25. * @version $Id: OperatingSystem.java 3958 2002-01-02 04:49:59Z spestov $
  26. * @since jEdit 4.0pre4
  27. */
  28. public class OperatingSystem
  29. {
  30. //{{{ isDOSDerived() method
  31. /**
  32. * Returns if we're running Windows 95/98/ME/NT/2000/XP, or OS/2.
  33. */
  34. public static final boolean isDOSDerived()
  35. {
  36. return isWindows() || isOS2();
  37. } //}}}
  38. //{{{ isWindows() method
  39. /**
  40. * Returns if we're running Windows 95/98/ME/NT/2000/XP.
  41. */
  42. public static final boolean isWindows()
  43. {
  44. return os == WINDOWS_9x || os == WINDOWS_NT;
  45. } //}}}
  46. //{{{ isWindows9x() method
  47. /**
  48. * Returns if we're running Windows 95/98/ME.
  49. */
  50. public static final boolean isWindows9x()
  51. {
  52. return os == WINDOWS_9x;
  53. } //}}}
  54. //{{{ isWindowsNT() method
  55. /**
  56. * Returns if we're running Windows NT/2000/XP.
  57. */
  58. public static final boolean isWindowsNT()
  59. {
  60. return os == WINDOWS_NT;
  61. } //}}}
  62. //{{{ isOS2() method
  63. /**
  64. * Returns if we're running OS/2.
  65. */
  66. public static final boolean isOS2()
  67. {
  68. return os == OS2;
  69. } //}}}
  70. //{{{ isUnix() method
  71. /**
  72. * Returns if we're running Unix (this includes MacOS X).
  73. */
  74. public static final boolean isUnix()
  75. {
  76. return os == UNIX || os == MAC_OS_X;
  77. } //}}}
  78. //{{{ isMacOS() method
  79. /**
  80. * Returns if we're running MacOS X.
  81. */
  82. public static final boolean isMacOS()
  83. {
  84. return os == MAC_OS_X;
  85. } //}}}
  86. //{{{ isJava14() method
  87. /**
  88. * Returns if Java 2 version 1.4 is in use.
  89. */
  90. public static final boolean hasJava14()
  91. {
  92. return java14;
  93. } //}}}
  94. //{{{ Private members
  95. private static final int UNIX = 0x31337;
  96. private static final int WINDOWS_9x = 0x640;
  97. private static final int WINDOWS_NT = 0x666;
  98. private static final int OS2 = 0xDEAD;
  99. private static final int MAC_OS_X = 0xABC;
  100. private static final int UNKNOWN = 0xBAD;
  101. private static int os;
  102. private static boolean java14;
  103. //{{{ Class initializer
  104. static
  105. {
  106. String osName = System.getProperty("os.name");
  107. if(osName.indexOf("Windows 9") != -1
  108. || osName.indexOf("Windows ME") != -1)
  109. {
  110. os = WINDOWS_9x;
  111. }
  112. else if(osName.indexOf("Windows") != -1)
  113. {
  114. os = WINDOWS_NT;
  115. }
  116. else if(osName.indexOf("OS/2") != -1)
  117. {
  118. os = OS2;
  119. }
  120. else if(File.separatorChar == '/'
  121. && new File("/dev").isDirectory())
  122. {
  123. if(osName.indexOf("Mac OS X") != -1)
  124. os = MAC_OS_X;
  125. else
  126. os = UNIX;
  127. }
  128. else
  129. {
  130. os = UNKNOWN;
  131. Log.log(Log.WARNING,OperatingSystem.class,
  132. "Unknown operating system: " + osName);
  133. }
  134. if(System.getProperty("java.version").compareTo("1.4") >= 0)
  135. java14 = true;
  136. } //}}}
  137. //}}}
  138. }