/*
 * Created on 24.07.2003
 *
 * To change the template for this generated file go to
 * Window>Preferences>Java>Code Generation>Code and Comments
 */
package de.skyrix.zsp.gui;

import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JPanel;
import javax.swing.JTabbedPane;
import javax.swing.UIManager;
import javax.swing.border.EtchedBorder;

import de.skyrix.zsp.conf.ZSPConfig;

/**
 * @author sell
 *
 * To change the template for this generated type comment go to
 * Window>Preferences>Java>Code Generation>Code and Comments
 */
public class ConfigDialog extends JDialog {

	public ConfigDialog() {
		super(new JDialog(), "Settings...", true);
		initGUI();
    GUITool.centerWindow(this);
	}
  
	private void initGUI() {
		final CFGPanelZideStore zidestorePanel = new CFGPanelZideStore();
		final CFGPanelProxy cachePanel = new CFGPanelProxy();
		final CFGPanelSpider spiderPanel = new CFGPanelSpider();

		JTabbedPane tabPane = new JTabbedPane();
		tabPane.addTab("Zidestore", zidestorePanel);
		tabPane.addTab("Proxy", cachePanel);
		tabPane.addTab("Spider", spiderPanel);

		tabPane.setBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED));

		getContentPane().setLayout(new BorderLayout());
		getContentPane().add(tabPane, BorderLayout.CENTER);

		JPanel buttonPanel1 = new JPanel(new FlowLayout(FlowLayout.RIGHT));
		JPanel buttonPanel2 = new JPanel(new GridLayout(0, 3));

		JButton button = null;
		button = new JButton("Ok");
		button.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				zidestorePanel.save();
				cachePanel.save();
				spiderPanel.save();
        ZSPConfig.storeConfig();
				dispose();
			}
		});
		buttonPanel2.add(button);
		button = new JButton("Cancel");
		button.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				dispose();

			}
		});
		buttonPanel2.add(button);
		button = new JButton("Apply");
		button.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				zidestorePanel.save();
				cachePanel.save();
				spiderPanel.save();
        ZSPConfig.storeConfig();
			}
		});
		buttonPanel2.add(button);

		buttonPanel1.add(buttonPanel2);
		getContentPane().add(buttonPanel1, BorderLayout.SOUTH);
	}

	public static void main(String[] args) {

		try {
			UIManager.setLookAndFeel("com.sun.java.swing.plaf.gtk.GTKLookAndFeel");
		}
		catch (Exception e) {
			try {
				UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
			}
			catch (Exception ex) {
			}
		}
    System.setProperty("zsp.config_file", "/home/sell/zsp.conf");
    
    ZSPConfig.loadConfig();

		ConfigDialog configDialog = new ConfigDialog();
		configDialog.pack();
		configDialog.show();
		System.exit(0);
	}
}
