changeset 3078:b6d79a32b07a

6699851: setMaximizedbounds not working properly on dual screen environment Reviewed-by: art, anthony
author dcherepanov
date Fri, 26 Nov 2010 14:36:42 +0300
parents 6c4e7fe53c36
children 3a2355dcef13
files src/share/classes/java/awt/Frame.java src/share/classes/sun/awt/AWTAccessor.java src/windows/classes/sun/awt/windows/WFramePeer.java
diffstat 3 files changed, 57 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/java/awt/Frame.java	Fri Nov 26 11:27:00 2010 +0300
+++ b/src/share/classes/java/awt/Frame.java	Fri Nov 26 14:36:42 2010 +0300
@@ -828,6 +828,11 @@
                         return frame.state;
                     }
                 }
+                public Rectangle getMaximizedBounds(Frame frame) {
+                    synchronized(frame.getObjectLock()) {
+                        return frame.maximizedBounds;
+                    }
+                }
             }
         );
     }
@@ -855,8 +860,10 @@
      * @see #getMaximizedBounds()
      * @since 1.4
      */
-    public synchronized void setMaximizedBounds(Rectangle bounds) {
-        this.maximizedBounds = bounds;
+    public void setMaximizedBounds(Rectangle bounds) {
+        synchronized(getObjectLock()) {
+            this.maximizedBounds = bounds;
+        }
         FramePeer peer = (FramePeer)this.peer;
         if (peer != null) {
             peer.setMaximizedBounds(bounds);
@@ -873,7 +880,9 @@
      * @since   1.4
      */
     public Rectangle getMaximizedBounds() {
-        return maximizedBounds;
+        synchronized(getObjectLock()) {
+            return maximizedBounds;
+        }
     }
 
 
--- a/src/share/classes/sun/awt/AWTAccessor.java	Fri Nov 26 11:27:00 2010 +0300
+++ b/src/share/classes/sun/awt/AWTAccessor.java	Fri Nov 26 14:36:42 2010 +0300
@@ -334,6 +334,10 @@
          * Gets the state of this frame.
          */
        int getExtendedState(Frame frame);
+        /*
+         * Gets the maximized bounds of this frame.
+         */
+       Rectangle getMaximizedBounds(Frame frame);
     }
 
     /*
--- a/src/windows/classes/sun/awt/windows/WFramePeer.java	Fri Nov 26 11:27:00 2010 +0300
+++ b/src/windows/classes/sun/awt/windows/WFramePeer.java	Fri Nov 26 14:36:42 2010 +0300
@@ -79,10 +79,50 @@
         if (b == null) {
             clearMaximizedBounds();
         } else {
-            setMaximizedBounds(b.x, b.y, b.width, b.height);
+            Rectangle adjBounds = (Rectangle)b.clone();
+            adjustMaximizedBounds(adjBounds);
+            setMaximizedBounds(adjBounds.x, adjBounds.y, adjBounds.width, adjBounds.height);
         }
     }
 
+    /**
+     * The incoming bounds describe the maximized size and position of the
+     * window on the monitor that displays the window. But the window manager
+     * expects that the bounds are based on the size and position of the
+     * primary monitor, even if the window ultimately maximizes onto a
+     * secondary monitor. And the window manager adjusts these values to
+     * compensate for differences between the primary monitor and the monitor
+     * that displays the window.
+     * The method translates the incoming bounds to the values acceptable
+     * by the window manager. For more details, please refer to 6699851.
+     */
+    private void adjustMaximizedBounds(Rectangle b) {
+        GraphicsConfiguration currentDevGC = getGraphicsConfiguration();
+
+        GraphicsDevice primaryDev = GraphicsEnvironment
+            .getLocalGraphicsEnvironment().getDefaultScreenDevice();
+        GraphicsConfiguration primaryDevGC = primaryDev.getDefaultConfiguration();
+
+        if (currentDevGC != null && currentDevGC != primaryDevGC) {
+            Rectangle currentDevBounds = currentDevGC.getBounds();
+            Rectangle primaryDevBounds = primaryDevGC.getBounds();
+
+            b.width -= (currentDevBounds.width - primaryDevBounds.width);
+            b.height -= (currentDevBounds.height - primaryDevBounds.height);
+        }
+    }
+
+    @Override
+    public boolean updateGraphicsData(GraphicsConfiguration gc) {
+        boolean result = super.updateGraphicsData(gc);
+        Rectangle bounds = AWTAccessor.getFrameAccessor().
+                               getMaximizedBounds((Frame)target);
+        if (bounds != null) {
+            setMaximizedBounds(bounds);
+        }
+        return result;
+    }
+
     @Override
     boolean isTargetUndecorated() {
         return ((Frame)target).isUndecorated();