PageRenderTime 46ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

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

#
Java | 200 lines | 118 code | 19 blank | 63 comment | 33 complexity | 835b1b93a7d29f4eba736226a9e8ca5e 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.awt.Rectangle;
  21. import java.awt.Toolkit;
  22. import javax.swing.UIManager;
  23. import java.io.File;
  24. import org.gjt.sp.util.Log;
  25. /**
  26. * Operating system detection routines.
  27. * @author Slava Pestov
  28. * @version $Id: OperatingSystem.java 4461 2003-02-04 01:19:51Z spestov $
  29. * @since jEdit 4.0pre4
  30. */
  31. public class OperatingSystem
  32. {
  33. public static final Rectangle getScreenBounds()
  34. {
  35. int screenX = (int)Toolkit.getDefaultToolkit().getScreenSize().getWidth();
  36. int screenY = (int)Toolkit.getDefaultToolkit().getScreenSize().getHeight();
  37. int x, y, w, h;
  38. if (isMacOS())
  39. {
  40. x = 0;
  41. y = 22;
  42. w = screenX;
  43. h = screenY - y - 4;//shadow size
  44. }
  45. else if (isWindows())
  46. {
  47. x = -4;
  48. y = -4;
  49. w = screenX - 2*x;
  50. h = screenY - 2*y;
  51. }
  52. else
  53. {
  54. x = 0;
  55. y = 0;
  56. w = screenX;
  57. h = screenY;
  58. }
  59. return new Rectangle(x,y,w,h);
  60. }
  61. //{{{ isDOSDerived() method
  62. /**
  63. * Returns if we're running Windows 95/98/ME/NT/2000/XP, or OS/2.
  64. */
  65. public static final boolean isDOSDerived()
  66. {
  67. return isWindows() || isOS2();
  68. } //}}}
  69. //{{{ isWindows() method
  70. /**
  71. * Returns if we're running Windows 95/98/ME/NT/2000/XP.
  72. */
  73. public static final boolean isWindows()
  74. {
  75. return os == WINDOWS_9x || os == WINDOWS_NT;
  76. } //}}}
  77. //{{{ isWindows9x() method
  78. /**
  79. * Returns if we're running Windows 95/98/ME.
  80. */
  81. public static final boolean isWindows9x()
  82. {
  83. return os == WINDOWS_9x;
  84. } //}}}
  85. //{{{ isWindowsNT() method
  86. /**
  87. * Returns if we're running Windows NT/2000/XP.
  88. */
  89. public static final boolean isWindowsNT()
  90. {
  91. return os == WINDOWS_NT;
  92. } //}}}
  93. //{{{ isOS2() method
  94. /**
  95. * Returns if we're running OS/2.
  96. */
  97. public static final boolean isOS2()
  98. {
  99. return os == OS2;
  100. } //}}}
  101. //{{{ isUnix() method
  102. /**
  103. * Returns if we're running Unix (this includes MacOS X).
  104. */
  105. public static final boolean isUnix()
  106. {
  107. return os == UNIX || os == MAC_OS_X;
  108. } //}}}
  109. //{{{ isMacOS() method
  110. /**
  111. * Returns if we're running MacOS X.
  112. */
  113. public static final boolean isMacOS()
  114. {
  115. return os == MAC_OS_X;
  116. } //}}}
  117. //{{{ isMacOSLF() method
  118. /**
  119. * Returns if we're running MacOS X and using the native look and feel.
  120. */
  121. public static final boolean isMacOSLF()
  122. {
  123. return (isMacOS() && UIManager.getLookAndFeel().isNativeLookAndFeel());
  124. } //}}}
  125. //{{{ isJava14() method
  126. /**
  127. * Returns if Java 2 version 1.4 is in use.
  128. */
  129. public static final boolean hasJava14()
  130. {
  131. return java14;
  132. } //}}}
  133. //{{{ Private members
  134. private static final int UNIX = 0x31337;
  135. private static final int WINDOWS_9x = 0x640;
  136. private static final int WINDOWS_NT = 0x666;
  137. private static final int OS2 = 0xDEAD;
  138. private static final int MAC_OS_X = 0xABC;
  139. private static final int UNKNOWN = 0xBAD;
  140. private static int os;
  141. private static boolean java14;
  142. //{{{ Class initializer
  143. static
  144. {
  145. if(System.getProperty("mrj.version") != null)
  146. {
  147. os = MAC_OS_X;
  148. }
  149. else
  150. {
  151. String osName = System.getProperty("os.name");
  152. if(osName.indexOf("Windows 9") != -1
  153. || osName.indexOf("Windows M") != -1)
  154. {
  155. os = WINDOWS_9x;
  156. }
  157. else if(osName.indexOf("Windows") != -1)
  158. {
  159. os = WINDOWS_NT;
  160. }
  161. else if(osName.indexOf("OS/2") != -1)
  162. {
  163. os = OS2;
  164. }
  165. else if(File.separatorChar == '/')
  166. {
  167. os = UNIX;
  168. }
  169. else
  170. {
  171. os = UNKNOWN;
  172. Log.log(Log.WARNING,OperatingSystem.class,
  173. "Unknown operating system: " + osName);
  174. }
  175. }
  176. if(System.getProperty("java.version").compareTo("1.4") >= 0
  177. && System.getProperty("jedit.nojava14") == null)
  178. java14 = true;
  179. } //}}}
  180. //}}}
  181. }