src/java.desktop/windows/classes/sun/awt/windows/WWindowPeer.java

Print this page


   1 /*
   2  * Copyright (c) 1996, 2014, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 392             }
 393         }
 394     }
 395 
 396     native void setMinSize(int width, int height);
 397 
 398 /*
 399  * ---- MODALITY SUPPORT ----
 400  */
 401 
 402     /**
 403      * Some modality-related code here because WFileDialogPeer, WPrintDialogPeer and
 404      *   WPageDialogPeer are descendants of WWindowPeer, not WDialogPeer
 405      */
 406 
 407     public boolean isModalBlocked() {
 408         return modalBlocker != null;
 409     }
 410 
 411      @Override
 412      @SuppressWarnings("deprecation")
 413     public void setModalBlocked(Dialog dialog, boolean blocked) {
 414         synchronized (((Component)getTarget()).getTreeLock()) // State lock should always be after awtLock
 415         {
 416             // use WWindowPeer instead of WDialogPeer because of FileDialogs and PrintDialogs
 417             WWindowPeer blockerPeer = (WWindowPeer)dialog.getPeer();

 418             if (blocked)
 419             {
 420                 modalBlocker = blockerPeer;
 421                 // handle native dialogs separately, as they may have not
 422                 // got HWND yet; modalEnable/modalDisable is called from
 423                 // their setHWnd() methods
 424                 if (blockerPeer instanceof WFileDialogPeer) {
 425                     ((WFileDialogPeer)blockerPeer).blockWindow(this);
 426                 } else if (blockerPeer instanceof WPrintDialogPeer) {
 427                     ((WPrintDialogPeer)blockerPeer).blockWindow(this);
 428                 } else {
 429                     modalDisable(dialog, blockerPeer.getHWnd());
 430                 }
 431             } else {
 432                 modalBlocker = null;
 433                 if (blockerPeer instanceof WFileDialogPeer) {
 434                     ((WFileDialogPeer)blockerPeer).unblockWindow(this);
 435                 } else if (blockerPeer instanceof WPrintDialogPeer) {
 436                     ((WPrintDialogPeer)blockerPeer).unblockWindow(this);
 437                 } else {


 592      public void setBounds(int x, int y, int width, int height, int op) {
 593          sysX = x;
 594          sysY = y;
 595          sysW = width;
 596          sysH = height;
 597 
 598          super.setBounds(x, y, width, height, op);
 599      }
 600 
 601     @Override
 602     public void print(Graphics g) {
 603         // We assume we print the whole frame,
 604         // so we expect no clip was set previously
 605         Shape shape = AWTAccessor.getWindowAccessor().getShape((Window)target);
 606         if (shape != null) {
 607             g.setClip(shape);
 608         }
 609         super.print(g);
 610     }
 611 
 612     @SuppressWarnings("deprecation")
 613     private void replaceSurfaceDataRecursively(Component c) {
 614         if (c instanceof Container) {
 615             for (Component child : ((Container)c).getComponents()) {
 616                 replaceSurfaceDataRecursively(child);
 617             }
 618         }
 619         ComponentPeer cp = c.getPeer();
 620         if (cp instanceof WComponentPeer) {
 621             ((WComponentPeer)cp).replaceSurfaceDataLater();
 622         }
 623     }
 624 
 625     public final Graphics getTranslucentGraphics() {
 626         synchronized (getStateLock()) {
 627             return isOpaque ? null : painter.getBackBuffer(false).getGraphics();
 628         }
 629     }
 630 
 631     @Override
 632     public void setBackground(Color c) {
 633         super.setBackground(c);
 634         synchronized (getStateLock()) {
 635             if (!isOpaque && ((Window)target).isVisible()) {
 636                 updateWindow(true);
 637             }
 638         }
 639     }


 801                 if (log.isLoggable(PlatformLogger.Level.FINE)) {
 802                     log.fine(" Assertion (newValue != true) failed for AppContext.GUI_DISPOSED ");
 803                 }
 804             }
 805             AppContext appContext = AppContext.getAppContext();
 806             synchronized (appContext) {
 807                 appContext.remove(ACTIVE_WINDOWS_KEY);
 808                 appContext.removePropertyChangeListener(AppContext.GUI_DISPOSED, this);
 809 
 810                 KeyboardFocusManager kfm = KeyboardFocusManager.getCurrentKeyboardFocusManager();
 811                 kfm.removePropertyChangeListener("activeWindow", activeWindowListener);
 812             }
 813         }
 814     }
 815 
 816     /*
 817      * Static inner class, listens for 'activeWindow' KFM property changes and
 818      * updates the list of active windows per AppContext, so the latest active
 819      * window is always at the end of the list. The list is stored in AppContext.
 820      */
 821     @SuppressWarnings( value = {"deprecation", "unchecked"})
 822     private static class ActiveWindowListener implements PropertyChangeListener {
 823         @Override
 824         public void propertyChange(PropertyChangeEvent e) {
 825             Window w = (Window)e.getNewValue();
 826             if (w == null) {
 827                 return;
 828             }
 829             AppContext appContext = SunToolkit.targetToAppContext(w);
 830             synchronized (appContext) {
 831                 WWindowPeer wp = (WWindowPeer)w.getPeer();
 832                 // add/move wp to the end of the list
 833                 List<WWindowPeer> l = (List<WWindowPeer>)appContext.get(ACTIVE_WINDOWS_KEY);
 834                 if (l != null) {
 835                     l.remove(wp);
 836                     l.add(wp);
 837                 }
 838             }
 839         }
 840     }
 841 }
   1 /*
   2  * Copyright (c) 1996, 2015, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 392             }
 393         }
 394     }
 395 
 396     native void setMinSize(int width, int height);
 397 
 398 /*
 399  * ---- MODALITY SUPPORT ----
 400  */
 401 
 402     /**
 403      * Some modality-related code here because WFileDialogPeer, WPrintDialogPeer and
 404      *   WPageDialogPeer are descendants of WWindowPeer, not WDialogPeer
 405      */
 406 
 407     public boolean isModalBlocked() {
 408         return modalBlocker != null;
 409     }
 410 
 411      @Override

 412     public void setModalBlocked(Dialog dialog, boolean blocked) {
 413         synchronized (((Component)getTarget()).getTreeLock()) // State lock should always be after awtLock
 414         {
 415             // use WWindowPeer instead of WDialogPeer because of FileDialogs and PrintDialogs
 416             WWindowPeer blockerPeer = AWTAccessor.getComponentAccessor()
 417                                                  .getPeer(dialog);
 418             if (blocked)
 419             {
 420                 modalBlocker = blockerPeer;
 421                 // handle native dialogs separately, as they may have not
 422                 // got HWND yet; modalEnable/modalDisable is called from
 423                 // their setHWnd() methods
 424                 if (blockerPeer instanceof WFileDialogPeer) {
 425                     ((WFileDialogPeer)blockerPeer).blockWindow(this);
 426                 } else if (blockerPeer instanceof WPrintDialogPeer) {
 427                     ((WPrintDialogPeer)blockerPeer).blockWindow(this);
 428                 } else {
 429                     modalDisable(dialog, blockerPeer.getHWnd());
 430                 }
 431             } else {
 432                 modalBlocker = null;
 433                 if (blockerPeer instanceof WFileDialogPeer) {
 434                     ((WFileDialogPeer)blockerPeer).unblockWindow(this);
 435                 } else if (blockerPeer instanceof WPrintDialogPeer) {
 436                     ((WPrintDialogPeer)blockerPeer).unblockWindow(this);
 437                 } else {


 592      public void setBounds(int x, int y, int width, int height, int op) {
 593          sysX = x;
 594          sysY = y;
 595          sysW = width;
 596          sysH = height;
 597 
 598          super.setBounds(x, y, width, height, op);
 599      }
 600 
 601     @Override
 602     public void print(Graphics g) {
 603         // We assume we print the whole frame,
 604         // so we expect no clip was set previously
 605         Shape shape = AWTAccessor.getWindowAccessor().getShape((Window)target);
 606         if (shape != null) {
 607             g.setClip(shape);
 608         }
 609         super.print(g);
 610     }
 611 

 612     private void replaceSurfaceDataRecursively(Component c) {
 613         if (c instanceof Container) {
 614             for (Component child : ((Container)c).getComponents()) {
 615                 replaceSurfaceDataRecursively(child);
 616             }
 617         }
 618         final Object cp = AWTAccessor.getComponentAccessor().getPeer(c);
 619         if (cp instanceof WComponentPeer) {
 620             ((WComponentPeer)cp).replaceSurfaceDataLater();
 621         }
 622     }
 623 
 624     public final Graphics getTranslucentGraphics() {
 625         synchronized (getStateLock()) {
 626             return isOpaque ? null : painter.getBackBuffer(false).getGraphics();
 627         }
 628     }
 629 
 630     @Override
 631     public void setBackground(Color c) {
 632         super.setBackground(c);
 633         synchronized (getStateLock()) {
 634             if (!isOpaque && ((Window)target).isVisible()) {
 635                 updateWindow(true);
 636             }
 637         }
 638     }


 800                 if (log.isLoggable(PlatformLogger.Level.FINE)) {
 801                     log.fine(" Assertion (newValue != true) failed for AppContext.GUI_DISPOSED ");
 802                 }
 803             }
 804             AppContext appContext = AppContext.getAppContext();
 805             synchronized (appContext) {
 806                 appContext.remove(ACTIVE_WINDOWS_KEY);
 807                 appContext.removePropertyChangeListener(AppContext.GUI_DISPOSED, this);
 808 
 809                 KeyboardFocusManager kfm = KeyboardFocusManager.getCurrentKeyboardFocusManager();
 810                 kfm.removePropertyChangeListener("activeWindow", activeWindowListener);
 811             }
 812         }
 813     }
 814 
 815     /*
 816      * Static inner class, listens for 'activeWindow' KFM property changes and
 817      * updates the list of active windows per AppContext, so the latest active
 818      * window is always at the end of the list. The list is stored in AppContext.
 819      */
 820     @SuppressWarnings("unchecked")
 821     private static class ActiveWindowListener implements PropertyChangeListener {
 822         @Override
 823         public void propertyChange(PropertyChangeEvent e) {
 824             Window w = (Window)e.getNewValue();
 825             if (w == null) {
 826                 return;
 827             }
 828             AppContext appContext = SunToolkit.targetToAppContext(w);
 829             synchronized (appContext) {
 830                 WWindowPeer wp = AWTAccessor.getComponentAccessor().getPeer(w);
 831                 // add/move wp to the end of the list
 832                 List<WWindowPeer> l = (List<WWindowPeer>)appContext.get(ACTIVE_WINDOWS_KEY);
 833                 if (l != null) {
 834                     l.remove(wp);
 835                     l.add(wp);
 836                 }
 837             }
 838         }
 839     }
 840 }