Example #1
0
  /**
   * Updates or creates a cell for the target spot. Is called after the user modified a spot
   * (location, radius, ...) somewhere else.
   *
   * @param spot the spot that was modified.
   */
  private mxICell updateCellOf(final Spot spot) {

    mxICell cell = graph.getCellFor(spot);
    graph.getModel().beginUpdate();
    try {
      if (DEBUG) System.out.println("[TrackScheme] modelChanged: updating cell for spot " + spot);
      if (null == cell) {
        // mxCell not present in graph. Most likely because the corresponding spot belonged
        // to an invisible track, and a cell was not created for it when TrackScheme was
        // launched. So we create one on the fly now.
        int row = getUnlaidSpotColumn();
        cell = insertSpotInGraph(spot, row);
        int frame = spot.getFeature(Spot.FRAME).intValue();
        rowLengths.put(frame, row + 1);
      }

      // Update cell look
      if (spotImageUpdater != null && doThumbnailCapture) {
        String style = cell.getStyle();
        String imageStr = spotImageUpdater.getImageString(spot);
        style =
            mxStyleUtils.setStyle(style, mxConstants.STYLE_IMAGE, "data:image/base64," + imageStr);
        graph.getModel().setStyle(cell, style);
      }
    } finally {
      graph.getModel().endUpdate();
    }
    return cell;
  }
Example #2
0
  /**
   * Captures and stores the thumbnail image that will be displayed in each spot cell, when using
   * styles that can display images.
   */
  private void createThumbnails() {
    // Group spots per frame
    Set<Integer> frames = model.getSpots().keySet();
    final HashMap<Integer, HashSet<Spot>> spotPerFrame =
        new HashMap<Integer, HashSet<Spot>>(frames.size());
    for (Integer frame : frames) {
      spotPerFrame.put(
          frame, new HashSet<Spot>(model.getSpots().getNSpots(frame, true))); // max size
    }
    for (Integer trackID : model.getTrackModel().trackIDs(true)) {
      for (Spot spot : model.getTrackModel().trackSpots(trackID)) {
        int frame = spot.getFeature(Spot.FRAME).intValue();
        spotPerFrame.get(frame).add(spot);
      }
    }
    // Set spot image to cell style
    if (null != spotImageUpdater) {
      gui.logger.setStatus("Collecting spot thumbnails.");
      int index = 0;
      try {
        graph.getModel().beginUpdate();

        // Iterate per frame
        for (Integer frame : frames) {
          for (Spot spot : spotPerFrame.get(frame)) {

            mxICell cell = graph.getCellFor(spot);
            String imageStr = spotImageUpdater.getImageString(spot);
            String style = cell.getStyle();
            style =
                mxStyleUtils.setStyle(
                    style, mxConstants.STYLE_IMAGE, "data:image/base64," + imageStr);
            graph.getModel().setStyle(cell, style);
          }
          gui.logger.setProgress((double) index++ / frames.size());
        }
      } finally {
        graph.getModel().endUpdate();
        gui.logger.setProgress(0d);
        gui.logger.setStatus("");
        thumbnailCaptured = true; // After that they will be kept in synch thanks to #modelChanged
      }
    }
  }
Example #3
0
 /**
  * Insert a spot in the {@link TrackSchemeFrame}, by creating a {@link mxCell} in the graph model
  * of this frame and position it according to its feature.
  */
 private mxICell insertSpotInGraph(Spot spot, int targetColumn) {
   mxICell cellAdded = graph.getCellFor(spot);
   if (cellAdded != null) {
     // cell for spot already exist, do nothing and return original spot
     return cellAdded;
   }
   // Instantiate JGraphX cell
   cellAdded = graph.addJGraphTVertex(spot);
   // Position it
   int row = spot.getFeature(Spot.FRAME).intValue() + 1;
   double x = (targetColumn - 1) * X_COLUMN_SIZE - DEFAULT_CELL_WIDTH / 2;
   double y = (0.5 + row) * Y_COLUMN_SIZE - DEFAULT_CELL_HEIGHT / 2;
   mxGeometry geometry = new mxGeometry(x, y, DEFAULT_CELL_WIDTH, DEFAULT_CELL_HEIGHT);
   cellAdded.setGeometry(geometry);
   // Set its style
   if (null != spotImageUpdater && doThumbnailCapture) {
     String imageStr = spotImageUpdater.getImageString(spot);
     graph
         .getModel()
         .setStyle(cellAdded, mxConstants.STYLE_IMAGE + "=" + "data:image/base64," + imageStr);
   }
   return cellAdded;
 }