本文整理了Java中org.eclipse.swt.widgets.Monitor.getClientArea()
方法的一些代码示例,展示了Monitor.getClientArea()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Monitor.getClientArea()
方法的具体详情如下:
包路径:org.eclipse.swt.widgets.Monitor
类名称:Monitor
方法名:getClientArea
[英]Returns a rectangle which describes the area of the receiver which is capable of displaying data.
[中]返回一个矩形,该矩形描述接收器能够显示数据的区域。
代码示例来源:origin: pentaho/pentaho-kettle
/**
* 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;
}
代码示例来源:origin: pentaho/pentaho-kettle
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 );
}
}
代码示例来源:origin: pentaho/pentaho-kettle
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 );
}
}
代码示例来源:origin: pentaho/pentaho-kettle
monitor = shell.getParent().getMonitor();
Rectangle monitorClientArea = monitor.getClientArea();
constrainRectangleToContainer( resizedRect, monitorClientArea );
代码示例来源:origin: pentaho/pentaho-kettle
monitor = shell.getParent().getMonitor();
Rectangle monitorClientArea = monitor.getClientArea();
代码示例来源:origin: org.eclipse.platform/org.eclipse.ui.workbench
/**
* This method was copy/pasted from JFace.
*/
private Rectangle getConstrainedShellBounds(Display display, Rectangle preferredSize) {
Rectangle result = new Rectangle(preferredSize.x, preferredSize.y, preferredSize.width,
preferredSize.height);
Point topLeft = new Point(preferredSize.x, preferredSize.y);
Monitor mon = Util.getClosestMonitor(display, topLeft);
Rectangle bounds = mon.getClientArea();
if (result.height > bounds.height) {
result.height = bounds.height;
}
if (result.width > bounds.width) {
result.width = bounds.width;
}
result.x = Math.max(bounds.x, Math.min(result.x, bounds.x + bounds.width - result.width));
result.y = Math.max(bounds.y, Math.min(result.y, bounds.y + bounds.height - result.height));
return result;
}
代码示例来源:origin: org.eclipse.platform/org.eclipse.swt.examples
/**
* Sets the size of the shell to it's "packed" size,
* unless that makes it larger than the monitor it is being displayed on,
* in which case just set the shell size to be slightly smaller than the monitor.
*/
static void setShellSize(ControlExample instance, Shell shell) {
Point size = shell.computeSize(SWT.DEFAULT, SWT.DEFAULT);
Rectangle monitorArea = shell.getMonitor().getClientArea();
shell.setSize(Math.min(size.x, monitorArea.width), Math.min(size.y, monitorArea.height));
}
}
代码示例来源:origin: org.eclipse.pde/org.eclipse.pde.runtime
@Override
protected Point getInitialLocation(Point size) {
if (fAnchor == null) {
return super.getInitialLocation(size);
}
Point point = fAnchor;
Rectangle monitor = getShell().getMonitor().getClientArea();
if (monitor.width < point.x + size.x) {
point.x = Math.max(0, point.x - size.x);
}
if (monitor.height < point.y + size.y) {
point.y = Math.max(0, point.y - size.y);
}
return point;
}
代码示例来源:origin: org.eclipse.pde/org.eclipse.pde.runtime
@Override
protected Point getInitialLocation(Point size) {
if (fAnchor == null) {
return super.getInitialLocation(size);
}
Point point = fAnchor;
Rectangle monitor = getShell().getMonitor().getClientArea();
if (monitor.width < point.x + size.x) {
point.x = Math.max(0, point.x - size.x);
}
if (monitor.height < point.y + size.y) {
point.y = Math.max(0, point.y - size.y);
}
return point;
}
代码示例来源:origin: infinitest/infinitest
private void sizeDialog(final Shell dialog) {
dialog.pack();
Monitor monitor = dialog.getShell().getMonitor();
if (monitor != null) {
if (dialog.getSize().x > monitor.getClientArea().width) {
dialog.setSize(monitor.getClientArea().width, dialog.getSize().y);
}
if (dialog.getSize().y > monitor.getClientArea().height) {
dialog.setSize(dialog.getSize().x, monitor.getClientArea().height);
}
}
dialog.layout();
}
代码示例来源:origin: org.eclipse.scout.sdk.deps/org.eclipse.swt.win32.win32.x86
void center () {
if (parent == null) return;
Rectangle rect = getBoundsInPixels ();
Rectangle parentRect = display.mapInPixels (parent, null, parent.getClientAreaInPixels());
int x = Math.max (parentRect.x, parentRect.x + (parentRect.width - rect.width) / 2);
int y = Math.max (parentRect.y, parentRect.y + (parentRect.height - rect.height) / 2);
Rectangle monitorRect = parent.getMonitor ().getClientArea();
if (x + rect.width > monitorRect.x + monitorRect.width) {
x = Math.max (monitorRect.x, monitorRect.x + monitorRect.width - rect.width);
} else {
x = Math.max (x, monitorRect.x);
}
if (y + rect.height > monitorRect.y + monitorRect.height) {
y = Math.max (monitorRect.y, monitorRect.y + monitorRect.height - rect.height);
} else {
y = Math.max (y, monitorRect.y);
}
setLocationInPixels (x, y);
}
代码示例来源:origin: org.eclipse.platform/org.eclipse.ui.workbench
/**
*
* Returns true iff the given rectangle is located in the client area of any
* monitor.
*
* @param display
* the display
* @param someRectangle
* a rectangle in display coordinates (not null)
* @return true iff the given point can be seen on any monitor
*/
public static boolean intersectsAnyMonitor(Display display,
Rectangle someRectangle) {
for (Monitor monitor : display.getMonitors()) {
if (monitor.getClientArea().intersects(someRectangle)) {
return true;
}
}
return false;
}
代码示例来源:origin: org.eclipse.swt.cocoa.macosx/x86_64
void center () {
if (parent == null) return;
Rectangle rect = getBounds ();
Rectangle parentRect = display.map (parent, null, parent.getClientArea());
int x = Math.max (parentRect.x, parentRect.x + (parentRect.width - rect.width) / 2);
int y = Math.max (parentRect.y, parentRect.y + (parentRect.height - rect.height) / 2);
Rectangle monitorRect = parent.getMonitor ().getClientArea();
if (x + rect.width > monitorRect.x + monitorRect.width) {
x = Math.max (monitorRect.x, monitorRect.x + monitorRect.width - rect.width);
} else {
x = Math.max (x, monitorRect.x);
}
if (y + rect.height > monitorRect.y + monitorRect.height) {
y = Math.max (monitorRect.y, monitorRect.y + monitorRect.height - rect.height);
} else {
y = Math.max (y, monitorRect.y);
}
setLocation (x, y);
}
代码示例来源:origin: org.eclipse.platform/org.eclipse.swt.gtk.linux.s390x
void center () {
if (parent == null) return;
Rectangle rect = getBoundsInPixels ();
Rectangle parentRect = display.mapInPixels (parent, null, parent.getClientAreaInPixels());
int x = Math.max (parentRect.x, parentRect.x + (parentRect.width - rect.width) / 2);
int y = Math.max (parentRect.y, parentRect.y + (parentRect.height - rect.height) / 2);
Rectangle monitorRect = DPIUtil.autoScaleUp(parent.getMonitor ().getClientArea());
if (x + rect.width > monitorRect.x + monitorRect.width) {
x = Math.max (monitorRect.x, monitorRect.x + monitorRect.width - rect.width);
} else {
x = Math.max (x, monitorRect.x);
}
if (y + rect.height > monitorRect.y + monitorRect.height) {
y = Math.max (monitorRect.y, monitorRect.y + monitorRect.height - rect.height);
} else {
y = Math.max (y, monitorRect.y);
}
setLocationInPixels (x, y);
}
代码示例来源:origin: org.eclipse.platform/org.eclipse.swt.gtk.aix.ppc
void center () {
if (parent == null) return;
Rectangle rect = getBoundsInPixels ();
Rectangle parentRect = display.mapInPixels (parent, null, parent.getClientAreaInPixels());
int x = Math.max (parentRect.x, parentRect.x + (parentRect.width - rect.width) / 2);
int y = Math.max (parentRect.y, parentRect.y + (parentRect.height - rect.height) / 2);
Rectangle monitorRect = DPIUtil.autoScaleUp(parent.getMonitor ().getClientArea());
if (x + rect.width > monitorRect.x + monitorRect.width) {
x = Math.max (monitorRect.x, monitorRect.x + monitorRect.width - rect.width);
} else {
x = Math.max (x, monitorRect.x);
}
if (y + rect.height > monitorRect.y + monitorRect.height) {
y = Math.max (monitorRect.y, monitorRect.y + monitorRect.height - rect.height);
} else {
y = Math.max (y, monitorRect.y);
}
setLocationInPixels (x, y);
}
代码示例来源:origin: org.eclipse.scout.sdk.deps/org.eclipse.jface.text
/**
* Crops the given bounds such that they lie completely on the closest monitor.
*
* @param bounds shell bounds to crop
* @since 3.4
*/
void cropToClosestMonitor(Rectangle bounds) {
Rectangle monitorBounds= getClosestMonitor(fSubjectControl.getDisplay(), bounds).getClientArea();
bounds.intersect(monitorBounds);
}
代码示例来源:origin: org.eclipse.scout.sdk.deps/org.eclipse.ui.ide
@Override
protected Point getInitialLocation(Point initialSize) {
Composite parent = getShell().getParent();
if (!centerOnMonitor || parent == null) {
return super.getInitialLocation(initialSize);
}
Monitor monitor = parent.getMonitor();
Rectangle monitorBounds = monitor.getClientArea();
Point 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)));
}
代码示例来源:origin: org.eclipse.platform/org.eclipse.jface.text
/**
* Crops the given bounds such that they lie completely on the closest monitor.
*
* @param bounds shell bounds to crop
* @since 3.4
*/
void cropToClosestMonitor(Rectangle bounds) {
Rectangle monitorBounds= Util.getClosestMonitor(fSubjectControl.getDisplay(), Geometry.centerPoint(bounds)).getClientArea();
bounds.intersect(monitorBounds);
}
代码示例来源:origin: org.eclipse.platform/org.eclipse.jface.text
protected Point getStackedLocation(Shell shell, Shell parent) {
Point p= parent.getLocation();
Point size= parent.getSize();
p.x += size.x / 4;
p.y += size.y;
p= parent.toDisplay(p);
Point shellSize= shell.getSize();
Monitor monitor= getClosestMonitor(parent.getDisplay(), new Rectangle(p.x, p.y, 0, 0));
Rectangle displayBounds= monitor.getClientArea();
constrainLocation(p, shellSize, displayBounds);
return p;
}
代码示例来源:origin: org.eclipse.scout.sdk.deps/org.eclipse.jface.text
protected Point getStackedLocation(Shell shell, Shell parent) {
Point p= parent.getLocation();
Point size= parent.getSize();
p.x += size.x / 4;
p.y += size.y;
p= parent.toDisplay(p);
Point shellSize= shell.getSize();
Monitor monitor= getClosestMonitor(parent.getDisplay(), new Rectangle(p.x, p.y, 0, 0));
Rectangle displayBounds= monitor.getClientArea();
constrainLocation(p, shellSize, displayBounds);
return p;
}
内容来源于网络,如有侵权,请联系作者删除!