/** Creates the images composing the grid when the color model is <code>GreyScale</code>. */
  private void createGridImagesForGreyScale() {
    int maxC = parent.getMaxC();
    List l = parent.getActiveChannelsInGrid();
    int n = l.size();
    clearList(gridImages);
    if (combinedImage != null) combinedImage.flush();
    switch (n) {
      case 0:
        for (int i = 0; i < maxC; i++) gridImages.add(null);
        combinedImage = null;
        break;
      case 1:
      case 2:
      case 3:
        if (isImageMappedRGB(l)) {
          BufferedImage image = parent.getCombinedGridImage();
          if (image == null) {
            for (int i = 0; i < maxC; i++) gridImages.add(null);
            break;
          }
          combinedImage = Factory.magnifyImage(gridRatio, image);

          int w = combinedImage.getWidth();
          int h = combinedImage.getHeight();

          DataBuffer buf = combinedImage.getRaster().getDataBuffer();
          List<ChannelData> list = parent.getSortedChannelData();
          Iterator<ChannelData> i = list.iterator();
          int index;
          while (i.hasNext()) {
            index = i.next().getIndex();
            if (l.contains(index)) {
              if (parent.isChannelRed(index)) {
                gridImages.add(
                    Factory.createBandImage(
                        buf, w, h, Factory.RED_MASK, Factory.RED_MASK, Factory.RED_MASK));
              } else if (parent.isChannelGreen(index)) {
                gridImages.add(
                    Factory.createBandImage(
                        buf, w, h, Factory.GREEN_MASK, Factory.GREEN_MASK, Factory.GREEN_MASK));
              } else if (parent.isChannelBlue(index)) {
                gridImages.add(
                    Factory.createBandImage(
                        buf, w, h, Factory.BLUE_MASK, Factory.BLUE_MASK, Factory.BLUE_MASK));
              }
            } else {
              gridImages.add(null);
            }
          }
        } else {
          retrieveGridImagesForGreyScale(l);
        }
        break;

      default:
        retrieveGridImagesForGreyScale(l);
    }
  }
 /** Creates the images composing the grid. */
 private void createGridImages() {
   // if (combinedImage == null) return;
   if (originalGridImages == null) originalGridImages = new ArrayList<BufferedImage>();
   clearList(gridImages);
   if (ImViewer.GREY_SCALE_MODEL.equals(parent.getColorModel())) {
     createGridImagesForGreyScale();
     return;
   }
   List l = parent.getActiveChannels();
   int maxC = parent.getMaxC();
   switch (l.size()) {
     case 0:
       for (int i = 0; i < maxC; i++) gridImages.add(null);
       break;
     case 1:
     case 2:
     case 3:
       if (isImageMappedRGB(l) && !parent.isCompressed()) {
         combinedImage = null;
         combinedImage = Factory.magnifyImage(gridRatio, renderedImage);
         int w = combinedImage.getWidth();
         int h = combinedImage.getHeight();
         DataBuffer buf = combinedImage.getRaster().getDataBuffer();
         List<ChannelData> list = parent.getSortedChannelData();
         Iterator<ChannelData> i = list.iterator();
         int index;
         while (i.hasNext()) {
           index = i.next().getIndex();
           if (parent.isChannelActive(index)) {
             if (parent.isChannelRed(index)) {
               gridImages.add(
                   Factory.createBandImage(
                       buf, w, h, Factory.RED_MASK, Factory.BLANK_MASK, Factory.BLANK_MASK));
             } else if (parent.isChannelGreen(index)) {
               gridImages.add(
                   Factory.createBandImage(
                       buf, w, h, Factory.BLANK_MASK, Factory.GREEN_MASK, Factory.BLANK_MASK));
             } else if (parent.isChannelBlue(index)) {
               gridImages.add(
                   Factory.createBandImage(
                       buf, w, h, Factory.BLANK_MASK, Factory.BLANK_MASK, Factory.BLUE_MASK));
             }
           } else {
             gridImages.add(null);
           }
         }
       } else {
         retrieveGridImages();
       }
       break;
     default:
       retrieveGridImages();
   }
 }
 /**
  * Retrieves the images composing the grid when the color model is <code>RBG</code> and when the
  * channels are not mapped to red, green or blue i.e. a channel mapped to yellow.
  */
 private void retrieveGridImages() {
   List<BufferedImage> images = parent.getGridImages();
   if (images != null) {
     Iterator<BufferedImage> i = images.iterator();
     boolean b = originalGridImages.size() == 0;
     BufferedImage img;
     while (i.hasNext()) {
       img = i.next();
       gridImages.add(Factory.magnifyImage(img, gridRatio, 0));
       if (b) originalGridImages.add(img);
     }
     combinedImage = Factory.magnifyImage(renderedImage, gridRatio, 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()));
       }
   }
 }
 /**
  * Loads the thumbnails for the passed collection of files.
  *
  * @param files The collection of files to handle.
  */
 private void loadFSThumbnails(List files) {
   List result = new ArrayList();
   try {
     ExperimenterData exp = (ExperimenterData) context.lookup(LookupNames.CURRENT_USER_DETAILS);
     long id = exp.getId();
     Map<DataObject, BufferedImage> m = service.getFSThumbnailSet(ctx, files, maxLength, id);
     Entry<DataObject, BufferedImage> entry;
     Iterator<Entry<DataObject, BufferedImage>> i = m.entrySet().iterator();
     BufferedImage thumb;
     DataObject obj;
     boolean valid = true;
     FileData f;
     while (i.hasNext()) {
       entry = i.next();
       obj = entry.getKey();
       thumb = entry.getValue();
       if (thumb == null) {
         thumb = Factory.createDefaultImageThumbnail(Factory.IMAGE_ICON);
       }
       if (obj.getId() > 0) result.add(new ThumbnailData(obj.getId(), thumb, valid));
       else result.add(new ThumbnailData(obj, thumb, valid));
     }
     currentThumbs = result;
   } catch (Exception e) {
     currentThumbs = result;
     context.getLogger().error(this, "Cannot retrieve thumbnail: " + e.getMessage());
   }
 }
  /**
   * Creates a concrete loader.
   *
   * @see DataBrowserModel#createDataLoader(boolean, Collection)
   */
  protected List<DataBrowserLoader> createDataLoader(boolean refresh, Collection ids) {
    if (!withThumbnails) return null;
    List<ImageDisplay> l = getNodes();
    Iterator<ImageDisplay> i = l.iterator();
    ImageSet node;
    List<DataObject> images = new ArrayList<DataObject>();
    ImageNode selected;
    WellSampleData data;
    Thumbnail thumb;
    while (i.hasNext()) {
      node = (ImageSet) i.next();
      if (node instanceof WellImageSet) {
        selected = ((WellImageSet) node).getSelectedWellSample();
        data = (WellSampleData) selected.getHierarchyObject();
        if (data.getId() < 0) {
          thumb = selected.getThumbnail();
          thumb.setValid(false);
          thumb.setFullScaleThumb(
              Factory.createDefaultImageThumbnail(wellDimension.width, wellDimension.height));
        } else images.add(data.getImage());
      }
    }

    if (images.size() == 0) return null;
    return createThumbnailsLoader(sorter.sort(images));
  }
 /**
  * Retrieves the images composing the grid when the color model is <code>GreyScale</code> and when
  * the channels are not mapped to red, green or blue i.e. a channel mapped to yellow.
  *
  * @param channels Collection of active channels in the grid.
  */
 private void retrieveGridImagesForGreyScale(List channels) {
   List<BufferedImage> images = parent.getGridImages();
   if (images != null) {
     int last = images.size() - 1;
     combinedImage = Factory.magnifyImage(gridRatio, images.get(last));
     images.remove(last);
     Iterator<BufferedImage> i = images.iterator();
     boolean b = originalGridImages.size() == 0 && !isImageMappedRGB(channels);
     BufferedImage img;
     while (i.hasNext()) {
       img = i.next();
       gridImages.add(Factory.magnifyImage(gridRatio, img));
       if (b) originalGridImages.add(img);
     }
   }
 }
 /**
  * Sets the image representing the file.
  *
  * @param path The path to the file.
  */
 void setThumbnail(String path) {
   if (path == null) return;
   this.thumbnail =
       Factory.createIcon(path, Factory.THUMB_DEFAULT_WIDTH / 2, Factory.THUMB_DEFAULT_HEIGHT / 2);
   if (thumbnail != null) {
     label.setText("");
     label.setIcon(thumbnail);
     label.repaint();
     revalidate();
     repaint();
   }
 }
Exemple #9
0
  /**
   * Writes the image.
   *
   * @param image The image to write to the file.
   * @param n The name of the image.
   * @throws EncoderException
   * @throws IOException
   */
  private void writeImage(BufferedImage image, String n) throws EncoderException, IOException {
    // n += "."+format;
    String extendedName = getExtendedName(n, format);
    File f = new File(extendedName);
    if (TIFFFilter.TIF.equals(format)) {
      Encoder encoder =
          new TIFFEncoder(
              Factory.createImage(image), new DataOutputStream(new FileOutputStream(f)));
      WriterImage.saveImage(encoder);
    } else WriterImage.saveImage(f, image, format);

    close();
  }
 /**
  * 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;
 }
  /**
   * Creates a concrete loader.
   *
   * @param row The row identifying the well.
   * @param column The column identifying the well.
   * @return See above.
   */
  DataBrowserLoader createFieldsLoader(int row, int column) {
    List<ImageDisplay> l = getNodes();
    Iterator<ImageDisplay> i = l.iterator();
    ImageSet node;
    List<DataObject> images = new ArrayList<DataObject>();
    WellSampleData data;
    Thumbnail thumb;
    WellImageSet wis;
    List<WellSampleNode> nodes;
    Iterator<WellSampleNode> j;
    WellSampleNode n;
    if (selectedNodes != null) selectedNodes.clear();
    while (i.hasNext()) {
      node = (ImageSet) i.next();
      if (node instanceof WellImageSet) {
        wis = (WellImageSet) node;
        if (wis.getRow() == row && wis.getColumn() == column) {
          setSelectedWell(wis);
          nodes = wis.getWellSamples();
          j = nodes.iterator();
          while (j.hasNext()) {
            n = j.next();
            data = (WellSampleData) n.getHierarchyObject();

            if (data.getId() < 0) {
              thumb = n.getThumbnail();
              thumb.setValid(false);
              thumb.setFullScaleThumb(
                  Factory.createDefaultImageThumbnail(wellDimension.width, wellDimension.height));
            } else images.add(data.getImage());
          }
        }
      }
    }

    if (images.size() == 0) return null;
    return new ThumbnailFieldsLoader(component, ctx, images, row, column);
  }
 /**
  * Sets the photo of the user.
  *
  * @param image The image to set.
  */
 void setUserPhoto(BufferedImage image) {
   if (image == null) return;
   BufferedImage img = Factory.scaleBufferedImage(image, UserProfileCanvas.WIDTH);
   userPicture.setImage(img);
 }
 /**
  * Creates a default thumbnail for the passed pixels set.
  *
  * @param pxd The pixels set to handle.
  * @return See above.
  */
 private BufferedImage createDefaultImage(PixelsData pxd) {
   if (pxd == null) return Factory.createDefaultImageThumbnail(-1);
   Dimension d =
       Factory.computeThumbnailSize(maxLength, maxLength, pxd.getSizeX(), pxd.getSizeY());
   return Factory.createDefaultImageThumbnail(d.width, d.height);
 }
  /** Save the results to an Excel File. */
  private void saveResults() {
    channelsSelectionForm = new ChannelSelectionForm(channelName);
    FileChooser chooser = view.createSaveToExcelChooser();
    chooser.addComponentToControls(channelsSelectionForm);
    int results = chooser.showDialog();
    if (results != JFileChooser.APPROVE_OPTION) return;
    File file = chooser.getFormattedSelectedFile();
    // TODO: Modify that code when we have various writer.

    if (!file.getAbsolutePath().endsWith(ExcelFilter.EXCEL)) {
      String fileName = file.getAbsolutePath() + "." + ExcelFilter.EXCEL;
      file = new File(fileName);
    }

    List<Integer> channels = channelsSelectionForm.getUserSelection();
    if (channels == null || channels.size() == 0) {
      UserNotifier un = MeasurementAgent.getRegistry().getUserNotifier();
      un.notifyInfo("Save Results", " Please select at least a channel.");
      view.setStatus("No Channel selected to output.");

      return;
    }

    try {
      ExcelWriter writer = new ExcelWriter(file.getAbsolutePath());
      writer.openFile();
      writer.createSheet("Channel Summary");
      Iterator<Coord3D> coordMapIterator = shapeMap.keySet().iterator();
      Coord3D currentCoord;
      int n = channels.size();
      Integer channel;
      if (channelSummarySelected(channels)) outputSummary(writer, shapeMap);
      BufferedImage originalImage = model.getRenderedImage();
      if (originalImage != null) {
        BufferedImage image = Factory.copyBufferedImage(originalImage);

        // Add the ROI for the current plane to the image.
        // TODO: Need to check that.
        model.setAttributes(MeasurementAttributes.SHOWID, true);
        model.getDrawingView().print(image.getGraphics());
        model.setAttributes(MeasurementAttributes.SHOWID, false);
        try {
          writer.addImageToWorkbook("ThumbnailImage", image);
        } catch (Exception e) {
          // TODO
        }
        int col = writer.getMaxColumn(0);
        writer.writeImage(0, col + 1, 256, 256, "ThumbnailImage");
      }
      if (channelSummarySelected(channels) && channels.size() != 1)
        while (coordMapIterator.hasNext()) {
          currentCoord = coordMapIterator.next();
          for (int i = 0; i < n; i++) {
            channel = channels.get(i);
            if (channel == ChannelSelectionForm.SUMMARYVALUE) continue;
            if (!nameMap.containsKey(channelName.get(channel))) continue;
            int rowIndex = 0;

            writer.createSheet("Channel Number " + channelName.get(channel));
            writeHeader(writer, rowIndex, currentCoord);
            channel = nameMap.get(channelName.get(channel));
            writeData(writer, rowIndex, currentCoord, channel.intValue());
          }
        }
      writer.close();
    } catch (Exception e) {
      Logger logger = MeasurementAgent.getRegistry().getLogger();
      logger.error(this, "Cannot save ROI results: " + e.toString());

      UserNotifier un = MeasurementAgent.getRegistry().getUserNotifier();
      String message = "An error occurred while trying to" + " save the data.\nPlease try again.";
      if (e instanceof NumberFormatException) {
        message =
            "We only support the British/American style of "
                + "representing numbers,\nusing a decimal point rather "
                + "than a comma.";
      }
      un.notifyInfo("Save Results", message);
      return;
    }

    Registry reg = MeasurementAgent.getRegistry();
    UserNotifier un = reg.getUserNotifier();
    un.notifyInfo("Save ROI results", "The ROI results have been " + "successfully saved.");
  }