Package com.smaxe.uv.na.webcam

Examples of com.smaxe.uv.na.webcam.IWebcam


    content.add(webcamComboBox);
    content.add(new JButton(new AbstractAction("Open") {
      private final static long serialVersionUID = -4792981545160764997L;

      public void actionPerformed(ActionEvent e) {
        final IWebcam webcam = (IWebcam) webcamComboBox
            .getSelectedItem();
       
        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());
                                }
                              });

                              popup.addSeparator();

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

                                public void actionPerformed(
                                    ActionEvent e) {
                                  webcam.setFrameFormat(new IWebcam.FrameFormat(
                                      160,
                                      120));
                                }
                              });

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

                                public void actionPerformed(
                                    ActionEvent e) {
                                  webcam.setFrameFormat(new IWebcam.FrameFormat(
                                      320,
                                      240));
                                }
                              });

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

                                public void actionPerformed(
                                    ActionEvent e) {
                                  webcam.setFrameFormat(new IWebcam.FrameFormat(
                                      640,
                                      480));
                                }
                              });

                              popup.show(
                                  (Component) source,
                                  e.getX(),
                                  e.getY());
                            }
                          }
                            break;
                          }
                        }
                      });

                  frame.addWindowListener(new WindowAdapter() {
                    @Override
                    public void windowClosing(WindowEvent e) {
                      webcam.close();
                    }
                  });

                  frame.pack();
                  frame.setVisible(true);
View Full Code Here

TOP

Related Classes of com.smaxe.uv.na.webcam.IWebcam

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.