From: jprocter Date: Fri, 1 Aug 2008 13:19:48 +0000 (+0000) Subject: new SequenceFetcher gui and visual delay indication for initialisation and fetching X-Git-Tag: Release_2_4~70 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=dbbd8851fe0e30aa9606657b5f4eb41e0db21563;p=jalview.git new SequenceFetcher gui and visual delay indication for initialisation and fetching --- diff --git a/src/jalview/gui/AlignFrame.java b/src/jalview/gui/AlignFrame.java index 15cbf01..e64b8e4 100755 --- a/src/jalview/gui/AlignFrame.java +++ b/src/jalview/gui/AlignFrame.java @@ -45,7 +45,7 @@ import jalview.ws.*; * @version $Revision$ */ public class AlignFrame - extends GAlignFrame implements DropTargetListener + extends GAlignFrame implements DropTargetListener, IProgressIndicator { /** DOCUMENT ME!! */ public static final int DEFAULT_WIDTH = 700; @@ -555,6 +555,9 @@ public class AlignFrame Hashtable progressBars; + /* (non-Javadoc) + * @see jalview.gui.IProgressIndicator#setProgressBar(java.lang.String, long) + */ public void setProgressBar(String message, long id) { if(progressBars == null) @@ -3468,7 +3471,7 @@ public class AlignFrame Vector seqsrch = (Vector) Discoverer.services.get("SeqSearch"); // TODO: move GUI generation code onto service implementation - so a client instance attaches itself to the GUI with method call like jalview.ws.MsaWSClient.bind(servicehandle, Desktop.instance, alignframe) Vector wsmenu = new Vector(); - final AlignFrame af = this; + final IProgressIndicator af = this; if (msaws != null) { // Add any Multiple Sequence Alignment Services diff --git a/src/jalview/gui/DasSourceBrowser.java b/src/jalview/gui/DasSourceBrowser.java index 09c8a3e..e695d3d 100755 --- a/src/jalview/gui/DasSourceBrowser.java +++ b/src/jalview/gui/DasSourceBrowser.java @@ -269,11 +269,10 @@ public class DasSourceBrowser refresh.setVisible(false); progressBar.setVisible(true); progressBar.setIndeterminate(true); - - dasSources = jalview.ws.DasSequenceFeatureFetcher.getDASSources(); - - appendLocalSources(); - + // Refresh the source list. + dasSources=null; + getDASSource(); + init(); loadingDasSources = false; @@ -298,7 +297,10 @@ public class DasSourceBrowser return selected; } - + /** + * retrieve das sources from registry and add local source list + * @return + */ public DasSource[] getDASSource() { if (dasSources == null) diff --git a/src/jalview/gui/Desktop.java b/src/jalview/gui/Desktop.java index ed968f8..262a9be 100755 --- a/src/jalview/gui/Desktop.java +++ b/src/jalview/gui/Desktop.java @@ -19,6 +19,7 @@ package jalview.gui; import jalview.io.*; + import java.awt.*; import java.awt.datatransfer.*; import java.awt.dnd.*; @@ -38,7 +39,7 @@ import javax.swing.event.MenuListener; */ public class Desktop extends jalview.jbgui.GDesktop implements DropTargetListener, - ClipboardOwner + ClipboardOwner, IProgressIndicator { /** DOCUMENT ME!! */ public static Desktop instance; @@ -829,7 +830,7 @@ public class Desktop public void inputSequence_actionPerformed(ActionEvent e) { - new SequenceFetcher(null); + new SequenceFetcher(this); } JPanel progressPanel; @@ -1390,4 +1391,27 @@ public class Desktop JOptionPane.ERROR_MESSAGE); } } + + /** + * Progress bars managed by the IProgressIndicator method. + */ + private Hashtable progressBars; + /* (non-Javadoc) + * @see jalview.gui.IProgressIndicator#setProgressBar(java.lang.String, long) + */ + public void setProgressBar(String message, long id) + { + if(progressBars == null) + { + progressBars = new Hashtable(); + } + + if(progressBars.get( new Long(id) )!=null) + { + JProgressBar progressPanel = (JProgressBar)progressBars.remove( new Long(id) ); + removeProgressPanel(progressPanel); + } else { + progressBars.put(new Long(id), addProgressPanel(message)); + } + } } diff --git a/src/jalview/gui/SequenceFetcher.java b/src/jalview/gui/SequenceFetcher.java index 1675304..53f75a4 100755 --- a/src/jalview/gui/SequenceFetcher.java +++ b/src/jalview/gui/SequenceFetcher.java @@ -23,6 +23,7 @@ import java.util.*; import java.awt.*; import java.awt.event.*; + import javax.swing.*; import MCview.*; @@ -33,6 +34,7 @@ import jalview.io.*; 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; @@ -41,16 +43,56 @@ import java.awt.Dimension; 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 @@ -108,6 +150,7 @@ extends JPanel implements Runnable 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( @@ -120,6 +163,23 @@ extends JPanel implements Runnable 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() { @@ -141,28 +201,74 @@ extends JPanel implements Runnable 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 @@ -213,8 +319,10 @@ extends JPanel implements Runnable } 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) { @@ -224,6 +332,19 @@ extends JPanel implements Runnable 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);