Ejemplo n.º 1
0
 /**
  * Returns a Transform that can be composed with the default Transform of a Graphics2D so that 72
  * units in user space will equal 1 inch in device space. Given a Graphics2D, g, one can reset the
  * transformation to create such a mapping by using the following pseudocode:
  *
  * <pre>
  *      GraphicsConfiguration gc = g.getGraphicsConfiguration();
  *
  *      g.setTransform(gc.getDefaultTransform());
  *      g.transform(gc.getNormalizingTransform());
  * </pre>
  *
  * Note that sometimes this Transform will be identity (e.g. for printers or metafile output) and
  * that this Transform is only as accurate as the information supplied by the underlying system.
  * For image buffers, this Transform will be the Identity transform, since there is no valid
  * distance measurement.
  */
 public AffineTransform getNormalizingTransform() {
   Win32GraphicsEnvironment ge =
       (Win32GraphicsEnvironment) GraphicsEnvironment.getLocalGraphicsEnvironment();
   double xscale = ge.getXResolution() / 72.0;
   double yscale = ge.getYResolution() / 72.0;
   return new AffineTransform(xscale, 0.0, 0.0, yscale, 0.0, 0.0);
 }
 @Override
 public boolean isAccelCapable() {
   // REMIND: Temp workaround for issues with using HW acceleration
   // in the browser on Vista when DWM is enabled
   // Note: isDWMCompositionEnabled is only relevant on Vista, returns
   // false on other systems.
   return !Win32GraphicsEnvironment.isDWMCompositionEnabled();
 }
Ejemplo n.º 3
0
  public void setOpaque(boolean isOpaque) {
    synchronized (getStateLock()) {
      if (this.isOpaque == isOpaque) {
        return;
      }
    }

    Window target = (Window) getTarget();

    if (!isOpaque) {
      SunToolkit sunToolkit = (SunToolkit) target.getToolkit();
      if (!sunToolkit.isWindowTranslucencySupported()
          || !sunToolkit.isTranslucencyCapable(target.getGraphicsConfiguration())) {
        return;
      }
    }

    boolean isVistaOS = Win32GraphicsEnvironment.isVistaOS();

    if (this.isOpaque != isOpaque && !isVistaOS) {
      // non-Vista OS: only replace the surface data if the opacity
      // status changed (see WComponentPeer.isAccelCapable() for more)
      replaceSurfaceDataRecursively(target);
    }

    synchronized (getStateLock()) {
      this.isOpaque = isOpaque;
      setOpaqueImpl(isOpaque);
      if (isOpaque) {
        TranslucentWindowPainter currentPainter = painter;
        if (currentPainter != null) {
          currentPainter.flush();
          painter = null;
        }
      } else {
        painter = TranslucentWindowPainter.createInstance(this);
      }
    }

    if (isVistaOS) {
      // On Vista: setting the window non-opaque makes the window look
      // rectangular, though still catching the mouse clicks within
      // its shape only. To restore the correct visual appearance
      // of the window (i.e. w/ the correct shape) we have to reset
      // the shape.
      Shape shape = target.getShape();
      if (shape != null) {
        target.setShape(shape);
      }
    }

    if (target.isVisible()) {
      updateWindow(true);
    }
  }
Ejemplo n.º 4
0
  public void setOpacity(float opacity) {
    if (!((SunToolkit) ((Window) target).getToolkit()).isWindowOpacitySupported()) {
      return;
    }

    if (opacity < 0.0f || opacity > 1.0f) {
      throw new IllegalArgumentException(
          "The value of opacity should be in the range [0.0f .. 1.0f].");
    }

    if (((this.opacity == 1.0f && opacity < 1.0f) || (this.opacity < 1.0f && opacity == 1.0f))
        && !Win32GraphicsEnvironment.isVistaOS()) {
      // non-Vista OS: only replace the surface data if opacity status
      // changed (see WComponentPeer.isAccelCapable() for more)
      replaceSurfaceDataRecursively((Component) getTarget());
    }

    this.opacity = opacity;

    final int maxOpacity = 0xff;
    int iOpacity = (int) (opacity * maxOpacity);
    if (iOpacity < 0) {
      iOpacity = 0;
    }
    if (iOpacity > maxOpacity) {
      iOpacity = maxOpacity;
    }

    setOpacity(iOpacity);

    synchronized (getStateLock()) {
      if (!isOpaque && ((Window) target).isVisible()) {
        updateWindow(true);
      }
    }
  }