I use this code to Highlight the vertex I click and its child by changing opacity. It only works however for the next child connected to the vertex I select. How could I do the same thing, clicking a vertex, but highlight also all the vertices connected to its child and the ones that lead to the cicked vertex. Thanks in advance
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);
}
}
}
});
}