PageRenderTime 110ms CodeModel.GetById 26ms RepoModel.GetById 0ms app.codeStats 0ms

/fstmerge/examples/jEdit/rev4676-4998/left-trunk-4998/org/gjt/sp/jedit/OperatingSystem.java

https://github.com/RoDaniel/featurehouse
Java | 299 lines | 225 code | 74 blank | 0 comment | 57 complexity | 9632461d0e36f7d8af5e0bad6b549838 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 = (int)choice.getBounds().x;
  83. int screenY = (int)choice.getBounds().y;
  84. int screenW = (int)choice.getBounds().width;
  85. int screenH = (int)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 if (isWindows())
  95. {
  96. x = screenX - 4;
  97. y = screenY - 4;
  98. w = screenW - 2*x;
  99. h = screenH - 2*y;
  100. }
  101. else
  102. {
  103. x = screenX;
  104. y = screenY;
  105. w = screenW;
  106. h = screenH;
  107. }
  108. return new Rectangle(x,y,w,h);
  109. }
  110. public static final boolean isDOSDerived()
  111. {
  112. return isWindows() || isOS2();
  113. }
  114. public static final boolean isWindows()
  115. {
  116. return os == WINDOWS_9x || os == WINDOWS_NT;
  117. }
  118. public static final boolean isWindows9x()
  119. {
  120. return os == WINDOWS_9x;
  121. }
  122. public static final boolean isWindowsNT()
  123. {
  124. return os == WINDOWS_NT;
  125. }
  126. public static final boolean isOS2()
  127. {
  128. return os == OS2;
  129. }
  130. public static final boolean isUnix()
  131. {
  132. return os == UNIX || os == MAC_OS_X;
  133. }
  134. public static final boolean isMacOS()
  135. {
  136. return os == MAC_OS_X;
  137. }
  138. public static boolean isX11()
  139. {
  140. return os == UNIX;
  141. }
  142. public static final boolean isVMS()
  143. {
  144. return os == VMS;
  145. }
  146. public static final boolean isMacOSLF()
  147. {
  148. return (isMacOS() && UIManager.getLookAndFeel().isNativeLookAndFeel());
  149. }
  150. public static final boolean hasScreenMenuBar()
  151. {
  152. if(!isMacOS())
  153. return false;
  154. else if(hasScreenMenuBar == -1)
  155. {
  156. String result = System.getProperty("apple.laf.useScreenMenuBar");
  157. if (result == null)
  158. result = System.getProperty("com.apple.macos.useScreenMenuBar");
  159. hasScreenMenuBar = ("true".equals(result)) ? 1 : 0;
  160. }
  161. return (hasScreenMenuBar == 1);
  162. }
  163. public static final boolean hasJava14()
  164. {
  165. return java14;
  166. }
  167. public static final boolean hasJava15()
  168. {
  169. return java15;
  170. }
  171. private static final int UNIX = 0x31337;
  172. private static final int WINDOWS_9x = 0x640;
  173. private static final int WINDOWS_NT = 0x666;
  174. private static final int OS2 = 0xDEAD;
  175. private static final int MAC_OS_X = 0xABC;
  176. private static final int VMS = 0xDEAD2;
  177. private static final int UNKNOWN = 0xBAD;
  178. private static int os;
  179. private static boolean java14;
  180. private static boolean java15;
  181. private static int hasScreenMenuBar = -1;
  182. static
  183. {
  184. if(System.getProperty("mrj.version") != null)
  185. {
  186. os = MAC_OS_X;
  187. }
  188. else
  189. {
  190. String osName = System.getProperty("os.name");
  191. if(osName.indexOf("Windows 9") != -1
  192. || osName.indexOf("Windows M") != -1)
  193. {
  194. os = WINDOWS_9x;
  195. }
  196. else if(osName.indexOf("Windows") != -1)
  197. {
  198. os = WINDOWS_NT;
  199. }
  200. else if(osName.indexOf("OS/2") != -1)
  201. {
  202. os = OS2;
  203. }
  204. else if(osName.indexOf("VMS") != -1)
  205. {
  206. os = VMS;
  207. }
  208. else if(File.separatorChar == '/')
  209. {
  210. os = UNIX;
  211. }
  212. else
  213. {
  214. os = UNKNOWN;
  215. Log.log(Log.WARNING,OperatingSystem.class,
  216. "Unknown operating system: " + osName);
  217. }
  218. }
  219. String javaVersion = System.getProperty("jedit.force.java.version");
  220. if(javaVersion == null || javaVersion.equals(""))
  221. javaVersion = System.getProperty("java.version");
  222. java14 = (javaVersion.compareTo("1.4") >= 0);
  223. java15 = (javaVersion.compareTo("1.5") >= 0);
  224. }
  225. }