// Get available screens
// O(n^3), this is nasty, but since we aren't dealling with
// many items it should be fine
for (int i=0; i < gd.length; i++)
{
GraphicsConfiguration gc = gd[i]
.getDefaultConfiguration();
// Don't add duplicates
if (window.intersects(gc.getBounds()))
{
for (Enumeration e = intersects.elements(); e.hasMoreElements();)
{
GraphicsConfiguration gcc = (GraphicsConfiguration)e.nextElement();
if (gcc.getBounds().equals(gc.getBounds()))
break;
}
intersects.add(gc);
}
}
GraphicsConfiguration choice = null;
if (intersects.size() > 0)
{
// Pick screen with largest intersection
for (Enumeration e = intersects.elements(); e.hasMoreElements();)
{
GraphicsConfiguration gcc = (GraphicsConfiguration)e.nextElement();
if (choice == null)
choice = gcc;
else
{
Rectangle int1 = choice.getBounds().intersection(window);
Rectangle int2 = gcc.getBounds().intersection(window);
int area1 = int1.width * int1.height;
int area2 = int2.width * int2.height;
if (area2 > area1)
choice = gcc;
}