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

/fstmerge/examples/jEdit/rev9022-9450/base-trunk-9022/org/gjt/sp/jedit/OperatingSystem.java

https://github.com/RoDaniel/featurehouse
Java | 302 lines | 222 code | 80 blank | 0 comment | 56 complexity | 01a4d089c434861c8b0890769e9c9d05 MD5 | raw file
  1. package org.gjt.sp.jedit;
  2. import java.awt.GraphicsConfiguration;
  3. import java.awt.GraphicsDevice;
  4. import java.awt.GraphicsEnvironment;
  5. import java.awt.Rectangle;
  6. import java.awt.Toolkit;
  7. import javax.swing.UIManager;
  8. import java.io.File;
  9. import java.util.Enumeration;
  10. import java.util.Vector;
  11. import org.gjt.sp.util.Log;
  12. public class OperatingSystem
  13. {
  14. public static final Rectangle getScreenBounds()
  15. {
  16. int screenX = (int)Toolkit.getDefaultToolkit().getScreenSize().getWidth();
  17. int screenY = (int)Toolkit.getDefaultToolkit().getScreenSize().getHeight();
  18. int x, y, w, h;
  19. if (isMacOS())
  20. {
  21. x = 0;
  22. y = 22;
  23. w = screenX;
  24. h = screenY - y - 4;
  25. }
  26. else if (isWindows())
  27. {
  28. x = -4;
  29. y = -4;
  30. w = screenX - 2*x;
  31. h = screenY - 2*y;
  32. }
  33. else
  34. {
  35. x = 0;
  36. y = 0;
  37. w = screenX;
  38. h = screenY;
  39. }
  40. return new Rectangle(x,y,w,h);
  41. }
  42. public static final Rectangle getScreenBounds(Rectangle window)
  43. {
  44. GraphicsDevice[] gd = GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices();
  45. Vector intersects = new Vector();
  46. for (int i=0; i < gd.length; i++)
  47. {
  48. GraphicsConfiguration gc = gd[i]
  49. .getDefaultConfiguration();
  50. if (window.intersects(gc.getBounds()))
  51. {
  52. for (Enumeration e = intersects.elements(); e.hasMoreElements();)
  53. {
  54. GraphicsConfiguration gcc = (GraphicsConfiguration)e.nextElement();
  55. if (gcc.getBounds().equals(gc.getBounds()))
  56. break;
  57. }
  58. intersects.add(gc);
  59. }
  60. }
  61. GraphicsConfiguration choice = null;
  62. if (intersects.size() > 0)
  63. {
  64. for (Enumeration e = intersects.elements(); e.hasMoreElements();)
  65. {
  66. GraphicsConfiguration gcc = (GraphicsConfiguration)e.nextElement();
  67. if (choice == null)
  68. choice = gcc;
  69. else
  70. {
  71. Rectangle int1 = choice.getBounds().intersection(window);
  72. Rectangle int2 = gcc.getBounds().intersection(window);
  73. int area1 = int1.width * int1.height;
  74. int area2 = int2.width * int2.height;
  75. if (area2 > area1)
  76. choice = gcc;
  77. }
  78. }
  79. }
  80. else
  81. choice = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration();
  82. int screenX = choice.getBounds().x;
  83. int screenY = choice.getBounds().y;
  84. int screenW = choice.getBounds().width;
  85. int screenH = choice.getBounds().height;
  86. int x, y, w, h;
  87. if (isMacOS())
  88. {
  89. x = screenX;
  90. y = screenY + 22;
  91. w = screenW;
  92. h = screenH - y - 4;
  93. }
  94. else
  95. {
  96. x = screenX;
  97. y = screenY;
  98. w = screenW;
  99. h = screenH;
  100. }
  101. return new Rectangle(x,y,w,h);
  102. }
  103. public static final boolean isDOSDerived()
  104. {
  105. return isWindows() || isOS2();
  106. }
  107. public static final boolean isWindows()
  108. {
  109. return os == WINDOWS_9x || os == WINDOWS_NT;
  110. }
  111. public static final boolean isWindows9x()
  112. {
  113. return os == WINDOWS_9x;
  114. }
  115. public static final boolean isWindowsNT()
  116. {
  117. return os == WINDOWS_NT;
  118. }
  119. public static final boolean isOS2()
  120. {
  121. return os == OS2;
  122. }
  123. public static final boolean isUnix()
  124. {
  125. return os == UNIX || os == MAC_OS_X;
  126. }
  127. public static final boolean isMacOS()
  128. {
  129. return os == MAC_OS_X;
  130. }
  131. public static boolean isX11()
  132. {
  133. return os == UNIX;
  134. }
  135. public static final boolean isVMS()
  136. {
  137. return os == VMS;
  138. }
  139. public static final boolean isMacOSLF()
  140. {
  141. return (isMacOS() && UIManager.getLookAndFeel().isNativeLookAndFeel());
  142. }
  143. public static final boolean hasScreenMenuBar()
  144. {
  145. if(!isMacOS())
  146. return false;
  147. else if(hasScreenMenuBar == -1)
  148. {
  149. String result = System.getProperty("apple.laf.useScreenMenuBar");
  150. if (result == null)
  151. result = System.getProperty("com.apple.macos.useScreenMenuBar");
  152. hasScreenMenuBar = ("true".equals(result)) ? 1 : 0;
  153. }
  154. return (hasScreenMenuBar == 1);
  155. }
  156. public static final boolean hasJava14()
  157. {
  158. return java14;
  159. }
  160. public static final boolean hasJava15()
  161. {
  162. return java15;
  163. }
  164. public static boolean isCaseInsensitiveFS()
  165. {
  166. return isDOSDerived() || isMacOS();
  167. }
  168. private static final int UNIX = 0x31337;
  169. private static final int WINDOWS_9x = 0x640;
  170. private static final int WINDOWS_NT = 0x666;
  171. private static final int OS2 = 0xDEAD;
  172. private static final int MAC_OS_X = 0xABC;
  173. private static final int VMS = 0xDEAD2;
  174. private static final int UNKNOWN = 0xBAD;
  175. private static int os;
  176. private static boolean java14;
  177. private static boolean java15;
  178. private static int hasScreenMenuBar = -1;
  179. static
  180. {
  181. if(System.getProperty("mrj.version") != null)
  182. {
  183. os = MAC_OS_X;
  184. }
  185. else
  186. {
  187. String osName = System.getProperty("os.name");
  188. if(osName.indexOf("Windows 9") != -1
  189. || osName.indexOf("Windows M") != -1)
  190. {
  191. os = WINDOWS_9x;
  192. }
  193. else if(osName.indexOf("Windows") != -1)
  194. {
  195. os = WINDOWS_NT;
  196. }
  197. else if(osName.indexOf("OS/2") != -1)
  198. {
  199. os = OS2;
  200. }
  201. else if(osName.indexOf("VMS") != -1)
  202. {
  203. os = VMS;
  204. }
  205. else if(File.separatorChar == '/')
  206. {
  207. os = UNIX;
  208. }
  209. else
  210. {
  211. os = UNKNOWN;
  212. Log.log(Log.WARNING,OperatingSystem.class,
  213. "Unknown operating system: " + osName);
  214. }
  215. }
  216. String javaVersion = System.getProperty("jedit.force.java.version");
  217. if(javaVersion == null || javaVersion.equals(""))
  218. javaVersion = System.getProperty("java.version");
  219. java14 = (javaVersion.compareTo("1.4") >= 0);
  220. java15 = (javaVersion.compareTo("1.5") >= 0);
  221. }
  222. }