/*
* 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 speech sensor.
 *
 * @author akipp
 */

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

import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.util.HashMap;
import java.util.Observable;

import javax.swing.JLabel;

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

public class SpeechPanel extends PanelTemplate {

	private static final long serialVersionUID = 1L;
	private JLabel lblNewSpeechText = new JLabel("New Speech:");
	private JLabel lblNewSpeech = new JLabel();
	private JLabel lblOldSpeechText = new JLabel("Last Speech:");
	private JLabel lblOldSpeech = new JLabel();

	public SpeechPanel() {
		setLayout(new GridBagLayout());
		GridBagConstraints c = new GridBagConstraints();

		c.fill = GridBagConstraints.HORIZONTAL;
		c.gridx = 1;
		c.gridy = 0;
		add(lblNewSpeechText, c);

		c.gridx = 2;
		c.gridy = 0;
		add(lblNewSpeech, c);

		c.gridx = 3;
		c.gridy = 0;
		add(lblOldSpeechText, c);

		c.gridx = 4;
		c.gridy = 0;
		add(lblOldSpeech, c);

	}

	@Override
	public void update(Observable o, Object arg) {
		if (o instanceof Communicator) {
			Communicator com = (Communicator) o;
			if (com.getRecipientTAG().equals(component)) {

				if (arg instanceof HashMap<?, ?>) {

					@SuppressWarnings("unchecked")
					HashMap<String, String> receivedProperties = (HashMap<String, String>) arg;

					lblOldSpeech.setText(lblNewSpeech.getText());
					lblNewSpeech.setText(receivedProperties.get(
							component + "_XML_TREE").toString());

				}
			}
		}
	}

}