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


Java Monitor类代码示例

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


Monitor类属于org.eclipse.swt.widgets包,在下文中一共展示了Monitor类的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: createDialogArea

import org.eclipse.swt.widgets.Monitor; //导入依赖的package包/类
@Override
protected Control createDialogArea(Composite parent)
{
	parent.setBackgroundMode(SWT.INHERIT_DEFAULT);
	parent.setBackground(BTSUIConstants.VIEW_BACKGROUND_DESELECTED_COLOR);
	Composite control = createContentArea(parent);
	control.setData("org.eclipse.e4.ui.css.id", "LoginDialog");
	Rectangle controlRect = control.getBounds();

	// looks strange in multi monitor environments
	// Rectangle displayBounds = shell.getDisplay().getBounds();

	shell.getDisplay();
	Monitor primary = Display.getDefault().getPrimaryMonitor();
	Rectangle displayBounds = primary.getBounds();

	int x = (displayBounds.width - controlRect.width) / 2;
	int y = (displayBounds.height - controlRect.height) / 2;
	shell.setBounds(x, y, controlRect.width, controlRect.height);

	return control;
}
 
开发者ID:cplutte,项目名称:bts,代码行数:23,代码来源:LoginDialog.java

示例8: StandardWidgetToolkit

import org.eclipse.swt.widgets.Monitor; //导入依赖的package包/类
public StandardWidgetToolkit(String... commandLineArgs) {
    this.swtRunnableFactory = RUNNABLE_FACTORY_OVERRIDE != null ? RUNNABLE_FACTORY_OVERRIDE : this;
    this.commandLineArgs = commandLineArgs;

    display = new Display();
    shell = new Shell(display);
    shell.setText("OAuth 2.0 Authorization Request");

    shell.setLayout(new FillLayout());
    Monitor monitor = display.getPrimaryMonitor();
    Rectangle bounds = monitor.getBounds();
    Dimension size = new Dimension((int) (bounds.width * 0.25), (int) (bounds.height * 0.55));
    shell.setSize(size.width, size.height);
    shell.setLocation((bounds.width - size.width) / 2, (bounds.height - size.height) / 2);

    Browser browser = new org.eclipse.swt.browser.Browser(shell, SWT.ON_TOP);

    swtInterceptingBrowser = new SwtInterceptingBrowser(browser, display, shell);
}
 
开发者ID:Microsoft,项目名称:oauth2-useragent,代码行数:20,代码来源:StandardWidgetToolkit.java

示例9: initShell

import org.eclipse.swt.widgets.Monitor; //导入依赖的package包/类
private void initShell() {
	shell = new Shell(Display.getCurrent(), SWT.APPLICATION_MODAL
			| SWT.SHEET);
	shell.setText("Feature-Expression Management Dialog");
	shell.setImage(VariantSyncPlugin.getDefault()
			.getImageDescriptor("icons/featureExpression.png")
			.createImage());
	shell.setSize(500, 485);

	GridLayout shellLayout = new GridLayout();
	shellLayout.marginWidth = 0;
	shellLayout.marginHeight = 0;
	shell.setLayout(shellLayout);

	Monitor primary = shell.getDisplay().getPrimaryMonitor();
	Rectangle bounds = primary.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);
}
 
开发者ID:1Tristan,项目名称:VariantSync,代码行数:22,代码来源:FeatureManagementDialog.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:gwt-plugins,项目名称:gwt-eclipse-plugin,代码行数:38,代码来源:BreadcrumbItemDropDown.java

示例11: 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

示例12: 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

示例13: getDisplayBounds

import org.eclipse.swt.widgets.Monitor; //导入依赖的package包/类
private Rectangle getDisplayBounds(final Point location) {

		Rectangle displayBounds;
		final Monitor[] allMonitors = _ownerControl.getDisplay().getMonitors();

		if (allMonitors.length > 1) {
			// By default present in the monitor of the control
			displayBounds = _ownerControl.getMonitor().getBounds();
			final Point p = new Point(location.x, location.y);

			// Search on which monitor the event occurred
			Rectangle tmp;
			for (final Monitor element : allMonitors) {
				tmp = element.getBounds();
				if (tmp.contains(p)) {
					displayBounds = tmp;
					break;
				}
			}

		} else {
			displayBounds = _ownerControl.getDisplay().getBounds();
		}

		return displayBounds;
	}
 
开发者ID:wolfgang-ch,项目名称:mytourbook,代码行数:27,代码来源:AnimatedToolTipShell.java

示例14: getDisplayBounds

import org.eclipse.swt.widgets.Monitor; //导入依赖的package包/类
public static Rectangle getDisplayBounds(final Control composite, final Point location) {

		Rectangle displayBounds;
		final Monitor[] allMonitors = composite.getDisplay().getMonitors();

		if (allMonitors.length > 1) {
			// By default present in the monitor of the control
			displayBounds = composite.getMonitor().getBounds();
			final Point p = new Point(location.x, location.y);

			// Search on which monitor the event occurred
			Rectangle tmp;
			for (final Monitor element : allMonitors) {
				tmp = element.getBounds();
				if (tmp.contains(p)) {
					displayBounds = tmp;
					break;
				}
			}

		} else {
			displayBounds = composite.getDisplay().getBounds();
		}

		return displayBounds;
	}
 
开发者ID:wolfgang-ch,项目名称:mytourbook,代码行数:27,代码来源:UI.java

示例15: 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


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