// Carnegie Mellon University
//   Information Networking Institute and
//   School of Computer Science
//
// Master Thesis: A Monitoring Tool for Overlay Network
// By: TungFai Chan and Annie Cheng
//
// File: AboutBox.java
// Path: userInterfaces/
// Description: About box for the application


package userInterfaces;

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.border.*;


public class AboutBox extends JDialog implements ActionListener {

    JPanel mainPanel = new JPanel();
    JPanel despPanel = new JPanel();
    JPanel buttonPanel = new JPanel();
    JPanel imagePanel = new JPanel();
    JPanel textPanel = new JPanel();
    JButton okButton = new JButton();
    JLabel logoImageControl = new JLabel();
    ImageIcon imageIcon;
    JLabel titleLabel = new JLabel();
    JLabel versionLabel = new JLabel();
    JLabel authorsLabel = new JLabel();
    JLabel subTitleLabel = new JLabel();
    BorderLayout mainPanelBorderLayout = new BorderLayout();
    BorderLayout despPanelBorderLayout = new BorderLayout();
    FlowLayout buttonPanelFlowLayout = new FlowLayout();
    FlowLayout flowLayout2 = new FlowLayout();
    GridLayout textGridLayout = new GridLayout();
    String product = "Overlay Network Monitor";
    String version = "2.0";
    String copyright = "Copyright (c) TungFai Chan and Annie Cheng";
    String comments = "Master Thesis";

    public AboutBox(Frame parent) {
	super(parent);
	enableEvents(AWTEvent.WINDOW_EVENT_MASK);
	try {
	    jbInit();
	}
	catch(Exception e) {
	    e.printStackTrace();
	}
	//imageControl1.setIcon(imageIcon);
	//pack();
    }

    private void jbInit() throws Exception  {
	//imageIcon = new ImageIcon(getClass().getResource("[Your Image]"));
	this.setTitle("About");
	this.setSize(new Dimension(426, 150));
        this.setResizable(false);
	mainPanel.setLayout(mainPanelBorderLayout);
	despPanel.setLayout(despPanelBorderLayout);
	buttonPanel.setLayout(buttonPanelFlowLayout);
	imagePanel.setLayout(buttonPanelFlowLayout);
	imagePanel.setBorder(new EmptyBorder(10, 10, 10, 10));
	textGridLayout.setRows(4);
	textGridLayout.setColumns(1);

	titleLabel.setFont(new java.awt.Font("SansSerif", 1, 12));
        titleLabel.setForeground(Color.black);
        titleLabel.setBorder(BorderFactory.createEtchedBorder());
        titleLabel.setText(product);
	versionLabel.setFont(new java.awt.Font("SansSerif", 0, 12));
        versionLabel.setForeground(Color.black);
        versionLabel.setText(version);
	authorsLabel.setFont(new java.awt.Font("SansSerif", 0, 12));
        authorsLabel.setForeground(Color.black);
        authorsLabel.setPreferredSize(new Dimension(300, 13));
        authorsLabel.setText(copyright);
	subTitleLabel.setFont(new java.awt.Font("SansSerif", 0, 12));
        subTitleLabel.setForeground(Color.black);
        subTitleLabel.setText(comments);
	textPanel.setLayout(textGridLayout);
	textPanel.setBorder(new EmptyBorder(10, 60, 10, 10));
        textPanel.setPreferredSize(new Dimension(300, 88));

        okButton.setFont(new java.awt.Font("SansSerif", 0, 12));
        okButton.setText("OK");
	okButton.addActionListener(this);
        okButton.setMnemonic(KeyEvent.VK_O);
	logoImageControl.setIcon(new ImageIcon(new java.net.URL("file:////home/tungfai/development/monitor/src/monitor/images/flashLight.gif")));
        mainPanel.setPreferredSize(new Dimension(360, 120));
        imagePanel.add(logoImageControl, null);
	despPanel.add(imagePanel, BorderLayout.WEST);
	this.getContentPane().add(mainPanel, null);

	textPanel.add(titleLabel, null);
	textPanel.add(versionLabel, null);
	textPanel.add(authorsLabel, null);
	textPanel.add(subTitleLabel, null);
	despPanel.add(textPanel, BorderLayout.CENTER);
	buttonPanel.add(okButton, null);
	mainPanel.add(buttonPanel, BorderLayout.SOUTH);
	mainPanel.add(despPanel, BorderLayout.NORTH);
    }

    protected void processWindowEvent(WindowEvent e) {
	if (e.getID() == WindowEvent.WINDOW_CLOSING) {
	    cancel();
	}
	super.processWindowEvent(e);
    }

    void cancel() {
	dispose();
    }

    public void actionPerformed(ActionEvent e) {
	if (e.getSource() == okButton) {
	    cancel();
	}
    }
}
