use of org.eclipse.swt.widgets.Monitor in project cogtool by cogtool.
the class ControllerNexus method checkWindowBounds.
/**
* Checks that a stored window location is still visible with the current
* screen layout.
* (Really, just checks that the top-left corner is on screen somewhere.)
*
* @param loc the location info to check
* @return a corrected rectangle, completely visible with the
* current screen layout
*/
protected static Rectangle checkWindowBounds(Rectangle loc) {
if (loc == null) {
return loc;
}
// Indicates that upper-left overlaps with the client area of the
// monitor.
boolean safe = false;
// Check if the window is fully contained on the client areas of
// some set of monitors
Monitor[] monitors = WindowUtil.GLOBAL_DISPLAY.getMonitors();
for (int i = 0; !safe && (i < monitors.length); i++) {
Monitor monitor = monitors[i];
if (monitor != null) {
safe = monitor.getClientArea().contains(loc.x, loc.y);
}
}
if (!safe) {
Monitor prim = WindowUtil.GLOBAL_DISPLAY.getPrimaryMonitor();
Rectangle r = prim.getClientArea();
loc.x = r.x;
loc.y = r.y;
if (loc.width > r.width) {
loc.width = r.width;
}
if (loc.height > r.height) {
loc.height = r.height;
}
}
return loc;
}
use of org.eclipse.swt.widgets.Monitor in project pentaho-kettle by pentaho.
the class BaseStepDialog method setSize.
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);
}
}
use of org.eclipse.swt.widgets.Monitor in project pentaho-kettle by pentaho.
the class WindowProperty method isClippedByUnalignedMonitors.
/**
* This method is needed in the case where the display has multiple monitors, but they do not form a uniform
* rectangle. In this case, it is possible for Geometry.moveInside() to not detect that the window is partially or
* completely clipped. We check to make sure at least the upper left portion of the rectangle is visible to give the
* user the ability to reposition the dialog in this rare case.
*
* @param constrainee
* @param display
* @return
*/
private boolean isClippedByUnalignedMonitors(Rectangle constrainee, Display display) {
boolean isClipped;
Monitor[] monitors = display.getMonitors();
if (monitors.length > 0) {
// Loop searches for a monitor proving false
isClipped = true;
for (Monitor monitor : monitors) {
if (monitor.getClientArea().contains(constrainee.x + 10, constrainee.y + 10)) {
isClipped = false;
break;
}
}
} else {
isClipped = false;
}
return isClipped;
}
use of org.eclipse.swt.widgets.Monitor in project pentaho-kettle by pentaho.
the class WindowProperty method setShell.
/**
* Performs calculations to size and position a dialog If the size passed in is too large for the primary monitor
* client area, it is shrunk to fit. If the positioning leaves part of the dialog outside the client area, it is
* centered instead Note that currently, many of the defaults in org.pentaho.di.ui.core/default.properties have crazy
* values. This causes the failsafe code in here to fire a lot more than is really necessary.
*
* @param shell
* The dialog to position and size
* @param onlyPosition
* Unused argument. If the window is outside the viewable client are, it must be resized to prevent
* inaccessibility.
* @param minWidth
* @param minHeight
*/
public void setShell(Shell shell, boolean onlyPosition, int minWidth, int minHeight) {
shell.setMaximized(maximized);
shell.setBounds(rectangle);
if (minWidth > 0 || minHeight > 0) {
Rectangle bounds = shell.getBounds();
if (bounds.width < minWidth) {
bounds.width = minWidth;
}
if (bounds.height < minHeight) {
bounds.height = minHeight;
}
shell.setSize(bounds.width, bounds.height);
}
// Just to double check: what is the preferred size of this dialog?
// This computed is a minimum. If the minimum is smaller than the
// size of the current shell, we make it larger.
//
Point computedSize = shell.computeSize(SWT.DEFAULT, SWT.DEFAULT);
Rectangle shellSize = shell.getBounds();
if (shellSize.width < computedSize.x) {
shellSize.width = computedSize.x;
}
if (shellSize.height < computedSize.y) {
shellSize.height = computedSize.y;
}
shell.setBounds(shellSize);
Rectangle entireClientArea = shell.getDisplay().getClientArea();
Rectangle resizedRect = Geometry.copy(shellSize);
constrainRectangleToContainer(resizedRect, entireClientArea);
//
if (!resizedRect.equals(shellSize) || isClippedByUnalignedMonitors(resizedRect, shell.getDisplay())) {
Monitor monitor = shell.getDisplay().getPrimaryMonitor();
if (shell.getParent() != null) {
monitor = shell.getParent().getMonitor();
}
Rectangle monitorClientArea = monitor.getClientArea();
constrainRectangleToContainer(resizedRect, monitorClientArea);
resizedRect.x = monitorClientArea.x + (monitorClientArea.width - resizedRect.width) / 2;
resizedRect.y = monitorClientArea.y + (monitorClientArea.height - resizedRect.height) / 2;
shell.setBounds(resizedRect);
}
}
use of org.eclipse.swt.widgets.Monitor in project eclipse.platform.text by eclipse.
the class AbstractInformationControlManager method getClosestMonitor.
/**
* Copied from org.eclipse.jface.window.Window. Returns the monitor whose client area contains
* the given point. If no monitor contains the point, returns the monitor that is closest to the
* point. If this is ever made public, it should be moved into a separate utility class.
*
* @param display the display to search for monitors
* @param rectangle the rectangle to find the closest monitor for (display coordinates)
* @return the monitor closest to the given point
* @since 3.3
*/
private Monitor getClosestMonitor(Display display, Rectangle rectangle) {
int closest = Integer.MAX_VALUE;
Point toFind = Geometry.centerPoint(rectangle);
Monitor[] monitors = display.getMonitors();
Monitor result = monitors[0];
for (Monitor current : monitors) {
Rectangle clientArea = current.getClientArea();
if (clientArea.contains(toFind)) {
return current;
}
int distance = Geometry.distanceSquared(Geometry.centerPoint(clientArea), toFind);
if (distance < closest) {
closest = distance;
result = current;
}
}
return result;
}
Aggregations