private void initListeners() {
		PatchPanelMediator mediator = PatchPanelMediator.getMediator();
		mediator.addDocumentChangedListener(new DocumentChangedListener() {
			@Override
			public void documentChanged(DocumentChangedEvent dce) {
				document = dce.getDocument();
				SwingUtilities.invokeLater(new Runnable() {
					@Override
					public void run() {
						widthField.setText(String.valueOf(document.getWidth()));
						heightField.setText(String.valueOf(document.getHeight()));
						animationCB.setSelectedIndex(document.getAnimationType().ordinal());
						outOfBoundsColorCB.setSelectedIndex(document.getOutOfBoundsColor().ordinal());
						tweenFramesField.setText(String.valueOf(document.getTweenCount()));
						tweenStyleCB.setSelectedIndex(document.getTweenStyle().ordinal());
					}
				});
			}
		});
		
		widthField.addFocusListener(new FocusListener() {
			@Override
			public void focusLost(FocusEvent fe) {
				try {
					int oldWidth = document.getWidth();
					int newWidth = Integer.parseInt(widthField.getText());
					if (oldWidth != newWidth) {
						document.setWidth(newWidth);
						PatchPanelMediator ppMediator = PatchPanelMediator.getMediator();
						ppMediator.fireSettingsChanged();
					}
				} catch (NumberFormatException nfe) {
					document.setWidth(100);
					PatchPanelMediator ppMediator = PatchPanelMediator.getMediator();
					ppMediator.fireSettingsChanged();
				}				
			}
			
			@Override
			public void focusGained(FocusEvent fe) {
				widthField.setSelectionStart(0);
				widthField.setSelectionEnd(Integer.MAX_VALUE);
			}
		});

		heightField.addFocusListener(new FocusListener() {

			@Override
			public void focusLost(FocusEvent arg0) {
				try {
					int oldHeight = document.getHeight();
					int newHeight = Integer.parseInt(heightField.getText());
					if (oldHeight != newHeight) {
						document.setHeight(newHeight);
						PatchPanelMediator ppMediator = PatchPanelMediator.getMediator();
						ppMediator.fireSettingsChanged();
					}
				} catch (NumberFormatException nfe) {
					document.setHeight(100);
					PatchPanelMediator ppMediator = PatchPanelMediator.getMediator();
					ppMediator.fireSettingsChanged();
				}
			}
			
			@Override
			public void focusGained(FocusEvent fe) {
				heightField.setSelectionStart(0);
				heightField.setSelectionEnd(Integer.MAX_VALUE);
			}
		});
		
		tweenFramesField.addFocusListener(new FocusAdapter() {

			@Override
			public void focusLost(FocusEvent arg0) {
				try {
					int oldTween = document.getTweenCount();
					int newTween = Integer.parseInt(tweenFramesField.getText());
					if (oldTween != newTween) {
						document.setTweenCount(newTween);
						PatchPanelMediator ppMediator = PatchPanelMediator.getMediator();
						ppMediator.fireSettingsChanged();
					}
				} catch (NumberFormatException nfe) {
					document.setTweenCount(10);
					PatchPanelMediator ppMediator = PatchPanelMediator.getMediator();
					ppMediator.fireSettingsChanged();
				}
			}
		});
		
		animationCB.addItemListener(new ItemListener() {
			
			@Override
			public void itemStateChanged(ItemEvent ie) {
				if (ie.getStateChange() == ItemEvent.SELECTED) {
					document.setAnimationType((AnimationType)ie.getItem());
					PatchPanelMediator ppMediator = PatchPanelMediator.getMediator();
					ppMediator.fireSettingsChanged();
				}
			}
		});
		
		outOfBoundsColorCB.addItemListener(new ItemListener() {

			@Override
			public void itemStateChanged(ItemEvent ie) {
				if (ie.getStateChange() == ItemEvent.SELECTED) {
					document.setOutOfBoundsColor((OutOfBoundsColor)ie.getItem());
					PatchPanelMediator ppMediator = PatchPanelMediator.getMediator();
					ppMediator.fireSettingsChanged();
				}
			}
		});
		
		tweenFramesField.addFocusListener(new FocusAdapter() {
			@Override
			public void focusGained(FocusEvent fe) {
				tweenFramesField.setSelectionStart(0);
				tweenFramesField.setSelectionEnd(Integer.MAX_VALUE);
			}
		});
		
		tweenStyleCB.addItemListener(new ItemListener() {
			@Override
			public void itemStateChanged(ItemEvent ie) {
				if (ie.getStateChange() == ItemEvent.SELECTED) {
					document.setTweenStyle((TweenStyle)ie.getItem());
					PatchPanelMediator ppMediator = PatchPanelMediator.getMediator();
					ppMediator.fireSettingsChanged();
				}
			}
		});
		
		testButton.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent ae) {
				JTestFrame tf = new JTestFrame();
				tf.setLocationRelativeTo(JPatchControlPanel.this.getRootPane());
				tf.setVisible(true);
				tf.setAlwaysOnTop(true);
				tf.beginAnimation();
			}
		});
	}