src/macosx/classes/sun/lwawt/LWWindowPeer.java

Print this page




  84 // TODO: VolatileImage
  85 //    private VolatileImage backBuffer;
  86     private volatile BufferedImage backBuffer;
  87 
  88     private volatile int windowState = Frame.NORMAL;
  89 
  90     // A peer where the last mouse event came to. Used to generate
  91     // MOUSE_ENTERED/EXITED notifications and by cursor manager to
  92     // find the component under cursor
  93     private static volatile LWComponentPeer lastMouseEventPeer = null;
  94 
  95     // Peers where all dragged/released events should come to,
  96     // depending on what mouse button is being dragged according to Cocoa
  97     private static LWComponentPeer mouseDownTarget[] = new LWComponentPeer[3];
  98 
  99     // A bitmask that indicates what mouse buttons produce MOUSE_CLICKED events
 100     // on MOUSE_RELEASE. Click events are only generated if there were no drag
 101     // events between MOUSE_PRESSED and MOUSE_RELEASED for particular button
 102     private static int mouseClickButtons = 0;
 103 
 104     private volatile boolean cachedFocusableWindow;
 105 
 106     private volatile boolean isOpaque = true;
 107 
 108     private static final Font DEFAULT_FONT = new Font("Lucida Grande", Font.PLAIN, 13);
 109 
 110     private static LWWindowPeer grabbingWindow;
 111 
 112     private volatile boolean skipNextFocusChange;
 113 
 114     /**
 115      * Current modal blocker or null.
 116      *
 117      * Synchronization: peerTreeLock.
 118      */
 119     private LWWindowPeer blocker;
 120 
 121     public LWWindowPeer(Window target, PlatformComponent platformComponent,
 122                         PlatformWindow platformWindow)
 123     {
 124         super(target, platformComponent);
 125         this.platformWindow = platformWindow;


 159 
 160         platformWindow.initialize(target, this, ownerDelegate);
 161     }
 162 
 163     @Override
 164     public void initialize() {
 165         super.initialize();
 166 
 167         updateInsets(platformWindow.getInsets());
 168 
 169         if (getTarget() instanceof Frame) {
 170             setTitle(((Frame)getTarget()).getTitle());
 171             setState(((Frame)getTarget()).getExtendedState());
 172         } else if (getTarget() instanceof Dialog) {
 173             setTitle(((Dialog)getTarget()).getTitle());
 174         }
 175 
 176         setAlwaysOnTop(getTarget().isAlwaysOnTop());
 177         updateMinimumSize();
 178 
 179         cachedFocusableWindow = getTarget().isFocusableWindow();
 180 
 181         setOpacity(getTarget().getOpacity());
 182         setOpaque(getTarget().isOpaque());
 183 
 184         // Create surface data and back buffer
 185         replaceSurfaceData(1, null);
 186     }
 187 
 188     // Just a helper method
 189     public PlatformWindow getPlatformWindow() {
 190         return platformWindow;
 191     }
 192 
 193     @Override
 194     protected LWWindowPeer getWindowPeerOrSelf() {
 195         return this;
 196     }
 197 
 198     @Override
 199     protected void initializeContainerPeer() {
 200         // No-op as LWWindowPeer doesn't have any containerPeer


 231         super.setVisible(visible);
 232 
 233         // TODO: update graphicsConfig, see 4868278
 234         // TODO: don't notify the delegate if our visibility is unchanged
 235 
 236         // it is important to call this method on EDT
 237         // to prevent the deadlocks during the painting of the lightweight delegates
 238         //TODO: WHY? This is a native-system related call. Perhaps NOT calling
 239         // the painting procedure right from the setVisible(), but rather relying
 240         // on the native Expose event (or, scheduling the repainting asynchronously)
 241         // is better?
 242         SwingUtilities.invokeLater(new Runnable() {
 243             @Override
 244             public void run() {
 245                 platformWindow.setVisible(visible);
 246                 if (isSimpleWindow()) {
 247                     LWKeyboardFocusManagerPeer manager = LWKeyboardFocusManagerPeer.
 248                         getInstance(getAppContext());
 249 
 250                     if (visible) {
 251                         updateFocusableWindowState();
 252                         changeFocusedWindow(true, true);
 253 
 254                     // Focus the owner in case this window is focused.
 255                     } else if (manager.getCurrentFocusedWindow() == getTarget()) {
 256                         LWWindowPeer owner = getOwnerFrameDialog(LWWindowPeer.this);
 257                         if (owner != null) {
 258                             // KFM will do all the rest.
 259                             owner.changeFocusedWindow(true, false);
 260                         }
 261                     }
 262                 }
 263             }
 264         });
 265     }
 266 
 267     @Override
 268     public GraphicsConfiguration getGraphicsConfiguration() {
 269         return graphicsConfig;
 270     }
 271 


 386         platformWindow.toFront();
 387     }
 388 
 389     @Override
 390     public void toBack() {
 391         platformWindow.toBack();
 392     }
 393 
 394     @Override
 395     public void setZOrder(ComponentPeer above) {
 396         throw new RuntimeException("not implemented");
 397     }
 398 
 399     @Override
 400     public void setAlwaysOnTop(boolean value) {
 401         platformWindow.setAlwaysOnTop(value);
 402     }
 403 
 404     @Override
 405     public void updateFocusableWindowState() {
 406         cachedFocusableWindow = getTarget().isFocusableWindow();
 407         platformWindow.updateFocusableWindowState();
 408     }
 409 
 410     @Override
 411     public void setModalBlocked(Dialog blocker, boolean blocked) {
 412         synchronized (getPeerTreeLock()) {
 413             this.blocker = blocked ? (LWWindowPeer)blocker.getPeer() : null;
 414         }
 415     }
 416 
 417     @Override
 418     public void updateMinimumSize() {
 419         Dimension d = null;
 420         if (getTarget().isMinimumSizeSet()) {
 421             d = getTarget().getMinimumSize();
 422         }
 423         if (d == null) {
 424             d = new Dimension(MINIMUM_WIDTH, MINIMUM_HEIGHT);
 425         }
 426         platformWindow.setMinimumSize(d.width, d.height);


1103                 owner.platformWindow.requestWindowFocus();
1104             }
1105 
1106             // DKFM will synthesize all the focus/activation events correctly.
1107             changeFocusedWindow(true, false);
1108             return true;
1109 
1110         // In case the toplevel is active but not focused, change focus directly,
1111         // as requesting native focus on it will not have effect.
1112         } else if (getTarget() == currentActive && !getTarget().hasFocus()) {
1113 
1114             changeFocusedWindow(true, false);
1115             return true;
1116         }
1117         return platformWindow.requestWindowFocus();
1118     }
1119 
1120     private boolean focusAllowedFor() {
1121         Window window = getTarget();
1122         // TODO: check if modal blocked
1123         return window.isVisible() && window.isEnabled() && window.isFocusableWindow();












1124     }
1125 
1126     public boolean isSimpleWindow() {
1127         Window window = getTarget();
1128         return !(window instanceof Dialog || window instanceof Frame);
1129     }
1130 
1131     /*
1132      * "Delegates" the responsibility of managing focus to keyboard focus manager.
1133      */
1134     private void changeFocusedWindow(boolean becomesFocused, boolean isShowing) {
1135         if (focusLog.isLoggable(PlatformLogger.FINE)) {
1136             focusLog.fine((becomesFocused?"gaining":"loosing") + " focus window: " + this);
1137         }
1138         if (isShowing && !getTarget().isAutoRequestFocus() || skipNextFocusChange) {
1139             focusLog.fine("skipping focus change");
1140             skipNextFocusChange = false;
1141             return;
1142         }
1143 
1144         if (!cachedFocusableWindow) {
1145             return;
1146         }
1147         if (becomesFocused) {
1148             synchronized (getPeerTreeLock()) {
1149                 if (blocker != null) {
1150                     if (focusLog.isLoggable(PlatformLogger.FINEST)) {
1151                         focusLog.finest("the window is blocked by " + blocker);
1152                     }
1153                     return;
1154                 }
1155             }
1156         }
1157 
1158         LWKeyboardFocusManagerPeer manager = LWKeyboardFocusManagerPeer.
1159             getInstance(getAppContext());
1160 
1161         Window oppositeWindow = becomesFocused ? manager.getCurrentFocusedWindow() : null;
1162 
1163         // Note, the method is not called:
1164         // - when the opposite (gaining focus) window is an owned/owner window.




  84 // TODO: VolatileImage
  85 //    private VolatileImage backBuffer;
  86     private volatile BufferedImage backBuffer;
  87 
  88     private volatile int windowState = Frame.NORMAL;
  89 
  90     // A peer where the last mouse event came to. Used to generate
  91     // MOUSE_ENTERED/EXITED notifications and by cursor manager to
  92     // find the component under cursor
  93     private static volatile LWComponentPeer lastMouseEventPeer = null;
  94 
  95     // Peers where all dragged/released events should come to,
  96     // depending on what mouse button is being dragged according to Cocoa
  97     private static LWComponentPeer mouseDownTarget[] = new LWComponentPeer[3];
  98 
  99     // A bitmask that indicates what mouse buttons produce MOUSE_CLICKED events
 100     // on MOUSE_RELEASE. Click events are only generated if there were no drag
 101     // events between MOUSE_PRESSED and MOUSE_RELEASED for particular button
 102     private static int mouseClickButtons = 0;
 103 


 104     private volatile boolean isOpaque = true;
 105 
 106     private static final Font DEFAULT_FONT = new Font("Lucida Grande", Font.PLAIN, 13);
 107 
 108     private static LWWindowPeer grabbingWindow;
 109 
 110     private volatile boolean skipNextFocusChange;
 111 
 112     /**
 113      * Current modal blocker or null.
 114      *
 115      * Synchronization: peerTreeLock.
 116      */
 117     private LWWindowPeer blocker;
 118 
 119     public LWWindowPeer(Window target, PlatformComponent platformComponent,
 120                         PlatformWindow platformWindow)
 121     {
 122         super(target, platformComponent);
 123         this.platformWindow = platformWindow;


 157 
 158         platformWindow.initialize(target, this, ownerDelegate);
 159     }
 160 
 161     @Override
 162     public void initialize() {
 163         super.initialize();
 164 
 165         updateInsets(platformWindow.getInsets());
 166 
 167         if (getTarget() instanceof Frame) {
 168             setTitle(((Frame)getTarget()).getTitle());
 169             setState(((Frame)getTarget()).getExtendedState());
 170         } else if (getTarget() instanceof Dialog) {
 171             setTitle(((Dialog)getTarget()).getTitle());
 172         }
 173 
 174         setAlwaysOnTop(getTarget().isAlwaysOnTop());
 175         updateMinimumSize();
 176 


 177         setOpacity(getTarget().getOpacity());
 178         setOpaque(getTarget().isOpaque());
 179 
 180         // Create surface data and back buffer
 181         replaceSurfaceData(1, null);
 182     }
 183 
 184     // Just a helper method
 185     public PlatformWindow getPlatformWindow() {
 186         return platformWindow;
 187     }
 188 
 189     @Override
 190     protected LWWindowPeer getWindowPeerOrSelf() {
 191         return this;
 192     }
 193 
 194     @Override
 195     protected void initializeContainerPeer() {
 196         // No-op as LWWindowPeer doesn't have any containerPeer


 227         super.setVisible(visible);
 228 
 229         // TODO: update graphicsConfig, see 4868278
 230         // TODO: don't notify the delegate if our visibility is unchanged
 231 
 232         // it is important to call this method on EDT
 233         // to prevent the deadlocks during the painting of the lightweight delegates
 234         //TODO: WHY? This is a native-system related call. Perhaps NOT calling
 235         // the painting procedure right from the setVisible(), but rather relying
 236         // on the native Expose event (or, scheduling the repainting asynchronously)
 237         // is better?
 238         SwingUtilities.invokeLater(new Runnable() {
 239             @Override
 240             public void run() {
 241                 platformWindow.setVisible(visible);
 242                 if (isSimpleWindow()) {
 243                     LWKeyboardFocusManagerPeer manager = LWKeyboardFocusManagerPeer.
 244                         getInstance(getAppContext());
 245 
 246                     if (visible) {

 247                         changeFocusedWindow(true, true);
 248 
 249                     // Focus the owner in case this window is focused.
 250                     } else if (manager.getCurrentFocusedWindow() == getTarget()) {
 251                         LWWindowPeer owner = getOwnerFrameDialog(LWWindowPeer.this);
 252                         if (owner != null) {
 253                             // KFM will do all the rest.
 254                             owner.changeFocusedWindow(true, false);
 255                         }
 256                     }
 257                 }
 258             }
 259         });
 260     }
 261 
 262     @Override
 263     public GraphicsConfiguration getGraphicsConfiguration() {
 264         return graphicsConfig;
 265     }
 266 


 381         platformWindow.toFront();
 382     }
 383 
 384     @Override
 385     public void toBack() {
 386         platformWindow.toBack();
 387     }
 388 
 389     @Override
 390     public void setZOrder(ComponentPeer above) {
 391         throw new RuntimeException("not implemented");
 392     }
 393 
 394     @Override
 395     public void setAlwaysOnTop(boolean value) {
 396         platformWindow.setAlwaysOnTop(value);
 397     }
 398 
 399     @Override
 400     public void updateFocusableWindowState() {

 401         platformWindow.updateFocusableWindowState();
 402     }
 403 
 404     @Override
 405     public void setModalBlocked(Dialog blocker, boolean blocked) {
 406         synchronized (getPeerTreeLock()) {
 407             this.blocker = blocked ? (LWWindowPeer)blocker.getPeer() : null;
 408         }
 409     }
 410 
 411     @Override
 412     public void updateMinimumSize() {
 413         Dimension d = null;
 414         if (getTarget().isMinimumSizeSet()) {
 415             d = getTarget().getMinimumSize();
 416         }
 417         if (d == null) {
 418             d = new Dimension(MINIMUM_WIDTH, MINIMUM_HEIGHT);
 419         }
 420         platformWindow.setMinimumSize(d.width, d.height);


1097                 owner.platformWindow.requestWindowFocus();
1098             }
1099 
1100             // DKFM will synthesize all the focus/activation events correctly.
1101             changeFocusedWindow(true, false);
1102             return true;
1103 
1104         // In case the toplevel is active but not focused, change focus directly,
1105         // as requesting native focus on it will not have effect.
1106         } else if (getTarget() == currentActive && !getTarget().hasFocus()) {
1107 
1108             changeFocusedWindow(true, false);
1109             return true;
1110         }
1111         return platformWindow.requestWindowFocus();
1112     }
1113 
1114     private boolean focusAllowedFor() {
1115         Window window = getTarget();
1116         // TODO: check if modal blocked
1117         return window.isVisible() && window.isEnabled() && isFocusableWindow();
1118     }
1119     
1120     private boolean isFocusableWindow() {
1121         boolean focusable = getTarget().isFocusableWindow();
1122         if (isSimpleWindow()) {
1123             LWWindowPeer ownerPeer = getOwnerFrameDialog(this);
1124             if (ownerPeer == null) {
1125                 return false;
1126             }
1127             return focusable && ownerPeer.getTarget().isFocusableWindow();
1128         }
1129         return focusable;
1130     }
1131 
1132     public boolean isSimpleWindow() {
1133         Window window = getTarget();
1134         return !(window instanceof Dialog || window instanceof Frame);
1135     }
1136 
1137     /*
1138      * "Delegates" the responsibility of managing focus to keyboard focus manager.
1139      */
1140     private void changeFocusedWindow(boolean becomesFocused, boolean isShowing) {
1141         if (focusLog.isLoggable(PlatformLogger.FINE)) {
1142             focusLog.fine((becomesFocused?"gaining":"loosing") + " focus window: " + this);
1143         }
1144         if (isShowing && !getTarget().isAutoRequestFocus() || skipNextFocusChange) {
1145             focusLog.fine("skipping focus change");
1146             skipNextFocusChange = false;
1147             return;
1148         }
1149         if (!isFocusableWindow() && becomesFocused) {
1150             focusLog.fine("the window is not focusable");            
1151             return;
1152         }
1153         if (becomesFocused) {
1154             synchronized (getPeerTreeLock()) {
1155                 if (blocker != null) {
1156                     if (focusLog.isLoggable(PlatformLogger.FINEST)) {
1157                         focusLog.finest("the window is blocked by " + blocker);
1158                     }
1159                     return;
1160                 }
1161             }
1162         }
1163 
1164         LWKeyboardFocusManagerPeer manager = LWKeyboardFocusManagerPeer.
1165             getInstance(getAppContext());
1166 
1167         Window oppositeWindow = becomesFocused ? manager.getCurrentFocusedWindow() : null;
1168 
1169         // Note, the method is not called:
1170         // - when the opposite (gaining focus) window is an owned/owner window.