/**
 * Copyright (c) 2011, Martin Foster <martin@ethereal-realms.org>
 * All rights reserved.
 * 
 * Redistribution and use in source and binary forms, with or without 
 * modification, are permitted provided that the following conditions are met:
 * 
 *     * Redistributions of source code must retain the above copyright notice, 
 *       this list of conditions and the following disclaimer.
 *     * Neither the name of the Ethereal-Realms.org nor the names of its
 *       contributors may be used to endorse or promote products derived
 *       from this software without specific prior written permission.
 * 
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */
package org.lyra.Interface;

import javax.swing.JPanel;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Frame;
import java.awt.Toolkit;
import java.awt.Window;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.swing.Box;
import javax.swing.JDialog;
import javax.swing.BoxLayout;
import javax.swing.JLabel;
import javax.swing.JTabbedPane;
import javax.swing.JButton;
import javax.swing.ImageIcon;
import javax.swing.JScrollPane;
import javax.swing.ScrollPaneConstants;

import org.lyra.Ledger;
import org.lyra.Lyra;
import org.lyra.Operations;
import org.lyra.Database.Comptroller;
import org.lyra.Host.Options;
import org.lyra.Host.Status;
import org.lyra.Interface.Options.LastDotFmPanel;
import org.lyra.Interface.Options.OptionsPanel;
import org.lyra.Interface.Options.HostsPanel;
import org.lyra.Interface.Options.InterfacePanel;
import org.lyra.Listener.WindowSizeListener;
import org.lyra.Widgets.ResizeIcon;

/**
 * The ability to manage and control features of the application start though
 * this interface.  Due to the complexity of all of the elements required to
 * manage controls for hosts, visual aspects and playback options the tabs
 * themselves are farmed out to other classes.
 * <p>
 * @author Martin Foster
 * @version 1.0.4, %Revision, 147%, %LastChangedDate, 06/11/11 4:57PM%
 */
public class ManageOptionDialog extends JDialog {

	// Serial Identity
	private static final long serialVersionUID = 1L;

	
	/*
	 * USER INTERFACE ELEMENTS
	 */
	
	// Holder Windows
	private JPanel jContentPane = null;

	// Tabs and Associated Pages
	private JTabbedPane tabbedFeatures = null;
	private JScrollPane scrollInterface = null;
	private InterfacePanel panelInterface = null;
	private HostsPanel panelHosts = null;
	private JScrollPane scrollHostOptions = null;
	private OptionsPanel panelHostOptions = null;
	private JScrollPane scrollLastDotFm = null;
	private LastDotFmPanel panelLastDotFm = null;
	
	// Holder of Southern Elements
	private JPanel panelHolder = null;
	
	// Control Features
	private JPanel panelControl = null;
	private JButton buttonSave = null;
	private JButton buttonCancel = null;
	
	// Window Controls
	private JPanel panelStatus = null;
	private JLabel iconResize = null;
	
	
	/*
	 * PACKAGE INSTANCE
	 */
	private Map<String,String> Lang;
	private Map<String,String> Global;
	
	private Ledger Logger;
	private Comptroller Manager;
	private Status Info;
	private Options Modes;
	
	/*
	 * CLASS INSTANCES
	 */
	private Interact Interface;
	private JDialog Parent = this;
	
	
	/**
	 * Basic constructor used for Visual Editors.   Establishes all of the
	 * necessary elements in order to display properly without enabling all
	 * of the features.
	 * <p>
	 * @param owner Parent window to block.
	 */
	@SuppressWarnings("serial")
	public ManageOptionDialog(Frame owner) {
		
		// Super Class Processing
		super(owner);
		
		/*
		 * Under normal circumstances this section will be passed on from the
		 * database.   However Visual Editors do not have this ability to we
		 * create a HashMap that can be used either way.
		 */
		Lang = new HashMap<String,String>(){
			{
				// Window Title
				put("Options.Window.Title","Manage Options and Preferences");
				
				// Tab Options
				put("Options.Tab.Interface","Look and Feel");
				put("Options.Tab.Features","Host Features");
				put("Options.Tab.Hosts","Host Management");
				
				// Tool Tips
				put("Options.Tab.Help","Expand or collapse help section...");
				put("Options.Tab.Save","Save settings...");
				put("Options.Tab.Cancel","Cancel changes...");
				
				// Help Sections
				put("Options.Section.Help","Help");
				put("Options.Interface.Help","Insightful Help Here...");
				
	        	// Generic features found elsewhere
	        	put("Button.Cancel","Cancel");
	        	put("Button.Save","Save");
	        	put("Button.Help","Help");
			}
		};
		
		// Establish Baseline
		initDialog(null);
	}
	// End of Constructor Method
	
	
	/**
	 * Primary application constructor which is passed all of the necessary
	 * elements in order to display settings and handle interaction.
	 * <p>
	 * @param logger Ledger instances for debugging and information.
	 * @param manager Database access manager instance.
	 * @param info Host status instance.
	 * @param modes Options and settings on the host.
	 * @param lang Language map for independent language elements.
	 * @param global Global settings and configuration options.
	 * @param parent Parent window to block.
	 */
	public ManageOptionDialog(
			Ledger logger, 
			Comptroller manager, 
			Status info,
			Options modes,
			Map<String,String> lang, 
			Map<String,String> global,
			Window parent) {
		
		// Have super class do its thing
		super(parent);
		
		// Pass up
		this.Logger  = logger;
		this.Manager = manager;
		this.Info    = info;
		this.Modes   = modes;
		this.Lang    = lang;
		this.Global  = global;
		
		// Create instance
		this.Interface = new Interact();
		
		// Initialise the Dialog
		initDialog(parent);
		
		// Add in window listener
		this.addWindowListener(Interface);
	 }
	// End of Constructor Class
	

	/**
	 * This method initialises the baseline elements for the frame and the
	 * components it houses.
	 * <p>
	 * @param parent Parent window to block.
	 */
	private void initDialog(Window parent) {
		
		// Establish modal state
		this.setModal(true);
		
		// Adjust Title
		this.setTitle(Lang.get("Options.Window.Title"));
		
		// Adjust Icon
		this.setIconImage(new ImageIcon(
				getClass().getResource(
						Lyra.IMG_SOURCE + Lyra.LYRA)).getImage());
		
		// Import user interface elements
		this.setContentPane(getJContentPane());
		

		// Set size according to requirements
		this.pack();
		
		// Set size appropriately
		this.setSize(
				Interface.setDimension(this));
		
		// Centre to parent
		this.setLocationRelativeTo(parent);

	}
	// End of initDialog Method

	
	/**
	 * This method initialises jContentPane.   Primarily responsible for
	 * importing the bulk of the user interface elements.
	 * <p>
	 * @return javax.swing.JPanel
	 */
	private JPanel getJContentPane() {
		
		// Check for Existence
		if (jContentPane == null) {
			
			// Create Instance
			jContentPane = new JPanel();
			
			// Establish Layout
			jContentPane.setLayout(new BorderLayout());

			// Insert Elements
			jContentPane.add(getPanelHolder(), BorderLayout.CENTER);
			jContentPane.add(getPanelStatus(), BorderLayout.SOUTH);
		}
		
		// Return Instance
		return jContentPane;
	}
	// End of getJContentPane Method

	
	/**
	 * This method initialises panelControl.  Control holds all of the necessary
	 * control buttons used to manage the features and options.	
	 * <p>
	 * @return javax.swing.JPanel	
	 */
	private JPanel getPanelControl() {
		
		// Check for Existence
		if (panelControl == null) {
			
			// Create Instance
			panelControl = new JPanel();
			
			// Establish Layout
			panelControl.setLayout(new BoxLayout(getPanelControl(), BoxLayout.X_AXIS));

			// Save and Cancel Buttons
			panelControl.add(getButtonSave(), null);
			panelControl.add(getButtonCancel(), null);
			
			// Spacer to force to the left
			panelControl.add(Box.createHorizontalGlue());
		}
		
		// Return Instance
		return panelControl;
	}
	// End of getPanelControl Method

	
	/**
	 * This method initialises panelWindow	
	 * 	
	 * @return javax.swing.JPanel	
	 */
	private JPanel getPanelStatus() {
		if (panelStatus == null) {
			panelStatus = new JPanel();
			panelStatus.setLayout(new BoxLayout(getPanelStatus(), BoxLayout.X_AXIS));

			// Add in resizing label/icon
			panelStatus.add(Box.createHorizontalGlue());
			panelStatus.add(getIconResize(), null);
		}
		return panelStatus;
	}

	
	/**
	 * This method initialises iconResize.  
	 * <p>
	 * @return javax.swing.JLabel
	 */
	private JLabel getIconResize() {
		
		// Verify existence of element
		if (iconResize == null) {

			// Create and establish baseline
			iconResize = new JLabel(new ResizeIcon());
			iconResize.setOpaque(false);
			
			/*
			 * Making this icon do something of use is one of the core reasons
			 * why it was added to the display itself.  Here we create an 
			 * instance and add the listener, since it is not used anywhere else
			 * we don't worry out creating an instance earlier.
			 */
			WindowSizeListener sizer = new WindowSizeListener(this);
			
			// Add in listener elements
			iconResize.addMouseListener(sizer);
			iconResize.addMouseMotionListener(sizer);
		}
		
		// Return label
		return iconResize;
	}
	// End of getIconResize Method
	
	
	/**
	 * This method initialises tabbedFeatures.  Permits the user to only be
	 * presented with a certain subset of the features.  Makes it cleaner and
	 * more organised.	
	 * <p>
	 * @return javax.swing.JTabbedPane	
	 */
	private JTabbedPane getTabbedFeatures() {
		
		// Check for Existence
		if (tabbedFeatures == null) {
			
			// Create Instance
			tabbedFeatures = new JTabbedPane();
			
			// Insert Tabs
			tabbedFeatures.addTab(Lang.get("Options.Tab.Interface"), null, getScrollInterface(), null);
			tabbedFeatures.addTab(Lang.get("Options.Tab.Hosts"), null, getPanelHosts(), null);
			tabbedFeatures.addTab(Lang.get("Options.Tab.Features"), null, getScrollHostOptions(), null);
			tabbedFeatures.addTab(Lang.get("Options.Tab.LastDotFm"), null, getScrollLastDotFm(), null);
			
			// Identifier and listener
			tabbedFeatures.setName("TAB.CONTAINER");
		}
		
		// Return Instance
		return tabbedFeatures;
	}
	// End of getTabbedFeatures Method

	
	/**
	 * This method initialises buttonSave.	
	 * <p>
	 * @return javax.swing.JButton	
	 */
	private JButton getButtonSave() {
		
		// Check for Instance
		if (buttonSave == null) {
			
			// Create Instance
			buttonSave = new JButton();
			
			// Text and Icon
			buttonSave.setText(Lang.get("Button.Save"));
			buttonSave.setToolTipText(Lang.get("Options.Tip.Save"));
			buttonSave.setIcon(new ImageIcon(
					getClass().getResource(
							Lyra.getIconByMap("Button-Accept"))));

			// Identifier and Action Listener
			buttonSave.setName("CONTROL.SAVE");
			buttonSave.addActionListener(Interface);
		}
		
		// Return Instance
		return buttonSave;
	}
	// End of getButtonSave Method

	
	/**
	 * This method initialises buttonCancel.	
	 * <p>
	 * @return javax.swing.JButton	
	 */
	private JButton getButtonCancel() {
		
		// Check for Existence
		if (buttonCancel == null) {
			
			// Create Instance
			buttonCancel = new JButton();
			
			// Text and Icon
			buttonCancel.setText(Lang.get("Button.Cancel"));
			buttonCancel.setToolTipText(Lang.get("Options.Tip.Cancel"));
			buttonCancel.setIcon(new ImageIcon(
					getClass().getResource(
							Lyra.getIconByMap("Button-Cancel"))));

			// Identifier and Listener
			buttonCancel.setName("CONTROL.CANCEL");
			buttonCancel.addActionListener(Interface);
		}
		
		// Return Instance
		return buttonCancel;
	}
	// End of getButtonCancel Method
	

	/**
	 * This method initialises panelHolder.	 This panel will combine the tabbed
	 * section and control buttons merging them into one defined panel.
	 * <p>
	 * @return javax.swing.JPanel	
	 */
	private JPanel getPanelHolder() {
		
		// Check for Existence
		if (panelHolder == null) {
			
			// Create Instance
			panelHolder = new JPanel();
			
			// Establish Layout
			panelHolder.setLayout(new BoxLayout(getPanelHolder(), BoxLayout.Y_AXIS));

			// Insert Elements
			panelHolder.add(getTabbedFeatures(), null);
			
			// Spacer and controls
			panelHolder.add(Box.createVerticalStrut(Constants.getSectionGap()));
			panelHolder.add(getPanelControl(), null);
		}
		
		// Return Instance
		return panelHolder;
	}
	// End of getPanelHolder Method
	

	/**
	 * This method initialises scrollInterface.  It is expected that the
	 * user interface options will take up a fair amount of space, hence we
	 * have a JScrollPane work for us.	
	 * <p>
	 * @return javax.swing.JScrollPane	
	 */
	private JScrollPane getScrollInterface() {
		
		// Check for Existence
		if (scrollInterface == null) {
			
			// Create Instance
			scrollInterface = new JScrollPane();
			
			// Insert Element
			scrollInterface.setViewportView(getPanelInterface());
			
			// Always display scroll bar
			scrollInterface.setVerticalScrollBarPolicy(
					ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
			
			// Identifier
			scrollInterface.setName("TAB.INTERFACE");
		}
		
		// Return Instance
		return scrollInterface;
	}
	// End of getScrollInterface Element

	
	/**
	 * This method initialises scrollLastDotFm.  This will permit the user to
	 * integrate with the Last.fm service.   Descriptions may be lengthy hence
	 * the scroll pane.
	 * <p>
	 * @return javax.swing.JScrollPane	
	 */
	private JScrollPane getScrollLastDotFm() {
		
		// Check for Existence
		if (scrollLastDotFm == null) {
			
			// Create Instance
			scrollLastDotFm = new JScrollPane();
			
			// Insert Element
			scrollLastDotFm.setViewportView(getPanelLastDotFm());
			
			// Always display scroll bar
			scrollLastDotFm.setVerticalScrollBarPolicy(
					ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
			
			// Identifier
			scrollLastDotFm.setName("TAB.LASTDOTFM");
		}
		
		// Return Instance
		return scrollLastDotFm;
	}
	// End of getScrollLastDotFm Element
	
	
	/**
	 * This method initialises panelHosts.  Imports an instance of 
	 * <i>org.lyra.Interface.Options.HostPanel</i> which will populate
	 * the user interface.	
	 * <p>
	 * @return org.lyra.Interface.Options.HostsPanel
	 * @see HostsPanel	
	 */
	private HostsPanel getPanelHosts() {
		
		// Check for Existence
		if (panelHosts == null) {
			
			/*
			 * We create an a new instance of a custom panel that carries all
			 * of the necessary components and base processing for us.
			 */
			panelHosts = new HostsPanel(Logger, Manager, Lang, this);
			
			// Identifier
			panelHosts.setName("TAB.HOSTS");
		}
		
		// Return Instance
		return panelHosts;
	}
	// End of getPanelHosts Method

	
	/**
	 * This method initialises panelInterface.  Imports an instance of
	 * <i>org.lyra.Interface.Options.InterfacePanel</i> class in order
	 * to populate the tab.	
	 * <p>
	 * @return org.lyra.Interface.Options.InterfacePanel
	 * @see InterfacePanel	
	 */
	private InterfacePanel getPanelInterface() {
		
		// Check for Existence
		if (panelInterface == null) {
			
			/*
			 * We create an a new instance of a custom panel that carries all
			 * of the necessary components and base processing for us.
			 */
			panelInterface = new InterfacePanel(Logger, Lang, Global, this);
		}
		
		// Return Instance
		return panelInterface;
	}
	// End of getPanelInterface Method
	

	/**
	 * This method initialises panelLastDotFm.  Imports an instance of
	 * <i>org.lyra.LastDotFm.Options.LastDotFmPanel</i> class in order
	 * to populate the tab.	
	 * <p>
	 * @return org.lyra.LastDotFm.Options.LastDotFmPanel
	 * @see LastDotFmPanel	
	 */
	private LastDotFmPanel getPanelLastDotFm() {
		
		// Check for Existence
		if (panelLastDotFm == null) {
			
			/*
			 * We create an a new instance of a custom panel that carries all
			 * of the necessary components and base processing for us.
			 */
			panelLastDotFm = new LastDotFmPanel(Logger, Global, Lang, this);
		}
		
		// Return Instance
		return panelLastDotFm;
	}
	// End of getPanelLastDotFm Method
	
	
	/**
	 * This method initialises scrollHostOptions.  Host options such as consume
	 * may overload the designated space for a window.   This will permit the
	 * panel to be loaded without resizing the supporting window.	
	 * 	<p>
	 * @return javax.swing.JScrollPane	
	 */
	private JScrollPane getScrollHostOptions() {
		
		// Check for Existence
		if (scrollHostOptions == null) {
			
			// Create Instance
			scrollHostOptions = new JScrollPane();
			
			// Insert Element
			scrollHostOptions.setViewportView(getPanelHostOptions());
			
			// Always display scroll bar
			scrollHostOptions.setVerticalScrollBarPolicy(
					ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
			
			// Identifier
			panelHostOptions.setName("TAB.FEATURES");
		}
		
		// Return Instance
		return scrollHostOptions;
	}
	// End of getScrollFeatures Method

	
	/**
	 * This method initialises panelHostOptions.  Imports an instance of
	 * <i>org.lyra.Interface.Options.HostOptionsPanel<i> and populates the
	 * tab for use.
	 * <p>
	 * @return org.Lyra.Interface.Options.HostOptionsPanel
	 * @see OptionsPanel
	 */
	private OptionsPanel getPanelHostOptions() {
		
		// Check for Existence
		if (panelHostOptions == null) {
			
			// Create Instance
			panelHostOptions = new OptionsPanel(Lang,Info);
		}
		
		// Return Instance
		return panelHostOptions;
	}
	// End of getPanelFeatures Method

	
	/* (non-Javadoc)
	 * @see java.awt.Dialog#setVisible(boolean)
	 */
	public void setVisible(boolean state) {
		
		/*
		 * When the window is once again set visible we need to update the
		 * panels with fresh information.  This will create the illusion that
		 * a new window has been opened instead of using the same instance.
		 */
		if (state) {

			// Host options
			getPanelHostOptions().setState();
			
			// Host addition and removal
			getPanelHosts().setState();
		}
					
		// Have the core class do its thing
		super.setVisible(state);
	}
	// End of setVisible Method
	
	
	
	/**
	 * The code separation from the user interface.   This Class handles all
	 * of the complexities of making the interface interactive.
	 * <p>
	 * @author Martin Foster
	 */
	private class Interact implements ActionListener, WindowListener {

		/*
		 * CLASS INSTANCES
		 */
		
		// File Operations
		private Operations fileOps;
		
		/**
		 * Default constructor
		 */
		public Interact() {
			
			// Create Instance
			fileOps = new Operations(Logger);
		}
		// End of constructor class
		
		
		/**
		 * This dialog could realistically be too long for the screen
		 * resolution, especially when dealing with Netbooks which older
		 * manuals have a resolution of 1024x600.  
		 * <p>
		 * @param parent Window component to extract elements from.
		 * @return Dimension the dialog will take.
		 */
		public Dimension setDimension(Window parent) {
			
			// Extract the screen resolution
			Dimension screen 
				= Toolkit.getDefaultToolkit().getScreenSize();
			
			// What is our maximum window size
			int max = (screen.getHeight() > Constants.getScreenBuffer())
				? (int)screen.getHeight() - Constants.getScreenBuffer()
				: (int)screen.getHeight();

			// New Height
			int width = (parent.getHeight() > max)
				? max
				: parent.getHeight();
			
			// Return dimension
			return new Dimension(parent.getWidth(), width);
		}
		// End of setDimension Method
		
		
		/* (non-Javadoc)
		 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
		 */
		public void actionPerformed(ActionEvent evt) {

			// We only deal with instances of JButton
			if (evt.getSource() instanceof JButton) {
			
				// Copy over the element
				JButton source = (JButton)evt.getSource();
				
				// Only two buttons we are dealing with
				if ((source.getName().equals(getButtonSave().getName())) 
				 || (source.getName().equals(getButtonCancel().getName())))
				{
					/*
					 * The owner has opted to save the settings.  This is a two
					 * step process really.   The first level we capture the
					 * states from the Tabs and then deal with the database
					 * updates.
					 */
					if (source.getName().equals(getButtonSave().getName())) {
						
						/*
						 * Interface features are fairly simple and straight
						 * forward operation.  What we capture we write to the
						 * database directly.
						 */
						
						// Extract Information
						Map<String,String> prefs 
							= getPanelInterface().getState();
						
						// Log captured hash
						Logger.debugHash(prefs);
						
						// Update information
						Manager.updateSettings(prefs);
						
						
						/*
						 * Last.fm Integration have two keys that have to be
						 * saved in order to complete the integration.
						 */
						
						// Extract Information
						Map<String,String> integration 
							= getPanelLastDotFm().getState();
						
						// Is it necessary
						if (integration != null) {
						
							// Log captured hash
							Logger.debugHash(integration);
						
							// Update information
							Manager.updateSettings(integration);
						}
						
						/*
						 * Host Options are dealt with using the org.lyra.Host
						 * package elements.  
						 */
						
						// Extract Information
						Map<String,String> options 
							= getPanelHostOptions().getState();
						
						// Consume Song
						Modes.setConsume(Boolean.parseBoolean(
								options.get("Host.Options.Consume")));
						
						// Random Play
						Modes.setRandom(Boolean.parseBoolean(
								options.get("Host.Options.Random")));
						
						// Repeat Play
						Modes.setRepeat(Boolean.parseBoolean(
								options.get("Host.Options.Repeat")));
						
						// Single / List Play
						Modes.setSingle(Boolean.parseBoolean(
								options.get("Host.Options.Single")));

						// Crossfading
						Modes.setCrossfade(Integer.parseInt(
								options.get("Host.Options.Crossfade")));

						
						/*
						 * Host creation and addition is a bit more complex
						 * then the other elements.   The state comes in a 
						 * form of a list and then we complete the operation
						 * accordingly.
						 */
						
						// Import Listing
						List<Map<String,String>> hosts = 
							getPanelHosts().getState();
						
						/*
						 * Cycle through and deal with the types we care about
						 * while the rest we ignore outright.
						 */
						for (Map<String,String> details: hosts) {
							
							// We insert the new entry
							if (details.get("Type").equals("ADD"))
								fileOps.hostCreate(
									Manager, 
									Lang, 
									details
								  );
							
							// We remove the entry
							else if (details.get("Type").equals("REMOVE"))
								fileOps.hostRemove(
									Manager, 
									Lang, 
									details
								  );
						}
					
					}
					
					
					/*
					 * At this stage pressing either button will essentially
					 * come to this result.  The dialog will be closed and 
					 * processing returned to its parent.
					 */
					Parent.setVisible(false);
				}
			}
		}
		// End of actionPerformed Method


		/* (non-Javadoc)
		 * @see java.awt.event.WindowListener#windowClosing(java.awt.event.WindowEvent)
		 */
		public void windowClosing(WindowEvent e) {
			
			// Just hide the window until we need it again
			Parent.setVisible(false);
			
		}
		// End of windowClosing Method

		
		/* (non-Javadoc)
		 * @see java.awt.event.WindowListener#windowActivated(java.awt.event.WindowEvent)
		 */
		public void windowActivated(WindowEvent arg0) {}
		
		/* (non-Javadoc)
		 * @see java.awt.event.WindowListener#windowClosed(java.awt.event.WindowEvent)
		 */
		public void windowClosed(WindowEvent e) {}
		
		/* (non-Javadoc)
		 * @see java.awt.event.WindowListener#windowDeactivated(java.awt.event.WindowEvent)
		 */
		public void windowDeactivated(WindowEvent e) {}

		/* (non-Javadoc)
		 * @see java.awt.event.WindowListener#windowDeiconified(java.awt.event.WindowEvent)
		 */
		public void windowDeiconified(WindowEvent e) {}

		/* (non-Javadoc)
		 * @see java.awt.event.WindowListener#windowIconified(java.awt.event.WindowEvent)
		 */
		public void windowIconified(WindowEvent e) {}

		/* (non-Javadoc)
		 * @see java.awt.event.WindowListener#windowOpened(java.awt.event.WindowEvent)
		 */
		public void windowOpened(WindowEvent e) {}
		
	}
	// End of Interact Class

}
