PageRenderTime 47ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

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

#
Java | 166 lines | 87 code | 16 blank | 63 comment | 28 complexity | 885b38215b495359f66895413945b6c9 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 javax.swing.UIManager;
  21. import java.io.File;
  22. import org.gjt.sp.util.Log;
  23. /**
  24. * Contains operating system detection routines.
  25. * @author Slava Pestov
  26. * @version $Id: OperatingSystem.java 4208 2002-05-29 11:19:57Z spestov $
  27. * @since jEdit 4.0pre4
  28. */
  29. public class OperatingSystem
  30. {
  31. //{{{ isDOSDerived() method
  32. /**
  33. * Returns if we're running Windows 95/98/ME/NT/2000/XP, or OS/2.
  34. */
  35. public static final boolean isDOSDerived()
  36. {
  37. return isWindows() || isOS2();
  38. } //}}}
  39. //{{{ isWindows() method
  40. /**
  41. * Returns if we're running Windows 95/98/ME/NT/2000/XP.
  42. */
  43. public static final boolean isWindows()
  44. {
  45. return os == WINDOWS_9x || os == WINDOWS_NT;
  46. } //}}}
  47. //{{{ isWindows9x() method
  48. /**
  49. * Returns if we're running Windows 95/98/ME.
  50. */
  51. public static final boolean isWindows9x()
  52. {
  53. return os == WINDOWS_9x;
  54. } //}}}
  55. //{{{ isWindowsNT() method
  56. /**
  57. * Returns if we're running Windows NT/2000/XP.
  58. */
  59. public static final boolean isWindowsNT()
  60. {
  61. return os == WINDOWS_NT;
  62. } //}}}
  63. //{{{ isOS2() method
  64. /**
  65. * Returns if we're running OS/2.
  66. */
  67. public static final boolean isOS2()
  68. {
  69. return os == OS2;
  70. } //}}}
  71. //{{{ isUnix() method
  72. /**
  73. * Returns if we're running Unix (this includes MacOS X).
  74. */
  75. public static final boolean isUnix()
  76. {
  77. return os == UNIX || os == MAC_OS_X;
  78. } //}}}
  79. //{{{ isMacOS() method
  80. /**
  81. * Returns if we're running MacOS X.
  82. */
  83. public static final boolean isMacOS()
  84. {
  85. return os == MAC_OS_X;
  86. } //}}}
  87. //{{{ isMacOSLF() method
  88. /**
  89. * Returns if we're running MacOS X and using the native L&F.
  90. */
  91. public static final boolean isMacOSLF()
  92. {
  93. return (isMacOS() && UIManager.getLookAndFeel().isNativeLookAndFeel());
  94. } //}}}
  95. //{{{ isJava14() method
  96. /**
  97. * Returns if Java 2 version 1.4 is in use.
  98. */
  99. public static final boolean hasJava14()
  100. {
  101. return java14;
  102. } //}}}
  103. //{{{ Private members
  104. private static final int UNIX = 0x31337;
  105. private static final int WINDOWS_9x = 0x640;
  106. private static final int WINDOWS_NT = 0x666;
  107. private static final int OS2 = 0xDEAD;
  108. private static final int MAC_OS_X = 0xABC;
  109. private static final int UNKNOWN = 0xBAD;
  110. private static int os;
  111. private static boolean java14;
  112. //{{{ Class initializer
  113. static
  114. {
  115. if(System.getProperty("mrj.version") != null)
  116. {
  117. os = MAC_OS_X;
  118. }
  119. else
  120. {
  121. String osName = System.getProperty("os.name");
  122. if(osName.indexOf("Windows 9") != -1
  123. || osName.indexOf("Windows ME") != -1)
  124. {
  125. os = WINDOWS_9x;
  126. }
  127. else if(osName.indexOf("Windows") != -1)
  128. {
  129. os = WINDOWS_NT;
  130. }
  131. else if(osName.indexOf("OS/2") != -1)
  132. {
  133. os = OS2;
  134. }
  135. else if(File.separatorChar == '/')
  136. {
  137. os = UNIX;
  138. }
  139. else
  140. {
  141. os = UNKNOWN;
  142. Log.log(Log.WARNING,OperatingSystem.class,
  143. "Unknown operating system: " + osName);
  144. }
  145. }
  146. if(System.getProperty("java.version").compareTo("1.4") >= 0)
  147. java14 = true;
  148. } //}}}
  149. //}}}
  150. }