{
final int PADDING = 20;
// calculate ideal heigh and width. try to be as large as possible
// within the bounds of the current client size
Size bounds = new Size(Window.getClientWidth() - PADDING,
Window.getClientHeight() - PADDING);
float widthRatio = bounds.width / ((float)sourceFrameSize.width);
float heightRatio = bounds.height / ((float)sourceFrameSize.height);
float ratio = Math.min(widthRatio, heightRatio);
// constrain initial width to between 300 and 1,200 pixels
width = Math.max(300, (int) (ratio * sourceFrameSize.width));
width = Math.min(1200, width);
// constrain initial height to between 300 and 900 pixels
height = Math.max(300, (int) (ratio * sourceFrameSize.height));
height = Math.min(900, height);
}
return new Size(width, height);
}