package osm.surveyor.matchtime.gui;
import java.awt.*;

@SuppressWarnings("serial")
public class AboutDialog extends Dialog
{
    //{{DECLARE_CONTROLS
    java.awt.Label label1;
    java.awt.Button okButton;
    java.awt.Label label2;
    //}}

    // Used for addNotify redundency check.
    boolean fComponentsAdjusted = false;

    class SymWindow extends java.awt.event.WindowAdapter
    {
        @Override
        public void windowClosing(java.awt.event.WindowEvent event) {
            Object object = event.getSource();
            if (object == AboutDialog.this) {
                AboutDialog_WindowClosing(event);
            }
        }
    }

    class SymAction implements java.awt.event.ActionListener
    {
        @Override
        public void actionPerformed(java.awt.event.ActionEvent event) {
            Object object = event.getSource();
            if (object == okButton) {
                okButton_Clicked(event);
            }
        }
    }

    public AboutDialog(Frame parent, boolean modal) {
        super(parent, modal);

        // This code is automatically generated by Visual Cafe when you add
        // components to the visual environment. It instantiates and initializes
        // the components. To modify the code, only use code syntax that matches
        // what Visual Cafe can generate, or Visual Cafe may be unable to back
        // parse your Java file into its visual environment.


        //{{INIT_CONTROLS
        setLayout(null);
        setVisible(false);
        setSize(360,114);
        label1 = new java.awt.Label(ReStamp.PROGRAM_NAME +" Version "+ ReStamp.PROGRAM_VARSION +" ("+ ReStamp.PROGRAM_UPDATE +")", Label.CENTER);
        label1.setBounds(10,10,340,20);
        add(label1);
        okButton = new java.awt.Button();
        okButton.setLabel("OK");
        okButton.setBounds(145,65,66,27);
        add(okButton);
        label2 = new java.awt.Label("Copyright(C) 2014,2020, yuuhayashi \n The MIT License (MIT).",Label.RIGHT);
        label2.setBounds(10,40,340,20);
        add(label2);
        setTitle("About... "+ ReStamp.PROGRAM_NAME);
        //}}

        //{{REGISTER_LISTENERS
        SymWindow aSymWindow = new SymWindow();
        this.addWindowListener(aSymWindow);
        SymAction lSymAction = new SymAction();
        okButton.addActionListener(lSymAction);
        //}}
    }

    public AboutDialog(Frame parent, String title, boolean modal) {
        this(parent, modal);
        setTitle(title);
    }

    @Override
    public void addNotify() {
        // Record the size of the window prior to calling parents addNotify.

        super.addNotify();

        // Only do this once.
        if (fComponentsAdjusted) {
            return;
        }

        // Adjust components according to the insets
        setSize(getInsets().left + getInsets().right + getSize().width, getInsets().top + getInsets().bottom + getSize().height);
        Component components[] = getComponents();
        for (Component component : components) {
            Point p = component.getLocation();
            p.translate(getInsets().left, getInsets().top);
            component.setLocation(p);
        }

        // Used for addNotify check.
        fComponentsAdjusted = true;
    }

    /**
    * Shows or hides the component depending on the boolean flag b.
    * @param b  if true, show the component; otherwise, hide the component.
    * @see java.awt.Component#isVisible
    */
    @Override
    public void setVisible(boolean b) {
        if(b) {
            Rectangle bounds = getParent().getBounds();
            Rectangle abounds = getBounds();
            setLocation(bounds.x + (bounds.width - abounds.width)/ 2,
            bounds.y + (bounds.height - abounds.height)/2);
        }
        super.setVisible(b);
    }

    void AboutDialog_WindowClosing(java.awt.event.WindowEvent event) {
        dispose();
    }

    void okButton_Clicked(java.awt.event.ActionEvent event) {
        //{{CONNECTION
        // Clicked from okButton Hide the Dialog
        dispose();
        //}}
    }
}
