本文整理汇总了Java中org.eclipse.swt.widgets.Shell.getLocation方法的典型用法代码示例。如果您正苦于以下问题:Java Shell.getLocation方法的具体用法?Java Shell.getLocation怎么用?Java Shell.getLocation使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.swt.widgets.Shell
的用法示例。
在下文中一共展示了Shell.getLocation方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setCenterinParent
import org.eclipse.swt.widgets.Shell; //导入方法依赖的package包/类
public static void setCenterinParent(Shell parentshell, Shell shell) {
int screenH = Toolkit.getDefaultToolkit().getScreenSize().height;
int screenW = Toolkit.getDefaultToolkit().getScreenSize().width;
int shellH = shell.getBounds().height;
int shellW = shell.getBounds().width;
// 如果窗口大小超过屏幕大小,调整为屏幕大小
if (shellH > screenH) {
shellH = screenH;
}
if (shellW > screenW) {
shellW = screenW;
}
int targetx = parentshell.getLocation().x + parentshell.getBounds().width / 2 - shell.getBounds().width / 2;
int targety = parentshell.getLocation().y + parentshell.getBounds().height / 2 - shell.getBounds().height / 2;
if (targetx + shellW > screenW) {
targetx = screenW - shellW;
}
if (targety + shellH > screenH) {
targety = screenH - shellH;
}
shell.setLocation(targetx, targety);
}
示例2: center
import org.eclipse.swt.widgets.Shell; //导入方法依赖的package包/类
/**
* Center the child shell within the parent shell window.
*/
public static void center(Shell parent, Shell child) {
int x = parent.getLocation().x +
(parent.getSize().x - child.getSize().x) / 2;
int y = parent.getLocation().y +
(parent.getSize().y - child.getSize().y) / 2;
if (x < 0) x = 0;
if (y < 0) y = 0;
child.setLocation(x,y);
}
示例3: saveDialogBounds
import org.eclipse.swt.widgets.Shell; //导入方法依赖的package包/类
/**
* Saves the bounds of the shell in the appropriate dialog settings. The
* bounds are recorded relative to the parent shell, if there is one, or
* display coordinates if there is no parent shell. Subclasses typically
* need not override this method, but may extend it (calling
* <code>super.saveDialogBounds</code> if additional bounds information
* should be stored. Clients may also call this method to persist the bounds
* at times other than closing the dialog.
*
* @param shell
* The shell whose bounds are to be stored
*/
protected void saveDialogBounds(Shell shell) {
IDialogSettings settings = getDialogSettings();
if (settings != null) {
Point shellLocation = shell.getLocation();
Point shellSize = shell.getSize();
Shell parent = getParentShell();
if (parent != null) {
Point parentLocation = parent.getLocation();
shellLocation.x -= parentLocation.x;
shellLocation.y -= parentLocation.y;
}
String prefix = getClass().getName();
if (persistSize) {
settings.put(prefix + DIALOG_WIDTH, shellSize.x);
settings.put(prefix + DIALOG_HEIGHT, shellSize.y);
}
if (persistLocation) {
settings.put(prefix + DIALOG_ORIGIN_X, shellLocation.x);
settings.put(prefix + DIALOG_ORIGIN_Y, shellLocation.y);
}
if (showPersistActions && showDialogMenu) {
settings.put(getClass().getName() + DIALOG_USE_PERSISTED_SIZE,
persistSize);
settings.put(getClass().getName() + DIALOG_USE_PERSISTED_LOCATION,
persistLocation);
}
}
}