1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/**
 * $Id: EditorKeyboardHandler.java,v 1.1 2009-10-23 11:32:08 gaudenz Exp $
 * Copyright (c) 2008, Gaudenz Alder
 */
package com.vci.client.workflow.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;
    }
 
}