import java.awt.*;
import java.awt.event.*;
+
import javax.swing.*;
import MCview.*;
import jalview.ws.DBRefFetcher;
import jalview.ws.ebi.EBIFetchClient;
import jalview.ws.seqfetcher.ASequenceFetcher;
+import jalview.ws.seqfetcher.DbSourceProxy;
import java.awt.Rectangle;
import java.awt.BorderLayout;
public class SequenceFetcher
extends JPanel implements Runnable
{
- ASequenceFetcher sfetch;
+ // ASequenceFetcher sfetch;
JInternalFrame frame;
+ IProgressIndicator guiWindow;
AlignFrame alignFrame;
StringBuffer result;
final String noDbSelected = "-- Select Database --";
Hashtable sources = new Hashtable();
- public SequenceFetcher(AlignFrame af)
+ private static ASequenceFetcher sfetch=null;
+ public SequenceFetcher(IProgressIndicator guiIndic)
{
- alignFrame = af;
- sfetch = new jalview.ws.SequenceFetcher();
+ final IProgressIndicator guiWindow = guiIndic;
+ final SequenceFetcher us = this;
+ // launch initialiser thread
+ Thread sf = new Thread(new Runnable() {
+
+ public void run()
+ {
+ if (sfetch==null)
+ {
+ /**
+ * give a visual indication that sequence fetcher construction is occuring
+ */
+ if ( guiWindow!=null )
+ {
+ guiWindow.setProgressBar("Initialising Sequence Database Fetchers", this.hashCode());
+ }
+ ASequenceFetcher sf = new jalview.ws.SequenceFetcher();
+ if ( guiWindow!=null )
+ {
+ guiWindow.setProgressBar("Initialising Sequence Database Fetchers", this.hashCode());
+ }
+ sfetch = sf;
+
+ }
+ us.initGui(guiWindow);
+ }
+ });
+ sf.start();
+ }
+ /**
+ * called by thread spawned by constructor
+ * @param guiWindow
+ */
+ private void initGui(IProgressIndicator guiWindow) {
+ this.guiWindow = guiWindow;
+ if (guiWindow instanceof AlignFrame)
+ {
+ alignFrame = (AlignFrame) guiWindow;
+ }
+
database.addItem(noDbSelected);
/*
* Dynamically generated database list
this.setLayout(borderLayout2);
database.setFont(new java.awt.Font("Verdana", Font.PLAIN, 11));
+ dbeg.setFont(new java.awt.Font("Verdana", Font.BOLD, 11));
jLabel1.setFont(new java.awt.Font("Verdana", Font.ITALIC, 11));
jLabel1.setHorizontalAlignment(SwingConstants.CENTER);
jLabel1.setText(
ok_actionPerformed();
}
});
+ clear.setText("Clear");
+ clear.addActionListener(new ActionListener()
+ {
+ public void actionPerformed(ActionEvent e)
+ {
+ clear_actionPerformed();
+ }
+ });
+
+ example.setText("Example");
+ example.addActionListener(new ActionListener()
+ {
+ public void actionPerformed(ActionEvent e)
+ {
+ example_actionPerformed();
+ }
+ });
close.setText("Close");
close.addActionListener(new ActionListener()
{
jPanel3.setLayout(borderLayout1);
borderLayout1.setVgap(5);
jPanel1.add(ok);
+ jPanel1.add(example);
+ jPanel1.add(clear);
jPanel1.add(close);
- jPanel3.add(jPanel2, java.awt.BorderLayout.WEST);
- jPanel2.add(database);
+ jPanel3.add(jPanel2, java.awt.BorderLayout.CENTER);
+ jPanel2.setLayout(borderLayout3);
+
+ database.addActionListener(new ActionListener() {
+
+ public void actionPerformed(ActionEvent e)
+ {
+ DbSourceProxy db=null;
+ try {
+ db = sfetch.getSourceProxy((String)sources.get(database.getSelectedItem()));
+ dbeg.setText("Example query: "+db.getTestQuery());
+ } catch (Exception ex)
+ {
+ dbeg.setText("");
+ }
+ jPanel2.repaint();
+ }
+ });
+ dbeg.setText("");
+ jPanel2.add(database, java.awt.BorderLayout.NORTH);
+ jPanel2.add(dbeg, java.awt.BorderLayout.CENTER);
+ jPanel2.add(jLabel1, java.awt.BorderLayout.SOUTH);
+ // jPanel2.setPreferredSize(new Dimension())
jPanel3.add(jScrollPane1, java.awt.BorderLayout.CENTER);
- jPanel3.add(jLabel1, java.awt.BorderLayout.NORTH);
this.add(jPanel1, java.awt.BorderLayout.SOUTH);
this.add(jPanel3, java.awt.BorderLayout.CENTER);
+ this.add(jPanel2,java.awt.BorderLayout.NORTH);
jScrollPane1.getViewport().add(textArea);
+
}
+ protected void example_actionPerformed()
+ {
+ DbSourceProxy db=null;
+ try {
+ db = sfetch.getSourceProxy((String)sources.get(database.getSelectedItem()));
+ textArea.setText(db.getTestQuery());
+ } catch (Exception ex)
+ {
+ }
+ jPanel3.repaint();
+ }
+ protected void clear_actionPerformed()
+ {
+ textArea.setText("");
+ jPanel3.repaint();
+ }
+ JLabel dbeg = new JLabel();
JComboBox database = new JComboBox();
JLabel jLabel1 = new JLabel();
JButton ok = new JButton();
+ JButton clear = new JButton();
+ JButton example = new JButton();
JButton close = new JButton();
JPanel jPanel1 = new JPanel();
JTextArea textArea = new JTextArea();
JScrollPane jScrollPane1 = new JScrollPane();
JPanel jPanel2 = new JPanel();
JPanel jPanel3 = new JPanel();
+ JPanel jPanel4 = new JPanel();
+
BorderLayout borderLayout1 = new BorderLayout();
BorderLayout borderLayout2 = new BorderLayout();
+ BorderLayout borderLayout3 = new BorderLayout();
public void close_actionPerformed(ActionEvent e)
{
try
}
AlignmentI aresult=null;
try {
+ guiWindow.setProgressBar("Fetching Sequences from "+database.getSelectedItem(), Thread.currentThread().hashCode());
aresult = sfetch.getSourceProxy((String)sources.get(database.getSelectedItem()))
.getSequenceRecords(textArea.getText());
+
}
catch (Exception e)
{
System.err.println("Retrieval failed for source ='"+database.getSelectedItem()+"' and query\n'"+textArea.getText()+"'\n");
e.printStackTrace();
}
+ catch (OutOfMemoryError e)
+ {
+ showErrorMessage("Out of Memory when retrieving " + textArea.getText()
+ + " from " + database.getSelectedItem()+"\nPlease see the Jalview FAQ for instructions for increasing the memory available to Jalview.\n");
+ e.printStackTrace();
+ }
+ catch (Error e)
+ {
+ showErrorMessage("Serious Error retrieving " + textArea.getText()
+ + " from " + database.getSelectedItem());
+ e.printStackTrace();
+ }
+ guiWindow.setProgressBar(null, Thread.currentThread().hashCode());
if (aresult!=null)
{
parseResult(aresult, null, null);