本文整理了Java中org.eclipse.jface.util.Geometry.centerPoint()
方法的一些代码示例,展示了Geometry.centerPoint()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Geometry.centerPoint()
方法的具体详情如下:
包路径:org.eclipse.jface.util.Geometry
类名称:Geometry
方法名:centerPoint
[英]Returns the point in the center of the given rectangle.
[中]返回给定矩形中心的点。
代码示例来源:origin: org.eclipse.rap/org.eclipse.rap.jface
private Point getInitialDialogLocation( Point initialSize ) {
Rectangle dispayBounds = getShell().getDisplay().getBounds();
Point centerPoint = Geometry.centerPoint( dispayBounds );
int x = centerPoint.x - ( initialSize.x / 2 );
int y = Math.min( centerPoint.y - ( initialSize.y * 2 / 3 ),
dispayBounds.height - initialSize.y );
return new Point( x, Math.max( 0, y ) );
}
//RAPEND [if]
代码示例来源:origin: org.eclipse.platform/org.eclipse.jface.text
/**
* Gets the closest monitor given an anchor and the subject area.
*
* @param area the subject area
* @param anchor the anchor
* @return the monitor closest to the edge of <code>area</code> defined by
* <code>anchor</code>
* @since 3.3
*/
private Monitor getClosestMonitor(Rectangle area, Anchor anchor) {
Point center;
if (ANCHOR_GLOBAL == anchor)
center= Geometry.centerPoint(area);
else
center= Geometry.centerPoint(Geometry.getExtrudedEdge(area, 0, anchor.getSWTFlag()));
return Util.getClosestMonitor(fSubjectControl.getDisplay(), center);
}
代码示例来源:origin: org.eclipse.scout.sdk.deps/org.eclipse.jface.text
/**
* Gets the closest monitor given an anchor and the subject area.
*
* @param area the subject area
* @param anchor the anchor
* @return the monitor closest to the edge of <code>area</code> defined by
* <code>anchor</code>
* @since 3.3
*/
private Monitor getClosestMonitor(Rectangle area, Anchor anchor) {
Point center;
if (ANCHOR_GLOBAL == anchor)
center= Geometry.centerPoint(area);
else
center= Geometry.centerPoint(Geometry.getExtrudedEdge(area, 0, anchor.getSWTFlag()));
return getClosestMonitor(fSubjectControl.getDisplay(), Geometry.createRectangle(center, new Point(0, 0)));
}
代码示例来源:origin: org.eclipse.scout.sdk.deps/org.eclipse.jface
/**
* 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 parent shell, or display bounds if there is no parent
* shell.
*
* @param initialSize
* the initial size of the shell, as returned by
* <code>getInitialSize</code>.
* @return the initial location of the shell
*/
protected Point getInitialLocation(Point initialSize) {
Composite parent = shell.getParent();
Monitor monitor = shell.getDisplay().getPrimaryMonitor();
if (parent != null) {
monitor = parent.getMonitor();
}
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)));
}
代码示例来源:origin: org.eclipse.rap/org.eclipse.rap.jface
/**
* 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 parent shell, or display bounds if there is no parent
* shell.
*
* @param initialSize
* the initial size of the shell, as returned by
* <code>getInitialSize</code>.
* @return the initial location of the shell
*/
protected Point getInitialLocation(Point initialSize) {
Composite parent = shell.getParent();
Monitor monitor = shell.getDisplay().getPrimaryMonitor();
if (parent != null) {
monitor = parent.getMonitor();
}
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)));
}
代码示例来源: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
.centerPoint(result));
代码示例来源:origin: org.eclipse.platform/org.eclipse.jface
/**
* 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 parent shell, or display bounds if there is no parent
* shell.
*
* @param initialSize
* the initial size of the shell, as returned by
* <code>getInitialSize</code>.
* @return the initial location of the shell
*/
protected Point getInitialLocation(Point initialSize) {
Composite parent = shell.getParent();
Monitor monitor = shell.getDisplay().getPrimaryMonitor();
if (parent != null) {
monitor = parent.getMonitor();
}
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)));
}
代码示例来源:origin: org.eclipse.scout.sdk.deps/org.eclipse.jface.text
/**
* 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 (int idx = 0; idx < monitors.length; idx++) {
Monitor current = monitors[idx];
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;
}
代码示例来源:origin: org.eclipse.scout.sdk.deps/org.eclipse.jface
.centerPoint(result));
代码示例来源:origin: org.eclipse.rap/org.eclipse.rap.jface
.centerPoint(result));
代码示例来源:origin: org.eclipse.platform/org.eclipse.jface.text
/**
* 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 toSearch point to find (display coordinates)
* @param rectangle rectangle to find (display coordinates)
* @return the monitor closest to the given point
* @since 3.3
*/
private Monitor getClosestMonitor(Display toSearch, Rectangle rectangle) {
int closest = Integer.MAX_VALUE;
Point toFind= Geometry.centerPoint(rectangle);
Monitor[] monitors = toSearch.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;
}
}
代码示例来源:origin: org.eclipse.scout.sdk.deps/org.eclipse.jface.text
int closest = Integer.MAX_VALUE;
Point toFind= Geometry.centerPoint(rectangle);
Monitor[] monitors = toSearch.getMonitors();
Monitor result = monitors[0];
int distance = Geometry.distanceSquared(Geometry.centerPoint(clientArea), toFind);
if (distance < closest) {
closest = distance;
代码示例来源: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.ui.workbench
@Override
protected void setDialogLocation(final Shell dialog,
IWorkbenchPart activePart) {
if (dialog == null)
return;
// Default to center on the display
Point dlgAnchor = Geometry.centerPoint(dialog.getDisplay().getBounds());
// Center the dialog within the activePart's pane (if any)
if (activePart != null) {
WorkbenchPart wbPart = (WorkbenchPart) activePart;
PartSite site = (PartSite) wbPart.getSite();
Control paneCtrl = (Control) site.getModel().getWidget();
// Get the center of the view pane's control
Rectangle viewBounds = paneCtrl.getBounds();
Point vCenter = Geometry.centerPoint(viewBounds);
// Map it to the display
dlgAnchor = paneCtrl.getParent().toDisplay(vCenter);
}
// Offset the point by half the dialog size
Rectangle dialogBounds = dialog.getBounds();
dlgAnchor.x -= (dialogBounds.width / 2);
dlgAnchor.y -= (dialogBounds.height / 2);
dialog.setLocation(dlgAnchor);
}
代码示例来源:origin: org.eclipse.rap/org.eclipse.rap.jface
.centerPoint(clientArea), toFind);
if (distance < closest) {
closest = distance;
代码示例来源:origin: org.eclipse.scout.sdk.deps/org.eclipse.jdt.ui
/**
* 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.
* <p>
* Copied from <code>org.eclipse.jface.window.Window.getClosestMonitor(Display, Point)</code>
* </p>
*
* @param display the display showing the monitors
* @param point point to find (display coordinates)
* @return the monitor closest to the given point
*/
private static Monitor getClosestMonitor(Display display, Point point) {
int closest= Integer.MAX_VALUE;
Monitor[] monitors= display.getMonitors();
Monitor result= monitors[0];
for (int i= 0; i < monitors.length; i++) {
Monitor current= monitors[i];
Rectangle clientArea= current.getClientArea();
if (clientArea.contains(point))
return current;
int distance= Geometry.distanceSquared(Geometry.centerPoint(clientArea), point);
if (distance < closest) {
closest= distance;
result= current;
}
}
return result;
}
代码示例来源:origin: org.eclipse.platform/org.eclipse.jface
int distance = Geometry.distanceSquared(Geometry.centerPoint(clientArea), toFind);
if (distance < closest) {
closest = distance;
代码示例来源:origin: org.eclipse.scout.sdk.deps/org.eclipse.jface
.centerPoint(clientArea), toFind);
if (distance < closest) {
closest = distance;
代码示例来源:origin: org.eclipse.platform/org.eclipse.e4.ui.workbench.renderers.swt
Monitor closestMonitor = Util.getClosestMonitor(display, Geometry.centerPoint(modelBounds));
Rectangle displayBounds = closestMonitor.getClientArea();
if (!modelBounds.intersects(displayBounds)) {
内容来源于网络,如有侵权,请联系作者删除!