Package versusSNP

Source Code of versusSNP.Document

package versusSNP;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.Observable;

import javax.swing.JOptionPane;

import versusSNP.blast.BlastList;
import versusSNP.genome.Genome;
import versusSNP.gui.Menu;
import versusSNP.gui.UICaption;
import versusSNP.gui.dialogs.QuerySubjectSelectDialog;

public class Document extends Observable {
  private LinkedList<Genome> genomes;
  private ArrayList<String> genomeNames;
  private ArrayList<BlastList> blastLists;
  private Genome queryGenome, subjectGenome;
  public int genomeCount;
  private Menu menu;
 
  public Document() {
    super();
    genomes = new LinkedList<Genome>();
    genomeNames = new ArrayList<String>();
    genomeCount = 0;
    blastLists = new ArrayList<BlastList>();
  }

  public Document(Menu menu) {
    this();
    this.menu = menu;
  }
 
  public void clear() {
    genomes = new LinkedList<Genome>();
    genomeNames = new ArrayList<String>();
    genomeCount = 0;
    blastLists = new ArrayList<BlastList>();
    queryGenome = subjectGenome = null;
    System.gc();
  }
 
  public LinkedList<Genome> getGenomes() {
    return genomes;
  }

  public String[] getGenomeNames() {
    return genomeNames.toArray(new String[genomeNames.size()]);
  }

  public int getGenomeCount() {
    return genomeCount;
  }

  public Genome getQueryGenome() {
    return queryGenome;
  }

  public Genome getSubjectGenome() {
    return subjectGenome;
  }
 
  public Genome getGenomeById(int id) throws IndexOutOfBoundsException {
    return genomes.get(id);
  }
 
  public ArrayList<BlastList> getBlastLists() {
    return blastLists;
  }

  public synchronized void addGenome(Genome genome) {
    genome.sortOrfList();
    genomes.add(genome);
    genomeCount++;
    genomeNames.add(genome.getName());
    if (queryGenome == null) {
      queryGenome = genome;
      updateAllViews();
    }
    if (menu != null)
      menu.enableMenuItems(genomeCount);
    if (genomes.size() > 1) {
      if (subjectGenome == null)
        subjectGenome = genome;
      loopQuerySubjectSelect(new QuerySubjectSelectDialog(getGenomeNames()));
    }
  }
 
  public void loopQuerySubjectSelect(QuerySubjectSelectDialog dialog) {
    if (dialog.showDialog() == JOptionPane.OK_OPTION) {
      if (dialog.getId1() == dialog.getId2()) {
        JOptionPane.showMessageDialog(null, UICaption.dialog_error_querysubjectselect_identical_ids, UICaption.dialog_caption_error, JOptionPane.ERROR_MESSAGE);
        loopQuerySubjectSelect(dialog);
      }
      setQuerySubjectGenome(dialog.getIds());
      updateAllViews();
    }
  }

  public void setQueryGenome(int id) throws IndexOutOfBoundsException {
    this.queryGenome = genomes.get(id);
  }

  public void setSubjectGenome(int id) throws IndexOutOfBoundsException {
    this.subjectGenome = genomes.get(id);
  }
 
  public void setQuerySubjectGenome(int[] ids) throws IndexOutOfBoundsException {
    setQueryGenome(ids[0]);
    setSubjectGenome(ids[1]);
  }

  public synchronized void addBlastList(BlastList blastList) {
    this.blastLists.add(blastList);
  }

  /**
   * send update to all observers
   */
  public synchronized void updateAllViews() {
    setChanged();
    notifyObservers();
  }
}
TOP

Related Classes of versusSNP.Document

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.