當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。