Package versusSNP.gui

Source Code of versusSNP.gui.SPanel

package versusSNP.gui;

import java.awt.BorderLayout;
import java.util.Observable;
import java.util.Observer;

import javax.swing.JPanel;
import javax.swing.JScrollPane;

import versusSNP.Document;
import versusSNP.Size;
import versusSNP.blast.util.SNPList;
import versusSNP.genome.SNP;
import versusSNP.gui.widgets.SNPTable;
import versusSNP.gui.widgets.SNPTableControl;
import versusSNP.gui.widgets.SNPTableModel;

public class SPanel extends JPanel implements Observer, SNPContainer {
  private static final long serialVersionUID = 4523539984887851973L;
  private SNPTable table;
  private SNPTableModel tableModel;
  private SNPTableControl tableControl;
  private SNPList snpList;
  private int record;

  public SPanel() {
    super();
    setLayout(new BorderLayout());
    setPreferredSize(Size.main_frame_west);
    tableModel = new SNPTableModel(headerTexts(), SNPTableControl.PAGE_RECORD_LIMIT);
    table = new SNPTable(tableModel);
    tableControl = new SNPTableControl(this);
    table.getSelectionModel().addListSelectionListener(tableModel);
    add(new JScrollPane(table), BorderLayout.CENTER);
    add(tableControl, BorderLayout.SOUTH);
  }
 
  private Object[] headerTexts() {
    return new Object[] {
        UICaption.table_column_query_position,
        UICaption.table_column_subject_position,
        UICaption.table_column_query_position_in_genome,
        UICaption.table_column_subject_position_in_genome,
        UICaption.table_column_query_position_in_codon,
        UICaption.table_column_subject_position_in_codon,
        UICaption.table_column_query_base,
        UICaption.table_column_subject_base,
        UICaption.table_column_amino_acid,
        UICaption.table_column_query_codon,
        UICaption.table_column_subject_codon,
        UICaption.table_column_query,
        UICaption.table_column_subject
      };
  }

  public void setHeaderTexts() {
    Object[] headerTexts = headerTexts();
    for (int i = 0; i < headerTexts.length; i++) {
      table.getColumnModel().getColumn(i).setHeaderValue(headerTexts[i]);
    }
  }

  @Override
  public void update(Observable o, Object arg) {
    Document document = (Document)o;
    if (document.getQueryGenome() != null && document.getSubjectGenome() != null) {
      SNPList snpList = document.getQueryGenome().getSSNPList(document.getSubjectGenome());
      if (snpList != null) {
        this.snpList = snpList;
        tableControl.setSnpList(snpList);
        accept(snpList);
      }
    }
  }

  @Override
  public void accept(SNPList snpList) {
    tableModel.accept(snpList, this);
    table.autoResizeColumns();
  }

  @Override
  public void add(SNP snp) {
    tableModel.addRow(new Object[]{snp.getQPos(), snp.getSPos(),
        snp.getQPosInGenome(), snp.getSPosInGenome(),
        snp.getQPosInCodon(), snp.getSPosInCodon(),
        snp.getQBase(), snp.getSBase(), snp.getQAA(),
        snp.getQCodon(), snp.getEquivalentSCodon(),
        snp.getQOrf(), snp.getSOrf()});
   
  }

  public SNPTable getTable() {
    return table;
  }

  @Override
  public int getRecord() {
    return record;
  }

  @Override
  public void setRecord(int record) {
    this.record = record;
  }

  @Override
  public void addRecord() {
    if (this.record/SNPTableControl.PAGE_RECORD_LIMIT
        <= snpList.size()/SNPTableControl.PAGE_RECORD_LIMIT)
      this.record += SNPTableControl.PAGE_RECORD_LIMIT;
  }

  @Override
  public void setMaxRecord() {
    this.record = snpList.size() - snpList.size()%SNPTableControl.PAGE_RECORD_LIMIT;
  }

  @Override
  public void subRecord() {
    if (this.record >= SNPTableControl.PAGE_RECORD_LIMIT)
      this.record -= SNPTableControl.PAGE_RECORD_LIMIT;
  }

  @Override
  public void reload() {
    accept(snpList);
  }
 
  public void setToolTipTexts() {
    tableControl.setToolTipTexts();
  }

  @Override
  public void updateInfo() {
    tableControl.setTableInfo(UICaption.getTableInfo(record, table.getSelectedRow()>0?table.getSelectedRow():0, snpList.size()));
  }

  @Override
  public void clear() {
    tableModel.setRowCount(0);
    tableControl.clear();
  }
}
TOP

Related Classes of versusSNP.gui.SPanel

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.