/** Creates the combobox holding the channel list. */
  private void createComboBox() {
    Object[][] channelCols = new Object[channelName.size()][2];
    List<ChannelData> metadata = model.getMetadata();
    Iterator<ChannelData> i = metadata.iterator();
    ChannelData channelData;
    int channel;
    int index = 0;
    while (i.hasNext()) {
      channelData = i.next();
      channel = channelData.getIndex();
      if (channelName.containsKey(channel)) {
        channelCols[index] = new Object[] {channelColour.get(channel), channelName.get(channel)};
        index++;
      }
    }
    // if (channelCols.length == 0)
    // return;

    channelSelection.setModel(new DefaultComboBoxModel(channelCols));
    channelSelection.setRenderer(new ColorListRenderer());
    if (selectedChannelName != null)
      if (nameMap.containsKey(selectedChannelName))
        selectedChannel = nameMap.get(selectedChannelName);
      else selectedChannel = 0;
    else selectedChannel = 0;
    if (selectedChannel >= channelSelection.getItemCount() || selectedChannel < 0) return;
    channelSelection.setSelectedIndex(selectedChannel);
    channelSelection.setEnabled(true);
  }
Ejemplo n.º 2
0
 /** Toggles the value of the boolean under the current selection. */
 private void toggleValue() {
   int col = fieldTable.getSelectedColumn();
   int row = fieldTable.getSelectedRow();
   Object v = (Boolean) fieldTable.getModel().getValueAt(row, col);
   Boolean value = Boolean.valueOf(false);
   if (v != null) value = (Boolean) v;
   boolean newValue = !(value.booleanValue());
   fieldTable.getModel().setValueAt(Boolean.valueOf(newValue), row, col);
   model.getDrawingView().repaint();
 }
 /**
  * Writes the header information for the file, image, projects, dataset.
  *
  * @param writer The Excel writer.
  * @param rowIndex The selected row.
  * @param currentCoord The coord of the shape being written.
  * @throws IOException Thrown if the data cannot be written.
  */
 private void writeHeader(ExcelWriter writer, int rowIndex, Coord3D currentCoord) {
   writer.writeElement(rowIndex, 0, "Image ");
   writer.writeElement(rowIndex, 1, model.getImageName());
   rowIndex++;
   writer.writeElement(rowIndex, 0, "Z ");
   writer.writeElement(rowIndex, 1, (currentCoord.getZSection() + 1));
   rowIndex++;
   writer.writeElement(rowIndex, 0, "T ");
   writer.writeElement(rowIndex, 1, (currentCoord.getTimePoint() + 1));
   rowIndex++;
 }
Ejemplo n.º 4
0
 /** Rebuilds Tree */
 void rebuildTable() {
   TreeMap<Long, ROI> roiList = model.getROI();
   Iterator<ROI> iterator = roiList.values().iterator();
   ROI roi;
   TreeMap<Coord3D, ROIShape> shapeList;
   Iterator<ROIShape> shapeIterator;
   objectsTable.clear();
   while (iterator.hasNext()) {
     roi = iterator.next();
     shapeList = roi.getShapes();
     shapeIterator = shapeList.values().iterator();
     while (shapeIterator.hasNext()) objectsTable.addROIShape(shapeIterator.next());
   }
   objectsTable.collapseAll();
 }
Ejemplo n.º 5
0
  /** Initializes the component composing the display. */
  private void initComponents() {
    infoLabel = new JLabel(MAGNIFICATION + " is " + model.getDrawingView().getScaleFactor());
    // create the table
    fieldTable = new FigureTable(new FigureTableModel(attributeFields, COLUMN_NAMES));
    fieldTable.getTableHeader().setReorderingAllowed(false);
    fieldTable.setRowHeight(26);
    fieldTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    fieldTable.setCellSelectionEnabled(true);
    fieldTable.setColumnSelectionAllowed(true);
    fieldTable.addMouseListener(
        new MouseAdapter() {
          public void mouseClicked(MouseEvent e) {

            int col = fieldTable.getSelectedColumn();
            int row = fieldTable.getSelectedRow();
            Object value = fieldTable.getValueAt(row, col);
            if (e.getClickCount() == 1) {
              if (value instanceof Boolean) {
                toggleValue();
              }
            } else if (e.getClickCount() > 1) {
              e.consume();
              if (value instanceof Color) {
                // Only if the figure is not read only.
                FigureTableModel ftm = (FigureTableModel) fieldTable.getModel();
                ROIFigure figure = ftm.getFigure();
                if (figure != null && !figure.isReadOnly())
                  if (figure.canEdit()) controller.showColorPicker((Color) value);
              } else if (value instanceof Boolean) {
                toggleValue();
              }
            }
          }
        });
    fieldTable.addPropertyChangeListener(
        new PropertyChangeListener() {

          public void propertyChange(PropertyChangeEvent evt) {
            String name = evt.getPropertyName();
            if (FigureTable.VALUE_CHANGED_PROPERTY.equals(name)) {
              handleValueChanged((String) evt.getNewValue());
            }
          }
        });
  }
Ejemplo n.º 6
0
  private void handleValueChanged(String text) {
    int row = fieldTable.getEditingRow();

    if (row < 0 || row >= attributeFields.size()) {
      return;
    }

    AttributeKey attr = getAttributeKey(row);

    FigureTableModel ftm = (FigureTableModel) fieldTable.getModel();
    ROIFigure figure = ftm.getFigure();

    if (attr.equals(MeasurementAttributes.TEXT)) {
      if (TextHolderFigure.class.isAssignableFrom(figure.getClass())) {
        ((TextHolderFigure) figure).setText(text);
      }
    } else if (attr.equals(MeasurementAttributes.FONT_SIZE)) {
      double d = parseDouble(text);
      figure.setAttribute(MeasurementAttributes.FONT_SIZE, d);
      figure.changed();
    } else if (attr.equals(MeasurementAttributes.STROKE_WIDTH)) {
      double d = parseDouble(text);
      figure.setAttribute(MeasurementAttributes.STROKE_WIDTH, d);
    } else if (attr.equals(MeasurementAttributes.WIDTH)) {
      try {
        double d = parseDouble(text);
        setFigureDimension(figure, MeasurementAttributes.WIDTH, d);
        if (isScaleProportionally()) {
          setFigureDimension(figure, MeasurementAttributes.HEIGHT, d);
        }
      } catch (Exception e) {
      }
    } else if (attr.equals(MeasurementAttributes.HEIGHT)) {
      try {
        double d = parseDouble(text);
        setFigureDimension(figure, MeasurementAttributes.HEIGHT, d);
        if (isScaleProportionally()) {
          setFigureDimension(figure, MeasurementAttributes.WIDTH, d);
        }
      } catch (Exception e) {
      }
    }
    model.getDrawingView().repaint();
  }
Ejemplo n.º 7
0
 /**
  * Returns the selected figures.
  *
  * @return See above.
  */
 Collection<Figure> getSelectedFigures() {
   return model.getSelectedFigures();
 }
Ejemplo n.º 8
0
 /** Invokes when new figures are selected. */
 void onSelectedFigures() {
   objectsTable.onSelectedFigures(model.getSelectedFigures());
 }
Ejemplo n.º 9
0
 /** Resets the component. */
 void reset() {
   model.getROIComponent().reset();
 }
  /**
   * Get the analysis results from the model and convert to the necessary array. data types using
   * the ROIStats wrapper then create the appropriate table data and summary statistics.
   */
  void displayAnalysisResults() {
    if (state == State.ANALYSING) return;
    this.ROIStats = model.getAnalysisResults();
    if (ROIStats == null || ROIStats.size() == 0) return;
    state = State.ANALYSING;
    channelSelection.setVisible(true);
    clearMaps();
    shapeStatsList = new TreeMap<Coord3D, Map<StatsType, Map>>(new Coord3D());
    pixelStats = new TreeMap<Coord3D, Map<Integer, Map<Point, Double>>>(new Coord3D());
    shapeMap = new TreeMap<Coord3D, ROIShape>(new Coord3D());
    minStats = new TreeMap<Coord3D, Map<Integer, Double>>(new Coord3D());
    maxStats = new TreeMap<Coord3D, Map<Integer, Double>>(new Coord3D());
    meanStats = new TreeMap<Coord3D, Map<Integer, Double>>(new Coord3D());
    sumStats = new TreeMap<Coord3D, Map<Integer, Double>>(new Coord3D());
    stdDevStats = new TreeMap<Coord3D, Map<Integer, Double>>(new Coord3D());

    Entry entry;
    Iterator j = ROIStats.entrySet().iterator();
    channelName = new TreeMap<Integer, String>();
    nameMap = new LinkedHashMap<String, Integer>();

    int minZ = Integer.MAX_VALUE, maxZ = Integer.MIN_VALUE;
    int minT = Integer.MAX_VALUE, maxT = Integer.MIN_VALUE;
    clearAllValues();
    Coord3D c3D;
    Map<StatsType, Map> shapeStats;
    ChannelData channelData;
    int channel;
    Iterator<ChannelData> i;
    List<ChannelData> metadata = model.getMetadata();
    while (j.hasNext()) {
      entry = (Entry) j.next();
      shape = (ROIShape) entry.getKey();
      c3D = shape.getCoord3D();
      minT = Math.min(minT, c3D.getTimePoint());
      maxT = Math.max(maxT, c3D.getTimePoint());
      minZ = Math.min(minZ, c3D.getZSection());
      maxZ = Math.max(maxZ, c3D.getZSection());

      shapeMap.put(c3D, shape);
      if (shape.getFigure() instanceof MeasureTextFigure) {
        state = State.READY;
        return;
      }

      shapeStats = AnalysisStatsWrapper.convertStats((Map) entry.getValue());
      shapeStatsList.put(c3D, shapeStats);

      minStats.put(c3D, shapeStats.get(StatsType.MIN));
      maxStats.put(c3D, shapeStats.get(StatsType.MAX));
      meanStats.put(c3D, shapeStats.get(StatsType.MEAN));
      sumStats.put(c3D, shapeStats.get(StatsType.SUM));
      stdDevStats.put(c3D, shapeStats.get(StatsType.STDDEV));
      pixelStats.put(c3D, shapeStats.get(StatsType.PIXEL_PLANEPOINT2D));

      /* really inefficient but hey.... quick hack just now till refactor */
      channelName.clear();
      nameMap.clear();
      channelColour.clear();

      i = metadata.iterator();
      List<String> names = new ArrayList<String>();
      String name;
      while (i.hasNext()) {
        channelData = i.next();
        channel = channelData.getIndex();
        if (model.isChannelActive(channel)) {
          name = channelData.getChannelLabeling();
          if (names.contains(name)) name += " " + channel;
          channelName.put(channel, name);
          nameMap.put(channelName.get(channel), channel);
          channelColour.put(channel, (Color) model.getActiveChannels().get(channel));
        }
      }
    }
    if (channelName.size() != channelColour.size() || nameMap.size() == 0) {
      createComboBox();
      List<String> names = channelSummaryModel.getRowNames();
      List<String> channelNames = new ArrayList<String>();
      Double data[][] = new Double[channelName.size()][names.size()];
      channelSummaryModel = new ChannelSummaryModel(names, channelNames, data);
      channelSummaryTable.setModel(channelSummaryModel);
      saveButton.setEnabled(false);
      showIntensityTable.setEnabled(false);
      if (intensityDialog != null) intensityDialog.setVisible(false);
      state = State.READY;
      return;
    }
    saveButton.setEnabled(true);
    showIntensityTable.setEnabled(true);
    maxZ = maxZ + 1;
    minZ = minZ + 1;
    maxT = maxT + 1;
    minT = minT + 1;

    createComboBox();
    Object[] nameColour = (Object[]) channelSelection.getSelectedItem();
    String string = (String) nameColour[1];
    selectedChannel = nameMap.get(string);
    zSlider.setMaximum(maxZ);
    zSlider.setMinimum(minZ);
    tSlider.setMaximum(maxT);
    tSlider.setMinimum(minT);
    zSlider.setVisible((maxZ != minZ));
    tSlider.setVisible((maxT != minT));
    tSlider.setValue(model.getCurrentView().getTimePoint() + 1);
    zSlider.setValue(model.getCurrentView().getZSection() + 1);
    coord = new Coord3D(zSlider.getValue() - 1, tSlider.getValue() - 1);
    shape = shapeMap.get(coord);
    populateData(coord, selectedChannel);
    saveButton.setEnabled(tableModel.getRowCount() > 0);
    state = State.READY;
  }
  /** 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.");
  }
Ejemplo n.º 12
0
 /** Updates the display when the magnification factor changes. */
 void onMagnificationChanged() {
   infoLabel.setText(MAGNIFICATION + " is " + model.getDrawingView().getScaleFactor());
 }