Exemple #1
0
 /**
  * Returns <code>true</code> if the unit bar is painted on top of the displayed image, <code>false
  * </code> otherwise.
  *
  * @return See above.
  */
 boolean isUnitBar() {
   return model.isUnitBar();
 }
Exemple #2
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());
  }