本文整理匯總了Java中org.eclipse.swt.widgets.Shell.getBounds方法的典型用法代碼示例。如果您正苦於以下問題:Java Shell.getBounds方法的具體用法?Java Shell.getBounds怎麽用?Java Shell.getBounds使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.eclipse.swt.widgets.Shell
的用法示例。
在下文中一共展示了Shell.getBounds方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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: getCenteredPosition
import org.eclipse.swt.widgets.Shell; //導入方法依賴的package包/類
/**
* Get the centered position for a window according to its' parent Shell
* and its' width and height.
* @param myWidth The windows' width.
* @param myHeight The windows' height.
* @param parentShell The parent Shell.
* @return An array containing the X and the Y position.
*/
public static int[] getCenteredPosition(int myWidth, int myHeight, Shell parentShell) {
// Calculate the current position.
Rectangle r = parentShell.getBounds();
Rectangle displayBounds = parentShell.getDisplay().getBounds();
int parentCenterX = r.x + (r.width / 2);
int parentCenterY = r.y + (r.height / 2);
int[] myPos = new int[2];
myPos[0] = parentCenterX - (myWidth / 2);
myPos[1] = parentCenterY - (myHeight / 2);
// Leaving upper or left bounds?
if (myPos[0] < 0) myPos[0] = 0;
if (myPos[1] < 0) myPos[1] = 0;
// Leaving lower or right bounds?
if (myPos[0] > displayBounds.width - myWidth) myPos[0] = displayBounds.width - myWidth;
if (myPos[1] > displayBounds.height - myHeight) myPos[1] = displayBounds.height - myHeight;
// Finished.
return myPos;
}
示例3: getShellTitlebarHeight
import org.eclipse.swt.widgets.Shell; //導入方法依賴的package包/類
/**
* Get height of the shell's titlebar
* @param s
* @return
*/
public static int getShellTitlebarHeight(Shell s){
Rectangle b = s.getBounds();
Rectangle t = s.computeTrim(b.x, b.y, b.width, b.height);
int tbarHeight = (b.y-t.y);
return tbarHeight;
}
示例4: getShellLeftEdgeWidth
import org.eclipse.swt.widgets.Shell; //導入方法依賴的package包/類
/**
* Get the width of the shell's left edge
* @param s
* @return
*/
public static int getShellLeftEdgeWidth(Shell s){
Rectangle b = s.getBounds();
Rectangle t = s.computeTrim(b.x, b.y, b.width, b.height);
int leftEW = (b.x-t.x);
if(s.getMaximized()){
return 0;
}else{
return leftEW;
}
}
示例5: getShellRightEdgeWidth
import org.eclipse.swt.widgets.Shell; //導入方法依賴的package包/類
/**
* Get the width of the shell's right edge
* @param s
* @return
*/
public static int getShellRightEdgeWidth(Shell s){
Rectangle b = s.getBounds();
Rectangle t = s.computeTrim(b.x, b.y, b.width, b.height);
int rightEW = ((t.width-b.width)-(b.x-t.x));
if(s.getMaximized()){
return 0;
}else{
return rightEW;
}
}
示例6: getShellBottomEdgeHeight
import org.eclipse.swt.widgets.Shell; //導入方法依賴的package包/類
/**
* Get the height of the shell's bottom edge
* @param s
* @return
*/
public static int getShellBottomEdgeHeight(Shell s){
Rectangle b = s.getBounds();
Rectangle t = s.computeTrim(b.x, b.y, b.width, b.height);
int bottomEH = ((t.height-b.height)-(b.y-t.y));
if(s.getMaximized()){
return 0;
}else{
return bottomEH;
}
}
示例7: setCenter
import org.eclipse.swt.widgets.Shell; //導入方法依賴的package包/類
public static void setCenter(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;
}
shell.setLocation(((screenW - shellW) / 2), ((screenH - shellH) / 2));
}
示例8: center
import org.eclipse.swt.widgets.Shell; //導入方法依賴的package包/類
private void center(Shell shell) {
Shell parent = (Shell) shell.getParent();
Rectangle bounds = parent.getBounds();
Point size = shell.getSize();
int x = bounds.x + bounds.width / 2 - size.x / 2;
int y = bounds.y + bounds.height / 2 - size.y / 2;
// System.err.println("ChoiceDialog: center: x=" + x + " y=" + y);
shell.setLocation(x, (y < 0) ? 0 : y);
}
示例9: center
import org.eclipse.swt.widgets.Shell; //導入方法依賴的package包/類
private static Point center(Display display, Shell shell) {
Monitor primary = display.getPrimaryMonitor();
Rectangle bounds = primary.getBounds();
Rectangle rect = shell.getBounds();
int x = bounds.x + (bounds.width - rect.width) / 2;
int y = bounds.y + (bounds.height - rect.height) / 2;
Point location = new Point(x, y);
return location;
}
示例10: launchXMLTextContainerWindow
import org.eclipse.swt.widgets.Shell; //導入方法依賴的package包/類
/**
* Launches the component property editor window for Unknown components. It is used to display XML content of Unknown
* components on property window.
*
* @return XML content of component.
*/
public String launchXMLTextContainerWindow() {
try{
String xmlText = this.xmlText;
Shell shell = new Shell(Display.getDefault().getActiveShell(), SWT.WRAP | SWT.MAX | SWT.APPLICATION_MODAL);
shell.setLayout(new GridLayout(1, false));
shell.setText("XML Content");
shell.setSize(439, 432);
text = new Text(shell, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL | SWT.CANCEL | SWT.MULTI);
text.setEditable(false);
text.setBackground(CustomColorRegistry.INSTANCE.getColorFromRegistry( 250, 250, 250));
if (this.xmlText != null) {
xmlText = xmlText.substring(xmlText.indexOf('\n') + 1);
xmlText = xmlText.substring(xmlText.indexOf('\n') + 1, xmlText.lastIndexOf('\n') - 13);
text.setText(xmlText);
} else
text.setText(Messages.EMPTY_XML_CONTENT);
GridData gd_text = new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1);
gd_text.widthHint = 360;
gd_text.heightHint = 360;
text.setLayoutData(gd_text);
Monitor primary = shell.getDisplay().getPrimaryMonitor();
Rectangle bounds = primary.getBounds();
Rectangle rect = shell.getBounds();
int x = bounds.x + (bounds.width - rect.width) / 2;
int y = bounds.y + (bounds.height - rect.height) / 2;
shell.setLocation(x, y);
shell.open();
shell.layout();
while (!shell.isDisposed()) {
if (!shell.getDisplay().readAndDispatch()) {
shell.getDisplay().sleep();
}
}
}catch(Exception e)
{
LOGGER.error("Error occurred while creating XML text container widget", e);
}
return getXmlText();
}
示例11: center
import org.eclipse.swt.widgets.Shell; //導入方法依賴的package包/類
/**
* Shell
*/
public static void center(final Shell shell) {
final Rectangle r1 = shell.getMonitor().getBounds(), r2 = shell.getBounds();
shell.setLocation(r1.x + (r1.width - r2.width) / 2, r1.y + (r1.height - r2.height) / 2);
}