Search in sources :

Example 16 with Monitor

use of org.eclipse.swt.widgets.Monitor in project eclipse-integration-commons by spring-projects.

the class ToolTip method fixupDisplayBounds.

private Point fixupDisplayBounds(Point tipSize, Point location) {
    if (respectDisplayBounds || respectMonitorBounds) {
        Rectangle bounds;
        Point rightBounds = new Point(tipSize.x + location.x, tipSize.y + location.y);
        Monitor[] ms = control.getDisplay().getMonitors();
        if (respectMonitorBounds && ms.length > 1) {
            // By default present in the monitor of the control
            bounds = control.getMonitor().getBounds();
            Point p = new Point(location.x, location.y);
            // Search on which monitor the event occurred
            Rectangle tmp;
            for (Monitor element : ms) {
                tmp = element.getBounds();
                if (tmp.contains(p)) {
                    bounds = tmp;
                    break;
                }
            }
        } else {
            bounds = control.getDisplay().getBounds();
        }
        if (!(bounds.contains(location) && bounds.contains(rightBounds))) {
            if (rightBounds.x > bounds.x + bounds.width) {
                location.x -= rightBounds.x - (bounds.x + bounds.width);
            }
            if (rightBounds.y > bounds.y + bounds.height) {
                location.y -= rightBounds.y - (bounds.y + bounds.height);
            }
            if (location.x < bounds.x) {
                location.x = bounds.x;
            }
            if (location.y < bounds.y) {
                location.y = bounds.y;
            }
        }
    }
    return location;
}
Also used : Monitor(org.eclipse.swt.widgets.Monitor) Rectangle(org.eclipse.swt.graphics.Rectangle) Point(org.eclipse.swt.graphics.Point)

Example 17 with Monitor

use of org.eclipse.swt.widgets.Monitor in project n4js by eclipse.

the class UIUtils method getInitialLocation.

/**
 * Returns the initial location to use for the shell. The default implementation centers the shell horizontally (1/2
 * of the difference to the left and 1/2 to the right) and vertically (1/3 above and 2/3 below) relative to the
 * active workbench windows shell, or display bounds if there is no parent shell.
 *
 * @param shell
 *            the shell which initial location has to be calculated.
 * @param initialSize
 *            the initial size of the shell, as returned by <code>getInitialSize</code>.
 * @return the initial location of the shell
 */
public static Point getInitialLocation(final Shell shell, final Point initialSize) {
    final Composite parent = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
    Monitor monitor = shell.getDisplay().getPrimaryMonitor();
    if (parent != null) {
        monitor = parent.getMonitor();
    }
    final Rectangle monitorBounds = monitor.getClientArea();
    Point centerPoint;
    if (parent != null) {
        centerPoint = Geometry.centerPoint(parent.getBounds());
    } else {
        centerPoint = Geometry.centerPoint(monitorBounds);
    }
    return new Point(centerPoint.x - (initialSize.x / 2), Math.max(monitorBounds.y, Math.min(centerPoint.y - (initialSize.y * 2 / 3), monitorBounds.y + monitorBounds.height - initialSize.y)));
}
Also used : Monitor(org.eclipse.swt.widgets.Monitor) Composite(org.eclipse.swt.widgets.Composite) Rectangle(org.eclipse.swt.graphics.Rectangle) Point(org.eclipse.swt.graphics.Point)

Example 18 with Monitor

use of org.eclipse.swt.widgets.Monitor in project egit by eclipse.

the class FixedJFaceToolTip method fixupDisplayBounds.

private Point fixupDisplayBounds(Point tipSize, Point location) {
    if (respectDisplayBounds || respectMonitorBounds) {
        Rectangle bounds;
        Point rightBounds = new Point(tipSize.x + location.x, tipSize.y + location.y);
        Monitor[] ms = control.getDisplay().getMonitors();
        if (respectMonitorBounds && ms.length > 1) {
            // By default present in the monitor of the control
            bounds = control.getMonitor().getBounds();
            Point p = new Point(location.x, location.y);
            // Search on which monitor the event occurred
            Rectangle tmp;
            for (int i = 0; i < ms.length; i++) {
                tmp = ms[i].getBounds();
                if (tmp.contains(p)) {
                    bounds = tmp;
                    break;
                }
            }
        } else {
            bounds = control.getDisplay().getBounds();
        }
        if (!(bounds.contains(location) && bounds.contains(rightBounds))) {
            if (rightBounds.x > bounds.x + bounds.width) {
                location.x -= rightBounds.x - (bounds.x + bounds.width);
            }
            if (rightBounds.y > bounds.y + bounds.height) {
                location.y -= rightBounds.y - (bounds.y + bounds.height);
            }
            if (location.x < bounds.x) {
                location.x = bounds.x;
            }
            if (location.y < bounds.y) {
                location.y = bounds.y;
            }
        }
    }
    return location;
}
Also used : Monitor(org.eclipse.swt.widgets.Monitor) Rectangle(org.eclipse.swt.graphics.Rectangle) Point(org.eclipse.swt.graphics.Point) Point(org.eclipse.swt.graphics.Point)

Example 19 with Monitor

use of org.eclipse.swt.widgets.Monitor in project whole by wholeplatform.

the class UIUtils method getActiveMonitor.

public static Monitor getActiveMonitor() {
    Display display = Display.getDefault();
    Point cursorLocation = display.getCursorLocation();
    Monitor[] monitors = display.getMonitors();
    for (Monitor monitor : monitors) if (monitor.getBounds().contains(cursorLocation))
        return monitor;
    return display.getPrimaryMonitor();
}
Also used : Monitor(org.eclipse.swt.widgets.Monitor) Point(org.eclipse.swt.graphics.Point) Display(org.eclipse.swt.widgets.Display)

Example 20 with Monitor

use of org.eclipse.swt.widgets.Monitor in project ServiceStack.Java by ServiceStack.

the class AddReferenceWizard method addPages.

@Override
public void addPages() {
    super.addPages();
    _page = new AddReferencePage();
    addPage(_page);
    _page.setPackageName(packageName);
    Shell shell = this.getShell();
    shell.setMinimumSize(550, 450);
    Display display = shell.getDisplay();
    Monitor primaryMonitor = display.getPrimaryMonitor();
    Rectangle bounds = primaryMonitor.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);
}
Also used : Shell(org.eclipse.swt.widgets.Shell) Monitor(org.eclipse.swt.widgets.Monitor) Rectangle(org.eclipse.swt.graphics.Rectangle) Display(org.eclipse.swt.widgets.Display)

Aggregations

Monitor (org.eclipse.swt.widgets.Monitor)20 Rectangle (org.eclipse.swt.graphics.Rectangle)15 Point (org.eclipse.swt.graphics.Point)12 Display (org.eclipse.swt.widgets.Display)6 Test (org.junit.Test)3 PropsUI (org.pentaho.di.ui.core.PropsUI)3 WindowProperty (org.pentaho.di.ui.core.gui.WindowProperty)3 AddReferenceWizard (net.servicestack.eclipse.wizard.AddReferenceWizard)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 WizardDialog (org.eclipse.jface.wizard.WizardDialog)1 Composite (org.eclipse.swt.widgets.Composite)1 Shell (org.eclipse.swt.widgets.Shell)1 ISelectionService (org.eclipse.ui.ISelectionService)1