コード例 #1
0
  public void updateGC() {
    int scrn = getScreenImOn();
    if (screenLog.isLoggable(PlatformLogger.Level.FINER)) {
      log.finer("Screen number: " + scrn);
    }

    // get current GD
    Win32GraphicsDevice oldDev = (Win32GraphicsDevice) winGraphicsConfig.getDevice();

    Win32GraphicsDevice newDev;
    GraphicsDevice devs[] = GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices();
    // Occasionally during device addition/removal getScreenImOn can return
    // a non-existing screen number. Use the default device in this case.
    if (scrn >= devs.length) {
      newDev =
          (Win32GraphicsDevice)
              GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
    } else {
      newDev = (Win32GraphicsDevice) devs[scrn];
    }

    // Set winGraphicsConfig to the default GC for the monitor this Window
    // is now mostly on.
    winGraphicsConfig = (Win32GraphicsConfig) newDev.getDefaultConfiguration();
    if (screenLog.isLoggable(PlatformLogger.Level.FINE)) {
      if (winGraphicsConfig == null) {
        screenLog.fine("Assertion (winGraphicsConfig != null) failed");
      }
    }

    // if on a different display, take off old GD and put on new GD
    if (oldDev != newDev) {
      oldDev.removeDisplayChangedListener(this);
      newDev.addDisplayChangedListener(this);
    }

    AWTAccessor.getComponentAccessor()
        .setGraphicsConfiguration((Component) target, winGraphicsConfig);
  }
コード例 #2
0
 /** @deprecated as of JDK version 1.3 replaced by <code>getConfig()</code> */
 @Deprecated
 public Win32GraphicsConfig(GraphicsDevice device, int visualnum) {
   this.screen = (Win32GraphicsDevice) device;
   this.visual = visualnum;
   ((Win32GraphicsDevice) device).addDisplayChangedListener(this);
 }
コード例 #3
0
 public Rectangle getBounds() {
   return getBounds(screen.getScreen());
 }
コード例 #4
0
 /**
  * Returns a new color model for this configuration. This call is only used internally, by images
  * and components that are associated with the graphics device. When attributes of that device
  * change (for example, when the device palette is updated), then this device-based color model
  * will be updated internally to reflect the new situation.
  */
 public ColorModel getDeviceColorModel() {
   return screen.getDynamicColorModel();
 }
コード例 #5
0
 /** Returns the color model associated with this configuration. */
 public synchronized ColorModel getColorModel() {
   return screen.getColorModel();
 }
  /*
   * From DisplayChangeListener interface.
   * Called from WToolkit and executed on the event thread when the
   * display settings are changed.
   */
  @Override
  public void displayChanged() {
    // getNumScreens() will return the correct current number of screens
    GraphicsDevice newDevices[] = new GraphicsDevice[getNumScreens()];
    GraphicsDevice oldScreens[] = screens;
    // go through the list of current devices and determine if they
    // could be reused, or will have to be replaced
    if (oldScreens != null) {
      for (int i = 0; i < oldScreens.length; i++) {
        if (!(screens[i] instanceof Win32GraphicsDevice)) {
          // REMIND: can we ever have anything other than Win32GD?
          assert (false) : oldScreens[i];
          continue;
        }
        Win32GraphicsDevice gd = (Win32GraphicsDevice) oldScreens[i];
        // devices may be invalidated from the native code when the
        // display change happens (device add/removal also causes a
        // display change)
        if (!gd.isValid()) {
          if (oldDevices == null) {
            oldDevices = new ArrayList<WeakReference<Win32GraphicsDevice>>();
          }
          oldDevices.add(new WeakReference<Win32GraphicsDevice>(gd));
        } else if (i < newDevices.length) {
          // reuse the device
          newDevices[i] = gd;
        }
      }
      oldScreens = null;
    }
    // create the new devices (those that weren't reused)
    for (int i = 0; i < newDevices.length; i++) {
      if (newDevices[i] == null) {
        newDevices[i] = makeScreenDevice(i);
      }
    }
    // install the new array of devices
    // Note: no synchronization here, it doesn't matter if a thread gets
    // a new or an old array this time around
    screens = newDevices;
    for (GraphicsDevice gd : screens) {
      if (gd instanceof DisplayChangedListener) {
        ((DisplayChangedListener) gd).displayChanged();
      }
    }
    // re-invalidate all old devices. It's needed because those in the list
    // may become "invalid" again - if the current default device is removed,
    // for example. Also, they need to be notified about display
    // changes as well.
    if (oldDevices != null) {
      int defScreen = getDefaultScreen();
      for (ListIterator<WeakReference<Win32GraphicsDevice>> it = oldDevices.listIterator();
          it.hasNext(); ) {
        Win32GraphicsDevice gd = it.next().get();
        if (gd != null) {
          gd.invalidate(defScreen);
          gd.displayChanged();
        } else {
          // no more references to this device, remove it
          it.remove();
        }
      }
    }
    // Reset the static GC for the (possibly new) default screen
    WToolkit.resetGC();

    // notify SunDisplayChanger list (e.g. VolatileSurfaceManagers and
    // CachingSurfaceManagers) about the display change event
    displayChanger.notifyListeners();
    // note: do not call super.displayChanged, we've already done everything
  }