/*
 * Copyright (C) 2016 Matthew Seal
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package org.mseal.control.server;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Toolkit;
import java.io.IOException;
import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextPane;
import javax.swing.SwingConstants;
import javax.swing.text.SimpleAttributeSet;
import javax.swing.text.StyleConstants;
import javax.swing.text.StyledDocument;
import static org.mseal.control.server.ServerControl.icons;

/**
 * Shows the about dialog
 *
 * @author Matthew Seal
 */
public class AboutDialog extends JFrame {

    /**
     * Constructor is protected access
     */
    protected AboutDialog() {
        initComponents();
    }
    
    private void initComponents() {
        setTitle("About");
        setSize(200, 300);
        setResizable(false);
        setLayout(new BorderLayout());
        setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        setIconImages(icons);
        
        JLabel icon = new JLabel();
        icon.setIcon(new ImageIcon(icons.get(0)));
        icon.setHorizontalAlignment(SwingConstants.CENTER);
        icon.setPreferredSize(new Dimension(200, 100));
        add(icon, BorderLayout.NORTH);
        
        final String txt = "ServerControl\nby Matthew Seal\n\n"
                + "Version: " + Version.VERSION;
        JTextPane text = new JTextPane();
        text.setBackground(getBackground());
        text.setText(txt);
        text.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 16));
        text.setEditable(false);
        add(text, BorderLayout.CENTER);
        StyledDocument doc = text.getStyledDocument();
        SimpleAttributeSet attr = new SimpleAttributeSet();
        StyleConstants.setAlignment(attr, StyleConstants.ALIGN_CENTER);
        doc.setParagraphAttributes(0, doc.getLength(), attr, false);

        
        text.setPreferredSize(new Dimension(200, 100));
        
        pack();
        
        Dimension s = Toolkit.getDefaultToolkit().getScreenSize();
        setLocation(s.width / 2 - getWidth() / 2,
                s.height / 2 - getHeight() / 2);
    }
}
