1 7 8 package java.awt; 9 10 import sun.security.util.SecurityConstants; 11 19 20 public class MouseInfo { 21 22 25 private MouseInfo() { 26 } 27 28 55 public static PointerInfo getPointerInfo() throws HeadlessException { 56 if (GraphicsEnvironment.isHeadless()) { 57 throw new HeadlessException (); 58 } 59 60 SecurityManager security = System.getSecurityManager(); 61 if (security != null) { 62 security.checkPermission(SecurityConstants.WATCH_MOUSE_PERMISSION); 63 } 64 65 Point point = new Point (0, 0); 66 int deviceNum = Toolkit.getDefaultToolkit().getMouseInfoPeer().fillPointWithCoords(point); 67 GraphicsDevice [] gds = GraphicsEnvironment.getLocalGraphicsEnvironment(). 68 getScreenDevices(); 69 PointerInfo retval = null; 70 if (areScreenDevicesIndependent(gds)) { 71 retval = new PointerInfo (gds[deviceNum], point); 72 } else { 73 for (int i = 0; i < gds.length; i++) { 74 GraphicsConfiguration gc = gds[i].getDefaultConfiguration(); 75 Rectangle bounds = gc.getBounds(); 76 if (bounds.contains(point)) { 77 retval = new PointerInfo (gds[i], point); 78 } 79 } 80 } 81 82 return retval; 83 } 84 85 private static boolean areScreenDevicesIndependent(GraphicsDevice [] gds) { 86 for (int i = 0; i < gds.length; i++) { 87 Rectangle bounds = gds[i].getDefaultConfiguration().getBounds(); 88 if (bounds.x != 0 || bounds.y != 0) { 89 return false; 90 } 91 } 92 return true; 93 } 94 95 103 public static int getNumberOfButtons() throws HeadlessException { 104 if (GraphicsEnvironment.isHeadless()) { 105 throw new HeadlessException (); 106 } 107 Object prop = Toolkit.getDefaultToolkit(). 108 getDesktopProperty("awt.mouse.numButtons"); 109 if (prop instanceof Integer ) { 110 return ((Integer )prop).intValue(); 111 } 112 113 assert false : "awt.mouse.numButtons is not an integer property"; 115 return 0; 116 } 117 118 } 119 | Popular Tags |