private void maximize() { mNonMaximizedLocation = mShell.getLocation(); mNonMaximizedSize = mShell.getSize(); Monitor monitor = mShell.getMonitor(); mShell.setBounds(monitor.getBounds()); }
private Rectangle getDisplayBounds(final Point location) { Rectangle displayBounds; final Monitor[] allMonitors = _ownerControl.getDisplay().getMonitors(); if (allMonitors.length > 1) { // By default present in the monitor of the control displayBounds = _ownerControl.getMonitor().getBounds(); final Point p = new Point(location.x, location.y); // Search on which monitor the event occurred Rectangle tmp; for (final Monitor element : allMonitors) { tmp = element.getBounds(); if (tmp.contains(p)) { displayBounds = tmp; break; } } } else { displayBounds = _ownerControl.getDisplay().getBounds(); } return displayBounds; }
public static Point centerWindow(Shell shell) { Monitor m = Display.getCurrent().getPrimaryMonitor(); Rectangle bounds = m.getBounds(); Rectangle rect = shell.getBounds(); int x = bounds.x + (bounds.width - rect.width) / 2; int y = bounds.y + (bounds.height - rect.height) / 2; return new Point(x, y); }
/** * Returns the monitor on which the application was launched. * * @param display * @return */ private static Monitor getMonitor(Display display) { Point mouse = display.getCursorLocation(); for (Monitor monitor : display.getMonitors()) { if (monitor.getBounds().contains(mouse)) { return monitor; } } return display.getPrimaryMonitor(); }
/** * Centers a dialog (Shell) on the <b>primary</b> (active) display. * * @param shell Shell to center on screen * @see Shell */ public static void centerDialogOnScreen(Shell shell) { // do it by monitor to support dual-head cards and still center things correctly onto the screen // people are on. -- Emil Monitor m = Display.getDefault().getPrimaryMonitor(); Rectangle bounds = m.getBounds(); int screen_x = bounds.width; int screen_y = bounds.height; shell.setLocation( screen_x / 2 - (shell.getBounds().width / 2), screen_y / 2 - (shell.getBounds().height / 2)); }
public boolean open() { display = Display.getCurrent(); shell = new Shell(display, SWT.NO_TRIM | SWT.TOOL); // SWT.NO_TRIM | SWT.TOO shell.setLayout(new FillLayout()); int[] size = CPerspective.getSplashSize(); shell.setSize(size[0], size[1]); Composite composite = new Composite(shell, SWT.NONE); composite.setLayout(new FillLayout()); container = new FlashContainer(composite, "splash"); container.addHookInterceptor( new OleHookInterceptor() { public boolean intercept(Msg message, int code, int param, int param2) { if (message.getMessage() == Win32Constant.WM_RBUTTONDOWN) { Point cursor = container.getParent().toControl(Display.getCurrent().getCursorLocation()); if (container.getBounds().contains(cursor) && container.isVisible()) { return true; } } return false; } }); container.loadMovie(0, CPerspective.getSplashSwfPath()); Monitor primary = shell.getMonitor(); 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; if (x < 0) x = 0; if (y < 0) y = 0; shell.setLocation(x, y); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) { display.sleep(); } } return true; }