1 22 23 package org.gjt.sp.jedit; 24 25 import java.awt.GraphicsConfiguration ; 26 import java.awt.GraphicsDevice ; 27 import java.awt.GraphicsEnvironment ; 28 import java.awt.Rectangle ; 29 import java.awt.Toolkit ; 30 import javax.swing.UIManager ; 31 import java.io.File ; 32 import java.util.Enumeration ; 33 import java.util.Vector ; 34 import org.gjt.sp.util.Log; 35 36 42 public class OperatingSystem 43 { 44 48 public static final Rectangle getScreenBounds() 49 { 50 int screenX = (int)Toolkit.getDefaultToolkit().getScreenSize().getWidth(); 51 int screenY = (int)Toolkit.getDefaultToolkit().getScreenSize().getHeight(); 52 int x, y, w, h; 53 54 if (isMacOS()) 55 { 56 x = 0; 57 y = 22; 58 w = screenX; 59 h = screenY - y - 4; } 61 else if (isWindows()) 62 { 63 x = -4; 64 y = -4; 65 w = screenX - 2*x; 66 h = screenY - 2*y; 67 } 68 else 69 { 70 x = 0; 71 y = 0; 72 w = screenX; 73 h = screenY; 74 } 75 76 return new Rectangle (x,y,w,h); 77 } 79 84 public static final Rectangle getScreenBounds(Rectangle window) 85 { 86 GraphicsDevice [] gd = GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices(); 87 Vector intersects = new Vector (); 88 89 for (int i=0; i < gd.length; i++) 93 { 94 GraphicsConfiguration gc = gd[i] 95 .getDefaultConfiguration(); 96 if (window.intersects(gc.getBounds())) 98 { 99 for (Enumeration e = intersects.elements(); e.hasMoreElements();) 100 { 101 GraphicsConfiguration gcc = (GraphicsConfiguration )e.nextElement(); 102 if (gcc.getBounds().equals(gc.getBounds())) 103 break; 104 } 105 intersects.add(gc); 106 } 107 } 108 109 GraphicsConfiguration choice = null; 110 if (intersects.size() > 0) 111 { 112 for (Enumeration e = intersects.elements(); e.hasMoreElements();) 114 { 115 GraphicsConfiguration gcc = (GraphicsConfiguration )e.nextElement(); 116 if (choice == null) 117 choice = gcc; 118 else 119 { 120 Rectangle int1 = choice.getBounds().intersection(window); 121 Rectangle int2 = gcc.getBounds().intersection(window); 122 int area1 = int1.width * int1.height; 123 int area2 = int2.width * int2.height; 124 if (area2 > area1) 125 choice = gcc; 126 } 127 } 128 } 129 else 130 choice = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration(); 131 132 int screenX = choice.getBounds().x; 134 int screenY = choice.getBounds().y; 135 int screenW = choice.getBounds().width; 136 int screenH = choice.getBounds().height; 137 int x, y, w, h; 138 139 if (isMacOS()) 140 { 141 x = screenX; 142 y = screenY + 22; 143 w = screenW; 144 h = screenH - y - 4; } 146 else 147 { 148 x = screenX; 149 y = screenY; 150 w = screenW; 151 h = screenH; 152 } 153 154 return new Rectangle (x,y,w,h); 156 } 158 162 public static final boolean isDOSDerived() 163 { 164 return isWindows() || isOS2(); 165 } 167 171 public static final boolean isWindows() 172 { 173 return os == WINDOWS_9x || os == WINDOWS_NT; 174 } 176 180 public static final boolean isWindows9x() 181 { 182 return os == WINDOWS_9x; 183 } 185 189 public static final boolean isWindowsNT() 190 { 191 return os == WINDOWS_NT; 192 } 194 198 public static final boolean isOS2() 199 { 200 return os == OS2; 201 } 203 207 public static final boolean isUnix() 208 { 209 return os == UNIX || os == MAC_OS_X; 210 } 212 216 public static final boolean isMacOS() 217 { 218 return os == MAC_OS_X; 219 } 221 227 public static boolean isX11() 228 { 229 return os == UNIX; 230 } 232 236 public static final boolean isVMS() 237 { 238 return os == VMS; 239 } 241 245 public static final boolean isMacOSLF() 246 { 247 return (isMacOS() && UIManager.getLookAndFeel().isNativeLookAndFeel()); 248 } 250 255 public static final boolean hasScreenMenuBar() 256 { 257 if(!isMacOS()) 258 return false; 259 else if(hasScreenMenuBar == -1) 260 { 261 String result = System.getProperty("apple.laf.useScreenMenuBar"); 262 if (result == null) 263 result = System.getProperty("com.apple.macos.useScreenMenuBar"); 264 hasScreenMenuBar = ("true".equals(result)) ? 1 : 0; 265 } 266 267 return (hasScreenMenuBar == 1); 268 } 270 274 public static final boolean hasJava14() 275 { 276 return java14; 280 } 282 286 public static final boolean hasJava15() 287 { 288 return java15; 289 } 291 295 public static boolean isCaseInsensitiveFS() 296 { 297 return isDOSDerived() || isMacOS(); 298 } 300 private static final int UNIX = 0x31337; 302 private static final int WINDOWS_9x = 0x640; 303 private static final int WINDOWS_NT = 0x666; 304 private static final int OS2 = 0xDEAD; 305 private static final int MAC_OS_X = 0xABC; 306 private static final int VMS = 0xDEAD2; 307 private static final int UNKNOWN = 0xBAD; 308 309 private static int os; 310 private static boolean java14; 311 private static boolean java15; 312 private static int hasScreenMenuBar = -1; 313 314 static 316 { 317 if(System.getProperty("mrj.version") != null) 318 { 319 os = MAC_OS_X; 320 } 321 else 322 { 323 String osName = System.getProperty("os.name"); 324 if(osName.indexOf("Windows 9") != -1 325 || osName.indexOf("Windows M") != -1) 326 { 327 os = WINDOWS_9x; 328 } 329 else if(osName.indexOf("Windows") != -1) 330 { 331 os = WINDOWS_NT; 332 } 333 else if(osName.indexOf("OS/2") != -1) 334 { 335 os = OS2; 336 } 337 else if(osName.indexOf("VMS") != -1) 338 { 339 os = VMS; 340 } 341 else if(File.separatorChar == '/') 342 { 343 os = UNIX; 344 } 345 else 346 { 347 os = UNKNOWN; 348 Log.log(Log.WARNING,OperatingSystem.class, 349 "Unknown operating system: " + osName); 350 } 351 } 352 353 String javaVersion = System.getProperty("jedit.force.java.version"); 356 if(javaVersion == null || javaVersion.equals("")) 357 javaVersion = System.getProperty("java.version"); 358 java14 = (javaVersion.compareTo("1.4") >= 0); 359 java15 = (javaVersion.compareTo("1.5") >= 0); 360 } 362 } 364 | Popular Tags |