/**
 * $Id: EditorKeyboardHandler.java,v 1.1 2012/11/15 13:26:46 gaudenz Exp $
 * Copyright (c) 2008, Gaudenz Alder
 */
package com.mxgraph.examples.swing.editor;

import javax.swing.ActionMap;
import javax.swing.InputMap;
import javax.swing.JComponent;
import javax.swing.KeyStroke;

import com.mxgraph.swing.mxGraphComponent;
import com.mxgraph.swing.handler.mxKeyboardHandler;
import com.mxgraph.swing.util.mxGraphActions;

/**
 * @author Administrator
 * 
 */
public class EditorKeyboardHandler extends mxKeyboardHandler
{

	/**
	 * 
	 * @param graphComponent
	 */
	public EditorKeyboardHandler(mxGraphComponent graphComponent)
	{
		super(graphComponent);
	}

	/**
	 * Return JTree's input map.
	 */
	protected InputMap getInputMap(int condition)
	{
		InputMap map = super.getInputMap(condition);

		if (condition == JComponent.WHEN_FOCUSED && map != null)
		{
			map.put(KeyStroke.getKeyStroke("control S"), "save");
			map.put(KeyStroke.getKeyStroke("control shift S"), "saveAs");
			map.put(KeyStroke.getKeyStroke("control N"), "new");
			map.put(KeyStroke.getKeyStroke("control O"), "open");

			map.put(KeyStroke.getKeyStroke("control Z"), "undo");
			map.put(KeyStroke.getKeyStroke("control Y"), "redo");
			map
					.put(KeyStroke.getKeyStroke("control shift V"),
							"selectVertices");
			map.put(KeyStroke.getKeyStroke("control shift E"), "selectEdges");
		}

		return map;
	}

	/**
	 * Return the mapping between JTree's input map and JGraph's actions.
	 */
	protected ActionMap createActionMap()
	{
		ActionMap map = super.createActionMap();

		map.put("save", new EditorActions.SaveAction(false));
		map.put("saveAs", new EditorActions.SaveAction(true));
		map.put("new", new EditorActions.NewAction());
		map.put("open", new EditorActions.OpenAction());
		map.put("undo", new EditorActions.HistoryAction(true));
		map.put("redo", new EditorActions.HistoryAction(false));
		map.put("selectVertices", mxGraphActions.getSelectVerticesAction());
		map.put("selectEdges", mxGraphActions.getSelectEdgesAction());

		return map;
	}

}

@@ -376,54 +376,8 @@
 ler;
-%0Aimport com.mxgraph.swing.util.mxGraphActions;
 %0A%0A/*
@@ -471,17 +471,17 @@
 dHandler
-%0A
+ 
 %7B%0A%0A%09/**%0A
@@ -578,18 +578,17 @@
 mponent)
-%0A%09
+ 
 %7B%0A%09%09supe
@@ -696,18 +696,17 @@
 ndition)
-%0A%09
+ 
 %7B%0A%09%09Inpu
@@ -805,19 +805,17 @@
 != null)
-%0A%09%09
+ 
 %7B%0A%09%09%09map
@@ -1043,24 +1043,27 @@
 open%22);%0A%0A%09%09%09
+// 
 map.put(KeyS
@@ -1103,24 +1103,27 @@
 %22undo%22);%0A%09%09%09
+// 
 map.put(KeyS
@@ -1171,17 +1171,21 @@
 %0A%09%09%09
+// 
 map%0A%09%09%09
-%09%09
+// 
 .put
@@ -1231,20 +1231,19 @@
 V%22),%0A%09%09%09
-%09%09%09%09
+// 
 %22selectV
@@ -1248,32 +1248,35 @@
 tVertices%22);%0A%09%09%09
+// 
 map.put(KeyStrok
@@ -1309,16 +1309,22 @@
 ift E%22),
+%0A%09%09%09//
  %22select
@@ -1474,18 +1474,17 @@
 ionMap()
-%0A%09
+ 
 %7B%0A%09%09Acti
@@ -1728,32 +1728,35 @@
 penAction());%0A%09%09
+// 
 map.put(%22undo%22, 
@@ -1789,32 +1789,35 @@
 ction(true));%0A%09%09
+// 
 map.put(%22redo%22, 
@@ -1851,32 +1851,35 @@
 tion(false));%0A%09%09
+// 
 map.put(%22selectV
@@ -1925,32 +1925,35 @@
 cesAction());%0A%09%09
+// 
 map.put(%22selectE

Disable Undo/Redo.