/*
* This file is part of the Remote Sensor Actuator Interface (ReSAI).
*
* Copyright(c) Andreas Kipp, Frederic Siepmann
* http://opensource.cit-ec.de/projects/resai
*
* This file may be licensed under the terms of of the
* GNU Lesser General Public License Version 3 (the ``LGPL''),
* or (at your option) any later version.
*
* Software distributed under the License is distributed
* on an ``AS IS'' basis, WITHOUT WARRANTY OF ANY KIND, either
* express or implied. See the LGPL for the specific language
* governing rights and limitations.
*
* You should have received a copy of the LGPL along with this
* program. If not, go to http://www.gnu.org/licenses/lgpl.html
* or write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* The development of this software was supported by the
* Excellence Cluster EXC 277 Cognitive Interaction Technology.
* The Excellence Cluster EXC 277 is a grant of the Deutsche
* Forschungsgemeinschaft (DFG) in the context of the German
* Excellence Initiative.
*
*/

/**
 * Panel for the webcam.
 *
 * @author akipp
 */

package de.unibi.airobots.resaijavaclient.gui.panels.components;

import java.util.HashMap;
import java.util.Observable;

import javax.swing.ImageIcon;
import javax.swing.JLabel;

import org.jivesoftware.smack.util.Base64;

import de.unibi.airobots.resaijavaclient.communicaton.Communicator;
import de.unibi.airobots.resaijavaclient.gui.panels.components.template.PanelTemplate;
import de.unibi.airobots.resaijavaclient.helper.DataPacker;

public class USBCamPanel extends PanelTemplate {

	private static final long serialVersionUID = 1L;
	private JLabel lblCamImage = new JLabel();
	
	public USBCamPanel() {
		add(lblCamImage);
	}
	
	@Override
	public void update(Observable o, Object arg) {
				if (o instanceof Communicator) {
			Communicator com = (Communicator) o;

			if (arg instanceof HashMap<?, ?>) {
				
				@SuppressWarnings("unchecked")
				HashMap<String, String> receivedProperties = (HashMap<String, String>) arg;

				if (com.getRecipientTAG().equals(component)) {
					String _img = receivedProperties.get(component + "_IMG")
							.toString();

					if (_img.length() > 0) {
						byte[] imageByte = DataPacker.decompressBytes(Base64.decode(_img));
						ImageIcon ic = new ImageIcon(imageByte);

						lblCamImage.setIcon(ic);
					}
				}
			}
		}
	}
}