49 import java.util.HashSet; 50 import java.util.Iterator; 51 import java.util.Locale; 52 import java.util.Map; 53 import java.util.NoSuchElementException; 54 import java.util.Set; 55 import java.util.StringTokenizer; 56 import java.util.TreeMap; 57 import java.util.Vector; 58 import java.util.concurrent.ConcurrentHashMap; 59 import sun.awt.AppContext; 60 import sun.awt.DisplayChangedListener; 61 import sun.awt.FontConfiguration; 62 import sun.awt.SunDisplayChanger; 63 import sun.font.CompositeFontDescriptor; 64 import sun.font.Font2D; 65 import sun.font.FontManager; 66 import sun.font.FontManagerFactory; 67 import sun.font.FontManagerForSGE; 68 import sun.font.NativeFont; 69 70 /** 71 * This is an implementation of a GraphicsEnvironment object for the 72 * default local GraphicsEnvironment. 73 * 74 * @see GraphicsDevice 75 * @see GraphicsConfiguration 76 */ 77 public abstract class SunGraphicsEnvironment extends GraphicsEnvironment 78 implements DisplayChangedListener { 79 80 public static boolean isOpenSolaris; 81 private static Font defaultFont; 82 83 public SunGraphicsEnvironment() { 84 java.security.AccessController.doPrivileged( 85 new java.security.PrivilegedAction<Object>() { 86 public Object run() { 87 String osName = System.getProperty("os.name"); 88 if ("SunOS".equals(osName)) { 89 String version = System.getProperty("os.version", "0.0"); 90 try { 91 float ver = Float.parseFloat(version); 92 if (ver > 5.10f) { 93 File f = new File("/etc/release"); 94 FileInputStream fis = new FileInputStream(f); 95 InputStreamReader isr 96 = new InputStreamReader(fis, "ISO-8859-1"); 97 BufferedReader br = new BufferedReader(isr); 98 String line = br.readLine(); 99 if (line.indexOf("OpenSolaris") >= 0) { 100 isOpenSolaris = true; 101 } else { 102 /* We are using isOpenSolaris as meaning 323 public void removeDisplayChangedListener(DisplayChangedListener client) { 324 displayChanger.remove(client); 325 } 326 327 /* 328 * ----END DISPLAY CHANGE SUPPORT---- 329 */ 330 331 /** 332 * Returns true if FlipBufferStrategy with COPIED buffer contents 333 * is preferred for this peer's GraphicsConfiguration over 334 * BlitBufferStrategy, false otherwise. 335 * 336 * The reason FlipBS could be preferred is that in some configurations 337 * an accelerated copy to the screen is supported (like Direct3D 9) 338 * 339 * @return true if flip strategy should be used, false otherwise 340 */ 341 public boolean isFlipStrategyPreferred(ComponentPeer peer) { 342 return false; 343 } 344 } | 49 import java.util.HashSet; 50 import java.util.Iterator; 51 import java.util.Locale; 52 import java.util.Map; 53 import java.util.NoSuchElementException; 54 import java.util.Set; 55 import java.util.StringTokenizer; 56 import java.util.TreeMap; 57 import java.util.Vector; 58 import java.util.concurrent.ConcurrentHashMap; 59 import sun.awt.AppContext; 60 import sun.awt.DisplayChangedListener; 61 import sun.awt.FontConfiguration; 62 import sun.awt.SunDisplayChanger; 63 import sun.font.CompositeFontDescriptor; 64 import sun.font.Font2D; 65 import sun.font.FontManager; 66 import sun.font.FontManagerFactory; 67 import sun.font.FontManagerForSGE; 68 import sun.font.NativeFont; 69 import java.security.AccessController; 70 import sun.security.action.GetPropertyAction; 71 72 /** 73 * This is an implementation of a GraphicsEnvironment object for the 74 * default local GraphicsEnvironment. 75 * 76 * @see GraphicsDevice 77 * @see GraphicsConfiguration 78 */ 79 public abstract class SunGraphicsEnvironment extends GraphicsEnvironment 80 implements DisplayChangedListener { 81 82 public static boolean isOpenSolaris; 83 private static Font defaultFont; 84 85 private static final boolean uiScaleEnabled; 86 private static final double debugScale; 87 88 static { 89 uiScaleEnabled = "true".equals(AccessController.doPrivileged( 90 new GetPropertyAction("sun.java2d.uiScale.enabled", "true"))); 91 debugScale = uiScaleEnabled ? getScaleFactor("sun.java2d.uiScale") : -1; 92 } 93 94 public SunGraphicsEnvironment() { 95 java.security.AccessController.doPrivileged( 96 new java.security.PrivilegedAction<Object>() { 97 public Object run() { 98 String osName = System.getProperty("os.name"); 99 if ("SunOS".equals(osName)) { 100 String version = System.getProperty("os.version", "0.0"); 101 try { 102 float ver = Float.parseFloat(version); 103 if (ver > 5.10f) { 104 File f = new File("/etc/release"); 105 FileInputStream fis = new FileInputStream(f); 106 InputStreamReader isr 107 = new InputStreamReader(fis, "ISO-8859-1"); 108 BufferedReader br = new BufferedReader(isr); 109 String line = br.readLine(); 110 if (line.indexOf("OpenSolaris") >= 0) { 111 isOpenSolaris = true; 112 } else { 113 /* We are using isOpenSolaris as meaning 334 public void removeDisplayChangedListener(DisplayChangedListener client) { 335 displayChanger.remove(client); 336 } 337 338 /* 339 * ----END DISPLAY CHANGE SUPPORT---- 340 */ 341 342 /** 343 * Returns true if FlipBufferStrategy with COPIED buffer contents 344 * is preferred for this peer's GraphicsConfiguration over 345 * BlitBufferStrategy, false otherwise. 346 * 347 * The reason FlipBS could be preferred is that in some configurations 348 * an accelerated copy to the screen is supported (like Direct3D 9) 349 * 350 * @return true if flip strategy should be used, false otherwise 351 */ 352 public boolean isFlipStrategyPreferred(ComponentPeer peer) { 353 return false; 354 } 355 356 public static boolean isUIScaleEnabled() { 357 return uiScaleEnabled; 358 } 359 360 public static double getDebugScale() { 361 return debugScale; 362 } 363 364 public static double getScaleFactor(String propertyName) { 365 366 String scaleFactor = AccessController.doPrivileged( 367 new GetPropertyAction(propertyName, "-1")); 368 369 if (scaleFactor == null || scaleFactor.equals("-1")) { 370 return -1; 371 } 372 373 try { 374 double units = 1.0; 375 376 if (scaleFactor.endsWith("x")) { 377 scaleFactor = scaleFactor.substring(0, scaleFactor.length() - 1); 378 } else if (scaleFactor.endsWith("dpi")) { 379 units = 96; 380 scaleFactor = scaleFactor.substring(0, scaleFactor.length() - 3); 381 } else if (scaleFactor.endsWith("%")) { 382 units = 100; 383 scaleFactor = scaleFactor.substring(0, scaleFactor.length() - 1); 384 } 385 386 double scale = Double.parseDouble(scaleFactor); 387 return scale <= 0 ? -1 : scale / units; 388 } catch (NumberFormatException ignored) { 389 return -1; 390 } 391 } 392 } |