2012-07-08 4 views
1

현재 Zest를 사용하여 트리를 표시하는 eclipse 용 플러그인을 개발 중입니다.Zest 그래프에 MouseListener 추가

두 번 누르기 기능을 추가하려고 했으므로 노드를 표시하는 그림에 사용자 정의 MouseListener을 추가하려고 시도했지만 노드를 드래그 할 수있는 자연스럽게 나타나는 기능을 무시합니다.

드래그를 위해 Draw2D 기반 기능을 추가하려했지만 작동하지 않았습니다. 시도한 코드는 다음과 같습니다.

private Point location; 

public void mousePressed(MouseEvent me) { 
    location = me.getLocation(); 
    me.consume(); 
} 

public void mouseReleased(MouseEvent me) { 
    location = null; 
    me.consume(); 
} 

public void mouseDragged(MouseEvent me) { 
    if (location == null) { 
     return; 
    } 
    Point moved= me.getLocation(); 
    if (moved == null) { 
     return; 
    } 

    Dimension offset= moved.getDifference(location); 
    if (offset.width == 0 && offset.height == 0) { 
     return; 
    } 
    location= moved; 

    UpdateManager uMgr= figure.getUpdateManager(); 
    LayoutManager lMgr= figure.getLayoutManager(); 
    Rectangle bounds= figure.getBounds(); 
    uMgr.addDirtyRegion(figure.getParent(), bounds); 
    bounds= bounds.getCopy().translate(offset.width, offset.height); 
    lMgr.setConstraint(figure, bounds); 
    figure.translate(offset.width, offset.height); 
    uMgr.addDirtyRegion(figure.getParent(), bounds); 
    me.consume(); 
} 

누구든지 내 코드 또는 해결 방법에 대한 해결책을 제공 할 수 있습니까?

답변

3

디버그 시각화 프로젝트에서 드래그 지원이 유지되는 동안 두 번 클릭 수신기를 추가했습니다.

우리의 코드는 http://code.google.com/a/eclipselabs.org/p/debugvisualisation/source/browse/hu.cubussapiens.debugvisualisation/src/hu/cubussapiens/debugvisualisation/views/DebugVisualisationView.java에 라인 159에 있습니다 : (내가 잘못 아니에요 경우)

// double click on nodes 
    graphViewer.getGraphControl().addMouseListener(new MouseAdapter() { 

      @Override 
      public void mouseDoubleClick(MouseEvent e) { 
       toggleOpen.run(); 
      } 
    }); 

당신은 된 MouseEvent에서 선택된 노드를 읽을 수 중 하나, 또는 그이있다 (현재 선택을 확인할 수 있습니다 접근 방식 우리는 프로젝트에서 찍은 천국).