Rectangle screenSize = display.getPrimaryMonitor().getBounds(); shell.setLocation( ( screenSize.width - shell.getBounds().width ) / 2, ( screenSize.height - shell.getBounds().height ) / 2 ); closeButton.setFocus();
public static void setSize( Shell shell, int minWidth, int minHeight, boolean packIt ) { PropsUI props = PropsUI.getInstance(); WindowProperty winprop = props.getScreen( shell.getText() ); if ( winprop != null ) { winprop.setShell( shell, minWidth, minHeight ); } else { if ( packIt ) { shell.pack(); } else { shell.layout(); } // OK, sometimes this produces dialogs that are waay too big. // Try to limit this a bit, m'kay? // Use the same algorithm by cheating :-) // winprop = new WindowProperty( shell ); winprop.setShell( shell, minWidth, minHeight ); // Now, as this is the first time it gets opened, try to put it in the middle of the screen... Rectangle shellBounds = shell.getBounds(); Monitor monitor = shell.getDisplay().getPrimaryMonitor(); if ( shell.getParent() != null ) { monitor = shell.getParent().getMonitor(); } Rectangle monitorClientArea = monitor.getClientArea(); int middleX = monitorClientArea.x + ( monitorClientArea.width - shellBounds.width ) / 2; int middleY = monitorClientArea.y + ( monitorClientArea.height - shellBounds.height ) / 2; shell.setLocation( middleX, middleY ); } }
public static void setSize( Shell shell, int prefWidth, int prefHeight ) { PropsUI props = PropsUI.getInstance(); WindowProperty winprop = props.getScreen( shell.getText() ); if ( winprop != null ) { winprop.setShell( shell, prefWidth, prefHeight ); } else { shell.layout(); winprop = new WindowProperty( shell.getText(), false, new Rectangle( 0, 0, prefWidth, prefHeight ) ); winprop.setShell( shell ); // Now, as this is the first time it gets opened, try to put it in the middle of the screen... Rectangle shellBounds = shell.getBounds(); Monitor monitor = shell.getDisplay().getPrimaryMonitor(); if ( shell.getParent() != null ) { monitor = shell.getParent().getMonitor(); } Rectangle monitorClientArea = monitor.getClientArea(); int middleX = monitorClientArea.x + ( monitorClientArea.width - shellBounds.width ) / 2; int middleY = monitorClientArea.y + ( monitorClientArea.height - shellBounds.height ) / 2; shell.setLocation( middleX, middleY ); } }
Monitor monitor = shell.getDisplay().getPrimaryMonitor(); if ( shell.getParent() != null ) { monitor = shell.getParent().getMonitor();
Monitor monitor = shell.getDisplay().getPrimaryMonitor(); if ( shell.getParent() != null ) { monitor = shell.getParent().getMonitor();
protected Splash( Display display, Shell splashShell ) throws KettleException { log = new LogChannel( Spoon.APP_NAME ); Rectangle displayBounds = display.getPrimaryMonitor().getBounds();
final Display display = getShell().getDisplay(); final Monitor monitor = display.getPrimaryMonitor(); final Rectangle rect; if (monitor != null) { rect = monitor.getClientArea(); } else { // In case we cannot find the primary monitor get the entire display rectangle // Note that it may include the dimensions of multiple monitors. rect = display.getBounds(); } System.out.println("Monitor width=" + String.valueOf(rect.width)); System.out.println("Monitor height=" + String.valueOf(rect.height));
/** * Returns the receiver's monitor. * * @return the receiver's monitor * * @since 1.2 */ public Monitor getMonitor() { checkWidget(); return display.getPrimaryMonitor(); }
public static void centerShell(Shell shell) { Rectangle displayBounds = shell.getDisplay().getPrimaryMonitor().getBounds(); Rectangle shellBounds = shell.getBounds(); int x = displayBounds.x + (displayBounds.width - shellBounds.width) >> 1; int y = displayBounds.y + (displayBounds.height - shellBounds.height) >> 1; shell.setLocation(x, y); }
/** * Starts the example. * @param args One optional argument specifying the simulation end time is * supported. */ public static void main(@Nullable String[] args) { final long endTime = args != null && args.length >= 1 ? Long .parseLong(args[0]) : Long.MAX_VALUE; final Display d = new Display(); @Nullable Monitor sec = null; for (final Monitor m : d.getMonitors()) { if (d.getPrimaryMonitor() != m) { sec = m; break; } } run(endTime, d, sec, null); }
/** * Starts the example. * @param args One optional argument specifying the simulation end time is * supported. */ public static void main(@Nullable String[] args) { final long endTime = args != null && args.length >= 1 ? Long .parseLong(args[0]) : Long.MAX_VALUE; final Display d = new Display(); @Nullable Monitor sec = null; for (final Monitor m : d.getMonitors()) { if (d.getPrimaryMonitor() != m) { sec = m; break; } } run(endTime, d, sec, null); }
private void positionWindow() { // place the window near the lower right-hand corner Monitor primary = display.getPrimaryMonitor(); Rectangle bounds = primary.getBounds(); Rectangle rect = shell.getBounds(); int x = bounds.x + (bounds.width - rect.width) - 5; int y = bounds.y + (bounds.height - rect.height) - 35; shell.setLocation(x, y); }
/** * Center a shell on the monitor * * @param display The display * @param shell The shell to center */ public static void centerShell(Display display, Shell shell) { Rectangle displayBounds = display.getPrimaryMonitor().getBounds(); Rectangle shellBounds = shell.getBounds(); int x = displayBounds.x + (displayBounds.width - shellBounds.width) >> 1; int y = displayBounds.y + (displayBounds.height - shellBounds.height) >> 1; shell.setLocation(x, y); }
/** * Centers the given shell on the parent shell. * * If the parent shell is null, the shell is centered on the display. * * If more than one monitor is used, the shell is centered on the * primary monitor. */ public static void centerShell(Shell parentShell, Shell shell) { Rectangle parentRect; Rectangle splashRect = shell.getBounds(); if (parentShell == null) { parentRect = shell.getDisplay().getPrimaryMonitor().getBounds(); } else { parentRect = parentShell.getBounds(); } int x = parentRect.x + (parentRect.width - splashRect.width) / 2; int y = parentRect.y + (parentRect.height - splashRect.height) / 2; shell.setLocation(x, y); }
/** * Centers the given shell on the parent shell. * * If the parent shell is null, the shell is centered on the display. * * If more than one monitor is used, the shell is centered on the * primary monitor. */ public static void centerShell(Shell parentShell, Shell shell) { Rectangle parentRect; Rectangle splashRect = shell.getBounds(); if (parentShell == null) { parentRect = shell.getDisplay().getPrimaryMonitor().getBounds(); } else { parentRect = parentShell.getBounds(); } int x = parentRect.x + (parentRect.width - splashRect.width) / 2; int y = parentRect.y + (parentRect.height - splashRect.height) / 2; shell.setLocation(x, y); }
public static String openNewShellDialog(Display display) { final Shell shell = new Shell(display , SWT.APPLICATION_MODAL); shell.setLayout(new GridLayout(1, false)); System.out.println(display.getPrimaryMonitor().getClientArea()); shell.setLocation(616, 500); //It seems the location is relative to the center of the Shell w.r.t client area shell.setSize(0,0); shell.setVisible(false); shell.open(); FileDialog d = new FileDialog(shell); String s = d.open(); shell.dispose (); while (!shell.isDisposed ()) { if (!display.readAndDispatch ()) display.sleep (); } return s; }
public static void main(String[] args) { Display display = new Display(); final Shell shell = new Shell(display); shell.setLayout(new FillLayout(SWT.VERTICAL)); shell.setText("StackOverflow"); Monitor primary = display.getPrimaryMonitor(); /* Get the available screen size (without start menu) */ Rectangle area = primary.getClientArea(); shell.pack(); /* Set the shell size */ shell.setBounds(area.x + area.width / 2, area.y, area.width / 2, area.height); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
public void getChildAtPoint(AccessibleControlEvent e) { NSPoint testPoint = new NSPoint(); testPoint.x = e.x; Monitor primaryMonitor = Display.getCurrent().getPrimaryMonitor(); testPoint.y = (int) (primaryMonitor.getBounds().height - e.y); Iterator iter = childRowToIdMap.values().iterator(); while (iter.hasNext()) { AccessibleTableRow row = (AccessibleTableRow) iter.next(); NSValue locationValue = new NSValue(row.getPositionAttribute(ACC.CHILDID_SELF).id); NSPoint location = locationValue.pointValue(); NSValue sizeValue = new NSValue(row.getSizeAttribute(ACC.CHILDID_SELF)); NSSize size = sizeValue.sizeValue(); if (location.y < testPoint.y && testPoint.y < (location.y + size.height)) { AccessibleControlEvent e2 = new AccessibleControlEvent(e.getSource()); e2.x = (int) testPoint.x; e2.y = (int) testPoint.y; row.getChildAtPoint(e); break; } } }
void updateSystemUIMode () { if ((window.collectionBehavior() & OS.NSWindowCollectionBehaviorFullScreenPrimary) != 0) return; if (!getMonitor ().equals (display.getPrimaryMonitor ())) return; int mode = display.systemUIMode, options = display.systemUIOptions; if (fullScreen) { mode = OS.kUIModeAllHidden; if (menuBar != null) { mode = OS.kUIModeContentHidden; } options = 0; } int[] uiMode = new int[1], uiOptions = new int[1]; OS.GetSystemUIMode(uiMode, uiOptions); if (uiMode[0] != mode || uiOptions[0] != options) OS.SetSystemUIMode (mode, options); if (fullScreen) window.setFrame(fullScreenFrame, true); }
/** * Make the window use all the screen and remove the title bar. */ void setFullScreen() { this.shell.setFullScreen(true); this.shell.setFocus(); final Monitor m = Display.getDefault().getPrimaryMonitor(); this.shell.setBounds(-1, -1, m.getBounds().width + 2, m.getBounds().height + 2); this.screenSize = new ScreenSize(m.getBounds().width, m.getBounds().height); }