View Javadoc

1   /*
2    * This file is a part of CAST project.
3    * (c) Copyright 2007, AGH University of Science & Technology
4    * https://caribou.iisg.agh.edu.pl/trac/cast
5    *
6    * Licensed under the Eclipse Public License, Version 1.0 (the "License").
7    * You may not use this file except in compliance with the License.
8    * You may obtain a copy of the License at
9    * http://www.eclipse.org/legal/epl-v10.html
10   */
11  /*
12   * File: MsgBoxHelper.java
13   * Created: 2007-00-00
14   * Author: awos
15   * $Id: SWTHelper.java 2311 2009-01-12 22:49:35Z tmilos $
16   */
17  
18  package pl.edu.agh.cast.ui.util;
19  
20  import org.eclipse.swt.graphics.Point;
21  import org.eclipse.swt.graphics.Rectangle;
22  import org.eclipse.swt.widgets.Shell;
23  
24  /**
25   * SWT helper functions.
26   *
27   * @author AGH CAST Team
28   */
29  public class SWTHelper {
30  
31  	/**
32  	 * Places dialog in the center of its parent.
33  	 *
34  	 * @param shell
35  	 *            the {@link Shell}
36  	 * @param parent
37  	 *            parent control
38  	 */
39  	public static void placeDialogInCenter(Shell shell, Shell parent) {
40  		Rectangle parentSize = parent.getBounds();
41  		Rectangle mySize = shell.getBounds();
42  
43  		int locationX = (parentSize.width - mySize.width) / 2 + parentSize.x;
44  		int locationY = (parentSize.height - mySize.height) / 2 + parentSize.y;
45  
46  		shell.setLocation(new Point(locationX, locationY));
47  	}
48  
49  }