private void exportROI(ROI roi) {
   final String imageType = "tiff";
   final Integer tempInteger = (Integer) jSpinnerJpegQuality.getValue();
   final float jpegQuality = Math.round(((float) (tempInteger.floatValue())) / 100);
   for (int i = 0; i < 9999; i++) {
     String num = i == 0 ? "" : "_" + String.valueOf(i);
     File outFile =
         new File(
             jFileChooserOutputDir.getSelectedFile()
                 + File.separator
                 + roi.getName()
                 + num
                 + "."
                 + imageType);
     if (outFile.exists()) {
       continue;
     }
     String result = imageSource.exportROI(roi, outFile, jpegQuality);
     System.out.println(result);
     AdvancedVirtualMicroscope.setStatusText(result, 5000);
   }
 }
 private void jButtonExportActionPerformed(
     java.awt.event.ActionEvent evt) { // GEN-FIRST:event_jButtonExportActionPerformed
   int count = 0;
   for (Object obj : exportObjs) {
     if (obj instanceof ROI) {
       count++;
     }
     if (obj instanceof ROI_Folder) {
       ArrayList<ROI> rois = ((ROI_Folder) obj).getROIs();
       count += rois.size();
     }
   }
   UIManager.put("ProgressBar[Enabled].foregroundPainter", new ProgressBarForegroundPainter());
   final AVM_ProgressMonitor pm =
       new AVM_ProgressMonitor(rootPane, "Exporting ROIs", "", 0, count + 1);
   Executors.newSingleThreadExecutor()
       .submit(
           () -> {
             int progress = 0;
             for (Object obj : exportObjs) {
               if (obj instanceof ROI) {
                 ROI roi = (ROI) obj;
                 pm.setNote("Exporting " + roi.getParent().toString() + "\"" + roi.toString());
                 pm.setProgress(progress++);
                 exportROI(roi);
                 if (pm.isCanceled()) {
                   return;
                 }
               }
               if (obj instanceof ROI_Folder) {
                 ArrayList<ROI> rois = ((ROI_Folder) obj).getROIs();
                 for (ROI roi : rois) {
                   pm.setNote("Exporting " + roi.getParent().toString() + "\"" + roi.toString());
                   pm.setProgress(progress++);
                   exportROI(roi);
                   if (pm.isCanceled()) {
                     return;
                   }
                 }
               }
             }
             pm.close();
             setVisible(false);
           });
 } // GEN-LAST:event_jButtonExportActionPerformed