サンプルコード
import java.awt.* import java.awt.event.* import javax.swing.* import groovy.swing.* import com.mxgraph.swing.* import com.mxgraph.swing.util.* import com.mxgraph.view.* import com.mxgraph.util.mxConstants class MyMouseAdapter extends mxMouseAdapter { def swingbuilder def graphcomp public MyMouseAdapter(asb, amxgc) { swingbuilder = asb graphcomp = amxgc } @Override public void mouseClicked(MouseEvent ev) { if( SwingUtilities.isRightMouseButton(ev) && graphcomp.getCellAt(ev.getX(), ev.getY()) != null ){ swingbuilder.popup.show(graphcomp, ev.getX(), ev.getY()) } } } def graph = new mxGraph() def mxgc = new mxGraphComponent(graph) sb = new SwingBuilder() def frm = sb.frame( title: "JGraphX - popup menu on cells", visible: true, size: [400, 150], resizable: true, show:true, contentPane: mxgc, defaultCloseOperation: WindowConstants.EXIT_ON_CLOSE ){ popupMenu(id:"popup"){ menuItem(text:"show cell label", mnemonic: "S", actionPerformed:{ def sm = graph.getSelectionModel() for(cell in sm.getCells()){ println "selected:${graph.getLabel(cell)}" } }) } parent = graph.getDefaultParent() graph.model.beginUpdate() try { def v1 = graph.insertVertex(parent, null, "処理1", 20, 20, 50, 30, "style1") def v2 = graph.insertVertex(parent, null, "処理2", 170, 20, 50, 30, "style2") def v3 = graph.insertVertex(parent, null, "処理3", 320, 20, 50, 30, "style3") graph.insertEdge(parent, null, "正常終了", v1, v2) graph.insertEdge(parent, null, "正常終了", v2, v3) mxgc.getGraphControl().addMouseListener(new MyMouseAdapter(sb, mxgc)) } finally { graph.model.endUpdate() } }実行結果
関連情報
JGraphxのダウンロードページ
0 件のコメント:
コメントを投稿