Ejemplo n.º 1
0
 /** Launches a dialog to select the file to attach to the <code>DataObject</code>. */
 private void selectFileToAttach() {
   JFrame owner = MetadataViewerAgent.getRegistry().getTaskBar().getFrame();
   FileChooser chooser =
       new FileChooser(
           owner, FileChooser.LOAD, "Choose File", "Select the file to attach.", filters, true);
   chooser.setMultiSelectionEnabled(true);
   IconManager icons = IconManager.getInstance();
   chooser.setTitleIcon(icons.getIcon(IconManager.ATTACHMENT_48));
   chooser.setApproveButtonText("Attach");
   chooser.addPropertyChangeListener(FileChooser.APPROVE_SELECTION_PROPERTY, this);
   UIUtilities.centerAndShow(chooser);
 }
    /**
     * Opens a dialog box for users to choose a local file.
     *
     * @see ActionListener#actionPerformed(ActionEvent)
     */
    public void actionPerformed(ActionEvent e) {
      List<FileFilter> filters;
      filters = new ArrayList<FileFilter>();
      filters.add(new EditorFileFilter());

      FileChooser chooser =
          new FileChooser(
              null, FileChooser.LOAD, "Open File", "Choose a file to open in the Editor", filters);
      chooser.addPropertyChangeListener(
          FileChooser.APPROVE_SELECTION_PROPERTY, ProtocolLinkEditor.this);
      UIUtilities.centerAndShow(chooser);
    }
Ejemplo n.º 3
0
  /** Brings up the folder chooser. */
  private void download() {
    JFrame f = MetadataViewerAgent.getRegistry().getTaskBar().getFrame();
    FileChooser chooser =
        new FileChooser(
            f,
            FileChooser.FOLDER_CHOOSER,
            "Download",
            "Select where to download the file.",
            null,
            true);
    chooser.setSelectedFileFull(view.getRefObjectName());
    IconManager icons = IconManager.getInstance();
    chooser.setTitleIcon(icons.getIcon(IconManager.DOWNLOAD_48));
    chooser.setApproveButtonText("Download");
    chooser.addPropertyChangeListener(
        new PropertyChangeListener() {

          public void propertyChange(PropertyChangeEvent evt) {
            String name = evt.getPropertyName();
            if (FileChooser.APPROVE_SELECTION_PROPERTY.equals(name)) {
              String path = (String) evt.getNewValue();
              if (path == null) {
                path = UIUtilities.getDefaultFolderAsString();
              }
              if (!path.endsWith(File.separator)) path += File.separator;
              model.download(new File(path));
            }
          }
        });
    chooser.centerDialog();
  }
 /** Brings up a dialog so that the user can select where to download the file. */
 private void download() {
   String name = null;
   if (data instanceof FileAnnotationData) {
     name = ((FileAnnotationData) data).getFileName();
   }
   JFrame f = MetadataViewerAgent.getRegistry().getTaskBar().getFrame();
   FileChooser chooser =
       new FileChooser(
           f, FileChooser.SAVE, "Download", "Select where to download the files.", null, true);
   if (name != null && name.trim().length() > 0) chooser.setSelectedFileFull(name);
   IconManager icons = IconManager.getInstance();
   chooser.setTitleIcon(icons.getIcon(IconManager.DOWNLOAD_48));
   chooser.setApproveButtonText("Download");
   chooser.addPropertyChangeListener(this);
   chooser.centerDialog();
 }
Ejemplo n.º 5
0
  /** Brings up the folder chooser to select where to save the files. */
  private void saveAsJPEG() {
    JFrame f = MetadataViewerAgent.getRegistry().getTaskBar().getFrame();
    FileChooser chooser =
        new FileChooser(
            f,
            FileChooser.FOLDER_CHOOSER,
            "Save As",
            "Select where to save locally the images as JPEG.",
            saveAsFilters);
    String s = UIUtilities.removeFileExtension(view.getRefObjectName());
    if (s != null && s.trim().length() > 0) chooser.setSelectedFile(s);
    chooser.setApproveButtonText("Save");
    IconManager icons = IconManager.getInstance();
    chooser.setTitleIcon(icons.getIcon(IconManager.SAVE_AS_48));
    chooser.addPropertyChangeListener(
        new PropertyChangeListener() {

          public void propertyChange(PropertyChangeEvent evt) {
            String name = evt.getPropertyName();
            if (FileChooser.APPROVE_SELECTION_PROPERTY.equals(name)) {
              // File[] files = (File[]) evt.getNewValue();
              String value = (String) evt.getNewValue();
              File folder = null; // files[0];
              if (value == null || value.trim().length() == 0)
                folder = UIUtilities.getDefaultFolder();
              else folder = new File(value);
              Object src = evt.getSource();
              if (src instanceof FileChooser) {
                ((FileChooser) src).setVisible(false);
                ((FileChooser) src).dispose();
              }
              model.saveAs(folder);
            }
          }
        });
    chooser.centerDialog();
  }
  /** 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.");
  }