From: Jim Procter Date: Mon, 5 Aug 2024 17:01:47 +0000 (+0100) Subject: JAL-4446 allow progress bar message to be changed whilst progress continues & todo... X-Git-Tag: Release_2_11_4_0~14^2~6^2~15 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=84126942cf15bed4109e81345e2412425cfa48ed;p=jalview.git JAL-4446 allow progress bar message to be changed whilst progress continues & todo re desktop's custom progress implementation --- diff --git a/src/jalview/gui/AlignFrame.java b/src/jalview/gui/AlignFrame.java index c81a5de..f61c073 100644 --- a/src/jalview/gui/AlignFrame.java +++ b/src/jalview/gui/AlignFrame.java @@ -1004,6 +1004,16 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, return null; } + public String getMessage(long id) + { + return progressBar.getMessage(id); + } + + public void setProgressBarMessage(long id, String message) + { + progressBar.setProgressBarMessage(id, message); + } + @Override public void registerHandler(final long id, final IProgressIndicatorHandler handler) @@ -1022,6 +1032,8 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, return progressBar == null ? false : progressBar.operationInProgress(); } + + /** * Sets the text of the status bar. Note that setting a null or empty value * will cause the status bar to be hidden, with possibly undesirable flicker diff --git a/src/jalview/gui/Desktop.java b/src/jalview/gui/Desktop.java index 9c542a3..394ef65 100644 --- a/src/jalview/gui/Desktop.java +++ b/src/jalview/gui/Desktop.java @@ -23,6 +23,7 @@ package jalview.gui; import java.awt.BorderLayout; import java.awt.Color; import java.awt.Component; +import java.awt.Container; import java.awt.Dimension; import java.awt.FontMetrics; import java.awt.Graphics; @@ -2903,10 +2904,13 @@ public class Desktop extends jalview.jbgui.GDesktop /** * Progress bars managed by the IProgressIndicator method. + * TODO - delegate to jalview.gui.ProgressBar */ private Hashtable progressBars; private Hashtable progressBarHandlers; + + private Hashtable progressBarMessages; /* * (non-Javadoc) @@ -2920,6 +2924,7 @@ public class Desktop extends jalview.jbgui.GDesktop { progressBars = new Hashtable<>(); progressBarHandlers = new Hashtable<>(); + progressBarMessages = new Hashtable<>(); } if (progressBars.get(Long.valueOf(id)) != null) @@ -2934,6 +2939,7 @@ public class Desktop extends jalview.jbgui.GDesktop else { progressBars.put(Long.valueOf(id), addProgressPanel(message)); + progressBarMessages.put(id, message); } } @@ -2994,6 +3000,36 @@ public class Desktop extends jalview.jbgui.GDesktop } } + + @Override + public String getMessage(long id) + { + return progressBarMessages.get(id); + } + + /** + * change the text shown alongside a progress bar + * @param id + * @param message + */ + @Override + public void setProgressBarMessage(long id,String message) + { + Container progBar = progressBars.get(id); + if (progBar == null || progBar.getComponentCount() == 0) + { + return; + } + for (Component component : progBar.getComponents()) + { + if (component.getClass().equals(JLabel.class)) + { + ((JLabel) component).setText(message);; + progBar.revalidate(); + } + } + } + /** * * @return true if any progress bars are still active diff --git a/src/jalview/gui/IProgressIndicator.java b/src/jalview/gui/IProgressIndicator.java index 387236a..cb67b35 100644 --- a/src/jalview/gui/IProgressIndicator.java +++ b/src/jalview/gui/IProgressIndicator.java @@ -65,4 +65,18 @@ public interface IProgressIndicator */ public JProgressBar getProgressBar(long id); + /** + * get the initial message shown when the progress bar was created via setProgressBar + * @param id + * @return null or the message used + */ + String getMessage(long id); + + /** + * change the text shown alongside a progress bar + * @param id + * @param message + */ + void setProgressBarMessage(long id, String message); + } diff --git a/src/jalview/gui/PCAPanel.java b/src/jalview/gui/PCAPanel.java index 091f79e..3f103e2 100644 --- a/src/jalview/gui/PCAPanel.java +++ b/src/jalview/gui/PCAPanel.java @@ -785,4 +785,14 @@ public class PCAPanel extends GPCAPanel { return progressBar.getProgressBar(id); } + + public String getMessage(long id) + { + return progressBar.getMessage(id); + } + + public void setProgressBarMessage(long id, String message) + { + progressBar.setProgressBarMessage(id, message); + } } diff --git a/src/jalview/gui/PaSiMapPanel.java b/src/jalview/gui/PaSiMapPanel.java index 7926efc..2a6d6a9 100644 --- a/src/jalview/gui/PaSiMapPanel.java +++ b/src/jalview/gui/PaSiMapPanel.java @@ -622,58 +622,20 @@ public class PaSiMapPanel extends GPaSiMapPanel } } - /* - * (non-Javadoc) - * - * @see jalview.gui.IProgressIndicator#setProgressBar(java.lang.String, long) - */ - @Override + public void setProgressBar(String message, long id) { progressBar.setProgressBar(message, id); - // if (progressBars == null) - // { - // progressBars = new Hashtable(); - // progressBarHandlers = new Hashtable(); - // } - // - // JPanel progressPanel; - // Long lId = Long.valueOf(id); - // GridLayout layout = (GridLayout) statusPanel.getLayout(); - // if (progressBars.get(lId) != null) - // { - // progressPanel = (JPanel) progressBars.get(Long.valueOf(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(); + } + + public String getMessage(long id) + { + return progressBar.getMessage(id); + } + + public void setProgressBarMessage(long id, String message) + { + progressBar.setProgressBarMessage(id, message); } /* diff --git a/src/jalview/gui/ProgressBar.java b/src/jalview/gui/ProgressBar.java index 9d2cb2c..e6ee641 100644 --- a/src/jalview/gui/ProgressBar.java +++ b/src/jalview/gui/ProgressBar.java @@ -49,6 +49,8 @@ public class ProgressBar implements IProgressIndicator * Progress bars in progress, keyed by any arbitrary long value */ Map progressBars; + + Map progressBarMessages; /* * Optional handlers for the progress bars @@ -92,6 +94,7 @@ public class ProgressBar implements IProgressIndicator this.statusBar = statusBar; this.progressBars = new Hashtable<>(); this.progressBarHandlers = new Hashtable<>(); + this.progressBarMessages = new Hashtable<>(); } @@ -153,13 +156,14 @@ public class ProgressBar implements IProgressIndicator JProgressBar progressBar = new JProgressBar(); progressBar.setIndeterminate(true); - + progressPanel.add(new JLabel(message), BorderLayout.WEST); progressPanel.add(progressBar, BorderLayout.CENTER); addRow(progressPanel); progressBars.put(id, progressPanel); + progressBarMessages.put(id, message); } refreshLayout(); @@ -271,6 +275,7 @@ public class ProgressBar implements IProgressIndicator /* * */ + @Override public JProgressBar getProgressBar(long id) { Container progBar = progressBars.get(id); @@ -287,5 +292,34 @@ public class ProgressBar implements IProgressIndicator } return null; } + + @Override + public String getMessage(long id) + { + return progressBarMessages.get(id); + } + + /** + * change the text shown alongside a progress bar + * @param id + * @param message + */ + @Override + public void setProgressBarMessage(long id,String message) + { + Container progBar = progressBars.get(id); + if (progBar == null || progBar.getComponentCount() == 0) + { + return; + } + for (Component component : progBar.getComponents()) + { + if (component.getClass().equals(JLabel.class)) + { + ((JLabel) component).setText(message);; + refreshLayout(); + } + } + } } diff --git a/src/jalview/gui/StructureChooser.java b/src/jalview/gui/StructureChooser.java index ce043fe..8f13084 100644 --- a/src/jalview/gui/StructureChooser.java +++ b/src/jalview/gui/StructureChooser.java @@ -1903,4 +1903,14 @@ public class StructureChooser extends GStructureChooser { return progressBar.getProgressBar(id); } + + public String getMessage(long id) + { + return progressIndicator.getMessage(id); + } + + public void setProgressBarMessage(long id, String message) + { + progressIndicator.setProgressBarMessage(id, message); + } } diff --git a/src/jalview/gui/WebserviceInfo.java b/src/jalview/gui/WebserviceInfo.java index e464b2b..1a7b0a0 100644 --- a/src/jalview/gui/WebserviceInfo.java +++ b/src/jalview/gui/WebserviceInfo.java @@ -952,4 +952,14 @@ public class WebserviceInfo extends GWebserviceInfo { return progressBar.getProgressBar(id); } + + public String getMessage(long id) + { + return progressBar.getMessage(id); + } + + public void setProgressBarMessage(long id, String message) + { + progressBar.setProgressBarMessage(id, message); + } }