gef中采用公共的快捷键功能的原理和实现

gef相关的编辑器类中采用快捷键处理器KeyHandler中注册相关类的Action并在

   protected KeyHandler getCommonKeyHandler(){

    if (sharedKeyHandler == null){

       sharedKeyHandler = new KeyHandler();

       sharedKeyHandler.put(

           KeyStroke.getPressed(SWT.F2, 0),

           getActionRegistry().getAction(GEFActionConstants.DIRECT_EDIT));

    }

    returnsharedKeyHandler;

}

gef视图编辑器类中的方法protectedvoid configureGraphicalViewer()中添加如下代码:

ScrollingGraphicalViewer viewer =(ScrollingGraphicalViewer)getGraphicalViewer();

ScalableFreeformRootEditPart root = new ScalableFreeformRootEditPart();

viewer.setKeyHandler(new GraphicalViewerKeyHandler(viewer)

           .setParent(getCommonKeyHandler()));

 

在大纲视图中的使用如下:

getViewer().setKeyHandler(getCommonKeyHandler());

你可能感兴趣的:(osgi,RCP,SWT,gef,draw2d)