package com.beyondtechnicallycorrect.pong.view;

import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;

import javax.swing.JButton;
import javax.swing.JPanel;

import com.beyondtechnicallycorrect.pong.models.game.CourtViewModelSubscription;
import com.beyondtechnicallycorrect.pong.viewmodel.AppViewModel;

public final class PongPanel
	extends JPanel
	implements ActionListener {
	
	private static final long serialVersionUID = -9201528908073199529L;
	
	private final String NEW_GAME_ACTION = "new game";
	
	private final AppViewModel m_appViewModel;
	private final JButton m_newGameButton;
	private final Court m_court;
	
	public PongPanel(
			AppViewModel appViewModel,
			CourtViewModelSubscription viewModelChangeSubscription
		) {
		
		super();
		
		m_appViewModel = appViewModel;
		
		this.setLayout(new BorderLayout());
		
		m_newGameButton = new JButton("New game");
		m_newGameButton.setMnemonic(KeyEvent.VK_N);
		m_newGameButton.setActionCommand(NEW_GAME_ACTION);
		m_newGameButton.addActionListener(this);
		this.add(m_newGameButton, BorderLayout.NORTH);
		
		m_court = new Court(appViewModel);
		viewModelChangeSubscription.subscribe(m_court);
		this.add(m_court, BorderLayout.CENTER);
	}
	
	@Override
	public void actionPerformed(ActionEvent e) {
		if(e.getActionCommand().equals(NEW_GAME_ACTION)) {
			m_newGameButton.setEnabled(false);
			m_appViewModel.startMatch();
		}
	}

}

@@ -176,16 +176,51 @@
 eyEvent;
+%0Aimport java.awt.event.KeyListener;
 %0A%0Aimport
@@ -487,16 +487,29 @@
 Listener
+, KeyListener
  %7B%0A%09%0A%09pr
@@ -1321,16 +1321,95 @@
 ENTER);%0A
+%09%09%0A%09%09this.setFocusable(true);%0A%09%09this.addKeyListener(this);%0A%09%09this.grabFocus();%0A
 %09%7D%0A%09%0A%09@O
@@ -1589,14 +1589,14 @@
 ();%0A
-
 %09%09%7D%0A%09%7D%0A%0A
 %7D%0A
@@ -1593,10 +1593,496 @@
 %09%09%7D%0A%09%7D%0A%0A
+%09@Override%0A%09public void keyPressed(KeyEvent e) %7B%0A%09%09char keyPressed = e.getKeyChar();%0A%09%09if(keyPressed == 'j') %7B%0A%09%09%09m_appViewModel.movePlayerPaddleLeft();%0A%09%09%7D%0A%09%09if(keyPressed == 'l') %7B%0A%09%09%09m_appViewModel.movePlayerPaddleRight();%0A%09%09%7D%0A%09%7D%0A%0A%09@Override%0A%09public void keyReleased(KeyEvent e) %7B%0A%09%09char keyPressed = e.getKeyChar();%0A%09%09if(keyPressed == 'j' %7C%7C keyPressed == 'l') %7B%0A%09%09%09m_appViewModel.stopMovingPlayerPaddle();%0A%09%09%7D%0A%09%7D%0A%0A%09@Override%0A%09public void keyTyped(KeyEvent e) %7B%0A%09%09// Do nothing%0A%09%7D%0A%0A
 %7D%0A

Add key press event handlers for moving player paddle