package windows;
import java.awt.event.*;
import java.awt.*;

import javax.swing.*;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;

import tournamentRunner.TournamentView;

/*
*Represents a Dialog box to create a new Tournament, with Name, Size and # of brackets
*/
public class NewTournamentWindow extends JDialog implements ActionListener{ //Retain reference to view to allow method calls
	private TournamentView view;
	private JButton confirm,cancel;
	private JTextField name, number, size;
	public NewTournamentWindow(TournamentView view){
		super(view, "New Tournament");
		this.view = view;
		DocListener dl = new DocListener(); //Listen for changes to text fields
		
		GridBagConstraints cons = new GridBagConstraints();
		cons.gridheight = 10;
		cons.gridwidth = this.getWidth();
		JPanel namePanel = new JPanel();
		namePanel.setLayout(new GridBagLayout());
		name = new JTextField("Tournament Name");
		name.setColumns(15);
		name.setHorizontalAlignment(JTextField.CENTER);
		namePanel.add(name);
		
		JPanel numberAndSize = new JPanel();
		numberAndSize.setLayout(new GridBagLayout());
		number = new JTextField("Number of Brackets");
		number.setColumns(10);
		number.setHorizontalAlignment(JTextField.CENTER);
		size = new JTextField("Bracket Size");
		size.setColumns(10);
		size.setHorizontalAlignment(JTextField.CENTER);
		numberAndSize.add(number);
		numberAndSize.add(size);
		
		name.getDocument().addDocumentListener(dl);
		number.getDocument().addDocumentListener(dl);
		size.getDocument().addDocumentListener(dl);
		
		JPanel closeOptions = new JPanel();
		confirm = new JButton("Confirm");
		confirm.addActionListener(this);
		confirm.setEnabled(false);
		closeOptions.add(confirm);
		
		cancel = new JButton("Cancel");
		cancel.addActionListener(this);
		cancel.setEnabled(true);
		closeOptions.add(cancel);
		
		this.setLayout(new GridLayout(3,1));
		this.setSize(400,200);
		
		add(namePanel);
		add(numberAndSize);
		add(closeOptions);
		
		Toolkit tlkt = Toolkit.getDefaultToolkit();
		this.setLocation((int)(tlkt.getScreenSize().getWidth()-this.getWidth())/2,(int)(tlkt.getScreenSize().getHeight()-this.getHeight())/2);
		this.setModal(true);
		this.setResizable(false);
		this.setAlwaysOnTop(true);
		this.setVisible(true);
		this.pack();
	}
	
	public void actionPerformed(ActionEvent e) { //If cancel, close the window, if confirm, attempt to create new bracket
		if(e.getSource() == cancel) this.dispose();	
		else{
			dispose();
			view.createNewBracket(name.getText(),number.getText(),size.getText());
		}
	}
	
	private class DocListener implements DocumentListener{ //If any fields are default text or blank, do not allow confirm
		public void changedUpdate(DocumentEvent e){
			enableButtons();
		}
		public void removeUpdate(DocumentEvent e){
			enableButtons();
		}
		public void insertUpdate(DocumentEvent e){
			enableButtons();
		}
		private void enableButtons(){
			if(name.getText().equals("Tournament Name") || name.getText().equals("") || 
					number.getText().equals("Number of Brackets") || number.getText().equals("") ||
						size.getText().equals("Bracket Size") || size.getText().equals("")){
				confirm.setEnabled(false);
			}
			else{
				confirm.setEnabled(true);
			}
		}
		
	}

}

@@ -205,17 +205,19 @@
 ew;%0A%0A/*%0A
-*
+ * 
 Represen
@@ -225,18 +225,14 @@
 s a 
-Dialog box
+window
  to 
@@ -244,17 +244,17 @@
 e a new 
-T
+t
 ournamen
@@ -258,44 +258,47 @@
 ment
-, with Name, Size and # of brackets%0A
+%0A * 5.30.16%0A * Ben Kelly and Ted Pyne%0A 
 */%0Ap
@@ -375,57 +375,8 @@
 ner%7B
- //Retain reference to view to allow method calls
 %0A%09pr
@@ -475,16 +475,73 @@
 , size;%0A
+%09//Creates a new window dependent on TournamentView view%0A
 %09public 
@@ -676,44 +676,8 @@
 r();
- //Listen for changes to text fields
 %0A%09%09%0A
@@ -986,16 +986,16 @@
 ENTER);%0A
+
 %09%09namePa
@@ -1008,17 +1008,16 @@
 d(name);
-%0A
 %09%09%0A%09%09JPa
@@ -2278,127 +2278,114 @@
 %09%7D%0A%09
-%0A%09public void actionPerformed(A
+//Resolves an a
 ction
-E
+ e
 vent 
-e) %7B //If cancel, close the window, if confirm, attempt to create new bracket
+of the confirm and cancel buttons%0A%09public void actionPerformed(ActionEvent e) %7B
 %0A%09%09i
@@ -2426,17 +2426,16 @@
 spose();
-%09
 %0A%09%09else%7B
@@ -2594,69 +2594,45 @@
 %7B //
-If any fields are default text or blank, do not allow confirm
+Listens for changes in the textfields
 %0A%09%09p

Update NewTournamentWindow.java