package org.cmdline.sudoku;

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.border.*;
import java.awt.image.BufferedImage;
import javax.imageio.*;
import javax.imageio.stream.*;
import java.io.*;

public class PDFInfo extends JDialog {
	JTextField header1 = new JTextField("Sunday Sudoku Solver",15);
	JTextField description = new JTextField(20);
//	JTextArea notes = new JTextArea(5,20);
	JTextPane notes = new JTextPane();
	int tries = 0;
	String imagePath = null;
	
	public static void main(String[] args) {
		new PDFInfo(args[1],new Frame(""),args[0]).setVisible(true);
	}
		
	public PDFInfo(final String pdfPath,Frame owner,final String imagePath) {
		super(owner,"PDF information",false);
 		this.imagePath = imagePath;
        setBackground(Color.white);
 		getContentPane().setLayout(new GridBagLayout());
        GridBagConstraints c = new GridBagConstraints();
		c.insets = insets(5,10,5,15);
       
 		getContentPane().setBackground(Color.white);
 		c.fill = c.NONE;
 		c.gridx = 0; c.gridy = 0;
 		c.gridwidth = 1;

 		c.anchor = c.WEST;
 		c.gridheight = 1;
 		getContentPane().add(new JLabel("Header"),c);
 		c.gridy = 3;
 		c.gridwidth = 2;
 		getContentPane().add(header1,c);
 		c.gridy = 5;
 		c.gridwidth = 3;
 		getContentPane().add(new JLabel("Descripton (Optional)"),c);
 		c.gridy= 7;
 		getContentPane().add(description,c);
 		c.gridy = 9;
 		TitledBorder notesTitle = BorderFactory.createTitledBorder("Notes (Optional)");
 		c.gridy = 11;
 		c.gridheight = 10;
 		c.fill = c.BOTH;
		int width = description.getWidth();
		int height = 175;
		Dimension d = new Dimension(width,height);
		notes.setSize(width,height);
		notes.setMinimumSize(d);
		notes.setMaximumSize(d);
		notes.setPreferredSize(d);
		JScrollPane holder = new JScrollPane(notes);
 		((JComponent)holder).setBorder(notesTitle);
 		getContentPane().add(holder,c);
 		c.fill = c.NONE;
 		c.gridy = 21;
 		c.gridwidth = 1;
 		c.gridheight = 1;
 		JButton ok = new JButton("OK");
 		ok.setBackground(Color.white);
 		getContentPane().add(ok,c);
 		ok.addActionListener(new ActionListener() {
 			public void actionPerformed(ActionEvent e) {
 				new Puzzle2PDF(imagePath,pdfPath,header1.getText(),description.getText(),notes.getText());
 				setVisible(false);
 				dispose();
// 				System.exit(0);
 			}
 		});
 		getRootPane().setDefaultButton(ok);
 		c.gridx = 1;
 		JButton cancel = new JButton("Cancel");
 		cancel.setBackground(Color.white);
 		getContentPane().add(cancel,c);
 		cancel.addActionListener(new ActionListener() {
 			public void actionPerformed(ActionEvent e) {
 				setVisible(false);
 				dispose();
// 				System.exit(0);
 			}
 		});
 		pack();
 		positionWindow();
	}
	
	public Insets insets(int t, int l, int b, int r)
	{
		return new Insets(t,l,b,r);
	}
		
	public void positionWindow()
	{
		Dimension sSize = this.getToolkit().getScreenSize();	// Position the window
  	 	int sHeight = sSize.height;
  	 	int sWidth = sSize.width;
  	 	Dimension aSize = this.getSize();
  	 	int aHeight = aSize.height;
  	 	int aWidth = aSize.width;
 	 	this.setLocation((sWidth-aWidth)/2,(sHeight-aHeight)/2);
	}
}