/*
Tiamat - a role-playing game framework
ScriptTableMouseAdapter.java - custom MouseAdapter for ScriptTable
 
 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.scriptTable;

import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

/**
 * ScriptTableMouseAdapter - custom MouseAdapter for ScriptTable
 * @author Hugues Johnson
 */
public class ScriptTableMouseAdapter extends MouseAdapter{

	public ScriptTableMouseAdapter(){
		super();
	}

	public void mouseClicked(MouseEvent event){
		if(event.getButton()==MouseEvent.BUTTON3){
			ScriptTable table=(ScriptTable)event.getSource();
			//need to force selected row if button3 is pressed
			int row=table.rowAtPoint(event.getPoint());
			table.getSelectionModel().setSelectionInterval(row,row);
			//now show the popup menu
			table.showPopupMenu(event.getPoint());
		} else{
			if(event.getClickCount()==2){
				//determine whether to expand or collapse the selected row
				ScriptTable table=(ScriptTable)event.getSource();
				int row=table.rowAtPoint(event.getPoint());
				int rowHeight=table.getRowHeight(row);
				int defaultRowHeight=table.getDefaultRowHeight();
				if(rowHeight>defaultRowHeight){
					table.onCollapseRow(row);
				} else{
					table.onExpandRow(row);
				}
			}
		}
	}
	
}