Exemplo n.º 1
52
 /**
  * Show the given message in a dialog box or independent window, depending on whether the source
  * component is contained in a Frame or not.
  *
  * @param c The Controller that calls this method, or null if it is not called by a Controller.
  *     (The Controller, if any, will be notified when the error message is cleared.)
  * @param message The message to display.
  */
 public void setErrorMessage(Controller c, String message) {
   if (popup != null) clearErrorMessage();
   if (message == null) return;
   errorSource = c;
   errorMessage = message;
   Component parent = source;
   while (parent != null && !(parent instanceof Frame)) parent = parent.getParent();
   if (parent != null) popup = new Dialog((Frame) parent, "Error Message", true); // modal dialog
   else popup = new Frame("Error Message"); // independent window
   popup.setBackground(Color.white);
   popup.add(new MC(message), BorderLayout.CENTER);
   Panel buttonBar = new Panel();
   buttonBar.setLayout(new FlowLayout(FlowLayout.RIGHT, 10, 10));
   Button OK = new Button("    OK    ");
   OK.addActionListener(this);
   buttonBar.add(OK);
   popup.add(buttonBar, BorderLayout.SOUTH);
   popup.pack();
   if (parent == null) popup.setLocation(100, 80);
   else popup.setLocation(parent.getLocation().x + 50, parent.getLocation().y + 30);
   popup.addWindowListener(
       new WindowAdapter() {
         public void windowClosing(WindowEvent evt) {
           popup.dispose();
         }
       });
   popup.show(); // make the dialog visible.
 }
Exemplo n.º 2
0
  public LWWindowPeer(
      Window target,
      PlatformComponent platformComponent,
      PlatformWindow platformWindow,
      PeerType peerType) {
    super(target, platformComponent);
    this.platformWindow = platformWindow;
    this.peerType = peerType;

    Window owner = target.getOwner();
    LWWindowPeer ownerPeer =
        owner == null ? null : (LWWindowPeer) AWTAccessor.getComponentAccessor().getPeer(owner);
    PlatformWindow ownerDelegate = (ownerPeer != null) ? ownerPeer.getPlatformWindow() : null;

    // The delegate.initialize() needs a non-null GC on X11.
    GraphicsConfiguration gc = getTarget().getGraphicsConfiguration();
    synchronized (getStateLock()) {
      // graphicsConfig should be updated according to the real window
      // bounds when the window is shown, see 4868278
      this.graphicsConfig = gc;
    }

    if (!target.isFontSet()) {
      target.setFont(DEFAULT_FONT);
    }

    if (!target.isBackgroundSet()) {
      target.setBackground(SystemColor.window);
    } else {
      // first we check if user provided alpha for background. This is
      // similar to what Apple's Java do.
      // Since JDK7 we should rely on setOpacity() only.
      // this.opacity = c.getAlpha();
    }

    if (!target.isForegroundSet()) {
      target.setForeground(SystemColor.windowText);
      // we should not call setForeground because it will call a repaint
      // which the peer may not be ready to do yet.
    }

    platformWindow.initialize(target, this, ownerDelegate);

    // Init warning window(for applets)
    SecurityWarningWindow warn = null;
    if (target.getWarningString() != null) {
      // accessSystemTray permission allows to display TrayIcon, TrayIcon tooltip
      // and TrayIcon balloon windows without a warning window.
      if (!AWTAccessor.getWindowAccessor().isTrayIconWindow(target)) {
        LWToolkit toolkit = (LWToolkit) Toolkit.getDefaultToolkit();
        warn = toolkit.createSecurityWarning(target, this);
      }
    }

    warningWindow = warn;
  }
Exemplo n.º 3
0
 // set to full screen
 public void init() {
   s = new ScreenManager();
   DisplayMode dm = s.findFirstCompatibleMode(modes);
   s.setFullScreen(dm);
   Window w = s.getFullScreenWindow();
   w.setFont(new Font("Arial", Font.PLAIN, 20));
   w.setBackground(Color.GREEN);
   w.setForeground(Color.WHITE);
   running = true;
 }
Exemplo n.º 4
0
  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);
  }