0
我使用此代碼通過更改不透明度來突出顯示單擊的頂點及其子級。它只適用於連接到我選擇的頂點的下一個孩子。我怎麼能做同樣的事情,點擊一個頂點,但也要突出顯示所有連接到它的子節點的頂點以及通向頂點的頂點。在此先感謝突出顯示jgraphx中的多個單元格
public void CellHighlight() {
graphComponent.getGraphControl().addMouseListener(new MouseAdapter() {
public void mouseReleased (MouseEvent e1) {
if (e1.getButton() == 1 && e1.getClickCount() == 2) {
final Object selectedCell = graphComponent.getCellAt(e1.getX(), e1.getY());
Object[] allCells = mxGraphModel.getChildren(graph.getModel(), graph.getDefaultParent());
if (selectedCell != null) {
if (graph.getModel().isVertex(selectedCell)) {
for(Object myCell: allCells) {
graph.getView().getState(myCell).getStyle().put(mxConstants.STYLE_OPACITY, OPACITY_PALE);
graph.getView().getState(myCell).getStyle().put(mxConstants.STYLE_TEXT_OPACITY, OPACITY_PALE);
}
List<Object> cellList = new ArrayList<Object>();
cellList.add(selectedCell);
Object[] outgoingEdges = mxGraphModel.getOutgoingEdges(graph.getModel(), selectedCell);
for(Object edge: outgoingEdges) {
cellList.add(graph.getModel().getTerminal(edge, false));
}
cellList.addAll(Arrays.asList(outgoingEdges));
for(Object myCell: cellList) {
graph.getView().getState(myCell).getStyle().put(mxConstants.STYLE_OPACITY, OPACITY_HIGHLIGHT);
graph.getView().getState(myCell).getStyle().put(mxConstants.STYLE_TEXT_OPACITY, OPACITY_HIGHLIGHT);
}
} else {
for(Object myCell: allCells) {
graph.getView().getState(myCell).getStyle().put(mxConstants.STYLE_OPACITY, OPACITY_HIGHLIGHT);
graph.getView().getState(myCell).getStyle().put(mxConstants.STYLE_TEXT_OPACITY, OPACITY_HIGHLIGHT);
}
}
mxRectangle bounds = graph.getBoundsForCells(allCells, true, true, true);
graph.repaint(bounds);
}
}
}
});
}