Esempio n. 1
0
 /**
  * Handles the exception thrown if any while creating the images for the split view.
  *
  * @param e The exception to handle.
  */
 private void handleGridImageCreationException(Exception e) {
   UserNotifier un = ImViewerAgent.getRegistry().getUserNotifier();
   un.notifyInfo("Split View", "Unable to create the images for the view");
   LogMessage msg = new LogMessage();
   msg.print("Grid Images creation");
   msg.print(e);
   ImViewerAgent.getRegistry().getLogger().error(this, msg);
   gridImages.clear();
   gridImagesAsTextures.clear();
 }
Esempio n. 2
0
 /** Sets the images composing the grid. */
 void setGridImages() {
   if (gridImages.size() != 0) return;
   clearList(originalGridImages);
   if (gridImagesAsTextures.size() != 0) return;
   try {
     if (ImViewerAgent.hasOpenGLSupport()) createGridImagesAsTextures();
     else createGridImages();
   } catch (Exception e) {
     handleGridImageCreationException(e);
   }
 }
Esempio n. 3
0
 /**
  * Creates the {@link #displayedImage}. The method should be invoked after the {@link
  * #setRenderedImage(BufferedImage)} method.
  */
 void createDisplayedProjectedImage() {
   if (projectedImage == null) return;
   if (displayedProjectedImage != null) displayedProjectedImage.flush();
   if (zoomFactor != ZoomAction.DEFAULT_ZOOM_FACTOR) {
     BufferedImage img = null;
     try {
       img = Factory.magnifyImage(projectedImage, zoomFactor, 0);
     } catch (Throwable e) {
       UserNotifier un = ImViewerAgent.getRegistry().getUserNotifier();
       un.notifyInfo("Magnification", "An error occurred while magnifying the image.");
     }
     if (img != null) displayedProjectedImage = img;
   } else displayedProjectedImage = projectedImage;
 }
Esempio n. 4
0
 /**
  * Sets the ratio of the grid image.
  *
  * @param gridRatio The value to set.
  */
 void setGridRatio(double gridRatio) {
   // if (ratio == 1) return; //We don't want to be too small.
   double max = ZoomGridAction.MAX_ZOOM_FACTOR;
   if (gridRatio > max) return;
   this.gridRatio = gridRatio;
   if (ImViewerAgent.hasOpenGLSupport()) return;
   if (CollectionUtils.isEmpty(originalGridImages)) {
     try {
       createGridImages();
     } catch (Exception e) {
       handleGridImageCreationException(e);
     }
     return;
   }
   int n = originalGridImages.size();
   clearList(gridImages);
   int maxC = parent.getMaxC();
   switch (n) {
     case 0:
       for (int i = 0; i < maxC; i++) gridImages.add(null);
       break;
     case 1:
     case 2:
     case 3:
       // TODO: Review that code.
       if (isImageMappedRGB(parent.getActiveChannels())) {
         try {
           createGridImages();
         } catch (Exception e) {
           handleGridImageCreationException(e);
         }
       } else {
         combinedImage = null;
         combinedImage = Factory.magnifyImage(gridRatio, renderedImage);
         Iterator<BufferedImage> i = originalGridImages.iterator();
         while (i.hasNext()) {
           gridImages.add(Factory.magnifyImage(gridRatio, i.next()));
         }
       }
       break;
     default:
       combinedImage = null;
       combinedImage = Factory.magnifyImage(gridRatio, renderedImage);
       Iterator<BufferedImage> i = originalGridImages.iterator();
       while (i.hasNext()) {
         gridImages.add(Factory.magnifyImage(gridRatio, i.next()));
       }
   }
 }
Esempio n. 5
0
  /**
   * Saves the displayed images.
   *
   * @param init Pass <code>true</code> to initialize the images to save, <code>false</code>
   *     otherwise.
   */
  void saveImage(boolean init) {
    UserNotifier un = ImViewerAgent.getRegistry().getUserNotifier();
    if (init) createImages(uiDelegate.getSavingType());
    // Builds the image to display.
    boolean unitBar = model.isUnitBar();
    String v = getUnitBarValue();
    int s = (int) getUnitBarSize();
    boolean constrain;
    try {
      String name = uiDelegate.getSelectedFilePath();

      // make sure the parent directory paths all exist
      FileUtils.forceMkdir(new File(name).getParentFile());

      if (imageComponents == null) {
        constrain =
            unitBar && v != null && s < mainImage.getWidth() && imageType == ImgSaverUI.IMAGE;
        writeSingleImage(mainImage, constrain, name);
      } else {
        if (mainImage == null) return;
        Iterator i;
        int h, w;
        BufferedImage newImage;
        Graphics2D g2;
        if (uiDelegate.isSaveImagesInSeparatedFiles()) {
          constrain =
              unitBar && v != null && s < mainImage.getWidth() && imageType == ImgSaverUI.IMAGE;
          writeSingleImage(mainImage, constrain, name);
          i = imageComponents.iterator();
          int j = 0;
          while (i.hasNext()) {
            constrain = unitBar && v != null && imageType != ImgSaverUI.LENS_IMAGE_AND_COMPONENTS;
            writeSingleImage((BufferedImage) i.next(), constrain, name + "_" + j);
            j++;
          }
        } else {
          int width = mainImage.getWidth();
          h = mainImage.getHeight();
          int n = imageComponents.size();
          w = width * (n + 1) + ImgSaverPreviewer.SPACE * (n - 1);

          newImage = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
          g2 = (Graphics2D) newImage.getGraphics();
          g2.setColor(Color.WHITE);
          ImagePaintingFactory.setGraphicRenderingSettings(g2);
          // Paint the original image.
          i = imageComponents.iterator();
          int x = 0;
          while (i.hasNext()) {
            g2.drawImage((BufferedImage) i.next(), null, x, 0);
            if (unitBar && v != null && imageType != ImgSaverUI.LENS_IMAGE_AND_COMPONENTS)
              ImagePaintingFactory.paintScaleBar(g2, x + width - s - 10, h - 10, s, v);
            x += width;
            g2.fillRect(x, 0, ImgSaverPreviewer.SPACE, h);
            x += ImgSaverPreviewer.SPACE;
          }
          g2.drawImage(mainImage, null, x, 0);
          if (unitBar
              && v != null
              && !(imageType == ImgSaverUI.LENS_IMAGE_AND_COMPONENTS
                  || imageType == ImgSaverUI.LENS_IMAGE))
            ImagePaintingFactory.paintScaleBar(g2, x + width - s - 10, h - 10, s, v);
          writeImage(newImage, name);
        }
      }
    } catch (Exception e) {
      if (e instanceof IOException || e.getCause() instanceof IOException)
        un.notifyInfo(
            "Save Image failure",
            "Could not access file "
                + uiDelegate.getSelectedFilePath()
                + "\nMake sure you have the necessary permissions to perform this action.");
      else un.notifyError("Save Image failure", "An error occurred while saving the image.", e);
      return;
    }
    notifySave(getExtendedName(uiDelegate.getSelectedFilePath(), format));
    if (uiDelegate.isSetDefaultFolder())
      UIUtilities.setDefaultFolder(uiDelegate.getCurrentDirectory());
  }