Package com.smaxe.uv.media.swing

Examples of com.smaxe.uv.media.swing.JVideoScreen


        if (webcam == null)
          return;

        final AtomicReference<JFrame> frameRef = new AtomicReference<JFrame>();

        final JVideoScreen videoScreen = new JVideoScreen();
        final AtomicBoolean videoScreenFlip = new AtomicBoolean(false);
        final AtomicBoolean videoScreenMirror = new AtomicBoolean(false);

        new Thread(new Runnable() {
          public void run() {
            try {
              webcam.open(new IWebcam.FrameFormat(320, 240),
                  new IWebcam.IListener() {
                    private VideoFrame lastFrame = new VideoFrame(
                        0, 0, null);

                    public void onVideoFrame(
                        final VideoFrame frame) {
                      SwingUtilities
                          .invokeLater(new Runnable() {
                            public void run() {
                              videoScreen
                                  .setFrame(frame);

                              if (lastFrame.width != frame.width
                                  || lastFrame.height != frame.height) {
                                final JFrame frame = frameRef
                                    .get();

                                if (frame != null)
                                  frame.pack();
                              }

                              lastFrame = frame;
                            }
                          });
                    }
                  });

              webcam.startCapture();

              SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                  final JFrame frame = new JFrame();

                  frameRef.set(frame);

                  frame.getContentPane().setLayout(
                      new BorderLayout());
                  frame.getContentPane().add(videoScreen,
                      BorderLayout.CENTER);

                  frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
                  frame.setResizable(false);
                  frame.setTitle(webcam.getName());

                  videoScreen
                      .addMouseListener(new MouseAdapter() {
                        @Override
                        public void mouseClicked(
                            final MouseEvent e) {
                          final int clickCount = e
                              .getClickCount();
                          final Object source = e
                              .getSource();

                          switch (clickCount) {
                          case 1: {
                            if (SwingUtilities
                                .isRightMouseButton(e)) {
                              JPopupMenu popup = new JPopupMenu();

                              popup.add(new AbstractAction(
                                  "Mirror") {
                                private final static long serialVersionUID = 0L;

                                public void actionPerformed(
                                    ActionEvent e) {
                                  videoScreenMirror
                                      .set(!videoScreenMirror
                                          .get());
                                  videoScreen
                                      .mirror(videoScreenMirror
                                          .get());
                                }
                              });

                              popup.add(new AbstractAction(
                                  "Flip") {
                                private final static long serialVersionUID = 0L;

                                public void actionPerformed(
                                    ActionEvent e) {
                                  videoScreenFlip
                                      .set(!videoScreenFlip
                                          .get());
                                  videoScreen
                                      .flip(videoScreenFlip
                                          .get());
                                }
                              });
View Full Code Here

TOP

Related Classes of com.smaxe.uv.media.swing.JVideoScreen

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.