[rfc][icedtea-web] centre of dialogues to centre of active monitor

Adam Domurad adomurad at redhat.com
Wed Jan 9 11:08:14 PST 2013


On 01/09/2013 01:53 PM, Adam Domurad wrote:
> On 01/08/2013 10:54 AM, Jiri Vanek wrote:
>> All dialogues in ITW are centred into middle of ALL monitors, which 
>> is really nasty.
>> During splashscreen development I have centred into middle of default 
>> screen. Well better but not perfect.
>> That time Omair suggested to centr into middle of active screen - 
>> active here is the one where is cursor.
>> Well I have finally come with something like this:)
>>
>>
> This looks OK to me, although I still get the dialog pop-ups flashing 
> on the wrong screen sometimes, before appearing on the correct one.
>
> Comments on impl class:
>> +public class ScreenFinder {
>> +
>> +    public static GraphicsDevice getCurrentScreen() {
>> +        Point p = MouseInfo.getPointerInfo().getLocation();
>> +        return getScreenOnCoords(p);
>> +
>> +    }
>> +    public static Rectangle getCurrentScreenSizeWithoutBounds() {
>> +        Point p = MouseInfo.getPointerInfo().getLocation();
>> +        return getScreenOnCoordsWithutBounds(p);
>> +
>> +    }
>> +
>> +     public static void  centerWindowsToCurrentScreen(Window w) {
>> +        Rectangle bounds = getCurrentScreenSizeWithoutBounds();
>> +        w.setLocation(bounds.x + (bounds.width - w.getWidth())/2,
>> +                bounds.y + (bounds.height - w.getHeight())/2);
>> +
>> +    }
>> +
>> +    public static GraphicsDevice getScreenOnCoords(Point point) {
>> +        GraphicsEnvironment e = 
>> GraphicsEnvironment.getLocalGraphicsEnvironment();
>> +        GraphicsDevice[] devices = e.getScreenDevices();
>> +        GraphicsDevice result = null;
>> +        //now get the configuration(s) for each device
>> +        for (GraphicsDevice device : devices) {
>> +            //GraphicsConfiguration[] configurations = 
>> device.getConfigurations();
>> +            //or?
>
> If you've settled on default device, I'd prefer to just simply use it.
>
>> +            GraphicsConfiguration[] configurations = new 
>> GraphicsConfiguration[]{device.getDefaultConfiguration()};
>> +            for (GraphicsConfiguration config : configurations) {
>> +                Rectangle gcBounds = config.getBounds();
>> +                if (gcBounds.contains(point)) {
>> +                    result = device;
>> +                }
>> +            }
>> +        }
>> +        if (result == null) {
>> +            //not found, get the default display
>> +            result = e.getDefaultScreenDevice();
>> +        }
>> +        return result;
>> +    }
>> +
>> +    public static Rectangle getScreenOnCoordsWithutBounds(Point p) {
>> +        GraphicsDevice device = getScreenOnCoords(p);
>> +        Rectangle screenSize = 
>> device.getDefaultConfiguration().getBounds();
>> +        Insets insets = 
>> Toolkit.getDefaultToolkit().getScreenInsets(device.getDefaultConfiguration());
>> +        return new Rectangle((int)screenSize.getX()+insets.left, 
>> (int)screenSize.getY()+insets.top, 
>> (int)screenSize.getWidth()-insets.left, 
>> (int)screenSize.getHeight()-insets.bottom);
>
> I'd prefer 4 temporary variables for these coordinates.
>
>> +    }
>> +
>> +
>> +}
>
> OK to push otherwise, though.
>
> Thanks,
> -Adam

Hmm actually as well, the "Fatal: Launch Error: " shows up for me on 
wrong monitor.

-Adam



More information about the distro-pkg-dev mailing list