
package uk.co.wingpath.modbusgui;

import uk.co.wingpath.util.*;
import uk.co.wingpath.gui.*;
import uk.co.wingpath.registration.*;
import uk.co.wingpath.io.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.net.*;
import java.util.*;

public class About
{
    public static SimpleDialog createDialog (Frontend frontend)
    {
        Product product = frontend.getProduct ();
        DialogCloseAction closeAction = new DialogCloseAction ()
            {
                public void dialogClosing (WWindow dialog)
                {
                    dialog.dispose ();
                }
            };
        SimpleDialog dialog = SimpleDialog.createModal (
            frontend.getMainFrame ());
        dialog.setCloseAction (closeAction);
        dialog.setTitle (product.getName () + " - About");

        dialog.addCloseButton ();

        JPanel panel = new JPanel ();
        dialog.setContent (panel);
        panel.setLayout (new BoxLayout (panel, BoxLayout.Y_AXIS));
        JLabel label;
        Font bigFont = new Font ("SansSerif", Font.BOLD, 24);
        Font smallFont = new Font ("SansSerif", Font.PLAIN, 12);

        URL url = product.getClass ().getClassLoader ().getResource ("image/wingpath.png");
        label = new JLabel (new ImageIcon (url));
        label.setAlignmentX (Component.CENTER_ALIGNMENT);
        panel.add (label);

        label = new JLabel (product.getName () + " " + product.getVersion ());
        label.setFont (bigFont);
        label.setAlignmentX (Component.CENTER_ALIGNMENT);
        panel.add (label);

        int year = Calendar.getInstance().get(Calendar.YEAR);
        label = new JLabel ("Copyright (C) Wingpath Limited 2002-" + year);
        label.setAlignmentX (Component.CENTER_ALIGNMENT);
        panel.add (label);

        label = new JLabel ("All Rights Reserved");
        label.setAlignmentX (Component.CENTER_ALIGNMENT);
        panel.add (label);

        StringBuilder text = new StringBuilder ();
        text.append ("<html><br>");

        String [] details = Registration.description (product.getCode (),
            product.getMajorVersion ());
        text.append ("Registration details:<ul>");

        for (int i = 1 ; i < details.length ; i++)
            text.append ("<li>" + details [i] + "</li>");

        text.append ("</ul>");

        text.append ("Environment:<ul>");
        String dataModel = System.getProperty ("sun.arch.data.model");
        if (dataModel == null)
            dataModel = System.getProperty ("com.ibm.vm.bitmode");
        if (dataModel == null)
            dataModel = "";
        else
            dataModel = " " + dataModel + "-bit";
        text.append ("<li>" + System.getProperty ("os.name") + " " +
            System.getProperty ("os.version") + " " +
            System.getProperty ("os.arch") + "</li>");
        text.append ("<li>" + System.getProperty ("java.vendor") + " " +
            System.getProperty ("java.version") + dataModel + "</li>");
        text.append ("<li>" + System.getProperty ("java.home") + "</li>");
        text.append ("<li>Serial comms library is " +
            (SerialConnection.isAvailable () ? "" : "not ") +
            "loaded</li>");
        text.append ("</ul>");

        text.append ("Web site: http://wingpath.co.uk<br>");
        text.append ("Email: support@wingpath.co.uk<br>");
        text.append ("<br>");

        JEditorPane pane = new JEditorPane ();
        pane.putClientProperty (JEditorPane.HONOR_DISPLAY_PROPERTIES,
            Boolean.TRUE);
        pane.setBackground (panel.getBackground ());
        label = new JLabel ();
        pane.setFont (label.getFont ());
        pane.setEditable (false);
        pane.setContentType ("text/html");
        pane.setText (text.toString ());
        pane.setAlignmentX (Component.CENTER_ALIGNMENT);
        panel.add (pane);

        dialog.setMinimumSize (500, 400);

        return dialog;
    }
}

