updateEditMenuBar();
}
- Hashtable progressBars;
+ Hashtable progressBars, progressBarHandlers;
/*
* (non-Javadoc)
if (progressBars == null)
{
progressBars = new Hashtable();
+ progressBarHandlers = new Hashtable();
}
JPanel progressPanel;
{
statusBar.setText(message);
}
-
+ if (progressBarHandlers.contains(new Long(id)))
+ {
+ progressBarHandlers.remove(new Long(id));
+ }
layout.setRows(layout.getRows() - 1);
}
else
setMenusForViewport();
validate();
}
+ 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() {
+ 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
/**
* Progress bars managed by the IProgressIndicator method.
*/
- private Hashtable progressBars;
+ private Hashtable progressBars, progressBarHandlers;
/*
* (non-Javadoc)
if (progressBars == null)
{
progressBars = new Hashtable();
+ progressBarHandlers = new Hashtable();
}
if (progressBars.get(new Long(id)) != null)
{
JProgressBar progressPanel = (JProgressBar) progressBars
.remove(new Long(id));
+ if (progressBarHandlers.contains(new Long(id)))
+ {
+ progressBarHandlers.remove(new Long(id));
+ }
removeProgressPanel(progressPanel);
}
else
progressBars.put(new Long(id), addProgressPanel(message));
}
}
+ /* (non-Javadoc)
+ * @see jalview.gui.IProgressIndicator#registerHandler(long, jalview.gui.IProgressIndicatorHandler)
+ */
+ 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() {
+ public void actionPerformed(ActionEvent e)
+ {
+ handler.cancelActivity(id);
+ us.setProgressBar("Cancelled "+((JLabel)progressPanel.getComponent(0)).getText(), id);
+ }
+ });
+ progressPanel.add(cancel, BorderLayout.EAST);
+ }
+ }
/**
* This will return the first AlignFrame viewing AlignViewport av. It will
* break if there are more than one AlignFrames viewing a particular av. This
* unique handle for this indicator\r
*/\r
public abstract void setProgressBar(String message, long id);\r
+ /**\r
+ * register a handler for the progress bar identified by id\r
+ * @param id\r
+ * @param handler\r
+ */\r
+ public abstract void registerHandler(long id, IProgressIndicatorHandler handler);\r
+ \r
\r
}\r
--- /dev/null
+package jalview.gui;\r
+\r
+public interface IProgressIndicatorHandler\r
+{\r
+ /**\r
+ * \r
+ * @return true if a cancel button can be shown \r
+ */\r
+ public boolean canCancel();\r
+ /**\r
+ * Callback to cancel activity if the cancel button is pressed.\r
+ * @param id\r
+ * @return true if activity was cancelled\r
+ */\r
+ public boolean cancelActivity(long id);\r
+}\r