001: /*
002: * @(#)MouseEvent.java 1.34 06/10/10
003: *
004: * Copyright 1990-2006 Sun Microsystems, Inc. All Rights Reserved.
005: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
006: *
007: * This program is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU General Public License version
009: * 2 only, as published by the Free Software Foundation.
010: *
011: * This program is distributed in the hope that it will be useful, but
012: * WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * General Public License version 2 for more details (a copy is
015: * included at /legal/license.txt).
016: *
017: * You should have received a copy of the GNU General Public License
018: * version 2 along with this work; if not, write to the Free Software
019: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA
021: *
022: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
023: * Clara, CA 95054 or visit www.sun.com if you need additional
024: * information or have any questions.
025: *
026: */
027:
028: package java.awt.event;
029:
030: import java.awt.Component;
031: import java.awt.GraphicsEnvironment;
032: import java.awt.Point;
033: import java.awt.Toolkit;
034: import java.io.IOException;
035: import java.io.ObjectInputStream;
036:
037: /**
038: * An event which indicates that a mouse action occurred in a component.
039: * A mouse action is considered to occur in a particular component if and only
040: * if the mouse cursor is over the unobscured part of the component's bounds
041: * when the action happens.
042: * Component bounds can be obscurred by the visible component's children or by a
043: * menu or by a top-level window.
044: * This event is used both for mouse events (click, enter, exit) and mouse
045: * motion events (moves and drags).
046: * <P>
047: * This low-level event is generated by a component object for:
048: * <ul>
049: * <li>Mouse Events
050: * <ul>
051: * <li>a mouse button is pressed
052: * <li>a mouse button is released
053: * <li>a mouse button is clicked (pressed and released)
054: * <li>the mouse cursor enters the unobscured part of component's geometry
055: * <li>the mouse cursor exits the unobscured part of component's geometry
056: * </ul>
057: * <li> Mouse Motion Events
058: * <ul>
059: * <li>the mouse is moved
060: * <li>the mouse is dragged
061: * </ul>
062: * </ul>
063: * <P>
064: * A <code>MouseEvent</code> object is passed to every
065: * <code>MouseListener</code>
066: * or <code>MouseAdapter</code> object which is registered to receive
067: * the "interesting" mouse events using the component's
068: * <code>addMouseListener</code> method.
069: * (<code>MouseAdapter</code> objects implement the
070: * <code>MouseListener</code> interface.) Each such listener object
071: * gets a <code>MouseEvent</code> containing the mouse event.
072: * <P>
073: * A <code>MouseEvent</code> object is also passed to every
074: * <code>MouseMotionListener</code> or
075: * <code>MouseMotionAdapter</code> object which is registered to receive
076: * mouse motion events using the component's
077: * <code>addMouseMotionListener</code>
078: * method. (<code>MouseMotionAdapter</code> objects implement the
079: * <code>MouseMotionListener</code> interface.) Each such listener object
080: * gets a <code>MouseEvent</code> containing the mouse motion event.
081: * <P>
082: * When a mouse button is clicked, events are generated and sent to the
083: * registered <code>MouseListener</code>s.
084: * The state of modal keys can be retrieved using {@link InputEvent#getModifiers}
085: * and {@link InputEvent#getModifiersEx}.
086: * The button mask returned by {@link InputEvent#getModifiers} reflects
087: * only the button that changed state, not the current state of all buttons.
088: * To get state of all buttons use {@link InputEvent#getModifiersEx} instead.
089: * The button which has changed state is returned by {@link MouseEvent#getButton}
090: * <P>
091: * For example, if the first mouse button is pressed, events are sent in the
092: * following order:
093: * <PRE>
094: * <b >id </b > <b >modifiers </b > <b >button </b >
095: * <code>MOUSE_PRESSED</code>: <code>BUTTON1_MASK</code> <code>BUTTON1</code>
096: * <code>MOUSE_RELEASED</code>: <code>BUTTON1_MASK</code> <code>BUTTON1</code>
097: * <code>MOUSE_CLICKED</code>: <code>BUTTON1_MASK</code> <code>BUTTON1</code>
098: * </PRE>
099: * When multiple mouse buttons are pressed, each press, release, and click
100: * results in a separate event.
101: * <P>
102: * For example, if the user presses <b>button 1</b> followed by
103: * <b>button 2</b>, and then releases them in the same order,
104: * the following sequence of events is generated:
105: * <PRE>
106: * <b >id </b > <b >modifiers </b > <b >button </b >
107: * <code>MOUSE_PRESSED</code>: <code>BUTTON1_MASK</code> <code>BUTTON1</code>
108: * <code>MOUSE_PRESSED</code>: <code>BUTTON2_MASK</code> <code>BUTTON2</code>
109: * <code>MOUSE_RELEASED</code>: <code>BUTTON1_MASK</code> <code>BUTTON1</code>
110: * <code>MOUSE_CLICKED</code>: <code>BUTTON1_MASK</code> <code>BUTTON1</code>
111: * <code>MOUSE_RELEASED</code>: <code>BUTTON2_MASK</code> <code>BUTTON2</code>
112: * <code>MOUSE_CLICKED</code>: <code>BUTTON2_MASK</code> <code>BUTTON2</code>
113: * </PRE>
114: * If <b>button 2</b> is released first, the
115: * <code>MOUSE_RELEASED</code>/<code>MOUSE_CLICKED</code> pair
116: * for <code>BUTTON2_MASK</code> arrives first,
117: * followed by the pair for <code>BUTTON1_MASK</code>.
118: * <p>
119: *
120: * <code>MOUSE_DRAGGED</code> events are delivered to the <code>Component</code>
121: * in which the mouse button was pressed until the mouse button is released
122: * (regardless of whether the mouse position is within the bounds of the
123: * <code>Component</code>). Due to platform-dependent Drag&Drop implementations,
124: * <code>MOUSE_DRAGGED</code> events may not be delivered during a native
125: * Drag&Drop operation.
126: *
127: * In a multi-screen environment mouse drag events are delivered to the
128: * <code>Component</code> even if the mouse position is outside the bounds of the
129: * <code>GraphicsConfiguration</code> associated with that
130: * <code>Component</code>. However, the reported position for mouse drag events
131: * in this case may differ from the actual mouse position:
132: * <ul>
133: * <li>In a multi-screen environment without a virtual device:
134: * <br>
135: * The reported coordinates for mouse drag events are clipped to fit within the
136: * bounds of the <code>GraphicsConfiguration</code> associated with
137: * the <code>Component</code>.
138: * <li>In a multi-screen environment with a virtual device:
139: * <br>
140: * The reported coordinates for mouse drag events are clipped to fit within the
141: * bounds of the virtual device associated with the <code>Component</code>.
142: * </ul>
143: *
144: * @author Carl Quinn
145: * 1.21 02/20/02
146: *
147: * @see MouseAdapter
148: * @see MouseListener
149: * @see MouseMotionAdapter
150: * @see MouseMotionListener
151: * @see MouseWheelListener
152: * @see <a href="http://java.sun.com/docs/books/tutorial/post1.0/ui/mouselistener.html">Tutorial: Writing a Mouse Listener</a>
153: * @see <a href="http://java.sun.com/docs/books/tutorial/post1.0/ui/mousemotionlistener.html">Tutorial: Writing a Mouse Motion Listener</a>
154: * @see <a href="http://www.awl.com/cp/javaseries/jcl1_2.html">Reference: The Java Class Libraries (update file)</a>
155: *
156: * @since 1.1
157: */
158: public class MouseEvent extends InputEvent {
159: /**
160: * The first number in the range of ids used for mouse events.
161: */
162: public static final int MOUSE_FIRST = 500;
163: /**
164: * The last number in the range of ids used for mouse events.
165: */
166: public static final int MOUSE_LAST = 507;
167: /**
168: * The "mouse clicked" event. This <code>MouseEvent</code>
169: * occurs when a mouse button is pressed and released.
170: */
171: public static final int MOUSE_CLICKED = MOUSE_FIRST;
172: /**
173: * The "mouse pressed" event. This <code>MouseEvent</code>
174: * occurs when a mouse button is pushed down.
175: */
176: public static final int MOUSE_PRESSED = 1 + MOUSE_FIRST; //Event.MOUSE_DOWN
177: /**
178: * The "mouse released" event. This <code>MouseEvent</code>
179: * occurs when a mouse button is let up.
180: */
181: public static final int MOUSE_RELEASED = 2 + MOUSE_FIRST; //Event.MOUSE_UP
182: /**
183: * The "mouse moved" event. This <code>MouseMotionEvent</code>
184: * occurs when the mouse position changes.
185: */
186: public static final int MOUSE_MOVED = 3 + MOUSE_FIRST; //Event.MOUSE_MOVE
187: /**
188: * The "mouse entered" event. This <code>MouseEvent</code>
189: * occurs when the mouse cursor enters the unobscured part of component's
190: * geometry.
191: */
192: public static final int MOUSE_ENTERED = 4 + MOUSE_FIRST; //Event.MOUSE_ENTER
193: /**
194: * The "mouse exited" event. This <code>MouseEvent</code>
195: * occurs when the mouse cursor exits the unobscured part of component's
196: * geometry.
197: */
198: public static final int MOUSE_EXITED = 5 + MOUSE_FIRST; //Event.MOUSE_EXIT
199: /**
200: * Indicates no mouse buttons; used by {@link #getButton}.
201: * @since 1.4
202: */
203: public static final int NOBUTTON = 0;
204:
205: /**
206: * Indicates mouse button #1; used by {@link #getButton}.
207: * @since 1.4
208: */
209: public static final int BUTTON1 = 1;
210:
211: /**
212: * Indicates mouse button #2; used by {@link #getButton}.
213: * @since 1.4
214: */
215: public static final int BUTTON2 = 2;
216:
217: /**
218: * Indicates mouse button #3; used by {@link #getButton}.
219: * @since 1.4
220: */
221: public static final int BUTTON3 = 3;
222:
223: /**
224: * The "mouse dragged" event. This <code>MouseMotionEvent</code>
225: * occurs when the mouse position changes while a mouse button is pressed.
226: */
227: public static final int MOUSE_DRAGGED = 6 + MOUSE_FIRST; //Event.MOUSE_DRAG
228: /**
229: * The "mouse wheel" event. This is the only <code>MouseWheelEvent</code>.
230: * It occurs when a mouse equipped with a wheel has its wheel rotated.
231: * @since 1.4
232: */
233: public static final int MOUSE_WHEEL = 7 + MOUSE_FIRST; //Event.MOUSE_WHEEL
234:
235: /**
236: * The mouse event's x coordinate.
237: * The x value is relative to the component that fired the event.
238: *
239: * @serial
240: * @see #getX()
241: */
242: int x;
243: /**
244: * The mouse event's y coordinate.
245: * The y value is relative to the component that fired the event.
246: *
247: * @serial
248: * @see #getY()
249: */
250: int y;
251: /**
252: * Indicates the number of quick consecutive clicks of
253: * a mouse button.
254: * clickCount will be valid for only three mouse events :<BR>
255: * <code>MOUSE_CLICKED</code>,
256: * <code>MOUSE_PRESSED</code> and
257: * <code>MOUSE_RELEASED</code>.
258: * For the above, the <code>clickCount</code> will be at least 1.
259: * For all other events the count will be 0.
260: *
261: * @serial
262: * @see #getClickCount().
263: */
264: int clickCount;
265: /**
266: * Indicates which, if any, of the mouse buttons has changed state.
267: *
268: * The only legal values are the following constants:
269: * <code>NOBUTTON</code>,
270: * <code>BUTTON1</code>,
271: * <code>BUTTON2</code> or
272: * <code>BUTTON3</code>.
273: * @serial
274: * @see #getButton().
275: */
276: int button;
277: /**
278: * A property used to indicate whether a Popup Menu
279: * should appear with a certain gestures.
280: * If <code>popupTrigger</code> = <code>false</code>,
281: * no popup menu should appear. If it is <code>true</code>
282: * then a popup menu should appear.
283: *
284: * @serial
285: * @see java.awt.PopupMenu
286: * @see #isPopupTrigger()
287: */
288: boolean popupTrigger = false;
289: /*
290: * JDK 1.1 serialVersionUID
291: */
292: private static final long serialVersionUID = -991214153494842848L;
293:
294: /**
295: * Constructs a <code>MouseEvent</code> object with the
296: * specified source component,
297: * type, modifiers, coordinates, and click count.
298: * <p>Note that passing in an invalid <code>id</code> results in
299: * unspecified behavior.
300: *
301: * @param source the <code>Component</code> that originated the event
302: * @param id the integer that identifies the event
303: * @param when a long int that gives the time the event occurred
304: * @param modifiers the modifier keys down during event (e.g. shift, ctrl,
305: * alt, meta)
306: * Either extended _DOWN_MASK or old _MASK modifiers
307: * should be used, but both models should not be mixed
308: * in one event. Use of the extended modifiers is
309: * preferred.
310: * @param x the horizontal x coordinate for the mouse location
311: * @param y the vertical y coordinate for the mouse location
312: * @param clickCount the number of mouse clicks associated with event
313: * @param popupTrigger a boolean, true if this event is a trigger for a
314: * popup menu
315: * @param button which of the mouse buttons has changed state.
316: * <code>NOBUTTON</code>,
317: * <code>BUTTON1</code>,
318: * <code>BUTTON2</code> or
319: * <code>BUTTON3</code>.
320: * @exception IllegalArgumentException if if an invalid <code>button</code>
321: * value is passed in.
322: * @since 1.4
323: */
324:
325: public MouseEvent(Component source, int id, long when,
326: int modifiers, int x, int y, int clickCount,
327: boolean popupTrigger, int button) {
328: super (source, id, when, modifiers);
329: if (button < NOBUTTON || button > BUTTON3) {
330: throw new IllegalArgumentException("Invalid button value");
331: }
332:
333: this .x = x;
334: this .y = y;
335: this .clickCount = clickCount;
336: this .popupTrigger = popupTrigger;
337: this .button = button;
338:
339: if ((getModifiers() != 0) && (getModifiersEx() == 0)) {
340: setNewModifiers();
341: } else if ((getModifiers() == 0)
342: && (getModifiersEx() != 0 || button != NOBUTTON)) {
343: setOldModifiers();
344: }
345: }
346:
347: /**
348: * Constructs a <code>MouseEvent</code> object with the
349: * specified source component,
350: * type, modifiers, coordinates, and click count.
351: * <p>Note that passing in an invalid <code>id</code> results in
352: * unspecified behavior.
353: *
354: * @param source the <code>Component</code> that originated the event
355: * @param id the integer that identifies the event
356: * @param when a long int that gives the time the event occurred
357: * @param modifiers the modifier keys down during event (e.g. shift, ctrl,
358: * alt, meta)
359: * Either extended _DOWN_MASK or old _MASK modifiers
360: * should be used, but both models should not be mixed
361: * in one event. Use of the extended modifiers is
362: * preferred.
363: * @param x the horizontal x coordinate for the mouse location
364: * @param y the vertical y coordinate for the mouse location
365: * @param clickCount the number of mouse clicks associated with event
366: * @param popupTrigger a boolean, true if this event is a trigger for a
367: * popup menu
368: */
369: public MouseEvent(Component source, int id, long when,
370: int modifiers, int x, int y, int clickCount,
371: boolean popupTrigger) {
372: this (source, id, when, modifiers, x, y, clickCount,
373: popupTrigger, NOBUTTON);
374: //super(source, id, when, modifiers);
375: //this.x = x;
376: //this.y = y;
377: //this.clickCount = clickCount;
378: //this.popupTrigger = popupTrigger;
379: }
380:
381: /**
382: * Returns the horizontal x position of the event relative to the
383: * source component.
384: *
385: * @return x an integer indicating horizontal position relative to
386: * the component
387: */
388: public int getX() {
389: return x;
390: }
391:
392: /**
393: * Returns the vertical y position of the event relative to the
394: * source component.
395: *
396: * @return y an integer indicating vertical position relative to
397: * the component
398: */
399: public int getY() {
400: return y;
401: }
402:
403: /**
404: * Returns the x,y position of the event relative to the source component.
405: *
406: * @return a <code>Point</code> object containing the x and y coordinates
407: * relative to the source component
408: *
409: */
410: public Point getPoint() {
411: int x;
412: int y;
413: synchronized (this ) {
414: x = this .x;
415: y = this .y;
416: }
417: return new Point(x, y);
418: }
419:
420: /**
421: * Translates the event's coordinates to a new position
422: * by adding specified <code>x</code> (horizontal) and <code>y</code>
423: * (vertical) offsets.
424: *
425: * @param x the horizontal x value to add to the current x
426: * coordinate position
427: * @param y the vertical y value to add to the current y
428: coordinate position
429: */
430: public synchronized void translatePoint(int x, int y) {
431: this .x += x;
432: this .y += y;
433: }
434:
435: /**
436: * Returns the number of mouse clicks associated with this event.
437: *
438: * @return integer value for the number of clicks
439: */
440: public int getClickCount() {
441: return clickCount;
442: }
443:
444: /**
445: * Returns which, if any, of the mouse buttons has changed state.
446: *
447: * @returns one of the following constants:
448: * <code>NOBUTTON</code>,
449: * <code>BUTTON1</code>,
450: * <code>BUTTON2</code> or
451: * <code>BUTTON3</code>.
452: * @since 1.4
453: */
454:
455: public int getButton() {
456: return button;
457: }
458:
459: /**
460: * Returns whether or not this mouse event is the popup menu
461: * trigger event for the platform.
462: * <p><b>Note</b>: Popup menus are triggered differently
463: * on different systems. Therefore, <code>isPopupTrigger</code>
464: * should be checked in both <code>mousePressed</code>
465: * and <code>mouseReleased</code>
466: * for proper cross-platform functionality.
467: *
468: * @return boolean, true if this event is the popup menu trigger
469: * for this platform
470: */
471: public boolean isPopupTrigger() {
472: return popupTrigger;
473: }
474:
475: /**
476: * Returns a String describing the modifier keys and mouse buttons
477: * that were down during the event, such as "Shift", or "Ctrl+Shift".
478: * These strings can be localized by changing the awt.properties file.
479: *
480: * @param modifiers a modifier mask describing the modifier keys and
481: * mouse buttons that were down during the event
482: * @return string a text description of the combination of modifier
483: * keys and mouse buttons that were down during the event
484: * @since 1.4
485: */
486: public static String getMouseModifiersText(int modifiers) {
487: StringBuffer buf = new StringBuffer();
488: if ((modifiers & InputEvent.ALT_MASK) != 0) {
489: buf.append(Toolkit.getProperty("AWT.alt", "Alt"));
490: buf.append("+");
491: }
492: if ((modifiers & InputEvent.META_MASK) != 0) {
493: buf.append(Toolkit.getProperty("AWT.meta", "Meta"));
494: buf.append("+");
495: }
496: if ((modifiers & InputEvent.CTRL_MASK) != 0) {
497: buf.append(Toolkit.getProperty("AWT.control", "Ctrl"));
498: buf.append("+");
499: }
500: if ((modifiers & InputEvent.SHIFT_MASK) != 0) {
501: buf.append(Toolkit.getProperty("AWT.shift", "Shift"));
502: buf.append("+");
503: }
504: if ((modifiers & InputEvent.ALT_GRAPH_MASK) != 0) {
505: buf
506: .append(Toolkit.getProperty("AWT.altGraph",
507: "Alt Graph"));
508: buf.append("+");
509: }
510: if ((modifiers & InputEvent.BUTTON1_MASK) != 0) {
511: buf.append(Toolkit.getProperty("AWT.button1", "Button1"));
512: buf.append("+");
513: }
514: if ((modifiers & InputEvent.BUTTON2_MASK) != 0) {
515: buf.append(Toolkit.getProperty("AWT.button2", "Button2"));
516: buf.append("+");
517: }
518: if ((modifiers & InputEvent.BUTTON3_MASK) != 0) {
519: buf.append(Toolkit.getProperty("AWT.button3", "Button3"));
520: buf.append("+");
521: }
522: if (buf.length() > 0) {
523: buf.setLength(buf.length() - 1); // remove trailing '+'
524: }
525: return buf.toString();
526: }
527:
528: /**
529: * Returns a parameter string identifying this event.
530: * This method is useful for event-logging and for debugging.
531: *
532: * @return a string identifying the event and its attributes
533: */
534: public String paramString() {
535: String str;
536: switch (id) {
537: case MOUSE_PRESSED:
538: str = "MOUSE_PRESSED";
539: break;
540:
541: case MOUSE_RELEASED:
542: str = "MOUSE_RELEASED";
543: break;
544:
545: case MOUSE_CLICKED:
546: str = "MOUSE_CLICKED";
547: break;
548:
549: case MOUSE_ENTERED:
550: str = "MOUSE_ENTERED";
551: break;
552:
553: case MOUSE_EXITED:
554: str = "MOUSE_EXITED";
555: break;
556:
557: case MOUSE_MOVED:
558: str = "MOUSE_MOVED";
559: break;
560:
561: case MOUSE_DRAGGED:
562: str = "MOUSE_DRAGGED";
563: break;
564:
565: case MOUSE_WHEEL:
566: str = "MOUSE_WHEEL";
567: break;
568:
569: default:
570: str = "unknown type";
571: }
572: str += ",(" + x + "," + y + ")" + modifiers;
573: return str + ",clickCount=" + clickCount;
574: }
575:
576: /**
577: * Sets new modifiers by the old ones.
578: * Also sets button. The mouse modifiers
579: * override overlaping key modifiers.
580: */
581:
582: private void setNewModifiers() {
583: if ((modifiers & BUTTON1_MASK) != 0) {
584: modifiers |= BUTTON1_DOWN_MASK;
585: }
586: if ((modifiers & BUTTON2_MASK) != 0) {
587: modifiers |= BUTTON2_DOWN_MASK;
588: }
589: if ((modifiers & BUTTON3_MASK) != 0) {
590: modifiers |= BUTTON3_DOWN_MASK;
591: }
592: if (id == MOUSE_PRESSED || id == MOUSE_RELEASED
593: || id == MOUSE_CLICKED) {
594: if ((modifiers & BUTTON1_MASK) != 0) {
595: button = BUTTON1;
596: modifiers &= ~BUTTON2_MASK & ~BUTTON3_MASK;
597: if (id == MOUSE_PRESSED) {
598: modifiers &= ~BUTTON1_DOWN_MASK;
599: }
600: } else if ((modifiers & BUTTON2_MASK) != 0) {
601: button = BUTTON2;
602: modifiers &= ~BUTTON1_MASK & ~BUTTON3_MASK;
603: if (id == MOUSE_PRESSED) {
604: modifiers &= ~BUTTON2_DOWN_MASK;
605: }
606: } else if ((modifiers & BUTTON3_MASK) != 0) {
607: button = BUTTON3;
608: modifiers &= ~BUTTON1_MASK & ~BUTTON2_MASK;
609: if (id == MOUSE_PRESSED) {
610: modifiers &= ~BUTTON3_DOWN_MASK;
611: }
612: }
613: }
614: if ((modifiers & InputEvent.SHIFT_MASK) != 0) {
615: modifiers |= InputEvent.SHIFT_DOWN_MASK;
616: }
617: if ((modifiers & InputEvent.CTRL_MASK) != 0) {
618: modifiers |= InputEvent.CTRL_DOWN_MASK;
619: }
620: if ((modifiers & InputEvent.ALT_GRAPH_MASK) != 0) {
621: modifiers |= InputEvent.ALT_GRAPH_DOWN_MASK;
622: }
623: }
624:
625: /**
626: * Sets old modifiers by the new ones.
627: */
628:
629: private void setOldModifiers() {
630: if (id == MOUSE_PRESSED || id == MOUSE_RELEASED
631: || id == MOUSE_CLICKED) {
632: switch (button) {
633: case BUTTON1:
634: modifiers |= BUTTON1_MASK;
635: break;
636: case BUTTON2:
637: modifiers |= BUTTON2_MASK;
638: break;
639: case BUTTON3:
640: modifiers |= BUTTON3_MASK;
641: break;
642: }
643: } else {
644: if ((modifiers & BUTTON1_DOWN_MASK) != 0) {
645: modifiers |= BUTTON1_MASK;
646: }
647: if ((modifiers & BUTTON2_DOWN_MASK) != 0) {
648: modifiers |= BUTTON2_MASK;
649: }
650: if ((modifiers & BUTTON3_DOWN_MASK) != 0) {
651: modifiers |= BUTTON3_MASK;
652: }
653: }
654: if ((modifiers & SHIFT_DOWN_MASK) != 0) {
655: modifiers |= SHIFT_MASK;
656: }
657: if ((modifiers & CTRL_DOWN_MASK) != 0) {
658: modifiers |= CTRL_MASK;
659: }
660: if ((modifiers & ALT_GRAPH_DOWN_MASK) != 0) {
661: modifiers |= ALT_GRAPH_MASK;
662: }
663: }
664:
665: /**
666: * Sets new modifiers by the old ones. The mouse modifiers
667: * override overlaping key modifiers.
668: * @serial
669: */
670: private void readObject(ObjectInputStream s) throws IOException,
671: ClassNotFoundException {
672: s.defaultReadObject();
673: if (getModifiers() != 0 && getModifiersEx() == 0) {
674: setNewModifiers();
675: }
676: }
677: }
|