* @version $Revision$
*/
public class WebserviceInfo extends GWebserviceInfo implements
- HyperlinkListener
+ HyperlinkListener, IProgressIndicator
{
/** Job is Queued */
{
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;
+ }
}
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.
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);
}
/**