package com.github.aureliano.edocs.app.gui;

import java.awt.Component;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Frame;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JPanel;

public class HelpDialog extends JDialog {

	private static final long serialVersionUID = -3369353227801827761L;

	public HelpDialog(Frame parent) {
		super(parent);
		this.buildGui(parent);
	}

	private void buildGui(Component parent) {
		JLabel labelTitle = this.createLabelTitle();
		JLabel labelDescription = this.createLabelDescription();
		JLabel labelVersion = this.createLabelVersion();
		JLabel labelCopyright = this.createLabelCopyright();
		JButton buttonOk = this.createButtonOk();
		
		this.createLayout(labelTitle, labelDescription, labelVersion, labelCopyright, buttonOk);

		super.setLocationRelativeTo(parent);
		super.setTitle("About e-Docs");
		super.setModal(true);
	}
	
	private void createLayout(JComponent... components) {
		JPanel panel = new JPanel(null);
		for (JComponent component : components) {
			panel.add(component);
		}
		
		super.pack();
		
		super.setContentPane(panel);
		super.setSize(new Dimension(320, 230));
		super.setResizable(false);
	}
	
	private JLabel createLabelTitle() {
		JLabel label = new JLabel("e-Docs");
		label.setBounds(120, 10, 100, 25);
		label.setFont(new Font(Font.SERIF, Font.BOLD, 18));
		
		return label;
	}
	
	private JLabel createLabelDescription() {
		String text = new StringBuilder("<html>")
			.append("<p align=\"center\">")
			.append("A digital document repository")
			.append("<br/>")
			.append("management application.")
			.append("</p>")
			.append("</html>")
			.toString();
		JLabel label = new JLabel(text);
		label.setBounds(50, 50, 300, 30);
		
		return label;
	}
	
	private JLabel createLabelVersion() {
		JLabel label = new JLabel("Version 0.1.0");
		label.setBounds(110, 90, 210, 25);
		
		return label;
	}
	
	private JLabel createLabelCopyright() {
		String text = new StringBuilder("<html>")
			.append("<p align=\"center\">")
			.append("(c) Copyright e-Docs contributors")
			.append("<br/>")
			.append("and others 2016. All rights reserved.")
			.append("</p>")
			.append("</html>")
			.toString();
		JLabel label = new JLabel(text);
		label.setBounds(25, 120, 400, 30);
		
		return label;
	}

	private JButton createButtonOk() {
		JButton button = new JButton("OK");
		button.setBounds(210, 170, 100, 25);
		
		button.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent e) {
				dispose();
			}
		});
		
		return button;
	}
}
@@ -209,16 +209,101 @@
 istener;
+%0Aimport java.io.IOException;%0Aimport java.io.InputStream;%0Aimport java.util.Properties;
 %0A%0Aimport
@@ -438,16 +438,84 @@
 Panel;%0A%0A
+import com.github.aureliano.edocs.common.exception.EDocsException;%0A%0A
 public c
@@ -619,16 +619,50 @@
 7761L;%0A%0A
+%09private Properties properties;%0A%09%0A
 %09public 
@@ -705,16 +705,39 @@
 arent);%0A
+%09%09this.loadMetadata();%0A
 %09%09this.b
@@ -751,24 +751,283 @@
 (parent);%0A%09%7D
+%0A%09%0A%09private void loadMetadata() %7B%0A%09%09this.properties = new Properties();%0A%09%09try(InputStream stream = ClassLoader.getSystemResourceAsStream(%22metadata.properties%22)) %7B%0A%09%09%09properties.load(stream);%0A%09%09%7D catch (IOException ex) %7B%0A%09%09%09throw new EDocsException(ex);%0A%09%09%7D%0A%09%7D
 %0A%0A%09private v
@@ -2451,14 +2451,54 @@
 ion 
-0.1.0%22
+%22 + this.properties.getProperty(%22app.version%22)
 );%0A%09

Read application version from metadata file.