0

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);
                    }
                } 


            }
                });
            }
user2598911
  • 379
  • 2
  • 6
  • 22

1 Answers1

0

Recursion is the answer!

As soon as I will have it handy I will post an explanation and the code I wrote in order to be able to delete a cell and have all its descendant (children, children of childrens and so on) automatically deleted as well. I think it's pretty easy to apply it in this context and I hope you got my hint.

vinnie
  • 189
  • 1
  • 5