/**
   * Register listener for camera move.
   *
   * @param pCanvas canvas for listener
   */
  public void registerMoveListener(Canvas pCanvas) {
    pCanvas.addKeyListener(cameraMoveListener);

    pCanvas.addMouseMotionListener(cameraMoveListener);

    pCanvas.addMouseListener(cameraMoveListener);
  }
Beispiel #2
0
  public ViewPanel(Node node, int renderType) {

    // Create render
    render = AppletModelManager.getInstance().createRender(node, renderType);
    Canvas canvas = render.getCanvas();

    render.setName(name);

    canvas.setPreferredSize(new Dimension(300, 300));
    canvas.setMinimumSize(new Dimension(100, 100));
    this.add(canvas, BorderLayout.CENTER);

    // Create render properties dialog
    renderDialog = new RenderProperties(render);
    renderDialog.setVisible(false);

    // Create pop-up menu
    popup = new JPopupMenu();

    JMenuItem menuItem = new JMenuItem("Properties");
    menuItem.addActionListener(this);
    popup.add(menuItem);

    // Add listener to components that can bring up popup menus.
    MouseListener popupListener = new PopupListener();
    canvas.addMouseListener(popupListener);

    this.setMinimumSize(new Dimension(100, 100));
    this.setPreferredSize(new Dimension(200, 200));
    SparkApplet.getViewPanel().add(this);
  }
  public Input(Canvas canvas) {
    canvas.addKeyListener(new InputReceiver());

    MouseInputReceiver mir = new MouseInputReceiver();
    canvas.addMouseListener(mir);
    canvas.addMouseMotionListener(mir);
  }
Beispiel #4
0
  public Overworld() {
    frame = new JFrame("Basic Game");
    JPanel panel = (JPanel) frame.getContentPane();
    panel.setPreferredSize(new Dimension(1000, 1000));
    panel.setLayout(null);

    canvas = new Canvas();
    canvas.setBounds(0, 0, 1020, 1020);
    canvas.setIgnoreRepaint(true);

    panel.add(canvas);

    canvas.addMouseListener(new MouseControl());
    canvas.addMouseMotionListener(new MyClass());
    canvas.addKeyListener(new KeyControl());

    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.pack();
    frame.setResizable(false);
    frame.setVisible(true);

    canvas.createBufferStrategy(2);
    bufferStrategy = canvas.getBufferStrategy();

    canvas.requestFocus();
  }
Beispiel #5
0
 @Override
 public synchronized void addMouseListener(MouseListener l) {
   if (System.getProperty("os.name").contains("Mac")) {
     super.addMouseListener(l);
   } else {
     mMouseListeners.add(l);
   }
 }
Beispiel #6
0
 /** Restore the previously active Event handlers. */
 final void restoreGui() {
   clearGui();
   for (final KeyListener l : canvasKeyListeners) canvas.addKeyListener(l);
   for (final KeyListener l : windowKeyListeners) window.addKeyListener(l);
   for (final KeyListener l : ijKeyListeners) ij.addKeyListener(l);
   for (final MouseListener l : canvasMouseListeners) canvas.addMouseListener(l);
   for (final MouseMotionListener l : canvasMouseMotionListeners)
     canvas.addMouseMotionListener(l);
   for (final MouseWheelListener l : windowMouseWheelListeners) window.addMouseWheelListener(l);
 }
  private void initListeners() {
    kh = new KeyHandler(this, camera);
    mh = new MouseHandler(this, camera);

    canvas.addKeyListener(kh);
    canvas.addMouseListener(mh);
    canvas.addMouseMotionListener(mh);
    this.addKeyListener(kh);
    this.addMouseListener(mh);
    this.addMouseMotionListener(mh);
  }
Beispiel #8
0
    /** Add new event handlers. */
    final void takeOverGui() {
      canvas.addKeyListener(Panorama_View.this);
      window.addKeyListener(Panorama_View.this);

      canvas.addMouseMotionListener(Panorama_View.this);

      canvas.addMouseListener(Panorama_View.this);

      ij.addKeyListener(Panorama_View.this);

      window.addMouseWheelListener(Panorama_View.this);
    }
 public void addBotListeners() {
   for (MouseListener l : defaultMouseListeners) {
     canvas.removeMouseListener(l);
   }
   for (MouseMotionListener l : defaultMouseMotionListeners) {
     canvas.removeMouseMotionListener(l);
   }
   for (MouseWheelListener l : defaultMouseWheelListeners) {
     canvas.removeMouseWheelListener(l);
   }
   canvas.addMouseListener(this);
   canvas.addMouseMotionListener(this);
   canvas.addMouseWheelListener(this);
 }
  /**
   * Register listener for mouse selection.
   *
   * @param pCanvas canvas for listener
   */
  public void registerMouseSelectionListener(Canvas pCanvas) {

    pCanvas.addMouseListener(objectSelectionListener);
    pCanvas.addMouseMotionListener(objectSelectionListener);
  }
Beispiel #11
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);
  }