/*
Tiamat - a role-playing game framework
EventPanel.java - A panel used to edit an event
    
 Copyright  (C) 2006 Hugues Johnson
 
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
 
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
the GNU General Public License for more details.
 
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/

package com.huguesjohnson.tiamat.tools;

import java.awt.Dimension;

import javax.swing.BoxLayout;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.border.TitledBorder;

import com.huguesjohnson.tiamat.Event;
import com.huguesjohnson.tiamat.StringTable;


/** 
 * EventPanel - A panel used to edit an event 
 * @author Hugues Johnson
 */
public class EventPanel extends JPanel{
	/* Determines if a de-serialized file is compatible with this class. See <a href="http://java.sun.com/j2se/1.5.0/docs/guide/serialization/spec/class.html">Java Object Serialization Specifications</a>. */
	private static final long serialVersionUID=2272048292426016933L;
	
	private ParameterTable parameterTable;
	private ActionSelectPanel actionSelectPanel;
	
	public EventPanel(){
		this.initComponents();
	}
	
	private void initComponents(){
		this.setLayout(new BoxLayout(this,BoxLayout.Y_AXIS));
		//add a panel to hold the action combobox
		this.actionSelectPanel=new ActionSelectPanel();
		this.add(this.actionSelectPanel);
		//add a table to hold the parameters
		JPanel tablePanel=new JPanel();
		tablePanel.setBorder(new TitledBorder("Parameters"));
		tablePanel.setLayout(new BoxLayout(tablePanel,BoxLayout.X_AXIS));
		this.parameterTable=new ParameterTable(new Dimension(80,70));
        JScrollPane scrollPane=new JScrollPane(this.parameterTable);
        tablePanel.add(scrollPane); 
		this.add(tablePanel);
		//set the focus and stuff
		this.actionSelectPanel.requestFocus();
	}
	
	public Event getEvent(){
		StringTable table=this.parameterTable.getStringTable();
		String action=this.actionSelectPanel.getAction();
		return(new Event(action,table));
	}
	
	public void setEvent(Event event){
		this.actionSelectPanel.setAction(new String(event.getAction()));
		this.parameterTable.setParameters(event.getParameters());
	}
}