From f40edd5d97571d331bd03489ef67858bbb2595bf Mon Sep 17 00:00:00 2001 From: Jim Procter Date: Thu, 29 Aug 2024 16:39:04 +0100 Subject: [PATCH] JAL-4446 improved reporting of progress, and transition between cancelable and non-cancelable phases of pasimap calculation --- src/jalview/analysis/PaSiMap.java | 18 ++++++++++++++++- src/jalview/gui/PaSiMapPanel.java | 12 +++++++++--- src/jalview/gui/PairwiseAlignPanel.java | 13 +++++++++++++ src/jalview/gui/ProgressBar.java | 32 +++++++++++++++++++------------ src/jalview/viewmodel/PaSiMapModel.java | 5 +++++ 5 files changed, 64 insertions(+), 16 deletions(-) diff --git a/src/jalview/analysis/PaSiMap.java b/src/jalview/analysis/PaSiMap.java index b2a17ac..5d7d435 100755 --- a/src/jalview/analysis/PaSiMap.java +++ b/src/jalview/analysis/PaSiMap.java @@ -67,6 +67,8 @@ public class PaSiMap implements Runnable private MatrixI eigenMatrix; + private volatile boolean canCancel; + /** * Constructor given the sequences to compute for, the similarity model to * use, and a set of parameters for sequence comparison @@ -228,6 +230,7 @@ public class PaSiMap implements Runnable @Override public void run() { + canCancel=true; try { // alignment = new PairwiseAlignPanel(seqs, true, 100, 5); @@ -237,11 +240,14 @@ public class PaSiMap implements Runnable cancel(); return; } + //alignment.setProgressMessage("Preparing to calculate pasimap..."); float[][] scores = alignment.getAlignmentScores(); // bigger index first // -- eg scores[14][13] SequenceI[] iseqs = alignment.getInputSequences(); Connectivity.getConnectivity(iseqs, scores, dim); - + + canCancel=false; + alignment.updateProgress(PairwiseAlignPanel.PROGRESSMESSAGE, "Creating the PaSiMap"); pairwiseScores = new Matrix(scores); pairwiseScores.fillDiagonal(); @@ -249,6 +255,7 @@ public class PaSiMap implements Runnable ccAnalysis cc = new ccAnalysis(pairwiseScores, dim); eigenMatrix = cc.run().mirrorCol(); + alignment.updateProgress(PairwiseAlignPanel.PROGRESSCOMPLETE, "Finished PaSiMap."); } catch (Exception q) { @@ -363,4 +370,13 @@ public class PaSiMap implements Runnable { return dim; } + + /** + * + * @return true if pasimap calculation can (still) be interrupted + */ + public boolean isCancellable() + { + return canCancel; + } } diff --git a/src/jalview/gui/PaSiMapPanel.java b/src/jalview/gui/PaSiMapPanel.java index 6c8d509..e3d5b0a 100644 --- a/src/jalview/gui/PaSiMapPanel.java +++ b/src/jalview/gui/PaSiMapPanel.java @@ -230,7 +230,6 @@ public class PaSiMapPanel extends GPaSiMapPanel addProgressListenerFor(pap); progressBar.registerHandler(progId, new IProgressIndicatorHandler() { - @Override public boolean cancelActivity(long id) { @@ -241,10 +240,9 @@ public class PaSiMapPanel extends GPaSiMapPanel @Override public boolean canCancel() { - return true; + return getPasimapModel().canCancel(); } }); - getPasimapModel().calculate(pap); if (!getPasimapModel().isCancelled()) { @@ -763,6 +761,14 @@ public class PaSiMapPanel extends GPaSiMapPanel { updateProgressBarEta((double) pcEvent.getNewValue()); } + else if (PairwiseAlignPanel.PROGRESSMESSAGE.equals(pcEvent.getPropertyName())) + { + setProgressBarMessage(progId, (String) pcEvent.getNewValue()); + } + else if (PairwiseAlignPanel.PROGRESSCOMPLETE.equals(pcEvent.getPropertyName())) + { + setProgressBarMessage(progId, (String) pcEvent.getNewValue()); + } } }); } diff --git a/src/jalview/gui/PairwiseAlignPanel.java b/src/jalview/gui/PairwiseAlignPanel.java index 36c1f01..90123f5 100755 --- a/src/jalview/gui/PairwiseAlignPanel.java +++ b/src/jalview/gui/PairwiseAlignPanel.java @@ -72,6 +72,9 @@ public class PairwiseAlignPanel extends GPairwiseAlignPanel protected static final String ETA = "eta_in_minutes"; + public static final String PROGRESSCOMPLETE = "finished_stop_progress"; + public static final String PROGRESSMESSAGE = "message_in_progress"; + private volatile boolean cancelled; private long total; @@ -465,4 +468,14 @@ public class PairwiseAlignPanel extends GPairwiseAlignPanel { return cancelled; } + + /** + * sends status updates to the progress bar for this panel + * @param type - PROGRESSMESSAGE or PROGRESSCOMPLETE + * @param message - the message (may be internationalised key) + */ + public void updateProgress(String type, String message) + { + firePropertyChange(type, "", MessageManager.getStringOrReturn("progress", message)); + } } diff --git a/src/jalview/gui/ProgressBar.java b/src/jalview/gui/ProgressBar.java index 37a4b94..364cf7a 100644 --- a/src/jalview/gui/ProgressBar.java +++ b/src/jalview/gui/ProgressBar.java @@ -240,15 +240,6 @@ public class ProgressBar implements IProgressIndicator "call setProgressBar before registering the progress bar's handler."); return; } - - /* - * Nothing useful to do if not a Cancel handler - */ - if (!handler.canCancel()) - { - return; - } - progressBarHandlers.put(id, handler); JButton cancel = new JButton( MessageManager.getString("action.cancel")); @@ -266,11 +257,22 @@ public class ProgressBar implements IProgressIndicator } }); progressPanel.add(cancel, BorderLayout.EAST); - refreshLayout(); + updateCancelHandler(progressPanel, handler); } }); } + protected void updateCancelHandler(Container progressPanel, IProgressIndicatorHandler handler) + { + for (Component j:progressPanel.getComponents()) + { + if (j instanceof JButton) + { + j.setEnabled(handler.canCancel()); + } + } + refreshLayout(); + } /* * @@ -316,8 +318,14 @@ public class ProgressBar implements IProgressIndicator { if (component.getClass().equals(JLabel.class)) { - ((JLabel) component).setText(message);; - refreshLayout(); + ((JLabel) component).setText(message); + IProgressIndicatorHandler handler = progressBarHandlers.get(id); + if (handler!=null) { + // show/hide cancel on message change + updateCancelHandler(progBar, handler); + } else { + refreshLayout(); + } } } } diff --git a/src/jalview/viewmodel/PaSiMapModel.java b/src/jalview/viewmodel/PaSiMapModel.java index ac070e8..6b6dc41 100644 --- a/src/jalview/viewmodel/PaSiMapModel.java +++ b/src/jalview/viewmodel/PaSiMapModel.java @@ -281,4 +281,9 @@ public class PaSiMapModel { pasimap.cancel(); } + + public boolean canCancel() + { + return (!isCancelled() && pasimap.isCancellable()); + } } -- 1.7.10.2