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

Print this page

        

@@ -59,10 +59,11 @@
 
     private static final int MINIMUM_WIDTH = 1;
     private static final int MINIMUM_HEIGHT = 1;
 
     private Insets insets = new Insets(0, 0, 0, 0);
+    private Rectangle maximizedBounds;
 
     private GraphicsDevice graphicsDevice;
     private GraphicsConfiguration graphicsConfig;
 
     private SurfaceData surfaceData;

@@ -174,12 +175,14 @@
     void initializeImpl() {
         super.initializeImpl();
 
 
         if (getTarget() instanceof Frame) {
-            setTitle(((Frame) getTarget()).getTitle());
-            setState(((Frame) getTarget()).getExtendedState());
+            Frame frame = (Frame) getTarget();
+            setTitle(frame.getTitle());
+            setState(frame.getExtendedState());
+            setMaximizedBounds(frame.getMaximizedBounds());
         } else if (getTarget() instanceof Dialog) {
             setTitle(((Dialog) getTarget()).getTitle());
         }
 
         updateAlwaysOnTopState();

@@ -541,13 +544,44 @@
     @Override
     public int getState() {
         return windowState;
     }
 
+    private boolean isMaximizedBoundsSet() {
+        synchronized (getStateLock()) {
+            return maximizedBounds != null;
+        }
+    }
+
+    private Rectangle getDefaultMaximizedBounds() {
+        GraphicsConfiguration config = getGraphicsConfiguration();
+        Insets screenInsets = ((CGraphicsDevice) config.getDevice())
+                .getScreenInsets();
+        Rectangle gcBounds = config.getBounds();
+        return new Rectangle(
+                gcBounds.x + screenInsets.left,
+                gcBounds.y + screenInsets.top,
+                gcBounds.width - screenInsets.left - screenInsets.right,
+                gcBounds.height - screenInsets.top - screenInsets.bottom);
+    }
+
     @Override
     public void setMaximizedBounds(Rectangle bounds) {
-        // TODO: not implemented
+        boolean isMaximizedBoundsSet;
+        synchronized (getStateLock()) {
+            this.maximizedBounds = (isMaximizedBoundsSet = (bounds != null))
+                    ? constrainBounds(bounds) : null;
+        }
+
+        setPlatformMaximizedBounds(isMaximizedBoundsSet ? maximizedBounds
+                : getDefaultMaximizedBounds());
+    }
+
+    private void setPlatformMaximizedBounds(Rectangle bounds) {
+        platformWindow.setMaximizedBounds(
+                bounds.x, bounds.y,
+                bounds.width, bounds.height);
     }
 
     @Override
     public void setBoundsPrivate(int x, int y, int width, int height) {
         setBounds(x, y, width, height, SET_BOUNDS | NO_EMBEDDED_CHECK);

@@ -633,10 +667,14 @@
         // First, update peer's bounds
         setBounds(x, y, w, h, SET_BOUNDS, false, false);
 
         // Second, update the graphics config and surface data
         final boolean isNewDevice = updateGraphicsDevice();
+        if (isNewDevice && !isMaximizedBoundsSet()) {
+            setPlatformMaximizedBounds(getDefaultMaximizedBounds());
+        }
+
         if (resized || isNewDevice) {
             replaceSurfaceData();
             updateMinimumSize();
         }
 

@@ -1055,10 +1093,13 @@
 
     @Override
     public final void displayChanged() {
         if (updateGraphicsDevice()) {
             updateMinimumSize();
+            if (!isMaximizedBoundsSet()) {
+                setPlatformMaximizedBounds(getDefaultMaximizedBounds());
+            }
         }
         // Replace surface unconditionally, because internal state of the
         // GraphicsDevice could be changed.
         replaceSurfaceData();
         repaintPeer();