예제 #1
0
  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;
  }
예제 #2
0
  private void maximize() {
    mNonMaximizedLocation = mShell.getLocation();
    mNonMaximizedSize = mShell.getSize();

    Monitor monitor = mShell.getMonitor();
    mShell.setBounds(monitor.getBounds());
  }
예제 #3
0
 public static Point centerWindow(Shell shell) {
   Monitor m = Display.getCurrent().getPrimaryMonitor();
   Rectangle bounds = m.getBounds();
   Rectangle rect = shell.getBounds();
   int x = bounds.x + (bounds.width - rect.width) / 2;
   int y = bounds.y + (bounds.height - rect.height) / 2;
   return new Point(x, y);
 }
예제 #4
0
파일: Main.java 프로젝트: p2y/arx
 /**
  * Returns the monitor on which the application was launched.
  *
  * @param display
  * @return
  */
 private static Monitor getMonitor(Display display) {
   Point mouse = display.getCursorLocation();
   for (Monitor monitor : display.getMonitors()) {
     if (monitor.getBounds().contains(mouse)) {
       return monitor;
     }
   }
   return display.getPrimaryMonitor();
 }
예제 #5
0
  /**
   * Centers a dialog (Shell) on the <b>primary</b> (active) display.
   *
   * @param shell Shell to center on screen
   * @see Shell
   */
  public static void centerDialogOnScreen(Shell shell) {
    // do it by monitor to support dual-head cards and still center things correctly onto the screen
    // people are on. -- Emil
    Monitor m = Display.getDefault().getPrimaryMonitor();
    Rectangle bounds = m.getBounds();

    int screen_x = bounds.width;
    int screen_y = bounds.height;

    shell.setLocation(
        screen_x / 2 - (shell.getBounds().width / 2),
        screen_y / 2 - (shell.getBounds().height / 2));
  }
 @Test
 public void test_getMonitor() {
   Monitor monitor = control.getMonitor();
   assertNotNull(monitor);
   Display display = control.getDisplay();
   Monitor[] monitors = display.getMonitors();
   int i;
   /* monitor must be listed in Display.getMonitors */
   for (i = 0; i < monitors.length; i++) {
     if (monitor.equals(monitors[i])) break;
   }
   if (i == monitors.length) {
     fail("Control.getMonitor does not return a monitor listed in Display.getMonitors");
   }
 }
 public void test_equalsLjava_lang_Object() {
   int i;
   for (i = 0; i < monitors.length; i++) {
     if (primary.equals(monitors[i])) break;
   }
   if (i == monitors.length) fail();
   for (i = 0; i < monitors.length; i++) {
     Monitor test = monitors[i];
     for (int j = 0; j < monitors.length; j++) {
       if (test.equals(monitors[j])) {
         if (i != j) fail("Monitors " + i + " and " + j + " should not be equal");
       }
     }
   }
 }
예제 #8
0
  public boolean open() {
    display = Display.getCurrent();

    shell = new Shell(display, SWT.NO_TRIM | SWT.TOOL); // SWT.NO_TRIM | SWT.TOO
    shell.setLayout(new FillLayout());

    int[] size = CPerspective.getSplashSize();
    shell.setSize(size[0], size[1]);

    Composite composite = new Composite(shell, SWT.NONE);
    composite.setLayout(new FillLayout());
    container = new FlashContainer(composite, "splash");

    container.addHookInterceptor(
        new OleHookInterceptor() {

          public boolean intercept(Msg message, int code, int param, int param2) {
            if (message.getMessage() == Win32Constant.WM_RBUTTONDOWN) {
              Point cursor =
                  container.getParent().toControl(Display.getCurrent().getCursorLocation());
              if (container.getBounds().contains(cursor) && container.isVisible()) {
                return true;
              }
            }
            return false;
          }
        });

    container.loadMovie(0, CPerspective.getSplashSwfPath());

    Monitor primary = shell.getMonitor();
    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;
    if (x < 0) x = 0;
    if (y < 0) y = 0;
    shell.setLocation(x, y);

    shell.open();

    while (!shell.isDisposed()) {
      if (!display.readAndDispatch()) {
        display.sleep();
      }
    }
    return true;
  }
  protected void setDialogPosition(Shell shell) {
    String position = this.getConfiguration().getProperty(CFG_POSITION, "left-top");
    if (DisplayManager.getDefaultDisplay() == null) {
      this.m_logger.severe("Could not get monitor device object for dialog.");
      return;
    }
    Monitor primaryMonitor = DisplayManager.getDefaultDisplay().getPrimaryMonitor();

    int offset = m_instance_count * 15;

    int x = 0, y = 0;

    // added 2008/04/07: set minimal width and height
    shell.setBounds(
        x, y, Math.max(shell.getBounds().width, 165), Math.max(shell.getBounds().height, 115));

    if (position.equalsIgnoreCase("left-top")) {
      x = 5 + offset;
      y = 5 + offset;
    }
    if (position.equalsIgnoreCase("right-top") || position.length() == 0) {
      y = 5 + offset;
      x = primaryMonitor.getClientArea().width - shell.getBounds().width - 30 - offset;
    }
    if (position.equalsIgnoreCase("left-bottom")) {
      x = 5;
      y = primaryMonitor.getClientArea().height - shell.getBounds().height - 35 - offset;
    }
    if (position.equalsIgnoreCase("right-bottom")) {
      x = primaryMonitor.getClientArea().width - shell.getBounds().width - 30 - offset;
      y = primaryMonitor.getClientArea().height - shell.getBounds().height - 35 - offset;
    }
    if (position.equalsIgnoreCase("center")) {
      x = (primaryMonitor.getClientArea().width / 2) - (shell.getBounds().width / 2) - 1 - offset;
      y =
          (primaryMonitor.getClientArea().height / 2)
              - (shell.getBounds().height / 2)
              - 35
              - offset;
    }

    // dialog has free defined position
    if (this.isFreePositioning()) {
      x = this.getFreePosX();
      y = this.getFreePosY();
    }

    shell.setBounds(x, y, shell.getBounds().width, shell.getBounds().height);
  }