From d221d910aad1d44bbc2e0a1f7ac44f5ceb575018 Mon Sep 17 00:00:00 2001 From: kiramt Date: Tue, 8 Aug 2017 14:01:54 +0100 Subject: [PATCH] JAL-2587 Added progress bar to overview. Not fully working yet. --- resources/lang/Messages.properties | 1 + resources/lang/Messages_es.properties | 1 + src/jalview/api/RendererListenerI.java | 8 +++ src/jalview/gui/OverviewCanvas.java | 16 +++-- src/jalview/gui/OverviewPanel.java | 43 +++++++++++- src/jalview/gui/ProgressPanel.java | 101 ++++++++++++++++++++++++++++ src/jalview/renderer/OverviewRenderer.java | 50 +++++++++++++- 7 files changed, 213 insertions(+), 7 deletions(-) create mode 100644 src/jalview/api/RendererListenerI.java create mode 100644 src/jalview/gui/ProgressPanel.java diff --git a/resources/lang/Messages.properties b/resources/lang/Messages.properties index 162f10f..d2e4933 100644 --- a/resources/lang/Messages.properties +++ b/resources/lang/Messages.properties @@ -1311,3 +1311,4 @@ label.occupancy_descr = Number of aligned positions label.show_experimental = Enable experimental features label.show_experimental_tip = Enable any new and currently 'experimental' features (see Latest Release Notes for details) label.warning_hidden = Warning: {0} {1} is currently hidden +label.oview_calc = Recalculating overview... \ No newline at end of file diff --git a/resources/lang/Messages_es.properties b/resources/lang/Messages_es.properties index 8385142..da03433 100644 --- a/resources/lang/Messages_es.properties +++ b/resources/lang/Messages_es.properties @@ -1311,3 +1311,4 @@ label.togglehidden = Mostrar regiones ocultas label.show_experimental = Habilitar funciones experimentales label.show_experimental_tip = Habilitar funciones nuevas y experimentales (ver Latest Release Notes para más detalles) label.warning_hidden = Advertencia: {0} {1} está actualmente oculto +label.oview_calc = Recalculando resumen \ No newline at end of file diff --git a/src/jalview/api/RendererListenerI.java b/src/jalview/api/RendererListenerI.java new file mode 100644 index 0000000..01b1a30 --- /dev/null +++ b/src/jalview/api/RendererListenerI.java @@ -0,0 +1,8 @@ +package jalview.api; + +import java.beans.PropertyChangeListener; + +public interface RendererListenerI extends PropertyChangeListener +{ + +} diff --git a/src/jalview/gui/OverviewCanvas.java b/src/jalview/gui/OverviewCanvas.java index 8f8cff7..6071e75 100644 --- a/src/jalview/gui/OverviewCanvas.java +++ b/src/jalview/gui/OverviewCanvas.java @@ -38,7 +38,10 @@ import javax.swing.Timer; public class OverviewCanvas extends JComponent { - public static final long RUNNING_TIME = 2000; + private static final long RUNNING_TIME = 2000; + + private static final int SPEED = 40; + private static final Color TRANS_GREY = new Color(100, 100, 100, 25); // This is set true if the alignment view changes whilst @@ -65,26 +68,27 @@ public class OverviewCanvas extends JComponent private AlignViewportI av; - private boolean resize = false; - private float alpha = 0f; private long startTime = -1; private final Timer timer; + private ProgressPanel progressPanel; + public OverviewCanvas(OverviewDimensions overviewDims, - AlignViewportI alignvp) + AlignViewportI alignvp, ProgressPanel pp) { od = overviewDims; av = alignvp; + progressPanel = pp; sr = new SequenceRenderer(av); sr.renderGaps = false; sr.forOverview = true; fr = new jalview.renderer.seqfeatures.FeatureRenderer(av); - timer = new Timer(40, new ActionListener() + timer = new Timer(SPEED, new ActionListener() { @Override @@ -174,6 +178,7 @@ public class OverviewCanvas extends JComponent setPreferredSize(new Dimension(od.getWidth(), od.getHeight())); or = new OverviewRenderer(sr, fr, od); + or.addPropertyChangeListener(progressPanel); miniMe = or.draw(od.getRows(av.getAlignment()), od.getColumns(av.getAlignment())); @@ -189,6 +194,7 @@ public class OverviewCanvas extends JComponent } System.gc(); + or.removePropertyChangeListener(progressPanel); if (restart) { restart = false; diff --git a/src/jalview/gui/OverviewPanel.java b/src/jalview/gui/OverviewPanel.java index 0b33b3b..af80725 100755 --- a/src/jalview/gui/OverviewPanel.java +++ b/src/jalview/gui/OverviewPanel.java @@ -20,6 +20,7 @@ */ package jalview.gui; +import jalview.renderer.OverviewRenderer; import jalview.util.MessageManager; import jalview.util.Platform; import jalview.viewmodel.OverviewDimensions; @@ -68,6 +69,8 @@ public class OverviewPanel extends JPanel implements Runnable, private boolean draggingBox = false; + private ProgressPanel progressPanel; + /** * Creates a new OverviewPanel object. * @@ -85,10 +88,15 @@ public class OverviewPanel extends JPanel implements Runnable, setSize(od.getWidth(), od.getHeight()); - oviewCanvas = new OverviewCanvas(od, av); setLayout(new BorderLayout()); + progressPanel = new ProgressPanel(OverviewRenderer.UPDATE, + MessageManager.getString("label.oview_calc")); + this.add(progressPanel, BorderLayout.SOUTH); + oviewCanvas = new OverviewCanvas(od, av, progressPanel); + add(oviewCanvas, BorderLayout.CENTER); + av.getRanges().addPropertyChangeListener(this); addComponentListener(new ComponentAdapter() @@ -271,9 +279,13 @@ public class OverviewPanel extends JPanel implements Runnable, return; } + // oviewCanvas.addPropertyChangeListener(OverviewRenderer.UPDATE, this); + Thread thread = new Thread(this); thread.start(); repaint(); + + } @Override @@ -314,10 +326,39 @@ public class OverviewPanel extends JPanel implements Runnable, av.getRanges().removePropertyChangeListener(this); } finally { + progressPanel = null; av = null; oviewCanvas = null; ap = null; od = null; } } + + /* private void addProgressBar() + { + progressPanel = new JPanel(new BorderLayout(10, 0)); + progressPanel.setBorder(new EmptyBorder(0, 3, 0, 20)); + + this.add(progressPanel, BorderLayout.SOUTH); + + progressBar = new OvProgressBar(); + progressBar.setMinimum(0); + + progressPanel.add(new JLabel("Recalculating overview..."), + BorderLayout.WEST); + progressPanel.add(progressBar, BorderLayout.CENTER); + } + + private void removeProgressBar() + { + if (progressPanel != null) + { + synchronized (progressPanel) + { + progressPanel.remove(progressBar); + this.remove(progressPanel); + progressPanel = null; + } + } + }*/ } diff --git a/src/jalview/gui/ProgressPanel.java b/src/jalview/gui/ProgressPanel.java new file mode 100644 index 0000000..f69f0cf --- /dev/null +++ b/src/jalview/gui/ProgressPanel.java @@ -0,0 +1,101 @@ +/* + * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$) + * Copyright (C) $$Year-Rel$$ The Jalview Authors + * + * This file is part of Jalview. + * + * Jalview is free software: you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation, either version 3 + * of the License, or (at your option) any later version. + * + * Jalview is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Jalview. If not, see . + * The Jalview Authors are detailed in the 'AUTHORS' file. + */ +package jalview.gui; + +import jalview.api.RendererListenerI; + +import java.awt.BorderLayout; +import java.beans.PropertyChangeEvent; + +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.JProgressBar; +import javax.swing.border.EmptyBorder; + +/** + * A class to manage a panel containing a label and progress bar updated by an + * event firing + * + * @author kmourao + * + */ +public class ProgressPanel extends JPanel implements RendererListenerI +{ + // max value of progress bar: values expected to be %s + private final int MAXVALUE = 100; + + // name of event property which updates the progress bar + private String eventName; + + private JProgressBar progressBar; + + private JLabel progressLabel; + + /** + * Construct a JPanel containing a progress bar and a label. + * + * @param eventPropertyName + * The name of the event property to update the progress bar + * @param label + * The label to place next to the progress bar + */ + public ProgressPanel(String eventPropertyName, String label) + { + super(new BorderLayout(10, 0)); + setBorder(new EmptyBorder(0, 3, 0, 20)); + + eventName = eventPropertyName; + + progressBar = new JProgressBar(); + progressBar.setMinimum(0); + progressLabel = new JLabel(label); + + add(progressLabel, BorderLayout.WEST); + add(progressBar, BorderLayout.CENTER); + } + + @Override + /** + * Update the progress bar in response to the event. Expects the value + * supplied by the event to be in the range 0-100 i.e. a percentage + */ + public void propertyChange(PropertyChangeEvent evt) + { + if (evt.getPropertyName().equals(eventName)) + { + int progress = (int) evt.getNewValue(); + + System.out.println(progress); + + progressBar.setValue(progress); + if (progress < MAXVALUE && !progressBar.isVisible()) + { + progressBar.setVisible(true); + progressLabel.setVisible(true); + } + else if (progress >= MAXVALUE) + { + progressBar.setVisible(false); + progressLabel.setVisible(false); + } + } + } +} diff --git a/src/jalview/renderer/OverviewRenderer.java b/src/jalview/renderer/OverviewRenderer.java index 46490cd..0baf2ce 100644 --- a/src/jalview/renderer/OverviewRenderer.java +++ b/src/jalview/renderer/OverviewRenderer.java @@ -22,6 +22,7 @@ package jalview.renderer; import jalview.api.AlignmentColsCollectionI; import jalview.api.AlignmentRowsCollectionI; +import jalview.api.RendererListenerI; import jalview.datamodel.AlignmentAnnotation; import jalview.datamodel.Annotation; import jalview.datamodel.SequenceI; @@ -32,9 +33,15 @@ import jalview.viewmodel.OverviewDimensions; import java.awt.Color; import java.awt.Graphics; import java.awt.image.BufferedImage; +import java.beans.PropertyChangeSupport; public class OverviewRenderer { + public static final String UPDATE = "OverviewUpdate"; + + protected PropertyChangeSupport changeSupport = new PropertyChangeSupport( + this); + private FeatureColourFinder finder; private jalview.api.SequenceRenderer sr; @@ -48,6 +55,9 @@ public class OverviewRenderer // raw number of pixels to allocate to each row private float pixelsPerSeq; + // height in pixels of graph + private int graphHeight; + // flag to indicate whether to halt drawing private volatile boolean redraw = false; @@ -59,6 +69,7 @@ public class OverviewRenderer pixelsPerCol = od.getPixelsPerCol(); pixelsPerSeq = od.getPixelsPerSeq(); + graphHeight = od.getGraphHeight(); miniMe = new BufferedImage(od.getWidth(), od.getHeight(), BufferedImage.TYPE_INT_RGB); } @@ -78,6 +89,7 @@ public class OverviewRenderer int rgbcolor = Color.white.getRGB(); int seqIndex = 0; int pixelRow = 0; + int alignmentHeight = miniMe.getHeight() - graphHeight; for (int alignmentRow : rows) { @@ -100,6 +112,7 @@ public class OverviewRenderer { if (redraw) { + break; } @@ -131,9 +144,31 @@ public class OverviewRenderer } colIndex++; } - pixelRow = endRow + 1; + + if (pixelRow != endRow + 1) + { + changeSupport.firePropertyChange(UPDATE, + Math.round(100 * (float) pixelRow / alignmentHeight), + Math.round( + 100 * ((float) (endRow + 1) / alignmentHeight))); + pixelRow = endRow + 1; + } seqIndex++; } + + // final update to progress bar if present + if (redraw) + { + changeSupport.firePropertyChange(UPDATE, + Math.round(100 * (float) (pixelRow - 1) / alignmentHeight), + 0); + } + else + { + changeSupport.firePropertyChange(UPDATE, + Math.round(100 * alignmentHeight / miniMe.getHeight() - 1), + Math.round(100 * alignmentHeight / miniMe.getHeight())); + } return miniMe; } @@ -186,8 +221,10 @@ public class OverviewRenderer { if (redraw) { + changeSupport.firePropertyChange(UPDATE, 99, 0); break; } + if (alignmentCol >= annotations.length) { break; // no more annotations to draw here @@ -221,6 +258,7 @@ public class OverviewRenderer colIndex++; } } + changeSupport.firePropertyChange(UPDATE, 99, 100); } public void setRedraw(boolean b) @@ -230,4 +268,14 @@ public class OverviewRenderer redraw = b; } } + + public void addPropertyChangeListener(RendererListenerI listener) + { + changeSupport.addPropertyChangeListener(listener); + } + + public void removePropertyChangeListener(RendererListenerI listener) + { + changeSupport.removePropertyChangeListener(listener); + } } -- 1.7.10.2