/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/*
* ImportFeaturesWindow.java
*
* Created on Jun 24, 2011, 3:22:40 PM
*/
package org.clothocad.tool.sequenceview;
import java.util.ArrayList;
import javax.swing.JProgressBar;
import javax.swing.SwingWorker;
import org.clothocore.api.core.Collector;
import org.clothocore.api.data.ObjLink;
import org.clothocore.api.data.ObjType;
import org.openide.util.Exceptions;
/**
*
* @author Henry
*/
public class ImportFeaturesWindow extends javax.swing.JFrame {
/** Creates new form ImportFeaturesWindow */
public ImportFeaturesWindow() {
initComponents();
this.setVisible(true);
}
public ImportFeaturesWindow(String type, String s, SequenceView sv, ArrayList<String> inputLines) {
initComponents();
_type = type;
_sequence = s;
parseTarget = inputLines;
_sv = sv;
ArrayList<ObjLink> collectionLinks = Collector.getAllLinksOf(ObjType.COLLECTION);
collectionComboBox.removeAllItems();
for (ObjLink oj : collectionLinks) {
collectionComboBox.addItem(oj);
}
collectionComboBox.setSelectedIndex(-1);
this.setSize(320, 180);
this.setVisible(true);
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
collectionComboBox = new javax.swing.JComboBox();
yesButton = new javax.swing.JButton();
cancelButton = new javax.swing.JButton();
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
statusLabel = new javax.swing.JLabel();
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
setTitle(org.openide.util.NbBundle.getMessage(ImportFeaturesWindow.class, "ImportFeaturesWindow.title")); // NOI18N
setAlwaysOnTop(true);
setMinimumSize(new java.awt.Dimension(223, 135));
collectionComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
yesButton.setText(org.openide.util.NbBundle.getMessage(ImportFeaturesWindow.class, "ImportFeaturesWindow.yesButton.text")); // NOI18N
yesButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
yesButtonActionPerformed(evt);
}
});
cancelButton.setText(org.openide.util.NbBundle.getMessage(ImportFeaturesWindow.class, "ImportFeaturesWindow.cancelButton.text")); // NOI18N
cancelButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
cancelButtonActionPerformed(evt);
}
});
jLabel1.setText(org.openide.util.NbBundle.getMessage(ImportFeaturesWindow.class, "ImportFeaturesWindow.jLabel1.text")); // NOI18N
jLabel2.setText(org.openide.util.NbBundle.getMessage(ImportFeaturesWindow.class, "ImportFeaturesWindow.jLabel2.text")); // NOI18N
statusLabel.setText(org.openide.util.NbBundle.getMessage(ImportFeaturesWindow.class, "ImportFeaturesWindow.statusLabel.text")); // NOI18N
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel1)
.addGroup(layout.createSequentialGroup()
.addComponent(jLabel2)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(statusLabel, javax.swing.GroupLayout.DEFAULT_SIZE, 158, Short.MAX_VALUE))
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
.addComponent(collectionComboBox, javax.swing.GroupLayout.Alignment.LEADING, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
.addComponent(yesButton)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(cancelButton))))
.addContainerGap())
);
layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {cancelButton, yesButton});
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jLabel1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(collectionComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(yesButton)
.addComponent(cancelButton))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel2)
.addComponent(statusLabel))
.addContainerGap(31, Short.MAX_VALUE))
);
layout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {cancelButton, yesButton});
pack();
}// </editor-fold>//GEN-END:initComponents
private void yesButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_yesButtonActionPerformed
if (collectionComboBox.getSelectedIndex() != -1) {
statusLabel.setText("Parsing for features. Please wait");
this.repaint();
try {
boolean finished = false;
if (_type.equals("genbank")) {
new SwingWorker() {
@Override
protected Object doInBackground() throws Exception {
_sv.parseForGenbankFeatures(_sequence, (ObjLink) collectionComboBox.getSelectedItem(), parseTarget);
return null;
}
}.execute();
} else if (_type.equals("ApE")) {
new SwingWorker() {
@Override
protected Object doInBackground() throws Exception {
_sv.parseForApEFeatures((ObjLink) collectionComboBox.getSelectedItem(), parseTarget);
return null;
}
}.execute();
}
javax.swing.JOptionPane.showMessageDialog(null, "Adding new Clotho Features into " + ((ObjLink) collectionComboBox.getSelectedItem()).name+" in the background.");
this.dispose();
} catch (Exception ex) {
javax.swing.JOptionPane.showMessageDialog(null, "Error parsing for genbank features. Please check that valid genbank file was used");
Exceptions.printStackTrace(ex);
}
} else {
statusLabel.setText("Collection not selected. Please select a Collection \nto save new Features into");
return;
}
}//GEN-LAST:event_yesButtonActionPerformed
private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelButtonActionPerformed
this.dispose();
}//GEN-LAST:event_cancelButtonActionPerformed
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new ImportFeaturesWindow().setVisible(true);
}
});
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton cancelButton;
private javax.swing.JComboBox collectionComboBox;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel statusLabel;
private javax.swing.JButton yesButton;
// End of variables declaration//GEN-END:variables
private ArrayList<String> parseTarget; //ArrayList of Strings representing lines from a gen bank file that needs to be parsed
private SequenceView _sv;
private String _sequence;
private String _type; //indicates what type of file is being imported
}