PageRenderTime 62ms CodeModel.GetById 32ms RepoModel.GetById 1ms app.codeStats 0ms

/projects/jsXe-04_beta/src/net/sourceforge/jsxe/OperatingSystem.java

https://gitlab.com/essere.lab.public/qualitas.class-corpus
Java | 185 lines | 93 code | 21 blank | 71 comment | 34 complexity | 0ff51a441479077f5241fd3099793aed MD5 | raw file
  1. /*
  2. OperatingSystem.java
  3. :tabSize=4:indentSize=4:noTabs=true:
  4. :folding=explicit:collapseFolds=1:
  5. Copyright (C) 2002 Slava Pestov
  6. Portions Copyright (C) 2002 Ian Lewis (IanLewis@member.fsf.org)
  7. This program is free software; you can redistribute it and/or
  8. modify it under the terms of the GNU General Public License
  9. as published by the Free Software Foundation; either version 2
  10. of the License, or (at your option) any later version.
  11. This program is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. GNU General Public License for more details.
  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. Optionally, you may find a copy of the GNU General Public License
  19. from http://www.fsf.org/copyleft/gpl.txt
  20. */
  21. package net.sourceforge.jsxe;
  22. import java.awt.Rectangle;
  23. import java.awt.Toolkit;
  24. import javax.swing.UIManager;
  25. import java.io.File;
  26. /**
  27. * Operating system detection routines.
  28. * @author Slava Pestov
  29. * @author Ian Lewis (<a href="mailto:IanLewis@member.fsf.org">IanLewis@member.fsf.org</a>)
  30. * @version $Id: OperatingSystem.java,v 1.3 2005/04/15 20:00:50 ian_lewis Exp $
  31. * @since jsXe 0.4 pre1
  32. */
  33. public class OperatingSystem {
  34. //{{{ getScreenBounds()
  35. public static final Rectangle getScreenBounds() {
  36. int screenX = (int)Toolkit.getDefaultToolkit().getScreenSize().getWidth();
  37. int screenY = (int)Toolkit.getDefaultToolkit().getScreenSize().getHeight();
  38. int x, y, w, h;
  39. if (isMacOS()) {
  40. x = 0;
  41. y = 22;
  42. w = screenX;
  43. h = screenY - y - 4;//shadow size
  44. } else {
  45. if (isWindows()) {
  46. x = -4;
  47. y = -4;
  48. w = screenX - 2*x;
  49. h = screenY - 2*y;
  50. } else {
  51. x = 0;
  52. y = 0;
  53. w = screenX;
  54. h = screenY;
  55. }
  56. }
  57. return new Rectangle(x,y,w,h);
  58. }//}}}
  59. //{{{ isDOSDerived() method
  60. /**
  61. * Returns if we're running Windows 95/98/ME/NT/2000/XP, or OS/2.
  62. */
  63. public static final boolean isDOSDerived() {
  64. return isWindows() || isOS2();
  65. } //}}}
  66. //{{{ isWindows() method
  67. /**
  68. * Returns if we're running Windows 95/98/ME/NT/2000/XP.
  69. */
  70. public static final boolean isWindows() {
  71. return os == WINDOWS_9x || os == WINDOWS_NT;
  72. } //}}}
  73. //{{{ isWindows9x() method
  74. /**
  75. * Returns if we're running Windows 95/98/ME.
  76. */
  77. public static final boolean isWindows9x() {
  78. return os == WINDOWS_9x;
  79. } //}}}
  80. //{{{ isWindowsNT() method
  81. /**
  82. * Returns if we're running Windows NT/2000/XP.
  83. */
  84. public static final boolean isWindowsNT() {
  85. return os == WINDOWS_NT;
  86. } //}}}
  87. //{{{ isOS2() method
  88. /**
  89. * Returns if we're running OS/2.
  90. */
  91. public static final boolean isOS2() {
  92. return os == OS2;
  93. } //}}}
  94. //{{{ isUnix() method
  95. /**
  96. * Returns if we're running Unix (this includes MacOS X).
  97. */
  98. public static final boolean isUnix() {
  99. return os == UNIX || os == MAC_OS_X;
  100. } //}}}
  101. //{{{ isMacOS() method
  102. /**
  103. * Returns if we're running MacOS X.
  104. */
  105. public static final boolean isMacOS() {
  106. return os == MAC_OS_X;
  107. } //}}}
  108. //{{{ isMacOSLF() method
  109. /**
  110. * Returns if we're running MacOS X and using the native look and feel.
  111. */
  112. public static final boolean isMacOSLF() {
  113. return (isMacOS() && UIManager.getLookAndFeel().isNativeLookAndFeel());
  114. }//}}}
  115. //{{{ isJava14() method
  116. /**
  117. * Returns if Java 2 version 1.4 is in use.
  118. */
  119. public static final boolean hasJava14() {
  120. return java14;
  121. } //}}}
  122. //{{{ Private members
  123. private static final int UNIX = 0x31337;
  124. private static final int WINDOWS_9x = 0x640;
  125. private static final int WINDOWS_NT = 0x666;
  126. private static final int OS2 = 0xDEAD;
  127. private static final int MAC_OS_X = 0xABC;
  128. private static final int UNKNOWN = 0xBAD;
  129. private static int os;
  130. private static boolean java14;
  131. //{{{ Class initializer
  132. static {
  133. if (System.getProperty("mrj.version") != null) {
  134. os = MAC_OS_X;
  135. } else {
  136. String osName = System.getProperty("os.name");
  137. if (osName.indexOf("Windows 9") != -1 || osName.indexOf("Windows M") != -1) {
  138. os = WINDOWS_9x;
  139. } else {
  140. if (osName.indexOf("Windows") != -1) {
  141. os = WINDOWS_NT;
  142. } else {
  143. if (osName.indexOf("OS/2") != -1) {
  144. os = OS2;
  145. } else {
  146. if(File.separatorChar == '/') {
  147. os = UNIX;
  148. } else {
  149. os = UNKNOWN;
  150. }
  151. }
  152. }
  153. }
  154. }
  155. if (System.getProperty("java.version").compareTo("1.4") >= 0) {
  156. java14 = true;
  157. }
  158. } //}}}
  159. //}}}
  160. }