Ejemplo 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();
 }
Ejemplo n.º 2
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;
 }
Ejemplo n.º 3
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());
  }