1 /**
2  * $Id: EditorKeyboardHandler.java,v 1.1 2009-10-23 11:32:08 gaudenz Exp $
3  * Copyright (c) 2008, Gaudenz Alder
4  */
5 package com.mxgraph.examples.swing.editor;
6 
7 import javax.swing.ActionMap;
8 import javax.swing.InputMap;
9 import javax.swing.JComponent;
10 import javax.swing.KeyStroke;
11 
12 import com.mxgraph.swing.mxGraphComponent;
13 import com.mxgraph.swing.handler.mxKeyboardHandler;
14 import com.mxgraph.swing.util.mxGraphActions;
15 
16 /**
17  * @author Administrator
18  *
19  */
20 public class EditorKeyboardHandler extends mxKeyboardHandler
21 {
22 
23 	/**
24 	 *
25 	 * @param graphComponent
26 	 */
EditorKeyboardHandler(mxGraphComponent graphComponent)27 	public EditorKeyboardHandler(mxGraphComponent graphComponent)
28 	{
29 		super(graphComponent);
30 	}
31 
32 	/**
33 	 * Return JTree's input map.
34 	 */
getInputMap(int condition)35 	protected InputMap getInputMap(int condition)
36 	{
37 		InputMap map = super.getInputMap(condition);
38 
39 		if (condition == JComponent.WHEN_FOCUSED && map != null)
40 		{
41 			map.put(KeyStroke.getKeyStroke("control S"), "save");
42 			map.put(KeyStroke.getKeyStroke("control shift S"), "saveAs");
43 			map.put(KeyStroke.getKeyStroke("control N"), "new");
44 			map.put(KeyStroke.getKeyStroke("control O"), "open");
45 
46 			map.put(KeyStroke.getKeyStroke("control Z"), "undo");
47 			map.put(KeyStroke.getKeyStroke("control Y"), "redo");
48 			map
49 					.put(KeyStroke.getKeyStroke("control shift V"),
50 							"selectVertices");
51 			map.put(KeyStroke.getKeyStroke("control shift E"), "selectEdges");
52 		}
53 
54 		return map;
55 	}
56 
57 	/**
58 	 * Return the mapping between JTree's input map and JGraph's actions.
59 	 */
createActionMap()60 	protected ActionMap createActionMap()
61 	{
62 		ActionMap map = super.createActionMap();
63 
64 		map.put("save", new EditorActions.SaveAction(false));
65 		map.put("saveAs", new EditorActions.SaveAction(true));
66 		map.put("new", new EditorActions.NewAction());
67 		map.put("open", new EditorActions.OpenAction());
68 		map.put("undo", new EditorActions.HistoryAction(true));
69 		map.put("redo", new EditorActions.HistoryAction(false));
70 		map.put("selectVertices", mxGraphActions.getSelectVerticesAction());
71 		map.put("selectEdges", mxGraphActions.getSelectEdgesAction());
72 
73 		return map;
74 	}
75 
76 }
77