Пример #1
0
  /** Returns true if the GraphicsDevice has been changed, false otherwise. */
  public boolean updateGraphicsDevice() {
    GraphicsDevice newGraphicsDevice = platformWindow.getGraphicsDevice();
    synchronized (getStateLock()) {
      if (graphicsDevice == newGraphicsDevice) {
        return false;
      }
      graphicsDevice = newGraphicsDevice;
    }

    final GraphicsConfiguration newGC = newGraphicsDevice.getDefaultConfiguration();

    if (!setGraphicsConfig(newGC)) return false;

    SunToolkit.executeOnEventHandlerThread(
        getTarget(),
        new Runnable() {
          public void run() {
            AWTAccessor.getComponentAccessor().setGraphicsConfiguration(getTarget(), newGC);
          }
        });
    return true;
  }
Пример #2
0
  /**
   * The incoming bounds describe the maximized size and position of the window on the monitor that
   * displays the window. But the window manager expects that the bounds are based on the size and
   * position of the primary monitor, even if the window ultimately maximizes onto a secondary
   * monitor. And the window manager adjusts these values to compensate for differences between the
   * primary monitor and the monitor that displays the window. The method translates the incoming
   * bounds to the values acceptable by the window manager. For more details, please refer to
   * 6699851.
   */
  private void adjustMaximizedBounds(Rectangle b) {
    GraphicsConfiguration currentDevGC = getGraphicsConfiguration();

    GraphicsDevice primaryDev =
        GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
    GraphicsConfiguration primaryDevGC = primaryDev.getDefaultConfiguration();

    if (currentDevGC != null && currentDevGC != primaryDevGC) {
      Rectangle currentDevBounds = currentDevGC.getBounds();
      Rectangle primaryDevBounds = primaryDevGC.getBounds();

      boolean isCurrentDevLarger =
          ((currentDevBounds.width - primaryDevBounds.width > 0)
              || (currentDevBounds.height - primaryDevBounds.height > 0));

      // the window manager doesn't seem to compensate for differences when
      // the primary monitor is larger than the monitor that display the window
      if (isCurrentDevLarger) {
        b.width -= (currentDevBounds.width - primaryDevBounds.width);
        b.height -= (currentDevBounds.height - primaryDevBounds.height);
      }
    }
  }