Coverage Report - us.daveread.basicquery.gui.GUIUtility
 
Classes in this File Line Coverage Branch Coverage Complexity
GUIUtility
90%
19/21
100%
4/4
3
 
 1  
 package us.daveread.basicquery.gui;
 2  
 
 3  
 import java.awt.Dimension;
 4  
 import java.awt.Point;
 5  
 import java.awt.Toolkit;
 6  
 import java.awt.Window;
 7  
 
 8  
 
 9  
 /**
 10  
  * <p>Title: GUI utilities</p>
 11  
  * <p>Description: </p>
 12  
  * <p>Copyright: Copyright (c) 2004-2014</p>
 13  
  * <p>Company: </p>
 14  
  * 
 15  
  * @author David Read
 16  
  */
 17  
 
 18  
 public class GUIUtility {
 19  
   /**
 20  
    * Don't want instances of this class created.
 21  
    */
 22  0
   private GUIUtility() {
 23  0
   }
 24  
 
 25  
   /**
 26  
    * Centers a window on the parent window or the screen.  If the parent
 27  
    * is null, or smaller than the child, the child is centered on the
 28  
    * screen.
 29  
    * @param winaChild The window being centered.
 30  
    * @param winaParent The parent window, or null if no parent frame exists.
 31  
    */
 32  
   public static void center(Window winaChild, Window winaParent) {
 33  
     Dimension dimlParentSize, dimlMySize;
 34  
     Point ptlUpperLeft;
 35  
     int ilX, ilY;
 36  11
     dimlMySize = winaChild.getSize();
 37  11
     if (winaParent == null) {
 38  1
       dimlParentSize = Toolkit.getDefaultToolkit().getScreenSize();
 39  1
       ptlUpperLeft = new Point(0, 0);
 40  
     } else {
 41  10
       dimlParentSize = winaParent.getSize();
 42  10
       ptlUpperLeft = winaParent.getLocation();
 43  
 
 44  10
       if (dimlMySize.width > dimlParentSize.width 
 45  
           || dimlMySize.height > dimlParentSize.height) {
 46  9
         dimlParentSize = Toolkit.getDefaultToolkit().getScreenSize();
 47  9
         ptlUpperLeft = new Point(0, 0);
 48  
       }
 49  
     }
 50  11
     if (dimlParentSize.width >= dimlMySize.width) {
 51  10
       ilX = (dimlParentSize.width - dimlMySize.width) / 2;
 52  
     } else {
 53  1
       ilX = 0;
 54  
     }
 55  11
     if (dimlParentSize.height >= dimlMySize.height) {
 56  10
       ilY = (dimlParentSize.height - dimlMySize.height) / 2;
 57  
     } else {
 58  1
       ilY = 0;
 59  
     }
 60  11
     ilX += ptlUpperLeft.x;
 61  11
     ilY += ptlUpperLeft.y;
 62  11
     winaChild.setLocation(ilX, ilY);
 63  11
   }
 64  
 }