我使用此代码通过更改不透明度来突出显示我单击的顶点及其子项。它只适用于连接到我选择的顶点的下一个子节点。我怎么能做同样的事情,点击一个顶点,但也要突出显示连接到它的子节点的所有顶点以及通向顶点的顶点。提前致谢
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);
}
}
}
});
}
答案 0 :(得分:0)
递归就是答案!
一旦我有方便的话,我会发布一个解释和我写的代码,以便能够删除一个单元格并让其所有后代(儿童,孩子的孩子等)自动删除。我认为在这种情况下应用它非常容易,我希望你得到我的暗示。