当前位置: 首页>>代码示例>>Java>>正文


Java Monitor.getClientArea方法代码示例

本文整理汇总了Java中org.eclipse.swt.widgets.Monitor.getClientArea方法的典型用法代码示例。如果您正苦于以下问题:Java Monitor.getClientArea方法的具体用法?Java Monitor.getClientArea怎么用?Java Monitor.getClientArea使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.eclipse.swt.widgets.Monitor的用法示例。


在下文中一共展示了Monitor.getClientArea方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getConstrainedShellBounds

import org.eclipse.swt.widgets.Monitor; //导入方法依赖的package包/类
/**
 * Given the desired position of the shell, this method returns an adjusted position such that the window is no
 * larger than its monitor, and does not extend beyond the edge of the monitor. This is used for computing the
 * initial window position via the parent shell, clients can use this as a utility method if they want to limit the
 * region in which the window may be moved.
 *
 * @param shell
 *            the shell which shell bounds is being calculated.
 * @param preferredSize
 *            the preferred position of the window.
 * @return a rectangle as close as possible to preferredSize that does not extend outside the monitor.
 */
public static Rectangle getConstrainedShellBounds(final Shell shell, final Point preferredSize) {

	final Point location = getInitialLocation(shell, preferredSize);
	final Rectangle result = new Rectangle(location.x, location.y, preferredSize.x, preferredSize.y);

	final Monitor monitor = getClosestMonitor(shell.getDisplay(), Geometry.centerPoint(result));

	final Rectangle bounds = monitor.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;
}
 
开发者ID:eclipse,项目名称:n4js,代码行数:37,代码来源:UIUtils.java

示例2: getInitialLocation

import org.eclipse.swt.widgets.Monitor; //导入方法依赖的package包/类
/**
 * 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)));
}
 
开发者ID:eclipse,项目名称:n4js,代码行数:33,代码来源:UIUtils.java

示例3: getClosestMonitor

import org.eclipse.swt.widgets.Monitor; //导入方法依赖的package包/类
/**
 * 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.
 *
 * @param toSearch
 *            point to find (display coordinates).
 * @param toFind
 *            point to find (display coordinates).
 * @return the monitor closest to the given point.
 */
private static Monitor getClosestMonitor(final Display toSearch, final Point toFind) {
	int closest = Integer.MAX_VALUE;

	final Monitor[] monitors = toSearch.getMonitors();
	Monitor result = monitors[0];

	for (int index = 0; index < monitors.length; index++) {
		final Monitor current = monitors[index];

		final Rectangle clientArea = current.getClientArea();

		if (clientArea.contains(toFind)) {
			return current;
		}

		final int distance = Geometry.distanceSquared(Geometry.centerPoint(clientArea), toFind);
		if (distance < closest) {
			closest = distance;
			result = current;
		}
	}

	return result;
}
 
开发者ID:eclipse,项目名称:n4js,代码行数:35,代码来源:UIUtils.java

示例4: calculateCenterOnCurrentDisplay

import org.eclipse.swt.widgets.Monitor; //导入方法依赖的package包/类
private Point calculateCenterOnCurrentDisplay(Point initialSize) {
	if (shell==null || shell.isDisposed()){
		return new Point(0,0);
	}
	/* fall back implemenrtation for unpersisted location */
	Composite parent = getParent();
	Monitor monitor = null;

	if (parent == null) {
		monitor = shell.getDisplay().getPrimaryMonitor();
	} else {
		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)));
}
 
开发者ID:de-jcup,项目名称:egradle,代码行数:26,代码来源:SelectConfigurationDialog.java

示例5: FXCanvasScrollApp

import org.eclipse.swt.widgets.Monitor; //导入方法依赖的package包/类
protected FXCanvasScrollApp() {
    shell = new Shell();
    shell.setText(this.getClass().getSimpleName());
    shell.setLayout(new FillLayout());

    ScrolledComposite scrollPane = new ScrolledComposite(shell, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
    FXCanvas fxCanvas = new FXCanvas(scrollPane, SWT.BORDER);
    fxCanvas.setScene(createScene(SCROLL_CONTAINER_ID));
    scrollPane.setContent(fxCanvas);
    scrollPane.setExpandHorizontal(true);
    scrollPane.setExpandVertical(true);
    fxCanvas.pack();
    scrollPane.setMinSize(fxCanvas.getSize());

    shell.pack();
    Monitor monitor = shell.getMonitor();
    Rectangle monitorRect = monitor.getClientArea();
    Rectangle shellRect = shell.getBounds();
    shellRect.x = Math.max(0, (monitorRect.width - shellRect.width) / 2);
    shellRect.y = Math.max(0, (monitorRect.height - shellRect.height) / 2);
    shell.setBounds(shellRect);
    shell.open();
}
 
开发者ID:teamfx,项目名称:openjfx-8u-dev-tests,代码行数:24,代码来源:FXCanvasScrollApp.java

示例6: FXCanvasBrowserApp

import org.eclipse.swt.widgets.Monitor; //导入方法依赖的package包/类
protected FXCanvasBrowserApp() {
    shell = new Shell();
    shell.setText(this.getClass().getSimpleName());
    shell.setLayout(new FillLayout());
    FXCanvas fxCanvas = new FXCanvas(shell, SWT.BORDER);

    browser = new WebView();
    browser.getEngine().getLoadWorker().stateProperty().addListener(
            new ChangeListener<State>() {
        public void changed(ObservableValue ov, State oldState, State newState) {
            if (newState == State.SUCCEEDED) {
                successLabel.setText(SUCCESS_MESSAGE);
            }
        }
    });
    fxCanvas.setScene(createScene());

    shell.pack();
    Monitor monitor = shell.getMonitor();
    Rectangle monitorRect = monitor.getClientArea();
    Rectangle shellRect = shell.getBounds();
    shellRect.x = Math.max(0, (monitorRect.width - shellRect.width) / 2);
    shellRect.y = Math.max(0, (monitorRect.height - shellRect.height) / 2);
    shell.setBounds(shellRect);
    shell.open();
}
 
开发者ID:teamfx,项目名称:openjfx-8u-dev-tests,代码行数:27,代码来源:FXCanvasBrowserApp.java

示例7: getClosestMonitor

import org.eclipse.swt.widgets.Monitor; //导入方法依赖的package包/类
/**
 * 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;
}
 
开发者ID:gwt-plugins,项目名称:gwt-eclipse-plugin,代码行数:38,代码来源:BreadcrumbItemDropDown.java

示例8: getClosestMonitor

import org.eclipse.swt.widgets.Monitor; //导入方法依赖的package包/类
/**
 * This method was copy/pasted from JFace.
 */
private static Monitor getClosestMonitor(final Display toSearch, final Point toFind) {
	int closest = Integer.MAX_VALUE;

	final Monitor[] monitors = toSearch.getMonitors();
	Monitor result = monitors[0];

	for (int idx = 0; idx < monitors.length; idx++) {
		final Monitor current = monitors[idx];

		final Rectangle clientArea = current.getClientArea();

		if (clientArea.contains(toFind)) { return current; }

		final int distance = Geometry.distanceSquared(Geometry.centerPoint(clientArea), toFind);
		if (distance < closest) {
			closest = distance;
			result = current;
		}
	}

	return result;
}
 
开发者ID:gama-platform,项目名称:gama,代码行数:26,代码来源:GamlSearchField.java

示例9: getConstrainedShellBounds

import org.eclipse.swt.widgets.Monitor; //导入方法依赖的package包/类
/**
 * This method was copy/pasted from JFace.
 */
private Rectangle getConstrainedShellBounds(final Display display, final Rectangle preferredSize) {
	final Rectangle result =
			new Rectangle(preferredSize.x, preferredSize.y, preferredSize.width, preferredSize.height);

	final Point topLeft = new Point(preferredSize.x, preferredSize.y);
	final Monitor mon = getClosestMonitor(display, topLeft);
	final 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;
}
 
开发者ID:gama-platform,项目名称:gama,代码行数:25,代码来源:GamlSearchField.java

示例10: getClosestMonitor

import org.eclipse.swt.widgets.Monitor; //导入方法依赖的package包/类
/**
 * 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;
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:35,代码来源:BreadcrumbItemDropDown.java

示例11: getInitialLocation

import org.eclipse.swt.widgets.Monitor; //导入方法依赖的package包/类
/**
 * 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)));
}
 
开发者ID:ghillairet,项目名称:gef-gwt,代码行数:34,代码来源:Window.java

示例12: getClosestMonitor

import org.eclipse.swt.widgets.Monitor; //导入方法依赖的package包/类
/**
 * 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 toFind
 *            point to find (display coordinates)
 * @return the montor closest to the given point
 */
private static Monitor getClosestMonitor(Display toSearch, Point toFind) {
	int closest = Integer.MAX_VALUE;

	Monitor[] monitors = toSearch.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;
}
 
开发者ID:ghillairet,项目名称:gef-gwt,代码行数:38,代码来源:Window.java

示例13: getConstrainedShellBounds

import org.eclipse.swt.widgets.Monitor; //导入方法依赖的package包/类
/**
 * Given the desired position of the window, this method returns an adjusted
 * position such that the window is no larger than its monitor, and does not
 * extend beyond the edge of the monitor. This is used for computing the
 * initial window position, and subclasses can use this as a utility method
 * if they want to limit the region in which the window may be moved.
 * 
 * @param preferredSize
 *            the preferred position of the window
 * @return a rectangle as close as possible to preferredSize that does not
 *         extend outside the monitor
 * 
 * @since 3.0
 */
protected Rectangle getConstrainedShellBounds(Rectangle preferredSize) {
	Rectangle result = new Rectangle(preferredSize.x, preferredSize.y,
			preferredSize.width, preferredSize.height);

	Monitor mon = getClosestMonitor(getShell().getDisplay(), Geometry
			.centerPoint(result));

	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;
}
 
开发者ID:ghillairet,项目名称:gef-gwt,代码行数:39,代码来源:Window.java

示例14: getDefaultLocation

import org.eclipse.swt.widgets.Monitor; //导入方法依赖的package包/类
private Point getDefaultLocation(Point initialSize, int offsetRight, int offsetTop) {
	Composite parent = getShell().getParent();

	Monitor monitor = getShell().getDisplay().getPrimaryMonitor();
	if (parent != null) {
		monitor = parent.getMonitor();
	}

	Rectangle monitorBounds = monitor.getClientArea();
	Point topRight;
	if (parent != null) {
		Rectangle parentBounds = parent.getBounds();
		topRight = new Point(parentBounds.x + parentBounds.width, parentBounds.y);
	} else {
		topRight = new Point(monitorBounds.x + monitorBounds.width, monitorBounds.y);
	}

	return new Point(topRight.x - (initialSize.x + offsetRight), //
			Math.max(monitorBounds.y, Math.min(topRight.y + offsetTop, monitorBounds.y + monitorBounds.height - initialSize.y)));
}
 
开发者ID:chgeo,项目名称:show-shortcuts,代码行数:21,代码来源:ShortcutPopup.java

示例15: getPrimaryScreenClientArea

import org.eclipse.swt.widgets.Monitor; //导入方法依赖的package包/类
public static Rectangle getPrimaryScreenClientArea(Display display) {
	Monitor primaryMonitorBySwt = display.getPrimaryMonitor();
	Rectangle primaryMonitorClientAreaBySwt = primaryMonitorBySwt.getClientArea();
	GraphicsDevice[]screens =  GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices();
	  for (GraphicsDevice screen : screens) {
		  if (isPrimaryMonitor(screen)) {
			  // Cut off any excess area such as OS task-bars. 
			  Rectangle primaryScreenBoundsByJava = new Rectangle(	
					screen.getDefaultConfiguration().getBounds().x,
				   	screen.getDefaultConfiguration().getBounds().y,
				   	screen.getDefaultConfiguration().getBounds().width,
					screen.getDefaultConfiguration().getBounds().height);
			 
			  return primaryMonitorClientAreaBySwt.intersection(primaryScreenBoundsByJava);				 
		  } 			 
	  }
	  
	  // No primary screen has been found by java, use SWT to get clientArea of PrimaryScreen as fallback.
	  return primaryMonitorClientAreaBySwt;
}
 
开发者ID:jeromewagener,项目名称:Sammelbox,代码行数:21,代码来源:ScreenUtils.java


注:本文中的org.eclipse.swt.widgets.Monitor.getClientArea方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。