+/*
+ * 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 <http://www.gnu.org/licenses/>.
+ * The Jalview Authors are detailed in the 'AUTHORS' file.
+ */
package jalview.gui;
import jalview.api.AlignViewportI;
import javax.swing.JComponent;
+
public class OverviewCanvas extends JComponent
{
private static final Color TRANS_GREY = new Color(100, 100, 100, 25);
+ // This is set true if the alignment view changes whilst
+ // the overview is being calculated
+ private volatile boolean restart = false;
+
private BufferedImage miniMe;
private BufferedImage lastMiniMe = null;
- public boolean updating = false;
- // This is set true if the user resizes whilst
- // the overview is being calculated
- public volatile boolean updateAgain = false;
// Can set different properties in this seqCanvas than
// main visible SeqCanvas
OverviewDimensions od;
- OverviewPanel op;
-
AlignViewport av;
AlignmentPanel ap;
public OverviewCanvas(OverviewDimensions overviewDims,
- AlignViewportI alignvp, AlignmentPanel alignp, OverviewPanel overp)
+ AlignViewportI alignvp, AlignmentPanel alignp)
{
od = overviewDims;
av = alignp.av;
ap = alignp;
- op = overp;
sr = new SequenceRenderer(av);
sr.renderGaps = false;
fr = new FeatureRenderer(ap);
}
+ /*
+ * Signals to drawing code that the associated alignment viewport
+ * has changed and a redraw will be required
+ */
+ public void restartDraw()
+ {
+ restart = true;
+ }
+
public void draw(boolean showSequenceFeatures, boolean showAnnotation)
{
miniMe = null;
if (showAnnotation)
{
renderer.updateFromAlignViewport(av);
- for (int col = 0; col < od.getWidth() && !updateAgain; col++)
+ for (int col = 0; col < od.getWidth() && !restart; col++)
{
mg.translate(col, od.getSequencesHeight());
renderer.drawGraph(mg, av.getAlignmentConservationAnnotation(),
}
System.gc();
- updating = false;
-
- if (updateAgain)
+ if (restart)
{
- updateAgain = false;
- op.updateOverviewImage();
+ restart = false;
+ draw(showSequenceFeatures, showAnnotation);
}
else
{
@Override
public void paintComponent(Graphics g)
{
- if (updating || updateAgain)
+ if (restart)
{
if (lastMiniMe == null)
{
// get hidden row and hidden column map once at beginning.
// clone featureRenderer settings to avoid race conditions... if state is
// updated just need to refresh again
- for (int row = 0; row < od.getSequencesHeight() && !updateAgain; row++)
+ for (int row = 0; row < od.getSequencesHeight() && !restart; row++)
{
boolean doCopy = true;
int currentrow = (int) (row * sampleRow);
seq = av.getAlignment().getSequenceAtAbsoluteIndex(lastrow);
}
- for (int col = 0; col < od.getWidth() && !updateAgain; col++)
+ for (int col = 0; col < od.getWidth() && !restart; col++)
{
if (doCopy)
{
private AlignmentPanel ap;
+ boolean updateRunning = false;
+
/**
* Creates a new OverviewPanel object.
*
(av.isShowAnnotation() && av
.getAlignmentConservationAnnotation() != null));
- oviewCanvas = new OverviewCanvas(od, av, ap, this);
+ oviewCanvas = new OverviewCanvas(od, av, ap);
setLayout(new BorderLayout());
add(oviewCanvas, BorderLayout.CENTER);
*/
public void updateOverviewImage()
{
- if (oviewCanvas.updating)
- {
- oviewCanvas.updateAgain = true;
- return;
- }
-
- oviewCanvas.updating = true;
-
if ((getWidth() > 0) && (getHeight() > 0))
{
od.setWidth(getWidth());
setPreferredSize(new Dimension(od.getWidth(), od.getHeight()));
+ if (updateRunning)
+ {
+ oviewCanvas.restartDraw();
+ return;
+ }
+
+ updateRunning = true;
Thread thread = new Thread(this);
thread.start();
repaint();
+ updateRunning = false;
}
@Override