コード例 #1
0
  /** Initializes the components composing the display. */
  private void initComponents() {
    ROINode root = new ROINode("root");
    objectsTable = new ROITable(new ROITableModel(root, COLUMN_NAMES), COLUMN_NAMES, this);
    objectsTable.setRootVisible(false);
    objectsTable.setColumnSelectionAllowed(true);
    objectsTable.setRowSelectionAllowed(true);
    treeSelectionListener =
        new TreeSelectionListener() {

          public void valueChanged(TreeSelectionEvent e) {
            TreeSelectionModel tsm = objectsTable.getTreeSelectionModel();
            if (tsm.isSelectionEmpty()) return;
            int[] index = tsm.getSelectionRows();
            if (index.length == 0) return;
            if (index.length == 1) {
              ROINode node = (ROINode) objectsTable.getNodeAtRow(objectsTable.getSelectedRow());
              if (node == null) return;
              Object nodeValue = node.getUserObject();
              if (nodeValue instanceof ROIShape)
                view.selectFigure(((ROIShape) nodeValue).getFigure());
              int col = objectsTable.getSelectedColumn();
              int row = objectsTable.getSelectedRow();

              if (row < 0 || col < 0) return;
            } else {
              ROIShape shape;
              for (int i = 0; i < index.length; i++) {
                shape = objectsTable.getROIShapeAtRow(index[i]);
                if (shape != null) {
                  view.selectFigure(shape.getFigure());
                  requestFocus();
                }
              }
            }
          }
        };

    objectsTable.addTreeSelectionListener(treeSelectionListener);

    ColumnFactory columnFactory =
        new ColumnFactory() {

          public void configureColumnWidths(JXTable table, TableColumnExt columnExt) {
            columnExt.setPreferredWidth(COLUMN_WIDTHS.get(columnExt.getHeaderValue()));
          }
        };
    objectsTable.setHorizontalScrollEnabled(true);
    objectsTable.setColumnControlVisible(true);
    objectsTable.setColumnFactory(columnFactory);
  }
コード例 #2
0
  /**
   * Selects the collection of figures.
   *
   * @param l The collection of objects to select.
   * @param clear Pass <code>true</code> to clear the selection <code>false</code> otherwise.
   */
  void setSelectedFigures(List<ROIShape> l, boolean clear) {
    Iterator<ROIShape> i = l.iterator();
    TreeSelectionModel tsm = objectsTable.getTreeSelectionModel();
    ROIFigure figure = null;
    ROIShape shape;
    if (clear) tsm.clearSelection();
    objectsTable.removeTreeSelectionListener(treeSelectionListener);

    try {
      while (i.hasNext()) {
        shape = i.next();
        figure = shape.getFigure();
        objectsTable.selectROIShape(figure.getROIShape());
      }
      objectsTable.repaint();
      if (figure != null) objectsTable.scrollToROIShape(figure.getROIShape());
    } catch (Exception e) {
      MeasurementAgent.getRegistry().getLogger().info(this, "Figure selection " + e);
    }

    objectsTable.addTreeSelectionListener(treeSelectionListener);
  }