1 7 8 package java.awt.event; 9 10 import java.awt.Event ; 11 import java.awt.Component ; 12 import java.awt.GraphicsEnvironment ; 13 import java.awt.Toolkit ; 14 15 37 public abstract class InputEvent extends ComponentEvent { 38 39 43 public static final int SHIFT_MASK = Event.SHIFT_MASK; 44 45 49 public static final int CTRL_MASK = Event.CTRL_MASK; 50 51 55 public static final int META_MASK = Event.META_MASK; 56 57 61 public static final int ALT_MASK = Event.ALT_MASK; 62 63 66 public static final int ALT_GRAPH_MASK = 1 << 5; 67 68 72 public static final int BUTTON1_MASK = 1 << 4; 73 74 79 public static final int BUTTON2_MASK = Event.ALT_MASK; 80 81 86 public static final int BUTTON3_MASK = Event.META_MASK; 87 88 92 public static final int SHIFT_DOWN_MASK = 1 << 6; 93 94 98 public static final int CTRL_DOWN_MASK = 1 << 7; 99 100 104 public static final int META_DOWN_MASK = 1 << 8; 105 106 110 public static final int ALT_DOWN_MASK = 1 << 9; 111 112 116 public static final int BUTTON1_DOWN_MASK = 1 << 10; 117 118 122 public static final int BUTTON2_DOWN_MASK = 1 << 11; 123 124 128 public static final int BUTTON3_DOWN_MASK = 1 << 12; 129 130 134 public static final int ALT_GRAPH_DOWN_MASK = 1 << 13; 135 136 137 static final int JDK_1_3_MODIFIERS = SHIFT_DOWN_MASK - 1; 138 139 146 long when; 147 148 158 int modifiers; 159 160 164 private transient boolean canAccessSystemClipboard; 165 166 static { 167 168 NativeLibLoader.loadLibraries(); 169 if (!GraphicsEnvironment.isHeadless()) { 170 initIDs(); 171 } 172 } 173 174 178 private static native void initIDs(); 179 180 195 InputEvent(Component source, int id, long when, int modifiers) { 196 super(source, id); 197 this.when = when; 198 this.modifiers = modifiers; 199 canAccessSystemClipboard = canAccessSystemClipboard(); 200 } 201 202 private boolean canAccessSystemClipboard() { 203 boolean b = false; 204 205 if (!GraphicsEnvironment.isHeadless()) { 206 SecurityManager sm = System.getSecurityManager(); 207 if (sm != null) { 208 try { 209 sm.checkSystemClipboardAccess(); 210 b = true; 211 } catch (SecurityException se) { 212 } 213 } else { 214 b = true; 215 } 216 } 217 218 return b; 219 } 220 221 224 public boolean isShiftDown() { 225 return (modifiers & SHIFT_MASK) != 0; 226 } 227 228 231 public boolean isControlDown() { 232 return (modifiers & CTRL_MASK) != 0; 233 } 234 235 238 public boolean isMetaDown() { 239 return (modifiers & META_MASK) != 0; 240 } 241 242 245 public boolean isAltDown() { 246 return (modifiers & ALT_MASK) != 0; 247 } 248 249 252 public boolean isAltGraphDown() { 253 return (modifiers & ALT_GRAPH_MASK) != 0; 254 } 255 256 259 public long getWhen() { 260 return when; 261 } 262 263 266 public int getModifiers() { 267 return modifiers & JDK_1_3_MODIFIERS; 268 } 269 270 303 public int getModifiersEx() { 304 return modifiers & ~JDK_1_3_MODIFIERS; 305 } 306 307 311 public void consume() { 312 consumed = true; 313 } 314 315 319 public boolean isConsumed() { 320 return consumed; 321 } 322 323 static final long serialVersionUID = -2482525981698309786L; 325 326 339 public static String getModifiersExText(int modifiers) { 340 StringBuffer buf = new StringBuffer (); 341 if ((modifiers & InputEvent.META_DOWN_MASK) != 0) { 342 buf.append(Toolkit.getProperty("AWT.meta", "Meta")); 343 buf.append("+"); 344 } 345 if ((modifiers & InputEvent.CTRL_DOWN_MASK) != 0) { 346 buf.append(Toolkit.getProperty("AWT.control", "Ctrl")); 347 buf.append("+"); 348 } 349 if ((modifiers & InputEvent.ALT_DOWN_MASK) != 0) { 350 buf.append(Toolkit.getProperty("AWT.alt", "Alt")); 351 buf.append("+"); 352 } 353 if ((modifiers & InputEvent.SHIFT_DOWN_MASK) != 0) { 354 buf.append(Toolkit.getProperty("AWT.shift", "Shift")); 355 buf.append("+"); 356 } 357 if ((modifiers & InputEvent.ALT_GRAPH_DOWN_MASK) != 0) { 358 buf.append(Toolkit.getProperty("AWT.altGraph", "Alt Graph")); 359 buf.append("+"); 360 } 361 if ((modifiers & InputEvent.BUTTON1_DOWN_MASK) != 0) { 362 buf.append(Toolkit.getProperty("AWT.button1", "Button1")); 363 buf.append("+"); 364 } 365 if ((modifiers & InputEvent.BUTTON2_DOWN_MASK) != 0) { 366 buf.append(Toolkit.getProperty("AWT.button2", "Button2")); 367 buf.append("+"); 368 } 369 if ((modifiers & InputEvent.BUTTON3_DOWN_MASK) != 0) { 370 buf.append(Toolkit.getProperty("AWT.button3", "Button3")); 371 buf.append("+"); 372 } 373 if (buf.length() > 0) { 374 buf.setLength(buf.length()-1); } 376 return buf.toString(); 377 } 378 } 379 380 | Popular Tags |