@Override public void selectionChanged(SelectionChangeEvent event) { if (DEBUG_SELECTION) System.out.println( "[TrackSchemeFrame] selectionChanged: received event " + event.hashCode() + " from " + event.getSource() + ". Fire flag is " + doFireSelectionChangeEvent); if (!doFireSelectionChangeEvent) return; doFireSelectionChangeEvent = false; { ArrayList<Object> newSelection = new ArrayList<Object>( selectionModel.getSpotSelection().size() + selectionModel.getEdgeSelection().size()); Iterator<DefaultWeightedEdge> edgeIt = selectionModel.getEdgeSelection().iterator(); while (edgeIt.hasNext()) { mxICell cell = graph.getCellFor(edgeIt.next()); if (null != cell) { newSelection.add(cell); } } Iterator<Spot> spotIt = selectionModel.getSpotSelection().iterator(); while (spotIt.hasNext()) { mxICell cell = graph.getCellFor(spotIt.next()); if (null != cell) { newSelection.add(cell); } } mxGraphSelectionModel mGSmodel = graph.getSelectionModel(); mGSmodel.setCells(newSelection.toArray()); } // Center on selection if we added one spot exactly Map<Spot, Boolean> spotsAdded = event.getSpots(); if (spotsAdded != null && spotsAdded.size() == 1) { boolean added = spotsAdded.values().iterator().next(); if (added) { Spot spot = spotsAdded.keySet().iterator().next(); centerViewOn(spot); } } doFireSelectionChangeEvent = true; }
/** Used to instantiate and configure the {@link JGraphXAdapter} that will be used for display. */ private JGraphXAdapter createGraph() { gui.logger.setStatus("Creating graph adapter."); final JGraphXAdapter graph = new JGraphXAdapter(model); graph.setAllowLoops(false); graph.setAllowDanglingEdges(false); graph.setCellsCloneable(false); graph.setCellsSelectable(true); graph.setCellsDisconnectable(false); graph.setCellsMovable(true); graph.setGridEnabled(false); graph.setLabelsVisible(true); graph.setDropEnabled(false); // Cells removed from JGraphX graph.addListener(mxEvent.CELLS_REMOVED, new CellRemovalListener()); // Cell selection change graph.getSelectionModel().addListener(mxEvent.CHANGE, new SelectionChangeListener()); // Return graph return graph; }