gpt4 book ai didi

click - 在 JUNG 中使用鼠标右键单击弹出菜单

转载 作者:行者123 更新时间:2023-12-01 02:35:23 24 4
gpt4 key购买 nike

我想创建一个弹出菜单,如果我右键单击 Canvas 就会出现该菜单。我怎样才能做到这一点?我应该修改哪个功能?任何帮助,将不胜感激。

最佳答案

protected class PopupGraphMousePlugin extends AbstractPopupGraphMousePlugin implements      MouseListener {

public PopupGraphMousePlugin() {
this(MouseEvent.BUTTON3_MASK);
}
public PopupGraphMousePlugin(int modifiers) {
super(modifiers);
}

/**
* If this event is over a station (vertex), pop up a menu to
* allow the user to perform a few actions; else, pop up a menu over the layout/canvas
*
* @param e
*/
@SuppressWarnings("unchecked")
protected void handlePopup(MouseEvent e) {
final VisualizationViewer<String,String> vv =(VisualizationViewer<String,String>)e.getSource();
final Point2D p = e.getPoint();
final Point2D ivp = p;
JPopupMenu popup = new JPopupMenu();

System.out.println("mouse event!");


GraphElementAccessor<String,String> pickSupport = vv.getPickSupport();
System.out.println("GraphElementAccessor!");
if(pickSupport != null) {



final String pickV = pickSupport.getVertex(vv.getGraphLayout(), ivp.getX(), ivp.getY());

if(pickV != null) {
System.out.println("pickVisnotNull");


popup.add(new AbstractAction("Add New") {
/**
*
*/


public void actionPerformed(ActionEvent e) {
System.out.println("person added");
}
});//new abstraction

}
}///if picksupport



}//handlePopup(MouseEvent e)
}//PopupGraphMousePlugin

那是你的第一个代码中的那个

这是第二部分
/Next, let's just build a simple mouse, to allow picking, translating, and zooming.
AbstractModalGraphMouse gMouse = new DefaultModalGraphMouse<Object, Object>();
vv.setGraphMouse(gMouse); //Add the mouse to our Visualization-Viewer.
//PluggableGraphMouse pgm = new PluggableGraphMouse();
gMouse.add(new PickingGraphMousePlugin<Object, Object>());
//pgm.add(new TranslatingGraphMousePlugin(MouseEvent.BUTTON3_MASK));
gMouse.add(new PopupGraphMousePlugin());
gMouse.add(new ScalingGraphMousePlugin(new CrossoverScalingControl(), 0, 1 / 1.1f, 1.1f));

关于click - 在 JUNG 中使用鼠标右键单击弹出菜单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10544970/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com