Package versusSNP.gui.dialogs

Source Code of versusSNP.gui.dialogs.TrimSequenceDialog

package versusSNP.gui.dialogs;

import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextField;
import javax.swing.JTextPane;

import versusSNP.Document;
import versusSNP.Size;
import versusSNP.genome.Genome;
import versusSNP.genome.ORF;
import versusSNP.gui.UICaption;
import versusSNP.gui.widgets.JORFComboBox;
import versusSNP.util.Utils;
import versusSNP.util.swing.ArrayListComboBoxModel;

public class TrimSequenceDialog extends JOptionPane implements GenericDialog, ActionListener {
  private static final long serialVersionUID = 7978765634723983305L;
  private JComboBox selector1;
  private JORFComboBox selector2;
  private JPanel panel1, panel2;
  private JTextField txtBegin, txtEnd;
  private JButton btnTrim;
  private JCheckBox cbComplement;
  private JTextPane txtSeq;
  private ORF selectedORF;

  public TrimSequenceDialog(Document document) {
    super();
    selector1 = new JComboBox(new ArrayListComboBoxModel(document.getGenomes()));
    selector2 = new JORFComboBox();
    panel1 = new JPanel(new GridLayout(2,2));
    panel2 = new JPanel(new GridLayout(1,1));
    txtBegin = new JTextField();
    txtEnd = new JTextField();
    txtSeq = new JTextPane();
//    txtSeq.setLineWrap(true);
    btnTrim = new JButton(UICaption.dialog_button_trim_sequence_trim);
    cbComplement = new JCheckBox(UICaption.dialog_checkbox_trim_sequence_complement);
    selector1.addActionListener(this);
    selector2.addActionListener(this);
    btnTrim.addActionListener(this);
    txtBegin.setPreferredSize(Size.dialog_textfield_numeric);
    txtEnd.setPreferredSize(Size.dialog_textfield_numeric);
    txtSeq.setPreferredSize(Size.dialog_textfield_sequence);
    panel1.add(new JLabel(UICaption.dialog_label_begin));
    panel1.add(txtBegin);
    panel1.add(new JLabel(UICaption.dialog_label_end));
    panel1.add(txtEnd);
    panel2.add(new JScrollPane(txtSeq, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED));
  }

  @Override
  public int showDialog() {
    Object[] options = {UICaption.dialog_option_ok, UICaption.dialog_option_cancel};
    return showOptionDialog(null, new Object[] {
        new JLabel(UICaption.dialog_label_trim_sequence_which_genome),
        selector1,
        new JLabel(UICaption.dialog_label_trim_sequence_which_orf),
        selector2,
        panel1,
        btnTrim,
        cbComplement,
        new JLabel(UICaption.dialog_label_trim_sequence_sequence),
        panel2 },
        UICaption.dialog_caption_trim_sequence,
        JOptionPane.OK_CANCEL_OPTION,
        JOptionPane.PLAIN_MESSAGE,
        null, options, options[0]);
  }

  @Override
  public void actionPerformed(ActionEvent ae) {
    Object obj = ae.getSource();
    if (obj.equals(selector1)) {
      Genome referenceGenome = (Genome) selector1.getSelectedItem();
      if (selector2.getReferenceGenome() == null ||
        selector2.getReferenceGenome() != referenceGenome) {
        selector2.setReferenceGenomeAndAddORF(referenceGenome);
      }
    } else if (obj.equals(selector2)) {
      selectedORF = (ORF) selector2.getSelectedItem();
    } else if (obj.equals(btnTrim)) {
      if (selectedORF == null) return;
      try {
        int begin = Utils.toIntegar(txtBegin.getText());
        int end = Utils.toIntegar(txtEnd.getText());
        if (cbComplement.isSelected()) {
          txtSeq.setText(selectedORF.getSequence().complementSequence(begin, end+1));
        } else {
          txtSeq.setText(selectedORF.getSequence().subString(begin, end));
        }
      } catch (NumberFormatException ex) {
        JOptionPane.showMessageDialog(null, UICaption.dialog_exception_parse_int_number_format, UICaption.dialog_caption_error, JOptionPane.ERROR_MESSAGE);
      } catch (IndexOutOfBoundsException ex) {
        JOptionPane.showMessageDialog(null,
                UICaption.dialog_exception_subsequence_index_out_of_bounds
                  + UICaption.dialog_label_sequence_length
                    + selectedORF.getLength(), UICaption.dialog_caption_error, JOptionPane.ERROR_MESSAGE);
      }
    }
  }
}
TOP

Related Classes of versusSNP.gui.dialogs.TrimSequenceDialog

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.