From: jprocter Date: Fri, 21 Sep 2012 16:15:32 +0000 (+0100) Subject: JAL-1165 allow progress indicators on the web service window X-Git-Tag: Jalview_2_9~307^2~3 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=7796bc87c98b21f199f9dc195401223984619091;p=jalview.git JAL-1165 allow progress indicators on the web service window --- diff --git a/src/jalview/gui/WebserviceInfo.java b/src/jalview/gui/WebserviceInfo.java index c3adbac..69fb44c 100755 --- a/src/jalview/gui/WebserviceInfo.java +++ b/src/jalview/gui/WebserviceInfo.java @@ -41,7 +41,7 @@ import jalview.ws.WSClientI; * @version $Revision$ */ public class WebserviceInfo extends GWebserviceInfo implements - HyperlinkListener + HyperlinkListener, IProgressIndicator { /** Job is Queued */ @@ -825,4 +825,107 @@ public class WebserviceInfo extends GWebserviceInfo implements { Desktop.hyperlinkUpdate(e); } + + // methods for implementing IProgressIndicator + // need to refactor to a reusable stub class + Hashtable progressBars, progressBarHandlers; + + /* + * (non-Javadoc) + * + * @see jalview.gui.IProgressIndicator#setProgressBar(java.lang.String, long) + */ + @Override + public void setProgressBar(String message, long id) + { + if (progressBars == null) + { + progressBars = new Hashtable(); + progressBarHandlers = new Hashtable(); + } + + JPanel progressPanel; + Long lId = new Long(id); + GridLayout layout = (GridLayout) statusPanel.getLayout(); + if (progressBars.get(lId) != null) + { + progressPanel = (JPanel) progressBars.get(new Long(id)); + statusPanel.remove(progressPanel); + progressBars.remove(lId); + progressPanel = null; + if (message != null) + { + statusBar.setText(message); + } + if (progressBarHandlers.contains(lId)) + { + progressBarHandlers.remove(lId); + } + layout.setRows(layout.getRows() - 1); + } + else + { + progressPanel = new JPanel(new BorderLayout(10, 5)); + + JProgressBar progressBar = new JProgressBar(); + progressBar.setIndeterminate(true); + + progressPanel.add(new JLabel(message), BorderLayout.WEST); + progressPanel.add(progressBar, BorderLayout.CENTER); + + layout.setRows(layout.getRows() + 1); + statusPanel.add(progressPanel); + + progressBars.put(lId, progressPanel); + } + // update GUI + // setMenusForViewport(); + validate(); + } + + @Override + public void registerHandler(final long id, + final IProgressIndicatorHandler handler) + { + if (progressBarHandlers == null || !progressBars.contains(new Long(id))) + { + throw new Error( + "call setProgressBar before registering the progress bar's handler."); + } + progressBarHandlers.put(new Long(id), handler); + final JPanel progressPanel = (JPanel) progressBars.get(new Long(id)); + if (handler.canCancel()) + { + JButton cancel = new JButton("Cancel"); + final IProgressIndicator us = this; + cancel.addActionListener(new ActionListener() + { + + @Override + public void actionPerformed(ActionEvent e) + { + handler.cancelActivity(id); + us.setProgressBar( + "Cancelled " + + ((JLabel) progressPanel.getComponent(0)) + .getText(), id); + } + }); + progressPanel.add(cancel, BorderLayout.EAST); + } + } + + /** + * + * @return true if any progress bars are still active + */ + @Override + public boolean operationInProgress() + { + if (progressBars != null && progressBars.size() > 0) + { + return true; + } + return false; + } } diff --git a/src/jalview/jbgui/GWebserviceInfo.java b/src/jalview/jbgui/GWebserviceInfo.java index 5d6b6eb..00806ed 100755 --- a/src/jalview/jbgui/GWebserviceInfo.java +++ b/src/jalview/jbgui/GWebserviceInfo.java @@ -52,6 +52,9 @@ public class GWebserviceInfo extends JPanel public JButton mergeResults = new JButton(); GridBagLayout gridBagLayout1 = new GridBagLayout(); + + public JPanel statusPanel = new JPanel(new GridLayout()); + public JLabel statusBar = new JLabel(); /** * Creates a new GWebserviceInfo object. @@ -110,6 +113,8 @@ public class GWebserviceInfo extends JPanel buttonPanel.add(cancel, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets( 19, 6, 16, 4), 0, 0)); + this.add(statusPanel, java.awt.BorderLayout.SOUTH); + statusPanel.add(statusBar, null); } /**