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

Print this page




 443     }
 444 
 445 /*
 446  * ----DISPLAY CHANGE SUPPORT----
 447  */
 448 
 449     /*
 450      * Called from native code when we have been dragged onto another screen.
 451      */
 452     void draggedToNewScreen() {
 453         SunToolkit.executeOnEventHandlerThread((Component)target,new Runnable()
 454         {
 455             public void run() {
 456                 displayChanged();
 457             }
 458         });
 459     }
 460 
 461     public void updateGC() {
 462         int scrn = getScreenImOn();
 463         if (screenLog.isLoggable(PlatformLogger.FINER)) {
 464             log.finer("Screen number: " + scrn);
 465         }
 466 
 467         // get current GD
 468         Win32GraphicsDevice oldDev = (Win32GraphicsDevice)winGraphicsConfig
 469                                      .getDevice();
 470 
 471         Win32GraphicsDevice newDev;
 472         GraphicsDevice devs[] = GraphicsEnvironment
 473             .getLocalGraphicsEnvironment()
 474             .getScreenDevices();
 475         // Occasionally during device addition/removal getScreenImOn can return
 476         // a non-existing screen number. Use the default device in this case.
 477         if (scrn >= devs.length) {
 478             newDev = (Win32GraphicsDevice)GraphicsEnvironment
 479                 .getLocalGraphicsEnvironment().getDefaultScreenDevice();
 480         } else {
 481             newDev = (Win32GraphicsDevice)devs[scrn];
 482         }
 483 
 484         // Set winGraphicsConfig to the default GC for the monitor this Window
 485         // is now mostly on.
 486         winGraphicsConfig = (Win32GraphicsConfig)newDev
 487                             .getDefaultConfiguration();
 488         if (screenLog.isLoggable(PlatformLogger.FINE)) {
 489             if (winGraphicsConfig == null) {
 490                 screenLog.fine("Assertion (winGraphicsConfig != null) failed");
 491             }
 492         }
 493 
 494         // if on a different display, take off old GD and put on new GD
 495         if (oldDev != newDev) {
 496             oldDev.removeDisplayChangedListener(this);
 497             newDev.addDisplayChangedListener(this);
 498         }
 499 
 500         AWTAccessor.getComponentAccessor().
 501             setGraphicsConfiguration((Component)target, winGraphicsConfig);
 502     }
 503 
 504     /**
 505      * From the DisplayChangedListener interface.
 506      *
 507      * This method handles a display change - either when the display settings
 508      * are changed, or when the window has been dragged onto a different


 713         }
 714     }
 715 
 716     public native void updateWindowImpl(int[] data, int width, int height);
 717 
 718     public void updateWindow() {
 719         updateWindow(false);
 720     }
 721 
 722     private void updateWindow(boolean repaint) {
 723         Window w = (Window)target;
 724         synchronized (getStateLock()) {
 725             if (isOpaque || !w.isVisible() ||
 726                 (w.getWidth() <= 0) || (w.getHeight() <= 0))
 727             {
 728                 return;
 729             }
 730             TranslucentWindowPainter currentPainter = painter;
 731             if (currentPainter != null) {
 732                 currentPainter.updateWindow(repaint);
 733             } else if (log.isLoggable(PlatformLogger.FINER)) {
 734                 log.finer("Translucent window painter is null in updateWindow");
 735             }
 736         }
 737     }
 738 
 739     /*
 740      * The method maps the list of the active windows to the window's AppContext,
 741      * then the method registers ActiveWindowListener, GuiDisposedListener listeners;
 742      * it executes the initilialization only once per AppContext.
 743      */
 744     @SuppressWarnings("unchecked")
 745     private static void initActiveWindowsTracking(Window w) {
 746         AppContext appContext = AppContext.getAppContext();
 747         synchronized (appContext) {
 748             List<WWindowPeer> l = (List<WWindowPeer>)appContext.get(ACTIVE_WINDOWS_KEY);
 749             if (l == null) {
 750                 l = new LinkedList<WWindowPeer>();
 751                 appContext.put(ACTIVE_WINDOWS_KEY, l);
 752                 appContext.addPropertyChangeListener(AppContext.GUI_DISPOSED, guiDisposedListener);
 753 
 754                 KeyboardFocusManager kfm = KeyboardFocusManager.getCurrentKeyboardFocusManager();
 755                 kfm.addPropertyChangeListener("activeWindow", activeWindowListener);
 756             }
 757         }
 758     }
 759 
 760     /*
 761      * The GuiDisposedListener class listens for the AppContext.GUI_DISPOSED property,
 762      * it removes the list of the active windows from the disposed AppContext and
 763      * unregisters ActiveWindowListener listener.
 764      */
 765     private static class GuiDisposedListener implements PropertyChangeListener {
 766         public void propertyChange(PropertyChangeEvent e) {
 767             boolean isDisposed = (Boolean)e.getNewValue();
 768             if (isDisposed != true) {
 769                 if (log.isLoggable(PlatformLogger.FINE)) {
 770                     log.fine(" Assertion (newValue != true) failed for AppContext.GUI_DISPOSED ");
 771                 }
 772             }
 773             AppContext appContext = AppContext.getAppContext();
 774             synchronized (appContext) {
 775                 appContext.remove(ACTIVE_WINDOWS_KEY);
 776                 appContext.removePropertyChangeListener(AppContext.GUI_DISPOSED, this);
 777 
 778                 KeyboardFocusManager kfm = KeyboardFocusManager.getCurrentKeyboardFocusManager();
 779                 kfm.removePropertyChangeListener("activeWindow", activeWindowListener);
 780             }
 781         }
 782     }
 783 
 784     /*
 785      * Static inner class, listens for 'activeWindow' KFM property changes and
 786      * updates the list of active windows per AppContext, so the latest active
 787      * window is always at the end of the list. The list is stored in AppContext.
 788      */
 789     @SuppressWarnings( value = {"deprecation", "unchecked"})


 443     }
 444 
 445 /*
 446  * ----DISPLAY CHANGE SUPPORT----
 447  */
 448 
 449     /*
 450      * Called from native code when we have been dragged onto another screen.
 451      */
 452     void draggedToNewScreen() {
 453         SunToolkit.executeOnEventHandlerThread((Component)target,new Runnable()
 454         {
 455             public void run() {
 456                 displayChanged();
 457             }
 458         });
 459     }
 460 
 461     public void updateGC() {
 462         int scrn = getScreenImOn();
 463         if (screenLog.isLoggable(PlatformLogger.Level.FINER)) {
 464             log.finer("Screen number: " + scrn);
 465         }
 466 
 467         // get current GD
 468         Win32GraphicsDevice oldDev = (Win32GraphicsDevice)winGraphicsConfig
 469                                      .getDevice();
 470 
 471         Win32GraphicsDevice newDev;
 472         GraphicsDevice devs[] = GraphicsEnvironment
 473             .getLocalGraphicsEnvironment()
 474             .getScreenDevices();
 475         // Occasionally during device addition/removal getScreenImOn can return
 476         // a non-existing screen number. Use the default device in this case.
 477         if (scrn >= devs.length) {
 478             newDev = (Win32GraphicsDevice)GraphicsEnvironment
 479                 .getLocalGraphicsEnvironment().getDefaultScreenDevice();
 480         } else {
 481             newDev = (Win32GraphicsDevice)devs[scrn];
 482         }
 483 
 484         // Set winGraphicsConfig to the default GC for the monitor this Window
 485         // is now mostly on.
 486         winGraphicsConfig = (Win32GraphicsConfig)newDev
 487                             .getDefaultConfiguration();
 488         if (screenLog.isLoggable(PlatformLogger.Level.FINE)) {
 489             if (winGraphicsConfig == null) {
 490                 screenLog.fine("Assertion (winGraphicsConfig != null) failed");
 491             }
 492         }
 493 
 494         // if on a different display, take off old GD and put on new GD
 495         if (oldDev != newDev) {
 496             oldDev.removeDisplayChangedListener(this);
 497             newDev.addDisplayChangedListener(this);
 498         }
 499 
 500         AWTAccessor.getComponentAccessor().
 501             setGraphicsConfiguration((Component)target, winGraphicsConfig);
 502     }
 503 
 504     /**
 505      * From the DisplayChangedListener interface.
 506      *
 507      * This method handles a display change - either when the display settings
 508      * are changed, or when the window has been dragged onto a different


 713         }
 714     }
 715 
 716     public native void updateWindowImpl(int[] data, int width, int height);
 717 
 718     public void updateWindow() {
 719         updateWindow(false);
 720     }
 721 
 722     private void updateWindow(boolean repaint) {
 723         Window w = (Window)target;
 724         synchronized (getStateLock()) {
 725             if (isOpaque || !w.isVisible() ||
 726                 (w.getWidth() <= 0) || (w.getHeight() <= 0))
 727             {
 728                 return;
 729             }
 730             TranslucentWindowPainter currentPainter = painter;
 731             if (currentPainter != null) {
 732                 currentPainter.updateWindow(repaint);
 733             } else if (log.isLoggable(PlatformLogger.Level.FINER)) {
 734                 log.finer("Translucent window painter is null in updateWindow");
 735             }
 736         }
 737     }
 738 
 739     /*
 740      * The method maps the list of the active windows to the window's AppContext,
 741      * then the method registers ActiveWindowListener, GuiDisposedListener listeners;
 742      * it executes the initilialization only once per AppContext.
 743      */
 744     @SuppressWarnings("unchecked")
 745     private static void initActiveWindowsTracking(Window w) {
 746         AppContext appContext = AppContext.getAppContext();
 747         synchronized (appContext) {
 748             List<WWindowPeer> l = (List<WWindowPeer>)appContext.get(ACTIVE_WINDOWS_KEY);
 749             if (l == null) {
 750                 l = new LinkedList<WWindowPeer>();
 751                 appContext.put(ACTIVE_WINDOWS_KEY, l);
 752                 appContext.addPropertyChangeListener(AppContext.GUI_DISPOSED, guiDisposedListener);
 753 
 754                 KeyboardFocusManager kfm = KeyboardFocusManager.getCurrentKeyboardFocusManager();
 755                 kfm.addPropertyChangeListener("activeWindow", activeWindowListener);
 756             }
 757         }
 758     }
 759 
 760     /*
 761      * The GuiDisposedListener class listens for the AppContext.GUI_DISPOSED property,
 762      * it removes the list of the active windows from the disposed AppContext and
 763      * unregisters ActiveWindowListener listener.
 764      */
 765     private static class GuiDisposedListener implements PropertyChangeListener {
 766         public void propertyChange(PropertyChangeEvent e) {
 767             boolean isDisposed = (Boolean)e.getNewValue();
 768             if (isDisposed != true) {
 769                 if (log.isLoggable(PlatformLogger.Level.FINE)) {
 770                     log.fine(" Assertion (newValue != true) failed for AppContext.GUI_DISPOSED ");
 771                 }
 772             }
 773             AppContext appContext = AppContext.getAppContext();
 774             synchronized (appContext) {
 775                 appContext.remove(ACTIVE_WINDOWS_KEY);
 776                 appContext.removePropertyChangeListener(AppContext.GUI_DISPOSED, this);
 777 
 778                 KeyboardFocusManager kfm = KeyboardFocusManager.getCurrentKeyboardFocusManager();
 779                 kfm.removePropertyChangeListener("activeWindow", activeWindowListener);
 780             }
 781         }
 782     }
 783 
 784     /*
 785      * Static inner class, listens for 'activeWindow' KFM property changes and
 786      * updates the list of active windows per AppContext, so the latest active
 787      * window is always at the end of the list. The list is stored in AppContext.
 788      */
 789     @SuppressWarnings( value = {"deprecation", "unchecked"})