001 package com.github.sarxos.webcam; 002 003 import java.awt.image.BufferedImage; 004 import java.util.EventObject; 005 006 007 /** 008 * Webcam event. 009 * 010 * @author Bartosz Firyn (SarXos) 011 */ 012 public class WebcamEvent extends EventObject { 013 014 private static final long serialVersionUID = 1L; 015 016 /** 017 * Image acquired from webcam 018 */ 019 private BufferedImage image = null; 020 021 /** 022 * Event type. 023 */ 024 private WebcamEventType type = null; 025 026 /** 027 * Webcam event. 028 * 029 * @param type the event type 030 * @param w the webcam object 031 */ 032 public WebcamEvent(WebcamEventType type, Webcam w) { 033 this(type, w, null); 034 } 035 036 /** 037 * Webcam event. 038 * 039 * @param type the event type 040 * @param w the webcam object 041 * @param image the image acquired from webcam 042 */ 043 public WebcamEvent(WebcamEventType type, Webcam w, BufferedImage image) { 044 super(w); 045 this.type = type; 046 this.image = image; 047 } 048 049 @Override 050 public Webcam getSource() { 051 return (Webcam) super.getSource(); 052 } 053 054 /** 055 * Return image acquired by webcam. This method will return not-null object 056 * <b>only</b> in case new image acquisition event. For all other events, it 057 * will simply return null. 058 * 059 * @return Acquired image 060 */ 061 public BufferedImage getImage() { 062 return image; 063 } 064 065 /** 066 * Return event type. 067 * 068 * @return Event type 069 * @see WebcamEventType 070 */ 071 public WebcamEventType getType() { 072 return type; 073 } 074 }