52 } 53 public int getExtendedState() { 54 return AWTAccessor.getFrameAccessor().getExtendedState((Frame)target); 55 } 56 57 // Convenience methods to save us from trouble of extracting 58 // Rectangle fields in native code. 59 private native void setMaximizedBounds(int x, int y, int w, int h); 60 private native void clearMaximizedBounds(); 61 62 private static final boolean keepOnMinimize = "true".equals( 63 AccessController.doPrivileged( 64 new GetPropertyAction( 65 "sun.awt.keepWorkingSetOnMinimize"))); 66 67 @Override 68 public void setMaximizedBounds(Rectangle b) { 69 if (b == null) { 70 clearMaximizedBounds(); 71 } else { 72 Rectangle adjBounds = (Rectangle)b.clone(); 73 adjustMaximizedBounds(adjBounds); 74 setMaximizedBounds(adjBounds.x, adjBounds.y, adjBounds.width, adjBounds.height); 75 } 76 } 77 78 /** 79 * The incoming bounds describe the maximized size and position of the 80 * window on the monitor that displays the window. But the window manager 81 * expects that the bounds are based on the size and position of the 82 * primary monitor, even if the window ultimately maximizes onto a 83 * secondary monitor. And the window manager adjusts these values to 84 * compensate for differences between the primary monitor and the monitor 85 * that displays the window. 86 * The method translates the incoming bounds to the values acceptable 87 * by the window manager. For more details, please refer to 6699851. 88 */ 89 private void adjustMaximizedBounds(Rectangle b) { 90 GraphicsConfiguration currentDevGC = getGraphicsConfiguration(); 91 92 GraphicsDevice primaryDev = GraphicsEnvironment 93 .getLocalGraphicsEnvironment().getDefaultScreenDevice(); 94 GraphicsConfiguration primaryDevGC = primaryDev.getDefaultConfiguration(); 95 96 if (currentDevGC != null && currentDevGC != primaryDevGC) { 97 Rectangle currentDevBounds = currentDevGC.getBounds(); 98 Rectangle primaryDevBounds = primaryDevGC.getBounds(); 99 100 boolean isCurrentDevLarger = 101 ((currentDevBounds.width - primaryDevBounds.width > 0) || 102 (currentDevBounds.height - primaryDevBounds.height > 0)); 103 104 // the window manager doesn't seem to compensate for differences when 105 // the primary monitor is larger than the monitor that display the window 106 if (isCurrentDevLarger) { 107 b.width -= (currentDevBounds.width - primaryDevBounds.width); 108 b.height -= (currentDevBounds.height - primaryDevBounds.height); 109 } 110 } 111 } 112 113 @Override 114 public boolean updateGraphicsData(GraphicsConfiguration gc) { 115 boolean result = super.updateGraphicsData(gc); 116 Rectangle bounds = AWTAccessor.getFrameAccessor(). 117 getMaximizedBounds((Frame)target); 118 if (bounds != null) { 119 setMaximizedBounds(bounds); 120 } 121 return result; 122 } 123 124 @Override 125 boolean isTargetUndecorated() { 126 return ((Frame)target).isUndecorated(); 127 } 128 129 @Override 130 public void reshape(int x, int y, int width, int height) { | 52 } 53 public int getExtendedState() { 54 return AWTAccessor.getFrameAccessor().getExtendedState((Frame)target); 55 } 56 57 // Convenience methods to save us from trouble of extracting 58 // Rectangle fields in native code. 59 private native void setMaximizedBounds(int x, int y, int w, int h); 60 private native void clearMaximizedBounds(); 61 62 private static final boolean keepOnMinimize = "true".equals( 63 AccessController.doPrivileged( 64 new GetPropertyAction( 65 "sun.awt.keepWorkingSetOnMinimize"))); 66 67 @Override 68 public void setMaximizedBounds(Rectangle b) { 69 if (b == null) { 70 clearMaximizedBounds(); 71 } else { 72 Rectangle adjBounds = adjustMaximizedBounds(b); 73 setMaximizedBounds(adjBounds.x, adjBounds.y, adjBounds.width, adjBounds.height); 74 } 75 } 76 77 /** 78 * The incoming bounds describe the maximized size and position of the 79 * window on the monitor that displays the window. But the window manager 80 * expects that the bounds are based on the size and position of the 81 * primary monitor, even if the window ultimately maximizes onto a 82 * secondary monitor. And the window manager adjusts these values to 83 * compensate for differences between the primary monitor and the monitor 84 * that displays the window. 85 * The method translates the incoming bounds to the values acceptable 86 * by the window manager. For more details, please refer to 6699851. 87 */ 88 private Rectangle adjustMaximizedBounds(Rectangle b) { 89 GraphicsConfiguration currentDevGC = getGraphicsConfiguration(); 90 91 GraphicsDevice primaryDev = GraphicsEnvironment 92 .getLocalGraphicsEnvironment().getDefaultScreenDevice(); 93 GraphicsConfiguration primaryDevGC = primaryDev.getDefaultConfiguration(); 94 95 double scaleX = 1.0; 96 double scaleY = 1.0; 97 98 int ht = primaryDev.getDisplayMode().getHeight(); 99 int wt = primaryDev.getDisplayMode().getWidth(); 100 // Rectangle fbc = currentDev.getFullScreenWindow().getBounds(); 101 102 if (currentDevGC != null && currentDevGC != primaryDevGC) { 103 Rectangle currentDevBounds = currentDevGC.getBounds(); 104 Rectangle primaryDevBounds = primaryDevGC.getBounds(); 105 106 //scale the bounds for proper comparisions. 107 scaleX = currentDevGC.getDefaultTransform().getScaleX(); 108 scaleY = currentDevGC.getDefaultTransform().getScaleY(); 109 currentDevBounds = scaleBounds(currentDevBounds, scaleX, scaleY); 110 b = scaleBounds(b, scaleX, scaleY); 111 Rectangle scaledPrimaryDevBounds = scaleBounds(primaryDevBounds, primaryDevGC.getDefaultTransform().getScaleX(), 112 primaryDevGC.getDefaultTransform().getScaleY()); 113 114 //due to floating point operations, it could be possible in some 115 //scenarios, that the width and height are slightly larger 116 //than the maximum permissible values. 117 if (b.width > currentDevBounds.width) { 118 b.width = currentDevBounds.width; 119 } 120 121 if (b.height > currentDevBounds.height) { 122 b.height = currentDevBounds.height; 123 } 124 125 //To maximize a window onto secondary screen, we still need to 126 //provide the primary screen coordinates, and set the width 127 //and height equal to primary screen bounds. 128 if (scaledPrimaryDevBounds.width < currentDevBounds.width && 129 b.width == currentDevBounds.width) { 130 b.width = primaryDevBounds.width; 131 } 132 133 if (scaledPrimaryDevBounds.height < currentDevBounds.height && 134 b.height == currentDevBounds.height) { 135 b.height = primaryDevBounds.height; 136 } 137 138 if (b.x == currentDevBounds.x) { 139 b.x = primaryDevBounds.x; 140 } 141 142 if (b.y == currentDevBounds.y) { 143 b.y = primaryDevBounds.y; 144 } 145 146 return b; 147 } else { 148 scaleX = primaryDevGC.getDefaultTransform().getScaleX(); 149 scaleY = primaryDevGC.getDefaultTransform().getScaleY(); 150 return scaleBounds(b, scaleX, scaleY); 151 } 152 } 153 154 private Rectangle scaleBounds(Rectangle source, double scaleX, double scaleY) { 155 Rectangle res = (Rectangle)source.clone(); 156 157 if (scaleX > 1.0) { 158 res.x = (int)(Math.ceil(source.x * scaleX)); 159 res.width =(int)(Math.ceil(source.width * scaleX)); 160 } 161 162 if (scaleY > 1.0) { 163 res.y = (int)(Math.ceil(source.y * scaleY)); 164 res.height = (int)(Math.ceil(source.height * scaleY)); 165 } 166 167 return res; 168 } 169 170 @Override 171 public boolean updateGraphicsData(GraphicsConfiguration gc) { 172 boolean result = super.updateGraphicsData(gc); 173 Rectangle bounds = AWTAccessor.getFrameAccessor(). 174 getMaximizedBounds((Frame)target); 175 if (bounds != null) { 176 setMaximizedBounds(bounds); 177 } 178 return result; 179 } 180 181 @Override 182 boolean isTargetUndecorated() { 183 return ((Frame)target).isUndecorated(); 184 } 185 186 @Override 187 public void reshape(int x, int y, int width, int height) { |