src/solaris/classes/sun/awt/X11/XAwtState.java

Print this page
rev 9830 : 8039642: Fix raw and unchecked warnings in sun.awt.*
Reviewed-by: darcy, prr


  23  * questions.
  24  */
  25 
  26 /**
  27  * This class is a placeholder for all internal static objects that represent
  28  * system state. We keep our representation up-to-date with actual system
  29  * state by tracking events, such as X Focus, Component under cursor etc.
  30  * All attributes should be static private with accessors to simpify change
  31  * tracking.
  32  */
  33 package sun.awt.X11;
  34 
  35 import java.awt.Component;
  36 import java.lang.ref.WeakReference;
  37 
  38 class XAwtState {
  39     /**
  40      * The mouse is over this component.
  41      * If the component is not disabled, it received MOUSE_ENTERED but no MOUSE_EXITED.
  42      */
  43     private static WeakReference componentMouseEnteredRef = null;
  44 
  45     static void setComponentMouseEntered(Component component) {
  46         XToolkit.awtLock();
  47         try {
  48             if (component == null) {
  49                 componentMouseEnteredRef = null;
  50                 return;
  51             }
  52             if (component != getComponentMouseEntered()) {
  53                 componentMouseEnteredRef = new WeakReference(component);
  54             }
  55         } finally {
  56             XToolkit.awtUnlock();
  57         }
  58     }
  59 
  60     static Component getComponentMouseEntered() {
  61         XToolkit.awtLock();
  62         try {
  63             if (componentMouseEnteredRef == null) {
  64                 return null;
  65             }
  66             return (Component)componentMouseEnteredRef.get();
  67         } finally {
  68             XToolkit.awtUnlock();
  69         }
  70     }
  71 
  72     /**
  73      * The XBaseWindow is created with OwnerGrabButtonMask
  74      * (see X vol. 1, 8.3.3.2) so inside the app Key, Motion, and Button events
  75      * are received by the window they actualy happened on, not the grabber.
  76      * Then XBaseWindow dispatches them to the grabber. As a result
  77      * XAnyEvent.get_window() returns actual window the event is originated,
  78      * though the event is dispatched by  the grabber.
  79      */
  80     private static boolean inManualGrab = false;
  81 
  82     static boolean isManualGrab() {
  83         return inManualGrab;
  84     }
  85 
  86     private static WeakReference grabWindowRef = null;
  87 
  88     /**
  89      * The X Active Grab overrides any other active grab by the same
  90      * client see XGrabPointer, XGrabKeyboard
  91      */
  92     static void setGrabWindow(XBaseWindow grabWindow) {
  93         setGrabWindow(grabWindow, false);
  94     }
  95 
  96     /**
  97      * Automatic passive grab doesn't override active grab see XGrabButton
  98      */
  99     static void setAutoGrabWindow(XBaseWindow grabWindow) {
 100         setGrabWindow(grabWindow, true);
 101     }
 102 
 103     private static void setGrabWindow(XBaseWindow grabWindow, boolean isAutoGrab) {
 104         XToolkit.awtLock();
 105         try {
 106             if (inManualGrab && isAutoGrab) {
 107                 return;
 108             }
 109             inManualGrab = grabWindow != null && !isAutoGrab;
 110             if (grabWindow == null) {
 111                 grabWindowRef = null;
 112                 return;
 113             }
 114             if (grabWindow != getGrabWindow()) {
 115                 grabWindowRef = new WeakReference(grabWindow);
 116             }
 117         } finally {
 118             XToolkit.awtUnlock();
 119         }
 120     }
 121 
 122     static XBaseWindow getGrabWindow() {
 123         XToolkit.awtLock();
 124         try {
 125             if (grabWindowRef == null) {
 126                 return null;
 127             }
 128             XBaseWindow xbw = (XBaseWindow)grabWindowRef.get();
 129             if( xbw != null && xbw.isDisposed() ) {
 130                 xbw = null;
 131                 grabWindowRef = null;
 132             }else if( xbw == null ) {
 133                 grabWindowRef = null;
 134             }
 135             return xbw;
 136         } finally {
 137             XToolkit.awtUnlock();
 138         }
 139     }
 140 }


  23  * questions.
  24  */
  25 
  26 /**
  27  * This class is a placeholder for all internal static objects that represent
  28  * system state. We keep our representation up-to-date with actual system
  29  * state by tracking events, such as X Focus, Component under cursor etc.
  30  * All attributes should be static private with accessors to simpify change
  31  * tracking.
  32  */
  33 package sun.awt.X11;
  34 
  35 import java.awt.Component;
  36 import java.lang.ref.WeakReference;
  37 
  38 class XAwtState {
  39     /**
  40      * The mouse is over this component.
  41      * If the component is not disabled, it received MOUSE_ENTERED but no MOUSE_EXITED.
  42      */
  43     private static WeakReference<Component> componentMouseEnteredRef = null;
  44 
  45     static void setComponentMouseEntered(Component component) {
  46         XToolkit.awtLock();
  47         try {
  48             if (component == null) {
  49                 componentMouseEnteredRef = null;
  50                 return;
  51             }
  52             if (component != getComponentMouseEntered()) {
  53                 componentMouseEnteredRef = new WeakReference<>(component);
  54             }
  55         } finally {
  56             XToolkit.awtUnlock();
  57         }
  58     }
  59 
  60     static Component getComponentMouseEntered() {
  61         XToolkit.awtLock();
  62         try {
  63             if (componentMouseEnteredRef == null) {
  64                 return null;
  65             }
  66             return componentMouseEnteredRef.get();
  67         } finally {
  68             XToolkit.awtUnlock();
  69         }
  70     }
  71 
  72     /**
  73      * The XBaseWindow is created with OwnerGrabButtonMask
  74      * (see X vol. 1, 8.3.3.2) so inside the app Key, Motion, and Button events
  75      * are received by the window they actualy happened on, not the grabber.
  76      * Then XBaseWindow dispatches them to the grabber. As a result
  77      * XAnyEvent.get_window() returns actual window the event is originated,
  78      * though the event is dispatched by  the grabber.
  79      */
  80     private static boolean inManualGrab = false;
  81 
  82     static boolean isManualGrab() {
  83         return inManualGrab;
  84     }
  85 
  86     private static WeakReference<XBaseWindow> grabWindowRef = null;
  87 
  88     /**
  89      * The X Active Grab overrides any other active grab by the same
  90      * client see XGrabPointer, XGrabKeyboard
  91      */
  92     static void setGrabWindow(XBaseWindow grabWindow) {
  93         setGrabWindow(grabWindow, false);
  94     }
  95 
  96     /**
  97      * Automatic passive grab doesn't override active grab see XGrabButton
  98      */
  99     static void setAutoGrabWindow(XBaseWindow grabWindow) {
 100         setGrabWindow(grabWindow, true);
 101     }
 102 
 103     private static void setGrabWindow(XBaseWindow grabWindow, boolean isAutoGrab) {
 104         XToolkit.awtLock();
 105         try {
 106             if (inManualGrab && isAutoGrab) {
 107                 return;
 108             }
 109             inManualGrab = grabWindow != null && !isAutoGrab;
 110             if (grabWindow == null) {
 111                 grabWindowRef = null;
 112                 return;
 113             }
 114             if (grabWindow != getGrabWindow()) {
 115                 grabWindowRef = new WeakReference<>(grabWindow);
 116             }
 117         } finally {
 118             XToolkit.awtUnlock();
 119         }
 120     }
 121 
 122     static XBaseWindow getGrabWindow() {
 123         XToolkit.awtLock();
 124         try {
 125             if (grabWindowRef == null) {
 126                 return null;
 127             }
 128             XBaseWindow xbw = grabWindowRef.get();
 129             if( xbw != null && xbw.isDisposed() ) {
 130                 xbw = null;
 131                 grabWindowRef = null;
 132             }else if( xbw == null ) {
 133                 grabWindowRef = null;
 134             }
 135             return xbw;
 136         } finally {
 137             XToolkit.awtUnlock();
 138         }
 139     }
 140 }