protected void updateLDS(int original_index, int new_index) {
    TableColumn tc = this.getColumn(new_index);
    int model_index = tc.getModelIndex();
    DataColumn dc = lds.getDataColumn(model_index);
    dc.setIncludePosition(new_index);
    if (Math.abs(original_index - new_index) == 1) {
      // two adjacent columns were swapped, so set include value for neighbor
      TableColumn tc2 = this.getColumn(original_index);
      int model_index2 = tc2.getModelIndex();
      DataColumn dc2 = lds.getDataColumn(model_index2);
      dc2.setIncludePosition(original_index);

      // swap names for dc and dc2, as well as table column header values and identifiers
      String name = dc.getName();
      int type = dc.getType();
      dc.setName(dc2.getName());
      dc.setType(dc2.getType());
      dc2.setName(name);
      dc2.setType(type);

      tc2.setHeaderValue(dc2.getName());
      tc2.setIdentifier(dc2.getName());

      tc.setHeaderValue(dc.getName());
      tc.setIdentifier(dc.getName());
    } else {
      syncIncludes();
    }
  }
 private void initEmptyTable() {
   _table.setModel(new DefaultTableModel());
   _colName = new TableColumn();
   _colName.setHeaderValue("Name");
   _colName.setIdentifier("Name");
   _table.addColumn(_colName);
   _colValue = new TableColumn();
   _colValue.setHeaderValue("Value");
   _colValue.setIdentifier("Value");
   _table.addColumn(_colValue);
 }
Пример #3
0
  /**
   * Set the state from the last saved in the PreferencesExt.
   *
   * @param store ok if null or empty
   */
  public void restoreState(PreferencesExt store) {
    if (store == null) return;

    int ncols = table.getColumnCount();

    // stored column order
    int[] modelIndex = (int[]) store.getBean("ColumnOrder", null);

    if ((modelIndex != null) && (modelIndex.length == ncols)) { // what about invisible ??

      // make invisible any not stored
      boolean[] visible = new boolean[ncols];
      for (int i = 0; i < modelIndex.length; i++)
        if (modelIndex[i] < ncols) visible[modelIndex[i]] = true;

      // modify popup menu
      for (int i = 0; i < ncols; i++)
        if (!visible[i]) {
          // System.out.println( colName[i]+" hide "+i);
          acts[i].hideColumn();
          acts[i].putValue(BAMutil.STATE, new Boolean(false));
        }

      // now set the header order
      TableColumnModel tcm = table.getColumnModel();
      int n = Math.min(modelIndex.length, table.getColumnCount());
      for (int i = 0; i < n; i++) {
        TableColumn tc = tcm.getColumn(i);
        tc.setModelIndex(modelIndex[i]);
        String name = model.getColumnName(modelIndex[i]);
        tc.setHeaderValue(name);
        tc.setIdentifier(name);
        if (useThreads && (modelIndex[i] == threadCol)) {
          threadHeaderRenderer = new ThreadHeaderRenderer(threadCol);
          tc.setHeaderRenderer(threadHeaderRenderer);
        } else tc.setHeaderRenderer(new SortedHeaderRenderer(name, modelIndex[i]));
      }
    }

    // set the column widths
    Object colWidths = store.getBean("ColumnWidths", null);
    if (colWidths == null) return;
    int[] size = (int[]) colWidths;

    if (size != null) setColumnWidths(size);
    if (debug) {
      System.out.println(" read widths = ");
      for (int i = 0; i < size.length; i++) System.out.print(" " + size[i]);
      System.out.println();
    }

    boolean isThreadsOn = store.getBoolean("isThreadsOn", false);
    if (useThreads) {
      model.setThreadsOn(isThreadsOn);
      threadHeaderRenderer.setOn(isThreadsOn);
    }

    int colNo = store.getInt("SortOnCol", 0);
    boolean reverse = store.getBoolean("SortReverse", false);
    model.setSortCol(colNo);
    model.setReverse(reverse);
    setSortCol(colNo, reverse);

    model.sort();
    table.fireDataChanged();
  }
  public void createColumns() {

    // clear column groups
    ColumnGroup groups[] = header.getColumnGroups();
    if (groups != null) {
      for (ColumnGroup group : groups) {
        header.removeColumnGroup(group);
      }
    }

    // clear the column model
    while (getColumnCount() > 0) {
      TableColumn col = getColumn(0);
      removeColumn(col);
    }

    // create the "average" group
    ColumnGroup averageGroup = new ColumnGroup("Average");
    header.addColumnGroup(averageGroup);

    JTextField editorField = new JTextField();
    editorField.setFont(editFont);
    DefaultCellEditor defaultEditor = new DefaultCellEditor(editorField);

    ColumnSettingParameter<CommonColumnType> csPar =
        parameters.getParameter(PeakListTableParameters.commonColumns);
    CommonColumnType visibleCommonColumns[] = csPar.getValue();

    // This is a workaround for a bug - we need to always show the ID, m/z
    // and RT columns, otherwise manual editing of peak identities does not
    // work.
    ArrayList<CommonColumnType> commonColumnsList =
        new ArrayList<>(Arrays.asList(visibleCommonColumns));
    commonColumnsList.remove(CommonColumnType.ROWID);
    commonColumnsList.remove(CommonColumnType.AVERAGEMZ);
    commonColumnsList.remove(CommonColumnType.AVERAGERT);
    commonColumnsList.add(0, CommonColumnType.ROWID);
    commonColumnsList.add(1, CommonColumnType.AVERAGEMZ);
    commonColumnsList.add(2, CommonColumnType.AVERAGERT);

    visibleCommonColumns = commonColumnsList.toArray(visibleCommonColumns);

    ColumnSettingParameter<DataFileColumnType> dfPar =
        parameters.getParameter(PeakListTableParameters.dataFileColumns);
    DataFileColumnType visibleDataFileColumns[] = dfPar.getValue();

    for (int i = 0; i < visibleCommonColumns.length; i++) {

      CommonColumnType commonColumn = visibleCommonColumns[i];
      int modelIndex = Arrays.asList(CommonColumnType.values()).indexOf(commonColumn);

      TableColumn newColumn = new TableColumn(modelIndex);
      newColumn.setHeaderValue(commonColumn.getColumnName());
      newColumn.setIdentifier(commonColumn);

      switch (commonColumn) {
        case AVERAGEMZ:
          newColumn.setCellRenderer(mzRenderer);
          break;
        case AVERAGERT:
          newColumn.setCellRenderer(rtRenderer);
          break;
        case IDENTITY:
          newColumn.setCellRenderer(identityRenderer);
          break;
        case COMMENT:
          newColumn.setCellRenderer(defaultRendererLeft);
          newColumn.setCellEditor(defaultEditor);
          break;
        case PEAKSHAPE:
          newColumn.setCellRenderer(peakShapeRenderer);
          break;
        default:
          newColumn.setCellRenderer(defaultRenderer);
      }

      this.addColumn(newColumn);
      newColumn.setPreferredWidth(csPar.getColumnWidth(modelIndex));
      if ((commonColumn == CommonColumnType.AVERAGEMZ)
          || (commonColumn == CommonColumnType.AVERAGERT)) {
        averageGroup.add(newColumn);
      }
    }

    for (int i = 0; i < peakList.getNumberOfRawDataFiles(); i++) {

      RawDataFile dataFile = peakList.getRawDataFile(i);
      ColumnGroup fileGroup = new ColumnGroup(dataFile.getName());
      header.addColumnGroup(fileGroup);

      for (int j = 0; j < visibleDataFileColumns.length; j++) {

        DataFileColumnType dataFileColumn = visibleDataFileColumns[j];
        int dataFileColumnIndex =
            Arrays.asList(DataFileColumnType.values()).indexOf(dataFileColumn);
        int modelIndex =
            CommonColumnType.values().length
                + (i * DataFileColumnType.values().length)
                + dataFileColumnIndex;

        TableColumn newColumn = new TableColumn(modelIndex);
        newColumn.setHeaderValue(dataFileColumn.getColumnName());
        newColumn.setIdentifier(dataFileColumn);

        switch (dataFileColumn) {
          case MZ:
            newColumn.setCellRenderer(mzRenderer);
            break;
          case PEAKSHAPE:
            newColumn.setCellRenderer(peakShapeRenderer);
            break;
          case STATUS:
            newColumn.setCellRenderer(peakStatusRenderer);
            break;
          case RT:
            newColumn.setCellRenderer(rtRenderer);
            break;
          case RT_START:
            newColumn.setCellRenderer(rtRenderer);
            break;
          case RT_END:
            newColumn.setCellRenderer(rtRenderer);
            break;
          case DURATION:
            newColumn.setCellRenderer(rtRenderer);
            break;
          case HEIGHT:
            newColumn.setCellRenderer(intensityRenderer);
            break;
          case AREA:
            newColumn.setCellRenderer(intensityRenderer);
            break;
          default:
            newColumn.setCellRenderer(defaultRenderer);
            break;
        }

        this.addColumn(newColumn);
        newColumn.setPreferredWidth(dfPar.getColumnWidth(dataFileColumnIndex));
        fileGroup.add(newColumn);
      }
    }
  }