public class ScreenUtils
{
public static Size getAdjustedWindowSize(Size preferredSize)
{
// compute available height (trim to max)
NativeScreen screen = NativeScreen.get();
int height = Math.min(screen.getAvailHeight(), preferredSize.height);
// trim height for large monitors
if (screen.getAvailHeight() >= (preferredSize.height-100))
{
if (BrowseCap.isMacintosh())
height = height - 107;
else if (BrowseCap.isWindows())
height = height - 89;
else
height = height - 80;
}
else
{
// adjust for window framing, etc.
if (Desktop.isDesktop())
height = height - 40;
else
height = height - 60;
// extra adjustment for firefox on windows (extra chrome in url bar)
if (BrowseCap.isWindows() && BrowseCap.isFirefox())
height = height - 25;
}
// extra adjustment for chrome on linux (which misreports the
// available height, excluding the menubar/taskbar)
if (BrowseCap.isLinux() && BrowseCap.isChrome())
height = height - 50;
// compute width (trim to max)
int width = Math.min(preferredSize.width, screen.getAvailWidth() - 20);
// return size
return new Size(width, height);
}