From 01dd0eed037513b5b2dbcd499dfd0cdd957cf0bd Mon Sep 17 00:00:00 2001 From: Jim Procter Date: Mon, 5 Aug 2024 18:39:23 +0100 Subject: [PATCH] JAL-4446 calculate and report PaSiMap ETA in progress bar --- src/jalview/gui/PaSiMapPanel.java | 49 +++++++++++++------------------ src/jalview/gui/PairwiseAlignPanel.java | 41 ++++++++++++++++++++++++-- 2 files changed, 59 insertions(+), 31 deletions(-) diff --git a/src/jalview/gui/PaSiMapPanel.java b/src/jalview/gui/PaSiMapPanel.java index 2a6d6a9..98a366e 100644 --- a/src/jalview/gui/PaSiMapPanel.java +++ b/src/jalview/gui/PaSiMapPanel.java @@ -181,7 +181,7 @@ public class PaSiMapPanel extends GPaSiMapPanel { working = true; progId = System.currentTimeMillis(); - progressBar = this; + progressBar = new jalview.gui.ProgressBar(statusPanel, statusBar); String message = MessageManager .getString("label.pasimap_recalculating"); if (getParent() == null) @@ -657,6 +657,24 @@ public class PaSiMapPanel extends GPaSiMapPanel updateProgressBar(progress); } + public void updateProgressBarWithEta(int progress, double minutes) + { + JProgressBar pBar = progressBar.getProgressBar(progId); + + if (pBar == null) + { + return; + } + int max=pBar.getMaximum(); + progressBar.setProgressBarMessage(progId, + progressBar.getMessage(progId) + " (" + + (Double.isNaN(minutes) ? " .. working ..)" + : (minutes < 1.0 ? "Less than a minute)" + : ((int) Math.ceil(minutes)) + " mins. to go)"))); + pBar.setMaximum(max); + pBar.setValue(progress); + + } public void updateProgressBar(int progress) { JProgressBar pBar = progressBar.getProgressBar(progId); @@ -685,7 +703,8 @@ public class PaSiMapPanel extends GPaSiMapPanel { if (PairwiseAlignPanel.PROGRESS.equals(pcEvent.getPropertyName())) { - updateProgressBar((int) pcEvent.getNewValue()); + updateProgressBarWithEta((int) pcEvent.getNewValue(), pap.getEta()); + } else if (PairwiseAlignPanel.TOTAL.equals(pcEvent.getPropertyName())) { @@ -700,32 +719,6 @@ public class PaSiMapPanel extends GPaSiMapPanel final IProgressIndicatorHandler handler) { progressBar.registerHandler(id, handler); - // if (progressBarHandlers == null || - // !progressBars.contains(Long.valueOf(id))) - // { - // throw new - // Error(MessageManager.getString("error.call_setprogressbar_before_registering_handler")); - // } - // progressBarHandlers.put(Long.valueOf(id), handler); - // final JPanel progressPanel = (JPanel) progressBars.get(Long.valueOf(id)); - // if (handler.canCancel()) - // { - // JButton cancel = new JButton( - // MessageManager.getString("action.cancel")); - // final IProgressIndicator us = this; - // cancel.addActionListener(new ActionListener() - // { - // - // @Override - // public void actionPerformed(ActionEvent e) - // { - // handler.cancelActivity(id); - // us.setProgressBar(MessageManager.formatMessage("label.cancelled_params", - // new String[]{((JLabel) progressPanel.getComponent(0)).getText()}), id); - // } - // }); - // progressPanel.add(cancel, BorderLayout.EAST); - // } } /** diff --git a/src/jalview/gui/PairwiseAlignPanel.java b/src/jalview/gui/PairwiseAlignPanel.java index 77ec0f5..4c3b30c 100755 --- a/src/jalview/gui/PairwiseAlignPanel.java +++ b/src/jalview/gui/PairwiseAlignPanel.java @@ -84,6 +84,11 @@ public class PairwiseAlignPanel extends GPairwiseAlignPanel private ScoreMatrix scoreMatrix; /** + * remaining time + */ + private double etime=Double.NaN; + + /** * Creates a new PairwiseAlignPanel object. * * @param viewport @@ -191,7 +196,7 @@ public class PairwiseAlignPanel extends GPairwiseAlignPanel int count = seqs.length; boolean first = true; - + long time=System.currentTimeMillis(); progress = 0; firePropertyChange(TOTAL, 0, total); @@ -251,6 +256,11 @@ public class PairwiseAlignPanel extends GPairwiseAlignPanel } firePropertyChange(PROGRESS, progress, ++progress); } + if (i