 /*
 * Copyright (C) 30-aout-2004  Jean-Yves Beaujean 
 * 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 jxtray.swing;

import jxtray.Jxtray;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;


import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JWindow;
import javax.swing.JOptionPane;

import jxtray.JxtFrame;
import jxtray.Messages;
import jxtray.gui.*;

import jxtray.util.UIUtilities;


public class JxtMenuListener implements ActionListener  
{

		private JxtFrame parent;
		/*
		 *  Constructeur de la classe
		 */
		public JxtMenuListener (JxtFrame parent)
		{
				this.parent = parent;
		}
		
		/*
		 *  
		 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
		 */
		public void actionPerformed( ActionEvent e)
		{
				if ( e.getActionCommand().equals("quit"))
					parent.quit();
				else if ( e.getActionCommand().equals("about"))
					open( new AboutDialog(parent));
				else if ( e.getActionCommand().equals("preferences") )
					open(new PropertiesDialog(parent));						
				else if ( e.getActionCommand().equals("newconnection") )
					open( new ConnectionDialog(parent) );
				else if ( e.getActionCommand().equals("driversjdbc") )
					open( new DriverDialog(parent) );
				else if ( e.getActionCommand().equals("sysproperties") )
					open( new SystemPropertiesDialog(parent) );		
				else if ( e.getActionCommand().equals("managesqlhistory") )
					open( new SQLHistoryDialog(parent) );
				else if ( e.getActionCommand().equals("clearsqlhistory") )
				{
					if ( Messages.question(Jxtray.getLang("action.clearcache")+" ?") == JOptionPane.YES_OPTION)
					{
						Jxtray.getSQLHistoryCache().clear();
						Jxtray.getSQLHistoryCache().writeXMLFile();
					}
				}
				else if ( e.getActionCommand().equals("helpmanual") )
					open( new HelpFrame() );
													
		}
		
	private void open( JDialog dia)
	{
		UIUtilities.center(dia);
		dia.setVisible(true);
			
	}
		
	private void open( JWindow dia)
	{
		UIUtilities.center(dia);
		dia.setVisible(true);
				
	}		
		
	private void open( JFrame frame)
	{
		UIUtilities.center(frame);
			frame.setVisible(true);
	}
}
