コード例 #1
0
 /** Refresh the cell widths in the table. */
 public void refreshCellWidths() {
   // set width of columns
   for (int i = 0; i < getColumnCount(); i++) {
     String name = getColumnName(i);
     TableColumn statColumn = getColumn(name);
     name = dataTable.getColumnName(i);
     TableColumn dataColumn = dataTable.getColumn(name);
     statColumn.setMaxWidth(dataColumn.getWidth());
     statColumn.setMinWidth(dataColumn.getWidth());
     statColumn.setWidth(dataColumn.getWidth());
   }
 }
コード例 #2
0
  /** Initializes the table. */
  protected void init() {
    dataTable
        .getColumnModel()
        .addColumnModelListener(
            new TableColumnModelListener() {
              public void columnAdded(TableColumnModelEvent e) {
                /** empty block */
              }

              public void columnRemoved(TableColumnModelEvent e) {
                /** empty block */
              }

              public void columnSelectionChanged(ListSelectionEvent e) {
                /** empty block */
              }

              public void columnMarginChanged(ChangeEvent e) {
                refreshTable();
              }

              public void columnMoved(TableColumnModelEvent e) {
                refreshTable();
              }
            });
    // assemble statistics data array
    Dataset workingData = dataTable.getWorkingData();
    double[] xstats = getStatistics(workingData.getXPoints());
    double[] ystats = getStatistics(workingData.getValidYPoints());
    if (statsData == null) {
      statsData = new Object[xstats.length][0];
    }
    for (int i = 0; i < xstats.length; i++) {
      String label = ToolsRes.getString("Table.Entry.Count"); // $NON-NLS-1$
      if (i == 5) {
        statsData[i] =
            new Object[] {label, new Integer((int) xstats[i]), new Integer((int) ystats[i])};
      } else {
        switch (i) {
          case 0:
            label = ToolsRes.getString("Table.Entry.Max");
            break; //$NON-NLS-1$
          case 1:
            label = ToolsRes.getString("Table.Entry.Min");
            break; //$NON-NLS-1$
          case 2:
            label = ToolsRes.getString("Table.Entry.Mean");
            break; //$NON-NLS-1$
          case 3:
            label = ToolsRes.getString("Table.Entry.StandardDev");
            break; //$NON-NLS-1$
          case 4:
            label = ToolsRes.getString("Table.Entry.StandardError"); // $NON-NLS-1$
        }
        statsData[i] = new Object[] {label, new Double(xstats[i]), new Double(ystats[i])};
      }
    }
    // set and configure table model and header
    setModel(tableModel);
    setGridColor(Color.blue);
    setEnabled(false);
    setTableHeader(null); // no table header
    labelRenderer = new LabelRenderer();
    setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
    setDefaultRenderer(Double.class, new ScientificRenderer(3));
    ListSelectionModel selectionModel = dataTable.getSelectionModel();
    selectionModel.addListSelectionListener(
        new ListSelectionListener() {
          public void valueChanged(ListSelectionEvent e) {
            Dataset workingData = dataTable.getWorkingData();
            double[] xstats = getStatistics(workingData.getXPoints());
            double[] ystats = getStatistics(workingData.getValidYPoints());
            int i = 0;
            for (; i < xstats.length - 1; i++) {
              statsData[i][1] = new Double(xstats[i]);
              statsData[i][2] = new Double(ystats[i]);
            }
            statsData[i][1] = new Integer((int) xstats[i]);
            statsData[i][2] = new Integer((int) ystats[i]);
            refreshTable();
          }
        });
    refreshCellWidths();
  }
コード例 #3
0
 /**
  * Returns the renderer for a cell specified by row and column.
  *
  * @param row the row number
  * @param column the column number
  * @return the cell renderer
  */
 public TableCellRenderer getCellRenderer(int row, int column) {
   int i = dataTable.convertColumnIndexToModel(column);
   if (i == 0) return labelRenderer;
   return getDefaultRenderer(tableModel.getValueAt(row, column).getClass());
 }