Exemple #1
0
  @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;
  }