Пример #1
0
  /** Opens the file. */
  private void openFile() {
    if (!(data instanceof FileAnnotationData)) return;

    FileAnnotationData fa = (FileAnnotationData) data;
    Registry reg = MetadataViewerAgent.getRegistry();
    UserNotifier un = reg.getUserNotifier();
    OriginalFile f = (OriginalFile) fa.getContent();
    Environment env = (Environment) reg.lookup(LookupNames.ENV);
    DownloadAndLaunchActivityParam activity;
    final long dataId = fa.getId();
    final File dir =
        new File(env.getOmeroFilesHome() + File.separatorChar + "file annotation " + dataId);
    if (!dir.exists()) {
      dir.mkdir();
    }
    if (f != null && f.isLoaded()) {
      activity = new DownloadAndLaunchActivityParam(f, dir, null);
    } else {
      activity =
          new DownloadAndLaunchActivityParam(
              dataId, DownloadAndLaunchActivityParam.FILE_ANNOTATION, dir, null);
    }
    un.notifyActivity(model.getSecurityContext(), activity);
    return;
  }
Пример #2
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();
 }
Пример #3
0
 /**
  * Creates or recycles the existing figure dialog.
  *
  * @param name The name to display.
  * @param pixels The pixels object of reference.
  * @param index One of the constants defined by this class.
  * @return See above.
  */
 FigureDialog createFigureDialog(String name, PixelsData pixels, int index) {
   if (figureDialog != null) return figureDialog;
   UserNotifier un = MetadataViewerAgent.getRegistry().getUserNotifier();
   if (FigureDialog.needPixels(index) && pixels == null) {
     un.notifyInfo("Figure", "The image is not valid," + " cannot create the figure.");
     return null;
   }
   JFrame f = MetadataViewerAgent.getRegistry().getTaskBar().getFrame();
   figureDialog = new FigureDialog(f, name, pixels, index, view.getRefObject().getClass());
   figureDialog.addPropertyChangeListener(this);
   return figureDialog;
 }
 /**
  * Implemented as specified by the {@link Importer} interface.
  *
  * @see Importer#importData(ImportableObject)
  */
 public void importData(ImportableObject data) {
   if (model.getState() == DISCARDED) return;
   if (data == null || data.getFiles() == null || data.getFiles().size() == 0) {
     UserNotifier un = ImporterAgent.getRegistry().getUserNotifier();
     un.notifyInfo("Import", "No Files to import.");
     return;
   }
   view.showRefreshMessage(chooser.isRefreshLocation());
   if (data.hasNewTags()) model.setTags(null);
   ImporterUIElement element = view.addImporterElement(data);
   if (model.getState() == IMPORTING) return;
   importData(element);
 }
Пример #5
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;
 }
    /**
     * Opens a dialog box for users to enter a URL
     *
     * @see ActionListener#actionPerformed(ActionEvent)
     */
    public void actionPerformed(ActionEvent e) {
      JFrame f = EditorAgent.getRegistry().getTaskBar().getFrame();
      InputDialog dialog = new InputDialog(f, "Enter ID of Editor File on Server", "");

      int option = dialog.centerMsgBox();
      if (option == InputDialog.SAVE) {
        String newFileID = dialog.getText();

        // could check valid ID (integer) etc?
        if (EditorLinkParam.isLinkValidId(newFileID)) {
          attributeEdited(TextParam.PARAM_VALUE, newFileID);
        } else {
          UserNotifier un = EditorAgent.getRegistry().getUserNotifier();
          un.notifyInfo("Not valid ID", "Did not enter a valid Editor file ID");
        }
      }
    }
Пример #7
0
  /** Modifies the existing password. */
  private void changePassword() {
    UserNotifier un;
    if (!oldPassword.isVisible()) {
      StringBuffer buf = new StringBuffer();
      buf.append(passwordNew.getPassword());
      String newPass = buf.toString();
      if (newPass == null || newPass.length() == 0) {
        un = MetadataViewerAgent.getRegistry().getUserNotifier();
        un.notifyInfo(PASSWORD_CHANGE_TITLE, "Please enter the new password.");
        passwordNew.requestFocus();
        return;
      }
      un = MetadataViewerAgent.getRegistry().getUserNotifier();
      un.notifyInfo(PASSWORD_CHANGE_TITLE, "Password changed.");
      passwordNew.setText("");
      model.resetPassword(newPass);
      return;
    }
    StringBuffer buf = new StringBuffer();
    buf.append(passwordNew.getPassword());
    String newPass = buf.toString();

    String pass = buf.toString();
    buf = new StringBuffer();
    buf.append(passwordConfirm.getPassword());
    String confirm = buf.toString();

    buf = new StringBuffer();
    buf.append(oldPassword.getPassword());
    String old = buf.toString();
    if (old == null || old.trim().length() == 0) {
      un = MetadataViewerAgent.getRegistry().getUserNotifier();
      un.notifyInfo(PASSWORD_CHANGE_TITLE, "Please specify your old password.");
      oldPassword.requestFocus();
      return;
    }
    if (newPass == null || newPass.length() == 0) {
      un = MetadataViewerAgent.getRegistry().getUserNotifier();
      un.notifyInfo(PASSWORD_CHANGE_TITLE, "Please enter your new password.");
      passwordNew.requestFocus();
      return;
    }

    if (pass == null || confirm == null || confirm.length() == 0 || !pass.equals(confirm)) {
      un = MetadataViewerAgent.getRegistry().getUserNotifier();
      un.notifyInfo(
          PASSWORD_CHANGE_TITLE, "The passwords entered do not match. " + "Please try again.");
      passwordNew.setText("");
      passwordConfirm.setText("");
      passwordNew.requestFocus();
      return;
    }
    model.changePassword(old, confirm);
  }
Пример #8
0
  /**
   * Sets the file to edit. If the file cannot be read by {@link TreeModelFactory#getTree()} then
   * the state of this model is re-set to {@link Editor#NEW}.
   *
   * @param file The file to edit.
   * @return See above.
   */
  boolean setFileToEdit(File file) {
    if (file == null) {
      fileToEdit = null;
      state = Editor.NEW;
      fileName = EditorFactory.BLANK_MODEL;
      return false;
    }
    TreeModel treeModel = null;

    // try opening file as recognised OMERO.editor file (pro.xml or cpe.xml)
    try {
      treeModel = TreeModelFactory.getTree(file);
      fileToEdit = file;
    } catch (ParsingException e) {

      // may get a parsing exception simply because the file was not
      // recognised as Editor File..

      Registry reg = EditorAgent.getRegistry();
      UserNotifier un = reg.getUserNotifier();

      // ... try opening as ANY xml file
      try {
        treeModel = TreeModelFactory.getTreeXml(file);
        // if this worked, we have an XML file converted to cpe.xml
        // .. tell user..
        un.notifyInfo(
            "File not recognised",
            "File was converted from an unrecognised format into\n"
                + "OMERO.editor's cpe.xml format.\nOverwriting the "
                + "original file will erase the original XML format.");
        // must avoid overwriting the original file...
        // 'Save' won't work.
        if (fileID > 0) { // try to read a file downloaded
          file.delete();
        }
        fileToEdit = null;
        setFileAnnotationData(null);

      } catch (ParsingException ex) {

        LogMessage message = new LogMessage();
        message.print(ex);
        reg.getLogger().error(this, message);

        // ...and notify the user. Use the exception message.
        String errMsg = ex.getMessage();
        un.notifyInfo("File Failed to Open", errMsg);
      }
    }

    if (treeModel == null) {
      fileToEdit = null;
      state = Editor.NEW;
      fileName = EditorFactory.BLANK_MODEL;
      return false;
    }

    fileName = file.getName();
    browser.setTreeModel(treeModel);
    state = Editor.READY;
    return true;
  }
Пример #9
0
  /**
   * Listens to property fired by the Editor dialog.
   *
   * @see PropertyChangeListener#propertyChange(PropertyChangeEvent)
   */
  public void propertyChange(PropertyChangeEvent evt) {
    String name = evt.getPropertyName();
    if (EditorDialog.CREATE_NO_PARENT_PROPERTY.equals(name)) {
      // reset text and tooltip
      String text = "";
      String description = "";
      AnnotationData annotation = null;
      if (data instanceof TagAnnotationData
          || data instanceof TermAnnotationData
          || data instanceof XMLAnnotationData) {
        annotation = (AnnotationData) data;
        text = annotation.getContentAsString();
        text = EditorUtil.truncate(text, TEXT_LENGTH, false);
      }
      if (data instanceof DoubleAnnotationData) {
        annotation = (AnnotationData) data;
        text = "" + ((DoubleAnnotationData) data).getDataValue();
      }
      if (data instanceof LongAnnotationData) {
        annotation = (AnnotationData) data;
        text = "" + ((LongAnnotationData) data).getDataValue();
      }
      if (data instanceof BooleanAnnotationData) {
        annotation = (AnnotationData) data;
        text = "" + ((BooleanAnnotationData) data).getValue();
      }
      description = model.getAnnotationDescription(annotation);
      if (annotation == null) return;
      label.setText(text);
      label.setToolTipText(formatToolTip(annotation, null));
      originalName = text;
      originalDescription = description;
      firePropertyChange(AnnotationUI.EDIT_TAG_PROPERTY, null, this);
    } else if (FileChooser.APPROVE_SELECTION_PROPERTY.equals(name)) {
      if (data == null) return;
      FileAnnotationData fa = (FileAnnotationData) data;
      OriginalFile f = (OriginalFile) fa.getContent();
      File folder;
      Object o = evt.getNewValue();
      if (o instanceof String) {
        String path = (String) o;
        if (!path.endsWith(File.separator)) {
          path += File.separator;
        }
        path += fa.getFileName();
        folder = new File(path);
      } else {
        File[] files = (File[]) o;
        folder = files[0];
      }
      if (folder == null) folder = UIUtilities.getDefaultFolder();
      UserNotifier un = MetadataViewerAgent.getRegistry().getUserNotifier();

      IconManager icons = IconManager.getInstance();

      DownloadActivityParam activity =
          new DownloadActivityParam(f, folder, icons.getIcon(IconManager.DOWNLOAD_22));
      // Check Name space
      activity.setLegend(fa.getDescription());
      un.notifyActivity(model.getSecurityContext(), activity);
    }
  }
Пример #10
0
 /** Message displayed when one of the required fields is left blank. */
 private void showRequiredField() {
   UserNotifier un = MetadataViewerAgent.getRegistry().getUserNotifier();
   un.notifyInfo("Edit Profile", "The required fields cannot be left " + "blank.");
   return;
 }
Пример #11
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());
  }
  /** 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.");
  }