Exemplo n.º 1
0
 /**
  * Shows or hides the text for the currently selected figure.
  *
  * @param show Pass <code>true</code> to show the text, <code>false</code> otherwise.
  * @param figure The selected figure.
  */
 void showText(boolean show, ROIFigure figure) {
   if (fieldTable == null) return;
   int n = fieldTable.getRowCount();
   if (n > 4) {
     FigureTableModel ftm = (FigureTableModel) fieldTable.getModel();
     ROIFigure f = ftm.getFigure();
     if (f != null && f == figure)
       fieldTable.getModel().setValueAt(show, getRowIndex(MeasurementAttributes.SHOWTEXT), 1);
   }
 }
Exemplo n.º 2
0
 /**
  * Returns <code>true</code> if the text has to be shown, <code>false</code> otherwise.
  *
  * @return See above.
  */
 boolean isShowText() {
   if (fieldTable == null) return false;
   int n = fieldTable.getRowCount();
   if (n > 4) {
     Object v = fieldTable.getModel().getValueAt(getRowIndex(MeasurementAttributes.SHOWTEXT), 1);
     if (v == null) return false;
     return (Boolean) v;
   }
   return false;
 }
Exemplo n.º 3
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();
 }
Exemplo n.º 4
0
 /**
  * Removes the ROI figures.
  *
  * @param figures The figures to remove.
  */
 void removeROIFigures(List<ROIFigure> figures) {
   if (figures == null || figures.size() == 0) return;
   FigureTableModel tm = (FigureTableModel) fieldTable.getModel();
   ROIFigure value = tm.getFigure();
   if (value == null) return;
   Iterator<ROIFigure> i = figures.iterator();
   ROIFigure figure;
   while (i.hasNext()) {
     figure = i.next();
     if (value.getROI().getID() == figure.getROI().getID()) tm.clearData();
   }
   fieldTable.repaint();
 }
Exemplo n.º 5
0
 /**
  * Returns <code>true</code> if the figure dimensions are to be scaled proportionally, <code>false
  * </code> otherwise.
  *
  * @return See above.
  */
 boolean isScaleProportionally() {
   if (fieldTable == null) return false;
   int n = fieldTable.getRowCount();
   if (n > 1) {
     Object v =
         fieldTable
             .getModel()
             .getValueAt(getRowIndex(MeasurementAttributes.SCALE_PROPORTIONALLY), 1);
     if (v == null) return false;
     return (Boolean) v;
   }
   return false;
 }
Exemplo n.º 6
0
 /**
  * Removes the ROI figure.
  *
  * @param figure The figure to remove.
  */
 void removeROIFigure(ROIFigure figure) {
   if (figure == null) return;
   FigureTableModel tm = (FigureTableModel) fieldTable.getModel();
   ROIFigure value = tm.getFigure();
   if (value == null) return;
   if (value.getROI().getID() == figure.getROI().getID()) tm.clearData();
 }
Exemplo n.º 7
0
 /**
  * Sets the new figure retrieved from the passed collection.
  *
  * @param l The collection to handle.
  */
 void setSelectedFigures(List<ROIShape> l) {
   FigureTableModel tableModel = (FigureTableModel) fieldTable.getModel();
   Iterator<ROIShape> i = l.iterator();
   // Register error and notify user.
   ROIShape shape;
   try {
     TableCellEditor editor = fieldTable.getCellEditor();
     if (editor != null) editor.stopCellEditing();
     while (i.hasNext()) {
       shape = i.next();
       tableModel.setData(shape.getFigure());
       fieldTable.repaint();
     }
   } catch (Exception e) {
     MeasurementAgent.getRegistry().getLogger().info(this, "Figures selection" + e);
   }
 }
Exemplo n.º 8
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();
  }
Exemplo n.º 9
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());
            }
          }
        });
  }
Exemplo n.º 10
0
 /** Clear the inspector after saving the data. */
 void clearData() {
   FigureTableModel tm = (FigureTableModel) fieldTable.getModel();
   tm.clearData();
 }
Exemplo n.º 11
0
 /**
  * Sets the data.
  *
  * @param figure The data to set.
  */
 void setModelData(ROIFigure figure) {
   FigureTableModel tableModel = (FigureTableModel) fieldTable.getModel();
   tableModel.setData(figure);
   fieldTable.repaint();
 }
Exemplo n.º 12
0
 /**
  * Sets the passed color to the currently selected cell. Returns the selected row.
  *
  * @param c The color to set.
  */
 int setCellColor(Color c) {
   int col = fieldTable.getSelectedColumn();
   int row = fieldTable.getSelectedRow();
   fieldTable.getModel().setValueAt(c, row, col);
   return row;
 }