private void updateMemDisplay() {
   if (product != null) {
     long storageMem = product.getRawStorageSize(productSubsetDef);
     double factor = 1.0 / (1024 * 1024);
     double megas = MathUtils.round(factor * storageMem, 10);
     if (megas > memWarnLimit) {
       memLabel.setForeground(MEM_LABEL_WARN_COLOR);
     } else {
       memLabel.setForeground(MEM_LABEL_NORM_COLOR);
     }
     memLabel.setText(MEM_LABEL_TEXT + megas + "M");
   } else {
     memLabel.setText(" ");
   }
 }
  private static void updateMetadata(
      final Product sourceProduct, final Product targetProduct, ProductSubsetDef subsetDef)
      throws IOException {

    try {
      final MetadataElement root = targetProduct.getMetadataRoot();
      if (root == null) return;

      final MetadataElement absRoot = root.getElement("Abstracted_Metadata");
      if (absRoot == null) return;

      boolean nearRangeOnLeft = isNearRangeOnLeft(targetProduct);

      final MetadataAttribute firstLineTime = absRoot.getAttribute("first_line_time");
      if (firstLineTime != null) {
        final ProductData.UTC startTime = targetProduct.getStartTime();
        if (startTime != null) firstLineTime.getData().setElems(startTime.getArray());
      }
      final MetadataAttribute lastLineTime = absRoot.getAttribute("last_line_time");
      if (lastLineTime != null) {
        final ProductData.UTC endTime = targetProduct.getEndTime();
        if (endTime != null) lastLineTime.getData().setElems(endTime.getArray());
      }
      final MetadataAttribute totalSize = absRoot.getAttribute("total_size");
      if (totalSize != null) totalSize.getData().setElemUInt(targetProduct.getRawStorageSize());

      if (nearRangeOnLeft) {
        setLatLongMetadata(targetProduct, absRoot, "first_near_lat", "first_near_long", 0.5f, 0.5f);
        setLatLongMetadata(
            targetProduct,
            absRoot,
            "first_far_lat",
            "first_far_long",
            targetProduct.getSceneRasterWidth() - 1 + 0.5f,
            0.5f);

        setLatLongMetadata(
            targetProduct,
            absRoot,
            "last_near_lat",
            "last_near_long",
            0.5f,
            targetProduct.getSceneRasterHeight() - 1 + 0.5f);
        setLatLongMetadata(
            targetProduct,
            absRoot,
            "last_far_lat",
            "last_far_long",
            targetProduct.getSceneRasterWidth() - 1 + 0.5f,
            targetProduct.getSceneRasterHeight() - 1 + 0.5f);
      } else {
        setLatLongMetadata(
            targetProduct,
            absRoot,
            "first_near_lat",
            "first_near_long",
            targetProduct.getSceneRasterWidth() - 1 + 0.5f,
            0.5f);
        setLatLongMetadata(targetProduct, absRoot, "first_far_lat", "first_far_long", 0.5f, 0.5f);

        setLatLongMetadata(
            targetProduct,
            absRoot,
            "last_near_lat",
            "last_near_long",
            targetProduct.getSceneRasterWidth() - 1 + 0.5f,
            targetProduct.getSceneRasterHeight() - 1 + 0.5f);
        setLatLongMetadata(
            targetProduct,
            absRoot,
            "last_far_lat",
            "last_far_long",
            0.5f,
            targetProduct.getSceneRasterHeight() - 1 + 0.5f);
      }

      final MetadataAttribute height = absRoot.getAttribute("num_output_lines");
      if (height != null) height.getData().setElemUInt(targetProduct.getSceneRasterHeight());

      final MetadataAttribute width = absRoot.getAttribute("num_samples_per_line");
      if (width != null) width.getData().setElemUInt(targetProduct.getSceneRasterWidth());

      final MetadataAttribute offsetX = absRoot.getAttribute("subset_offset_x");
      if (offsetX != null && subsetDef.getRegion() != null)
        offsetX.getData().setElemUInt(subsetDef.getRegion().x);

      final MetadataAttribute offsetY = absRoot.getAttribute("subset_offset_y");
      if (offsetY != null && subsetDef.getRegion() != null)
        offsetY.getData().setElemUInt(subsetDef.getRegion().y);

      final MetadataAttribute slantRange = absRoot.getAttribute("slant_range_to_first_pixel");
      if (slantRange != null) {
        final TiePointGrid srTPG = targetProduct.getTiePointGrid("slant_range_time");
        if (srTPG != null) {
          final double slantRangeTime;
          if (nearRangeOnLeft) {
            slantRangeTime = srTPG.getPixelDouble(0, 0) / 1000000000.0; // ns to s
          } else {
            slantRangeTime =
                srTPG.getPixelDouble(targetProduct.getSceneRasterWidth() - 1, 0)
                    / 1000000000.0; // ns to s
          }
          final double halfLightSpeed = 299792458.0 / 2.0;
          final double slantRangeDist = slantRangeTime * halfLightSpeed;
          slantRange.getData().setElemDouble(slantRangeDist);
        }
      }

      setSubsetSRGRCoefficients(sourceProduct, targetProduct, subsetDef, absRoot, nearRangeOnLeft);
    } catch (Exception e) {
      throw new IOException(e);
    }
  }