< prev index next >
src/java.desktop/windows/classes/sun/awt/windows/WFramePeer.java
Print this page
@@ -67,12 +67,11 @@
@Override
public void setMaximizedBounds(Rectangle b) {
if (b == null) {
clearMaximizedBounds();
} else {
- Rectangle adjBounds = (Rectangle)b.clone();
- adjustMaximizedBounds(adjBounds);
+ Rectangle adjBounds = adjustMaximizedBounds(b);
setMaximizedBounds(adjBounds.x, adjBounds.y, adjBounds.width, adjBounds.height);
}
}
/**
@@ -84,32 +83,90 @@
* 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) {
+ private Rectangle adjustMaximizedBounds(Rectangle b) {
GraphicsConfiguration currentDevGC = getGraphicsConfiguration();
GraphicsDevice primaryDev = GraphicsEnvironment
.getLocalGraphicsEnvironment().getDefaultScreenDevice();
GraphicsConfiguration primaryDevGC = primaryDev.getDefaultConfiguration();
+ double scaleX = 1.0;
+ double scaleY = 1.0;
+
+ int ht = primaryDev.getDisplayMode().getHeight();
+ int wt = primaryDev.getDisplayMode().getWidth();
+// Rectangle fbc = currentDev.getFullScreenWindow().getBounds();
+
if (currentDevGC != null && currentDevGC != primaryDevGC) {
Rectangle currentDevBounds = currentDevGC.getBounds();
Rectangle primaryDevBounds = primaryDevGC.getBounds();
- boolean isCurrentDevLarger =
- ((currentDevBounds.width - primaryDevBounds.width > 0) ||
- (currentDevBounds.height - primaryDevBounds.height > 0));
-
- // the window manager doesn't seem to compensate for differences when
- // the primary monitor is larger than the monitor that display the window
- if (isCurrentDevLarger) {
- b.width -= (currentDevBounds.width - primaryDevBounds.width);
- b.height -= (currentDevBounds.height - primaryDevBounds.height);
+ //scale the bounds for proper comparisions.
+ scaleX = currentDevGC.getDefaultTransform().getScaleX();
+ scaleY = currentDevGC.getDefaultTransform().getScaleY();
+ currentDevBounds = scaleBounds(currentDevBounds, scaleX, scaleY);
+ b = scaleBounds(b, scaleX, scaleY);
+ Rectangle scaledPrimaryDevBounds = scaleBounds(primaryDevBounds, primaryDevGC.getDefaultTransform().getScaleX(),
+ primaryDevGC.getDefaultTransform().getScaleY());
+
+ //due to floating point operations, it could be possible in some
+ //scenarios, that the width and height are slightly larger
+ //than the maximum permissible values.
+ if (b.width > currentDevBounds.width) {
+ b.width = currentDevBounds.width;
+ }
+
+ if (b.height > currentDevBounds.height) {
+ b.height = currentDevBounds.height;
+ }
+
+ //To maximize a window onto secondary screen, we still need to
+ //provide the primary screen coordinates, and set the width
+ //and height equal to primary screen bounds.
+ if (scaledPrimaryDevBounds.width < currentDevBounds.width &&
+ b.width == currentDevBounds.width) {
+ b.width = primaryDevBounds.width;
}
+
+ if (scaledPrimaryDevBounds.height < currentDevBounds.height &&
+ b.height == currentDevBounds.height) {
+ b.height = primaryDevBounds.height;
+ }
+
+ if (b.x == currentDevBounds.x) {
+ b.x = primaryDevBounds.x;
+ }
+
+ if (b.y == currentDevBounds.y) {
+ b.y = primaryDevBounds.y;
}
+
+ return b;
+ } else {
+ scaleX = primaryDevGC.getDefaultTransform().getScaleX();
+ scaleY = primaryDevGC.getDefaultTransform().getScaleY();
+ return scaleBounds(b, scaleX, scaleY);
+ }
+ }
+
+ private Rectangle scaleBounds(Rectangle source, double scaleX, double scaleY) {
+ Rectangle res = (Rectangle)source.clone();
+
+ if (scaleX > 1.0) {
+ res.x = (int)(Math.ceil(source.x * scaleX));
+ res.width =(int)(Math.ceil(source.width * scaleX));
+ }
+
+ if (scaleY > 1.0) {
+ res.y = (int)(Math.ceil(source.y * scaleY));
+ res.height = (int)(Math.ceil(source.height * scaleY));
+ }
+
+ return res;
}
@Override
public boolean updateGraphicsData(GraphicsConfiguration gc) {
boolean result = super.updateGraphicsData(gc);
< prev index next >