图上的选择事件侦听器

Selection event listener on graph

我想在图表上实现一个选择事件侦听器,以更改所选顶点的样式。

我试过以下方法:

    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

如何使用 jgraphxjgrapht 捕获选择事件?

选择事件是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
            }
        }

    });