我想在图形上实现一个选择事件监听器来改变所选顶点的样式。
我尝试了以下内容:
String[] events =
{mxEvent.ADD, mxEvent.ADD_CELLS, mxEvent.ADD_OVERLAY, mxEvent.AFTER_PAINT,
mxEvent.ALIGN_CELLS, mxEvent.BEFORE_PAINT, mxEvent.BEFORE_UNDO,
mxEvent.BEGIN_UPDATE, mxEvent.CELL_CONNECTED, mxEvent.CELLS_ADDED,
mxEvent.CELLS_FOLDED, mxEvent.CELLS_MOVED, mxEvent.CELLS_ORDERED,
mxEvent.CELLS_REMOVED, mxEvent.CELLS_RESIZED, mxEvent.CELLS_TOGGLED,
mxEvent.CHANGE, mxEvent.CLEAR, mxEvent.CONNECT, mxEvent.CONNECT_CELL,
mxEvent.CONTINUE, mxEvent.DONE, mxEvent.DOWN, mxEvent.END_UPDATE,
mxEvent.EXECUTE, mxEvent.FIRED, mxEvent.FLIP_EDGE, mxEvent.FOLD_CELLS,
mxEvent.GROUP_CELLS, mxEvent.INSERT, mxEvent.LABEL_CHANGED,
mxEvent.LAYOUT_CELLS, mxEvent.MARK, mxEvent.MOVE_CELLS, mxEvent.NOTIFY,
mxEvent.ORDER_CELLS, mxEvent.PAINT, mxEvent.REDO, mxEvent.REMOVE_CELLS,
mxEvent.REMOVE_CELLS_FROM_PARENT, mxEvent.REMOVE_OVERLAY, mxEvent.REPAINT,
mxEvent.RESIZE_CELLS, mxEvent.ROOT, mxEvent.SCALE,
mxEvent.SCALE_AND_TRANSLATE, mxEvent.SELECT, mxEvent.SPLIT_EDGE,
mxEvent.START, mxEvent.START_EDITING, mxEvent.STOP, mxEvent.TOGGLE_CELLS,
mxEvent.TRANSLATE, mxEvent.UNDO, mxEvent.UNGROUP_CELLS, mxEvent.UP,
mxEvent.UPDATE_CELL_SIZE};
for (String event : events) {
jgxAdapter.addListener(event, new mxEventSource.mxIEventListener() {
@Override
public void invoke(Object sender, mxEventObject evt) {
System.out.println(evt.getName());
}
});
}
但是在控制台中打印的唯一事件是:
cellsAdded, addCells, cellsResized, updateCellSize, repaint and cellConnected
如何使用jgraphx
或jgrapht
答案 0 :(得分:1)
选择事件为mxEvent.CHANGE
,应通过mxGraphSelectionModel
收听。
jgxAdapter.getSelectionModel().addListener(mxEvent.CHANGE, new mxIEventListener() {
@Override
public void invoke(Object sender, mxEventObject evt) {
mxGraphSelectionModel sm = (mxGraphSelectionModel) sender;
mxCell cell = (mxCell) sm.getCell();
if (cell != null && cell.isVertex()) {
//do something
}
}
});