Пример #1
0
  /**
   * Creates an undecorated transparent frame.
   *
   * @param gc the <tt>GraphicsConfiguration</tt> to use
   */
  private TransparentFrame(GraphicsConfiguration gc) {
    super(gc);

    setUndecorated(true);
    AWTUtilitiesWrapper.setWindowOpaque(this, false);
    AWTUtilitiesWrapper.setWindowOpacity(this, 1f);
  }
Пример #2
0
  /**
   * Creates a transparent undecorated frame. If the transparency is not supported creates a normal
   * undecorated frame.
   *
   * @return the created frame
   */
  public static TransparentFrame createTransparentFrame() {
    isTranslucencySupported =
        AWTUtilitiesWrapper.isTranslucencySupported(AWTUtilitiesWrapper.PERPIXEL_TRANSLUCENT);

    GraphicsConfiguration translucencyCapableGC =
        GraphicsEnvironment.getLocalGraphicsEnvironment()
            .getDefaultScreenDevice()
            .getDefaultConfiguration();

    if (!AWTUtilitiesWrapper.isTranslucencyCapable(translucencyCapableGC)) {
      translucencyCapableGC = null;

      GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment();
      GraphicsDevice[] devices = env.getScreenDevices();

      for (int i = 0; i < devices.length && translucencyCapableGC == null; i++) {
        GraphicsConfiguration[] configs = devices[i].getConfigurations();
        for (int j = 0; j < configs.length && translucencyCapableGC == null; j++) {
          if (AWTUtilitiesWrapper.isTranslucencyCapable(configs[j])) {
            translucencyCapableGC = configs[j];
          }
        }
      }
      if (translucencyCapableGC == null) {
        isTranslucencySupported = false;
      }
    }

    if (isTranslucencySupported) return new TransparentFrame(translucencyCapableGC);

    return new TransparentFrame();
  }
 private static boolean calcAlphaModelSupported() {
   if (AWTUtilitiesWrapper.isTranslucencyAPISupported()) {
     return AWTUtilitiesWrapper.isTranslucencySupported(AWTUtilitiesWrapper.TRANSLUCENT);
   }
   try {
     return WindowUtils.isWindowAlphaSupported();
   } catch (Throwable e) {
     return false;
   }
 }
 public void setWindowMask(final Window window, @Nullable final Shape mask) {
   try {
     if (AWTUtilitiesWrapper.isTranslucencySupported(AWTUtilitiesWrapper.PERPIXEL_TRANSPARENT)) {
       AWTUtilitiesWrapper.setWindowShape(window, mask);
     } else {
       WindowUtils.setWindowMask(window, mask);
     }
   } catch (Throwable e) {
     LOG.debug(e);
   }
 }
 private static void setAlphaMode(Window window, float ratio) {
   try {
     if (SystemInfo.isMacOSLeopard) {
       if (window instanceof JWindow) {
         ((JWindow) window).getRootPane().putClientProperty("Window.alpha", 1.0f - ratio);
       } else if (window instanceof JDialog) {
         ((JDialog) window).getRootPane().putClientProperty("Window.alpha", 1.0f - ratio);
       } else if (window instanceof JFrame) {
         ((JFrame) window).getRootPane().putClientProperty("Window.alpha", 1.0f - ratio);
       }
     } else if (AWTUtilitiesWrapper.isTranslucencySupported(AWTUtilitiesWrapper.TRANSLUCENT)) {
       AWTUtilitiesWrapper.setWindowOpacity(window, 1.0f - ratio);
     } else {
       WindowUtils.setWindowAlpha(window, 1.0f - ratio);
     }
   } catch (Throwable e) {
     LOG.debug(e);
   }
 }