コード例 #1
0
 @Override
 public void setVisible(final boolean b) {
   super.setVisible(b);
   if (b) {
     WindowUtils.setWindowTransparent(this, true);
   }
 }
コード例 #2
0
 private static boolean calcAlphaModelSupported() {
   if (AWTUtilitiesWrapper.isTranslucencyAPISupported()) {
     return AWTUtilitiesWrapper.isTranslucencySupported(AWTUtilitiesWrapper.TRANSLUCENT);
   }
   try {
     return WindowUtils.isWindowAlphaSupported();
   } catch (Throwable e) {
     return false;
   }
 }
コード例 #3
0
 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);
   }
 }
コード例 #4
0
 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);
   }
 }
コード例 #5
0
 public void setAlpha(final float alpha) {
   WindowUtils.setWindowAlpha(this, alpha);
 }
コード例 #6
0
 public TranslucentFrame() {
   super(WindowUtils.getAlphaCompatibleGraphicsConfiguration());
   this.init();
 }
コード例 #7
0
ファイル: TestPlayer.java プロジェクト: ioz9/vlcj
  public TestPlayer(String[] args) {
    if (RuntimeUtil.isWindows()) {
      // If running on Windows and you want the mouse/keyboard event hack...
      videoSurface = new WindowsCanvas();
    } else {
      videoSurface = new Canvas();
    }

    Logger.debug("videoSurface={}", videoSurface);

    videoSurface.setBackground(Color.black);
    videoSurface.setSize(800, 600); // Only for initial layout

    // Since we're mixing lightweight Swing components and heavyweight AWT
    // components this is probably a good idea
    JPopupMenu.setDefaultLightWeightPopupEnabled(false);

    TestPlayerMouseListener mouseListener = new TestPlayerMouseListener();
    videoSurface.addMouseListener(mouseListener);
    videoSurface.addMouseMotionListener(mouseListener);
    videoSurface.addMouseWheelListener(mouseListener);
    videoSurface.addKeyListener(new TestPlayerKeyListener());

    List<String> vlcArgs = new ArrayList<String>();

    vlcArgs.add("--no-plugins-cache");
    vlcArgs.add("--no-video-title-show");
    vlcArgs.add("--no-snapshot-preview");
    vlcArgs.add("--quiet");
    vlcArgs.add("--quiet-synchro");
    vlcArgs.add("--intf");
    vlcArgs.add("dummy");

    // Special case to help out users on Windows (supposedly this is not actually needed)...
    // if(RuntimeUtil.isWindows()) {
    // vlcArgs.add("--plugin-path=" + WindowsRuntimeUtil.getVlcInstallDir() + "\\plugins");
    // }
    // else {
    // vlcArgs.add("--plugin-path=/home/linux/vlc/lib");
    // }

    // vlcArgs.add("--plugin-path=" + System.getProperty("user.home") + "/.vlcj");

    Logger.debug("vlcArgs={}", vlcArgs);

    mainFrame = new JFrame("VLCJ Test Player");
    mainFrame.setIconImage(
        new ImageIcon(getClass().getResource("/icons/vlcj-logo.png")).getImage());

    FullScreenStrategy fullScreenStrategy = new DefaultFullScreenStrategy(mainFrame);

    mediaPlayerFactory = new MediaPlayerFactory(vlcArgs.toArray(new String[vlcArgs.size()]));
    mediaPlayerFactory.setUserAgent("vlcj test player");

    List<AudioOutput> audioOutputs = mediaPlayerFactory.getAudioOutputs();
    Logger.debug("audioOutputs={}", audioOutputs);

    mediaPlayer = mediaPlayerFactory.newEmbeddedMediaPlayer(fullScreenStrategy);
    mediaPlayer.setVideoSurface(mediaPlayerFactory.newVideoSurface(videoSurface));
    mediaPlayer.setPlaySubItems(true);

    mediaPlayer.setEnableKeyInputHandling(false);
    mediaPlayer.setEnableMouseInputHandling(false);

    controlsPanel = new PlayerControlsPanel(mediaPlayer);
    videoAdjustPanel = new PlayerVideoAdjustPanel(mediaPlayer);

    mainFrame.setLayout(new BorderLayout());
    mainFrame.setBackground(Color.black);
    mainFrame.add(videoSurface, BorderLayout.CENTER);
    mainFrame.add(controlsPanel, BorderLayout.SOUTH);
    mainFrame.add(videoAdjustPanel, BorderLayout.EAST);
    mainFrame.setJMenuBar(buildMenuBar());
    mainFrame.pack();
    mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    mainFrame.addWindowListener(
        new WindowAdapter() {
          @Override
          public void windowClosing(WindowEvent evt) {
            Logger.debug("windowClosing(evt={})", evt);

            if (videoSurface instanceof WindowsCanvas) {
              ((WindowsCanvas) videoSurface).release();
            }

            if (mediaPlayer != null) {
              mediaPlayer.release();
              mediaPlayer = null;
            }

            if (mediaPlayerFactory != null) {
              mediaPlayerFactory.release();
              mediaPlayerFactory = null;
            }
          }
        });

    // Global AWT key handler, you're better off using Swing's InputMap and
    // ActionMap with a JFrame - that would solve all sorts of focus issues too
    Toolkit.getDefaultToolkit()
        .addAWTEventListener(
            new AWTEventListener() {
              @Override
              public void eventDispatched(AWTEvent event) {
                if (event instanceof KeyEvent) {
                  KeyEvent keyEvent = (KeyEvent) event;
                  if (keyEvent.getID() == KeyEvent.KEY_PRESSED) {
                    if (keyEvent.getKeyCode() == KeyEvent.VK_F12) {
                      controlsPanel.setVisible(!controlsPanel.isVisible());
                      videoAdjustPanel.setVisible(!videoAdjustPanel.isVisible());
                      mainFrame.getJMenuBar().setVisible(!mainFrame.getJMenuBar().isVisible());
                      mainFrame.invalidate();
                      mainFrame.validate();
                    } else if (keyEvent.getKeyCode() == KeyEvent.VK_A) {
                      mediaPlayer.setAudioDelay(mediaPlayer.getAudioDelay() - 50000);
                    } else if (keyEvent.getKeyCode() == KeyEvent.VK_S) {
                      mediaPlayer.setAudioDelay(mediaPlayer.getAudioDelay() + 50000);
                    }
                    // else if(keyEvent.getKeyCode() == KeyEvent.VK_N) {
                    // mediaPlayer.nextFrame();
                    // }
                    else if (keyEvent.getKeyCode() == KeyEvent.VK_1) {
                      mediaPlayer.setTime(60000 * 1);
                    } else if (keyEvent.getKeyCode() == KeyEvent.VK_2) {
                      mediaPlayer.setTime(60000 * 2);
                    } else if (keyEvent.getKeyCode() == KeyEvent.VK_3) {
                      mediaPlayer.setTime(60000 * 3);
                    } else if (keyEvent.getKeyCode() == KeyEvent.VK_4) {
                      mediaPlayer.setTime(60000 * 4);
                    } else if (keyEvent.getKeyCode() == KeyEvent.VK_5) {
                      mediaPlayer.setTime(60000 * 5);
                    } else if (keyEvent.getKeyCode() == KeyEvent.VK_6) {
                      mediaPlayer.setTime(60000 * 6);
                    } else if (keyEvent.getKeyCode() == KeyEvent.VK_7) {
                      mediaPlayer.setTime(60000 * 7);
                    } else if (keyEvent.getKeyCode() == KeyEvent.VK_8) {
                      mediaPlayer.setTime(60000 * 8);
                    } else if (keyEvent.getKeyCode() == KeyEvent.VK_9) {
                      mediaPlayer.setTime(60000 * 9);
                    }
                  }
                }
              }
            },
            AWTEvent.KEY_EVENT_MASK);

    mainFrame.setVisible(true);

    mediaPlayer.addMediaPlayerEventListener(new TestPlayerMediaPlayerEventListener());

    // Won't work with OpenJDK or JDK1.7, requires a Sun/Oracle JVM (currently)
    boolean transparentWindowsSupport = true;
    try {
      Class.forName("com.sun.awt.AWTUtilities");
    } catch (Exception e) {
      transparentWindowsSupport = false;
    }

    Logger.debug("transparentWindowsSupport={}", transparentWindowsSupport);

    if (transparentWindowsSupport) {
      final Window test =
          new Window(null, WindowUtils.getAlphaCompatibleGraphicsConfiguration()) {
            private static final long serialVersionUID = 1L;

            @Override
            public void paint(Graphics g) {
              Graphics2D g2 = (Graphics2D) g;

              g2.setRenderingHint(
                  RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
              g2.setRenderingHint(
                  RenderingHints.KEY_TEXT_ANTIALIASING,
                  RenderingHints.VALUE_TEXT_ANTIALIAS_LCD_HRGB);

              g.setColor(Color.white);
              g.fillRoundRect(100, 150, 100, 100, 32, 32);

              g.setFont(new Font("Sans", Font.BOLD, 32));
              g.drawString("Heavyweight overlay test", 100, 300);
            }
          };

      AWTUtilities.setWindowOpaque(test, false); // Doesn't work in full-screen exclusive
      // mode, you would have to use 'simulated'
      // full-screen - requires Sun/Oracle JDK
      test.setBackground(new Color(0, 0, 0, 0)); // This is what you do in JDK7

      // mediaPlayer.setOverlay(test);
      // mediaPlayer.enableOverlay(true);
    }

    // This might be useful
    // enableMousePointer(false);
  }
コード例 #8
0
  public static void main(String[] args) {
    try {
      System.setProperty("sun.java2d.noddraw", "true");
      UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    } catch (Exception e) {
    }
    JFrame f = new JFrame("Balloon Test");
    final String BALLOON_TEXT =
        "<html><center>"
            + "This is some sample balloon text<br>"
            + "which has been formatted with html.<br>"
            + "Click to dismiss.</center></html>";
    final JLabel content = new JLabel(BALLOON_TEXT);
    content.setIconTextGap(10);
    content.setBorder(new EmptyBorder(0, 8, 0, 8));
    content.setSize(content.getPreferredSize());
    content.setIcon(new InfoIcon());
    JLabel label = new JLabel("Click anywhere for more information");
    label.setHorizontalAlignment(SwingConstants.CENTER);
    label.addMouseListener(
        new MouseAdapter() {
          private MouseListener listener =
              new MouseAdapter() {
                public void mousePressed(MouseEvent e) {
                  hidePopup(e);
                }
              };
          private Popup popup;

          private void hidePopup(MouseEvent e) {
            e.getComponent().removeMouseListener(listener);
            if (popup != null) popup.hide();
          }

          public void mousePressed(MouseEvent e) {
            hidePopup(e);
            popup = BalloonManager.getBalloon(e.getComponent(), content, e.getX(), e.getY());
            popup.show();
            content.getParent().addMouseListener(listener);
          }
        });
    f.getContentPane().add(label);
    f.pack();
    f.setSize(new Dimension(300, 300));
    f.setLocation(100, 100);
    try {
      // Force a load of JNA
      WindowUtils.setWindowMask(f, WindowUtils.MASK_NONE);
      f.setVisible(true);
      f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    } catch (UnsatisfiedLinkError e) {
      e.printStackTrace();
      String msg = e.getMessage() + "\nError loading the JNA library";
      JTextArea area = new JTextArea(msg);
      area.setOpaque(false);
      area.setFont(UIManager.getFont("Label.font"));
      area.setEditable(false);
      area.setColumns(80);
      area.setRows(8);
      area.setWrapStyleWord(true);
      area.setLineWrap(true);
      JOptionPane.showMessageDialog(
          null,
          new JScrollPane(area),
          "Library Load Error: "
              + System.getProperty("os.name")
              + "/"
              + System.getProperty("os.arch"),
          JOptionPane.ERROR_MESSAGE);
      System.exit(1);
    }
  }