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;
}
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)));
}
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;
}
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();
}
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);
}
Aggregations