//# 0 errors, 18 messages
//#
/*
    //#CoreUIUtils.java:1:1: class: com.dmdirc.ui.CoreUIUtils
    //#CoreUIUtils.java:1:1: method: com.dmdirc.ui.CoreUIUtils.com.dmdirc.ui.CoreUIUtils__static_init
 * Copyright (c) 2006-2009 Chris Smith, Shane Mc Cormack, Gregory Holmes
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */
package com.dmdirc.ui;

import java.awt.GraphicsConfiguration;
import java.awt.GraphicsDevice;
import java.awt.MouseInfo;
import java.awt.PointerInfo;
import java.awt.Rectangle;
import java.awt.Window;

/**
 * Core UI Utilities.
 */
public class CoreUIUtils {
    //#CoreUIUtils.java:34: method: void com.dmdirc.ui.CoreUIUtils.com.dmdirc.ui.CoreUIUtils()
    //#CoreUIUtils.java:34: end of method: void com.dmdirc.ui.CoreUIUtils.com.dmdirc.ui.CoreUIUtils()
    
    /**
     * Centre the specified window on the active monitor.
     * 
     * @param window Window to centre
     */
    public static void centreWindow(final Window window) {
        // Get the Location of the mouse pointer
        final PointerInfo myPointerInfo = MouseInfo.getPointerInfo();
    //#CoreUIUtils.java:43: method: void com.dmdirc.ui.CoreUIUtils.centreWindow(Window)
    //#input(void centreWindow(Window)): window
    //#pre[1] (void centreWindow(Window)): window != null
    //#presumption(void centreWindow(Window)): (-(java.awt.Window:getHeight(...)@56 - gcBounds.height@50))/2 + gcBounds.y@50 in {-2_147_483_648..4_294_967_295}
    //#presumption(void centreWindow(Window)): (-(java.awt.Window:getWidth(...)@55 - gcBounds.width@50))/2 + gcBounds.x@50 in {-2_147_483_648..4_294_967_295}
    //#presumption(void centreWindow(Window)): java.awt.GraphicsConfiguration:getBounds(...)@50 != null
    //#presumption(void centreWindow(Window)): java.awt.GraphicsDevice:getDefaultConfiguration(...)@47 != null
    //#presumption(void centreWindow(Window)): java.awt.MouseInfo:getPointerInfo(...)@43 != null
    //#presumption(void centreWindow(Window)): java.awt.PointerInfo:getDevice(...)@45 != null
        // Get the Device (screen) the mouse pointer is on
        final GraphicsDevice myDevice = myPointerInfo.getDevice();
        // Get the configuration for the device
        final GraphicsConfiguration myGraphicsConfig =
                myDevice.getDefaultConfiguration();
        // Get the bounds of the device
        final Rectangle gcBounds = myGraphicsConfig.getBounds();
        // Calculate the centre of the screen
        // gcBounds.x and gcBounds.y give the co ordinates where the screen
        // starts. gcBounds.width and gcBounds.height return the size in pixels
        // of the screen.
        final int xPos = gcBounds.x + ((gcBounds.width - window.getWidth()) / 2);
        final int yPos = gcBounds.y + ((gcBounds.height - window.getHeight()) / 2);
        // Set the location of the window
        window.setLocation(xPos, yPos);
    }
    //#CoreUIUtils.java:59: end of method: void com.dmdirc.ui.CoreUIUtils.centreWindow(Window)
}    //#output(com.dmdirc.ui.CoreUIUtils__static_init): __Descendant_Table[com/dmdirc/ui/CoreUIUtils]
    //#post(com.dmdirc.ui.CoreUIUtils__static_init): __Descendant_Table[com/dmdirc/ui/CoreUIUtils] == &__Dispatch_Table
    //#CoreUIUtils.java:: end of method: com.dmdirc.ui.CoreUIUtils.com.dmdirc.ui.CoreUIUtils__static_init
    //#CoreUIUtils.java:: end of class: com.dmdirc.ui.CoreUIUtils
