package net.mkonrad.synes.ctrl;

import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;

import net.mkonrad.synes.gui.SceneCore;

public class GlobalKeyListener extends KeyAdapter
{
	private SceneCore _sceneCore;
	
	public GlobalKeyListener(SceneCore sceneCore)
	{
		_sceneCore = sceneCore;
	}

	public void keyPressed(KeyEvent e)
	{
		int keyCode = e.getKeyCode();
		
		if ((keyCode == KeyEvent.VK_C) && e.isControlDown())
		{
			_sceneCore.getParentWindow().dispose();
			System.exit(0);    // exit() alone isn't sufficient most of the time
		}
		
		if (_sceneCore.getPickingCtrl().getState() == CentralPickingCtrl.STATE_READY)
		{
      if (keyCode == KeyEvent.VK_PAGE_UP)
      {
        _sceneCore.getGuiCtrl().dive();
      }
      
      if (keyCode == KeyEvent.VK_PAGE_DOWN)
      {
        _sceneCore.getGuiCtrl().comeUp();
      }
      
      if (keyCode == KeyEvent.VK_L)
      {
        _sceneCore.toggleCurrLayerType();
      }
		}
		else if(_sceneCore.getPickingCtrl().getState() == CentralPickingCtrl.STATE_GRAPH_MOVE)
		{
      if (keyCode == KeyEvent.VK_BACK_SPACE || keyCode == KeyEvent.VK_DELETE)
      {
        _sceneCore.getPickingCtrl().getLinePickingCtrl().removeGraph();
      }
		}
    
    if (keyCode == KeyEvent.VK_O)
    {
      _sceneCore.changeOrbitMode();
    }
	}
}
