X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2Fjalview%2Fappletgui%2FAlignmentPanel.java;h=e9081b079bac50b3f13dd132d50e63f6093a05a7;hb=afffa24481a7d3cb65ae41e0948c16a5f490f302;hp=6c866ee740cfdf930324f3a6f7558a18d156a970;hpb=59d682209891099d46b960509907c79e3fb276fe;p=jalview.git
diff --git a/src/jalview/appletgui/AlignmentPanel.java b/src/jalview/appletgui/AlignmentPanel.java
index 6c866ee..e9081b0 100644
--- a/src/jalview/appletgui/AlignmentPanel.java
+++ b/src/jalview/appletgui/AlignmentPanel.java
@@ -1,33 +1,53 @@
/*
- * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8)
- * Copyright (C) 2012 J Procter, AM Waterhouse, LM Lui, J Engelhardt, G Barton, M Clamp, S Searle
+ * 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.
+ * 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 .
+ * 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.appletgui;
-import java.awt.*;
-import java.awt.event.*;
-import java.util.Hashtable;
-import java.util.Vector;
-
+import jalview.analysis.AnnotationSorter;
+import jalview.api.AlignViewportI;
import jalview.api.AlignmentViewPanel;
-import jalview.datamodel.*;
+import jalview.bin.JalviewLite;
+import jalview.datamodel.AlignmentI;
+import jalview.datamodel.SearchResultsI;
+import jalview.datamodel.SequenceI;
import jalview.structure.StructureSelectionManager;
-
-public class AlignmentPanel extends Panel implements AdjustmentListener,
- AlignmentViewPanel
+import jalview.viewmodel.ViewportListenerI;
+import jalview.viewmodel.ViewportRanges;
+
+import java.awt.BorderLayout;
+import java.awt.Color;
+import java.awt.Dimension;
+import java.awt.FontMetrics;
+import java.awt.Frame;
+import java.awt.Graphics;
+import java.awt.Panel;
+import java.awt.Scrollbar;
+import java.awt.event.AdjustmentEvent;
+import java.awt.event.AdjustmentListener;
+import java.awt.event.ComponentAdapter;
+import java.awt.event.ComponentEvent;
+import java.beans.PropertyChangeEvent;
+import java.util.List;
+
+public class AlignmentPanel extends Panel
+ implements AdjustmentListener, AlignmentViewPanel, ViewportListenerI
{
public AlignViewport av;
@@ -48,23 +68,11 @@ public class AlignmentPanel extends Panel implements AdjustmentListener,
AnnotationLabels alabels;
+ ViewportRanges vpRanges;
+
// this value is set false when selection area being dragged
boolean fastPaint = true;
- public void finalize()
- {
- alignFrame = null;
- av = null;
- seqPanel = null;
- seqPanelHolder = null;
- sequenceHolderPanel = null;
- scalePanel = null;
- scalePanelHolder = null;
- annotationPanel = null;
- annotationPanelHolder = null;
- annotationSpaceFillerHolder = null;
- }
-
public AlignmentPanel(AlignFrame af, final AlignViewport av)
{
try
@@ -77,6 +85,7 @@ public class AlignmentPanel extends Panel implements AdjustmentListener,
alignFrame = af;
this.av = av;
+ vpRanges = av.getRanges();
seqPanel = new SeqPanel(av, this);
idPanel = new IdPanel(av, this);
scalePanel = new ScalePanel(av, this);
@@ -85,10 +94,9 @@ public class AlignmentPanel extends Panel implements AdjustmentListener,
annotationPanelHolder.add(annotationPanel, BorderLayout.CENTER);
sequenceHolderPanel.add(annotationPanelHolder, BorderLayout.SOUTH);
-
alabels = new AnnotationLabels(this);
- setAnnotationVisible(av.showAnnotation);
+ setAnnotationVisible(av.isShowAnnotation());
idPanelHolder.add(idPanel, BorderLayout.CENTER);
idSpaceFillerPanel1.add(idwidthAdjuster, BorderLayout.CENTER);
@@ -105,9 +113,29 @@ public class AlignmentPanel extends Panel implements AdjustmentListener,
addComponentListener(new ComponentAdapter()
{
+ @Override
public void componentResized(ComponentEvent evt)
{
- setScrollValues(av.getStartRes(), av.getStartSeq());
+ // reset the viewport ranges when the alignment panel is resized
+ // in particular, this initialises the end residue value when Jalview
+ // is initialised
+ if (av.getWrapAlignment())
+ {
+ int widthInRes = seqPanel.seqCanvas
+ .getWrappedCanvasWidth(seqPanel.seqCanvas.getWidth());
+ vpRanges.setViewportWidth(widthInRes);
+ }
+ else
+ {
+ int widthInRes = seqPanel.seqCanvas.getWidth()
+ / av.getCharWidth();
+ int heightInSeq = seqPanel.seqCanvas.getHeight()
+ / av.getCharHeight();
+
+ vpRanges.setViewportWidth(widthInRes);
+ vpRanges.setViewportHeight(heightInSeq);
+ }
+ // setScrollValues(vpRanges.getStartRes(), vpRanges.getStartSeq());
if (getSize().height > 0
&& annotationPanelHolder.getSize().height > 0)
{
@@ -130,6 +158,7 @@ public class AlignmentPanel extends Panel implements AdjustmentListener,
final AlignmentPanel ap = this;
av.addPropertyChangeListener(new java.beans.PropertyChangeListener()
{
+ @Override
public void propertyChange(java.beans.PropertyChangeEvent evt)
{
if (evt.getPropertyName().equals("alignment"))
@@ -139,7 +168,13 @@ public class AlignmentPanel extends Panel implements AdjustmentListener,
}
}
});
+ av.getRanges().addPropertyChangeListener(this);
+ }
+ @Override
+ public AlignViewportI getAlignViewport()
+ {
+ return av;
}
public SequenceRenderer getSequenceRenderer()
@@ -147,11 +182,20 @@ public class AlignmentPanel extends Panel implements AdjustmentListener,
return seqPanel.seqCanvas.sr;
}
- public FeatureRenderer getFeatureRenderer()
+ @Override
+ public jalview.api.FeatureRenderer getFeatureRenderer()
{
return seqPanel.seqCanvas.fr;
}
+ @Override
+ public jalview.api.FeatureRenderer cloneFeatureRenderer()
+ {
+ FeatureRenderer nfr = new FeatureRenderer(av);
+ nfr.transferSettings(seqPanel.seqCanvas.fr);
+ return nfr;
+ }
+
public void alignmentChanged()
{
av.alignmentChanged(this);
@@ -173,9 +217,10 @@ public class AlignmentPanel extends Panel implements AdjustmentListener,
idPanel.idCanvas.image = null;
FontMetrics fm = getFontMetrics(av.getFont());
- scalePanel.setSize(new Dimension(10, av.charHeight + fm.getDescent()));
- idwidthAdjuster.setSize(new Dimension(10, av.charHeight
- + fm.getDescent()));
+ scalePanel.setSize(
+ new Dimension(10, av.getCharHeight() + fm.getDescent()));
+ idwidthAdjuster.setSize(
+ new Dimension(10, av.getCharHeight() + fm.getDescent()));
av.updateSequenceIdColours();
annotationPanel.image = null;
int ap = annotationPanel.adjustPanelHeight(false);
@@ -190,11 +235,6 @@ public class AlignmentPanel extends Panel implements AdjustmentListener,
annotationPanel.repaint();
validate();
repaint();
-
- if (overviewPanel != null)
- {
- overviewPanel.updateOverviewImage();
- }
}
public void setIdWidth(int w, int h)
@@ -258,7 +298,7 @@ public class AlignmentPanel extends Panel implements AdjustmentListener,
* Highlight the given results on the alignment.
*
*/
- public void highlightSearchResults(SearchResults results)
+ public void highlightSearchResults(SearchResultsI results)
{
scrollToPosition(results);
seqPanel.seqCanvas.highlightSearchResults(results);
@@ -271,7 +311,7 @@ public class AlignmentPanel extends Panel implements AdjustmentListener,
* @param results
* @return false if results were not found
*/
- public boolean scrollToPosition(SearchResults results)
+ public boolean scrollToPosition(SearchResultsI results)
{
return scrollToPosition(results, true);
}
@@ -285,10 +325,24 @@ public class AlignmentPanel extends Panel implements AdjustmentListener,
* - when set, the overview will be recalculated (takes longer)
* @return false if results were not found
*/
- public boolean scrollToPosition(SearchResults results,
+ public boolean scrollToPosition(SearchResultsI results,
boolean redrawOverview)
{
+ return scrollToPosition(results, 0, redrawOverview, false);
+ }
+ /**
+ * scroll the view to show the position of the highlighted region in results
+ * (if any)
+ *
+ * @param results
+ * @param redrawOverview
+ * - when set, the overview will be recalculated (takes longer)
+ * @return false if results were not found
+ */
+ public boolean scrollToPosition(SearchResultsI results,
+ int verticalOffset, boolean redrawOverview, boolean centre)
+ {
// do we need to scroll the panel?
if (results != null && results.getSize() > 0)
{
@@ -298,19 +352,23 @@ public class AlignmentPanel extends Panel implements AdjustmentListener,
{
return false;
}
+ /*
+ * allow for offset of target sequence (actually scroll to one above it)
+ */
+
SequenceI seq = alignment.getSequenceAt(seqIndex);
int[] r = results.getResults(seq, 0, alignment.getWidth());
if (r == null)
{
- if (av.applet.debug)
+ if (JalviewLite.debug)
{// DEBUG
- System.out
- .println("DEBUG: scroll didn't happen - results not within alignment : "
+ System.out.println(
+ "DEBUG: scroll didn't happen - results not within alignment : "
+ seq.getStart() + "," + seq.getEnd());
}
return false;
}
- if (av.applet.debug)
+ if (JalviewLite.debug)
{
// DEBUG
/*
@@ -322,6 +380,20 @@ public class AlignmentPanel extends Panel implements AdjustmentListener,
}
int start = r[0];
int end = r[1];
+
+ /*
+ * To centre results, scroll to positions half the visible width
+ * left/right of the start/end positions
+ */
+ if (centre)
+ {
+ int offset = (vpRanges.getEndRes() - vpRanges.getStartRes() + 1) / 2
+ - 1;
+ start = Math.max(start - offset, 0);
+ end = end + offset - 1;
+ // end = Math.min(end + offset, seq.getEnd() - 1);
+ }
+
if (start < 0)
{
return false;
@@ -330,6 +402,11 @@ public class AlignmentPanel extends Panel implements AdjustmentListener,
{
return false;
}
+
+ /*
+ * allow for offset of target sequence (actually scroll to one above it)
+ */
+ seqIndex = Math.max(0, seqIndex - verticalOffset);
return scrollTo(start, end, seqIndex, false, redrawOverview);
}
return true;
@@ -343,11 +420,12 @@ public class AlignmentPanel extends Panel implements AdjustmentListener,
int start = -1;
if (av.hasHiddenColumns())
{
- start = av.getColumnSelection().findColumnPosition(ostart);
- end = av.getColumnSelection().findColumnPosition(end);
+ AlignmentI al = av.getAlignment();
+ start = al.getHiddenColumns().absoluteToVisibleColumn(ostart);
+ end = al.getHiddenColumns().absoluteToVisibleColumn(end);
if (start == end)
{
- if (!scrollToNearest && !av.getColumnSelection().isVisible(ostart))
+ if (!scrollToNearest && !al.getHiddenColumns().isVisible(ostart))
{
// don't scroll - position isn't visible
return false;
@@ -358,7 +436,8 @@ public class AlignmentPanel extends Panel implements AdjustmentListener,
{
start = ostart;
}
- if (!av.wrapAlignment)
+
+ if (!av.getWrapAlignment())
{
/*
* int spos=av.getStartRes(),sqpos=av.getStartSeq(); if ((startv =
@@ -369,55 +448,73 @@ public class AlignmentPanel extends Panel implements AdjustmentListener,
* av.getStartSeq()) > seqIndex) { setScrollValues(av.getStartRes(),
* seqIndex); } else if ((ends = av.getEndSeq()) <= seqIndex) {
* setScrollValues(av.getStartRes(), starts + seqIndex - ends + 1); }
- *
- * /*
*/
- if ((av.getStartRes() > end)
- || (av.getEndRes() < start)
- || ((av.getStartSeq() > seqIndex) || (av.getEndSeq() < seqIndex)))
- {
- if (start > av.getAlignment().getWidth() - hextent)
- {
- start = av.getAlignment().getWidth() - hextent;
- if (start < 0)
- {
- start = 0;
- }
- }
- if (seqIndex > av.getAlignment().getHeight() - vextent)
- {
- seqIndex = av.getAlignment().getHeight() - vextent;
- if (seqIndex < 0)
- {
- seqIndex = 0;
- }
- }
- // System.out.println("trying to scroll to: "+start+" "+seqIndex);
- setScrollValues(start, seqIndex);
- }/**/
+ // below is scrolling logic up to Jalview 2.8.2
+ // if ((av.getStartRes() > end)
+ // || (av.getEndRes() < start)
+ // || ((av.getStartSeq() > seqIndex) || (av.getEndSeq() < seqIndex)))
+ // {
+ // if (start > av.getAlignment().getWidth() - hextent)
+ // {
+ // start = av.getAlignment().getWidth() - hextent;
+ // if (start < 0)
+ // {
+ // start = 0;
+ // }
+ //
+ // }
+ // if (seqIndex > av.getAlignment().getHeight() - vextent)
+ // {
+ // seqIndex = av.getAlignment().getHeight() - vextent;
+ // if (seqIndex < 0)
+ // {
+ // seqIndex = 0;
+ // }
+ // }
+ // setScrollValues(start, seqIndex);
+ // }
+ // logic copied from jalview.gui.AlignmentPanel:
+ if ((startv = vpRanges.getStartRes()) >= start)
+ {
+ /*
+ * Scroll left to make start of search results visible
+ */
+ setScrollValues(start - 1, seqIndex);
+ }
+ else if ((endv = vpRanges.getEndRes()) <= end)
+ {
+ /*
+ * Scroll right to make end of search results visible
+ */
+ setScrollValues(startv + 1 + end - endv, seqIndex);
+ }
+ else if ((starts = vpRanges.getStartSeq()) > seqIndex)
+ {
+ /*
+ * Scroll up to make start of search results visible
+ */
+ setScrollValues(vpRanges.getStartRes(), seqIndex);
+ }
+ else if ((ends = vpRanges.getEndSeq()) <= seqIndex)
+ {
+ /*
+ * Scroll down to make end of search results visible
+ */
+ setScrollValues(vpRanges.getStartRes(),
+ starts + seqIndex - ends + 1);
+ }
+ /*
+ * Else results are already visible - no need to scroll
+ */
}
else
{
- scrollToWrappedVisible(start);
+ vpRanges.scrollToWrappedVisible(start);
}
- if (redrawOverview && overviewPanel != null)
- {
- overviewPanel.setBoxPosition();
- }
- paintAlignment(redrawOverview);
- return true;
- }
- void scrollToWrappedVisible(int res)
- {
- int cwidth = seqPanel.seqCanvas
- .getWrappedCanvasWidth(seqPanel.seqCanvas.getSize().width);
- if (res <= av.getStartRes() || res >= (av.getStartRes() + cwidth))
- {
- vscroll.setValue(res / cwidth);
- av.startRes = vscroll.getValue() * cwidth;
- }
+ paintAlignment(redrawOverview, false);
+ return true;
}
public OverviewPanel getOverviewPanel()
@@ -432,11 +529,16 @@ public class AlignmentPanel extends Panel implements AdjustmentListener,
public void setAnnotationVisible(boolean b)
{
- if (!av.wrapAlignment)
+ if (!av.getWrapAlignment())
{
annotationSpaceFillerHolder.setVisible(b);
annotationPanelHolder.setVisible(b);
}
+ else
+ {
+ annotationSpaceFillerHolder.setVisible(false);
+ annotationPanelHolder.setVisible(false);
+ }
validate();
repaint();
}
@@ -445,78 +547,87 @@ public class AlignmentPanel extends Panel implements AdjustmentListener,
* automatically adjust annotation panel height for new annotation whilst
* ensuring the alignment is still visible.
*/
+ @Override
public void adjustAnnotationHeight()
{
// TODO: display vertical annotation scrollbar if necessary
// this is called after loading new annotation onto alignment
if (alignFrame.getSize().height == 0)
{
- System.out.println("NEEDS FIXING");
+ System.out.println(
+ "adjustAnnotationHeight frame size zero NEEDS FIXING");
}
fontChanged();
validateAnnotationDimensions(true);
apvscroll.addNotify();
hscroll.addNotify();
validate();
- paintAlignment(true);
+ paintAlignment(true, false);
}
/**
- * calculate the annotation dimensions and refresh slider values accordingly.
- * need to do repaints/notifys afterwards.
+ * Calculate the annotation dimensions and refresh slider values accordingly.
+ * Need to do repaints/notifys afterwards.
*/
protected void validateAnnotationDimensions(boolean adjustPanelHeight)
{
- boolean modified = false;
- int height = av.calcPanelHeight();
- int minsize = 0;
- if (hscroll.isVisible())
- {
- height += (minsize = hscroll.getPreferredSize().height);
- }
- if (apvscroll.isVisible())
- {
- minsize += apvscroll.getPreferredSize().height;
- }
- int mheight = height;
- Dimension d = sequenceHolderPanel.getSize(), e = idPanel.getSize();
- int seqandannot = d.height - scalePanelHolder.getSize().height;
- // sets initial preferred height
- if ((height + 40) > seqandannot / 2)
+ int rowHeight = av.getCharHeight();
+ int alignmentHeight = rowHeight * av.getAlignment().getHeight();
+ int annotationHeight = av.calcPanelHeight();
+
+ int mheight = annotationHeight;
+ Dimension d = sequenceHolderPanel.getSize();
+
+ int availableHeight = d.height - scalePanelHolder.getHeight();
+
+ if (adjustPanelHeight)
{
- height = seqandannot / 2;
+ /*
+ * If not enough vertical space, maximize annotation height while keeping
+ * at least two rows of alignment visible
+ */
+ if (annotationHeight + alignmentHeight > availableHeight)
+ {
+ annotationHeight = Math.min(annotationHeight,
+ availableHeight - 2 * rowHeight);
+ }
}
- if (!adjustPanelHeight)
+ else
{
// maintain same window layout whilst updating sliders
- height = annotationPanelHolder.getSize().height;
+ annotationHeight = annotationPanelHolder.getSize().height;
}
- if (seqandannot - height < 5)
+ if (availableHeight - annotationHeight < 5)
{
- height = seqandannot;
+ annotationHeight = availableHeight;
}
- annotationPanel.setSize(new Dimension(d.width, height));
- alabels.setSize(new Dimension(e.width, height));
- annotationSpaceFillerHolder.setSize(new Dimension(e.width, height));
- annotationPanelHolder.setSize(new Dimension(d.width, height));
- seqPanelHolder.setSize(d.width, seqandannot - height);
- seqPanel.seqCanvas
- .setSize(d.width, seqPanel.seqCanvas.getSize().height);
+
+ annotationPanel.setSize(new Dimension(d.width, annotationHeight));
+ annotationPanelHolder.setSize(new Dimension(d.width, annotationHeight));
+ // seqPanelHolder.setSize(d.width, seqandannot - height);
+ seqPanel.seqCanvas.setSize(d.width,
+ seqPanel.seqCanvas.getSize().height);
+
+ Dimension e = idPanel.getSize();
+ alabels.setSize(new Dimension(e.width, annotationHeight));
+ annotationSpaceFillerHolder
+ .setSize(new Dimension(e.width, annotationHeight));
+
int s = apvscroll.getValue();
- if (s > mheight - height)
+ if (s > mheight - annotationHeight)
{
s = 0;
}
- apvscroll.setValues(s, height, 0, mheight);
- annotationPanel.setScrollOffset(apvscroll.getValue());
- alabels.setScrollOffset(apvscroll.getValue());
+ apvscroll.setValues(s, annotationHeight, 0, mheight);
+ annotationPanel.setScrollOffset(apvscroll.getValue(), false);
+ alabels.setScrollOffset(apvscroll.getValue(), false);
}
public void setWrapAlignment(boolean wrap)
{
- av.startSeq = 0;
- av.startRes = 0;
+ vpRanges.setStartEndSeq(0, vpRanges.getVisibleAlignmentHeight());
+ vpRanges.setStartRes(0);
scalePanelHolder.setVisible(!wrap);
hscroll.setVisible(!wrap);
@@ -527,7 +638,7 @@ public class AlignmentPanel extends Panel implements AdjustmentListener,
annotationPanelHolder.setVisible(false);
annotationSpaceFillerHolder.setVisible(false);
}
- else if (av.showAnnotation)
+ else if (av.isShowAnnotation())
{
annotationPanelHolder.setVisible(true);
annotationSpaceFillerHolder.setVisible(true);
@@ -538,6 +649,7 @@ public class AlignmentPanel extends Panel implements AdjustmentListener,
fontChanged(); // This is so that the scalePanel is resized correctly
validate();
+ sequenceHolderPanel.validate();
repaint();
}
@@ -546,222 +658,273 @@ public class AlignmentPanel extends Panel implements AdjustmentListener,
int vextent = 0;
- // return value is true if the scroll is valid
- public boolean scrollUp(boolean up)
+ public void setScrollValues(int xpos, int ypos)
{
- if (up)
+ int x = xpos;
+ int y = ypos;
+
+ if (av.getWrapAlignment())
{
- if (vscroll.getValue() < 1)
- {
- return false;
- }
- setScrollValues(hscroll.getValue(), vscroll.getValue() - 1);
+ setScrollingForWrappedPanel(x);
}
else
{
- if (vextent + vscroll.getValue() >= av.getAlignment().getHeight())
+ int width = av.getAlignment().getVisibleWidth();
+ int height = av.getAlignment().getHeight();
+
+ if (x < 0)
{
- return false;
+ x = 0;
}
- setScrollValues(hscroll.getValue(), vscroll.getValue() + 1);
- }
- repaint();
- return true;
- }
+ hextent = seqPanel.seqCanvas.getSize().width / av.getCharWidth();
+ vextent = seqPanel.seqCanvas.getSize().height / av.getCharHeight();
- public boolean scrollRight(boolean right)
- {
- if (!right)
- {
- if (hscroll.getValue() < 1)
+ if (hextent > width)
{
- return false;
+ hextent = width;
}
- setScrollValues(hscroll.getValue() - 1, vscroll.getValue());
- }
- else
- {
- if (hextent + hscroll.getValue() >= av.getAlignment().getWidth())
+
+ if (vextent > height)
{
- return false;
+ vextent = height;
}
- setScrollValues(hscroll.getValue() + 1, vscroll.getValue());
- }
- repaint();
- return true;
- }
+ if ((hextent + x) > width)
+ {
+ System.err.println("hextent was " + hextent + " and x was " + x);
- public void setScrollValues(int x, int y)
- {
- int width = av.getAlignment().getWidth();
- int height = av.getAlignment().getHeight();
+ x = width - hextent;
+ }
- if (av.hasHiddenColumns())
- {
- width = av.getColumnSelection().findColumnPosition(width);
- }
- if (x < 0)
- {
- x = 0;
- }
- ;
+ if ((vextent + y) > height)
+ {
+ y = height - vextent;
+ }
- hextent = seqPanel.seqCanvas.getSize().width / av.charWidth;
- vextent = seqPanel.seqCanvas.getSize().height / av.charHeight;
+ if (y < 0)
+ {
+ y = 0;
+ }
- if (hextent > width)
- {
- hextent = width;
- }
+ if (x < 0)
+ {
+ System.err.println("x was " + x);
+ x = 0;
+ }
- if (vextent > height)
- {
- vextent = height;
- }
+ hscroll.setValues(x, hextent, 0, width);
+ vscroll.setValues(y, vextent, 0, height);
- if ((hextent + x) > width)
- {
- System.err.println("hextent was " + hextent + " and x was " + x);
+ // AWT scrollbar does not fire adjustmentValueChanged for setValues
+ // so also call adjustment code!
+ adjustHorizontal(x);
+ adjustVertical(y);
- x = width - hextent;
+ sendViewPosition();
}
+ }
- if ((vextent + y) > height)
+ /**
+ * Respond to adjustment event when horizontal or vertical scrollbar is
+ * changed
+ *
+ * @param evt
+ * adjustment event encoding whether apvscroll, hscroll or vscroll
+ * changed
+ */
+ @Override
+ public void adjustmentValueChanged(AdjustmentEvent evt)
+ {
+ // Note that this event is NOT fired by the AWT scrollbar when setValues is
+ // called. Instead manually call adjustHorizontal and adjustVertical
+ // directly.
+ if (evt == null || evt.getSource() == apvscroll)
{
- y = height - vextent;
+ annotationPanel.setScrollOffset(apvscroll.getValue(), false);
+ alabels.setScrollOffset(apvscroll.getValue(), false);
}
-
- if (y < 0)
+ if (evt == null || evt.getSource() == hscroll)
{
- y = 0;
+ int x = hscroll.getValue();
+ adjustHorizontal(x);
}
- if (x < 0)
+ if (evt == null || evt.getSource() == vscroll)
{
- System.err.println("x was " + x);
- x = 0;
+ int offy = vscroll.getValue();
+ adjustVertical(offy);
}
- av.setStartSeq(y);
+ }
- int endSeq = y + vextent;
- if (endSeq > av.getAlignment().getHeight())
+ private void adjustHorizontal(int x)
+ {
+ int oldX = vpRanges.getStartRes();
+ int oldwidth = vpRanges.getViewportWidth();
+ int width = seqPanel.seqCanvas.getWidth() / av.getCharWidth();
+
+ // if we're scrolling to the position we're already at, stop
+ // this prevents infinite recursion of events when the scroll/viewport
+ // ranges values are the same
+ if ((x == oldX) && (width == oldwidth))
{
- endSeq = av.getAlignment().getHeight();
+ return;
}
+ vpRanges.setViewportStartAndWidth(x, width);
- av.setEndSeq(endSeq);
- av.setStartRes(x);
- av.setEndRes((x + (seqPanel.seqCanvas.getSize().width / av.charWidth)) - 1);
-
- hscroll.setValues(x, hextent, 0, width);
- vscroll.setValues(y, vextent, 0, height);
-
- if (overviewPanel != null)
+ if (av.getWrapAlignment() || !fastPaint)
{
- overviewPanel.setBoxPosition();
+ repaint();
}
sendViewPosition();
-
}
- public void adjustmentValueChanged(AdjustmentEvent evt)
+ private void adjustVertical(int newY)
{
- int oldX = av.getStartRes();
- int oldY = av.getStartSeq();
-
- if (evt == null || evt.getSource() == apvscroll)
- {
- annotationPanel.setScrollOffset(apvscroll.getValue());
- alabels.setScrollOffset(apvscroll.getValue());
- // annotationPanel.image=null;
- // alabels.image=null;
- // alabels.repaint();
- // annotationPanel.repaint();
- }
- if (evt == null || evt.getSource() == hscroll)
- {
- int x = hscroll.getValue();
- av.setStartRes(x);
- av.setEndRes(x + seqPanel.seqCanvas.getSize().width
- / av.getCharWidth() - 1);
- }
-
- if (evt == null || evt.getSource() == vscroll)
+ if (av.getWrapAlignment())
{
- int offy = vscroll.getValue();
- if (av.getWrapAlignment())
+ /*
+ * if we're scrolling to the position we're already at, stop
+ * this prevents infinite recursion of events when the scroll/viewport
+ * ranges values are the same
+ */
+ int oldX = vpRanges.getStartRes();
+ int oldY = vpRanges.getWrappedScrollPosition(oldX);
+ if (oldY == newY)
{
- int rowSize = seqPanel.seqCanvas
- .getWrappedCanvasWidth(seqPanel.seqCanvas.getSize().width);
- av.setStartRes(vscroll.getValue() * rowSize);
- av.setEndRes((vscroll.getValue() + 1) * rowSize);
+ return;
}
- else
+ if (newY > -1)
{
- av.setStartSeq(offy);
- av.setEndSeq(offy + seqPanel.seqCanvas.getSize().height
- / av.getCharHeight());
+ /*
+ * limit page up/down to one width's worth of positions
+ */
+ int rowSize = vpRanges.getViewportWidth();
+ int newX = newY > oldY ? oldX + rowSize : oldX - rowSize;
+ vpRanges.setViewportStartAndWidth(Math.max(0, newX), rowSize);
}
}
-
- if (overviewPanel != null)
+ else
{
- overviewPanel.setBoxPosition();
+ int height = seqPanel.seqCanvas.getHeight() / av.getCharHeight();
+ int oldY = vpRanges.getStartSeq();
+ int oldheight = vpRanges.getViewportHeight();
+
+ // if we're scrolling to the position we're already at, stop
+ // this prevents infinite recursion of events when the scroll/viewport
+ // ranges values are the same
+ if ((newY == oldY) && (height == oldheight))
+ {
+ return;
+ }
+ vpRanges.setViewportStartAndHeight(newY, height);
}
-
- int scrollX = av.startRes - oldX;
- int scrollY = av.startSeq - oldY;
-
- if (av.getWrapAlignment() || !fastPaint || av.MAC)
+ if (av.getWrapAlignment() || !fastPaint)
{
repaint();
}
- else
+ sendViewPosition();
+ }
+
+ /**
+ * A helper method to return the AlignmentPanel in the other (complementary)
+ * half of a SplitFrame view. Returns null if not in a SplitFrame.
+ *
+ * @return
+ */
+ private AlignmentPanel getComplementPanel()
+ {
+ AlignmentPanel ap = null;
+ if (alignFrame != null)
{
- // Make sure we're not trying to draw a panel
- // larger than the visible window
- if (scrollX > av.endRes - av.startRes)
+ SplitFrame sf = alignFrame.getSplitFrame();
+ if (sf != null)
{
- scrollX = av.endRes - av.startRes;
- }
- else if (scrollX < av.startRes - av.endRes)
- {
- scrollX = av.startRes - av.endRes;
+ AlignFrame other = sf.getComplement(alignFrame);
+ if (other != null)
+ {
+ ap = other.alignPanel;
+ }
}
+ }
+ return ap;
+ }
- idPanel.idCanvas.fastPaint(scrollY);
- seqPanel.seqCanvas.fastPaint(scrollX, scrollY);
-
- scalePanel.repaint();
- if (av.getShowAnnotation())
+ /**
+ * Follow a scrolling change in the (cDNA/Protein) complementary alignment.
+ * The aim is to keep the two alignments 'lined up' on their centre columns.
+ *
+ * @param sr
+ * holds mapped region(s) of this alignment that we are scrolling
+ * 'to'; may be modified for sequence offset by this method
+ * @param seqOffset
+ * the number of visible sequences to show above the mapped region
+ */
+ protected void scrollToCentre(SearchResultsI sr, int seqOffset)
+ {
+ /*
+ * To avoid jumpy vertical scrolling (if some sequences are gapped or not
+ * mapped), we can make the scroll-to location a sequence above the one
+ * actually mapped.
+ */
+ SequenceI mappedTo = sr.getResults().get(0).getSequence();
+ List seqs = av.getAlignment().getSequences();
+
+ /*
+ * This is like AlignmentI.findIndex(seq) but here we are matching the
+ * dataset sequence not the aligned sequence
+ */
+ boolean matched = false;
+ for (SequenceI seq : seqs)
+ {
+ if (mappedTo == seq.getDatasetSequence())
{
- annotationPanel.fastPaint(av.getStartRes() - oldX);
+ matched = true;
+ break;
}
}
- sendViewPosition();
+ if (!matched)
+ {
+ return; // failsafe, shouldn't happen
+ }
+ /*
+ * Scroll to position but centring the target residue. Also set a state flag
+ * to prevent adjustmentValueChanged performing this recursively.
+ */
+ scrollToPosition(sr, seqOffset, true, true);
}
private void sendViewPosition()
{
StructureSelectionManager.getStructureSelectionManager(av.applet)
- .sendViewPosition(this, av.startRes, av.endRes, av.startSeq,
- av.endSeq);
+ .sendViewPosition(this, vpRanges.getStartRes(),
+ vpRanges.getEndRes(), vpRanges.getStartSeq(),
+ vpRanges.getEndSeq());
}
- public void paintAlignment(boolean updateOverview)
+ /**
+ * Repaint the alignment and annotations, and, optionally, any overview window
+ */
+ @Override
+ public void paintAlignment(boolean updateOverview,
+ boolean updateStructures)
{
+ final AnnotationSorter sorter = new AnnotationSorter(getAlignment(),
+ av.isShowAutocalculatedAbove());
+ sorter.sort(getAlignment().getAlignmentAnnotation(),
+ av.getSortAnnotationsBy());
repaint();
- if (updateOverview)
+ if (updateStructures)
{
jalview.structure.StructureSelectionManager
.getStructureSelectionManager(av.applet)
.sequenceColoursChanged(this);
-
+ }
+ if (updateOverview)
+ {
if (overviewPanel != null)
{
overviewPanel.updateOverviewImage();
@@ -769,48 +932,56 @@ public class AlignmentPanel extends Panel implements AdjustmentListener,
}
}
+ @Override
public void update(Graphics g)
{
paint(g);
}
+ @Override
public void paint(Graphics g)
{
invalidate();
Dimension d = idPanel.idCanvas.getSize();
- idPanel.idCanvas.setSize(d.width, seqPanel.seqCanvas.getSize().height);
-
- if (av.getWrapAlignment())
+ final int canvasHeight = seqPanel.seqCanvas.getSize().height;
+ if (canvasHeight != d.height)
{
- int maxwidth = av.getAlignment().getWidth();
-
- if (av.hasHiddenColumns())
- {
- maxwidth = av.getColumnSelection().findColumnPosition(maxwidth) - 1;
- }
+ idPanel.idCanvas.setSize(d.width, canvasHeight);
+ }
- int canvasWidth = seqPanel.seqCanvas
- .getWrappedCanvasWidth(seqPanel.seqCanvas.getSize().width);
+ setScrollValues(vpRanges.getStartRes(), vpRanges.getStartSeq());
- if (canvasWidth > 0)
+ seqPanel.seqCanvas.repaint();
+ idPanel.idCanvas.repaint();
+ if (!av.getWrapAlignment())
+ {
+ if (av.isShowAnnotation())
{
- int max = maxwidth / canvasWidth;
- vscroll.setMaximum(1 + max);
- vscroll.setUnitIncrement(1);
- vscroll.setVisibleAmount(1);
+ alabels.repaint();
+ annotationPanel.repaint();
}
- }
- else
- {
- setScrollValues(av.getStartRes(), av.getStartSeq());
+ scalePanel.repaint();
}
- alabels.repaint();
+ }
- seqPanel.seqCanvas.repaint();
- scalePanel.repaint();
- annotationPanel.repaint();
- idPanel.idCanvas.repaint();
+ /**
+ * Set vertical scroll bar parameters for wrapped panel
+ *
+ * @param topLeftColumn
+ * the column position at top left (0..)
+ */
+ private void setScrollingForWrappedPanel(int topLeftColumn)
+ {
+ int scrollPosition = vpRanges.getWrappedScrollPosition(topLeftColumn);
+ int maxScroll = vpRanges.getWrappedMaxScroll(topLeftColumn);
+
+ /*
+ * a scrollbar's value can be set to at most (maximum-extent)
+ * so we add extent (1) to the maxScroll value
+ */
+ vscroll.setUnitIncrement(1);
+ vscroll.setValues(scrollPosition, 1, 0, maxScroll + 1);
}
protected Panel sequenceHolderPanel = new Panel();
@@ -821,72 +992,58 @@ public class AlignmentPanel extends Panel implements AdjustmentListener,
protected Panel seqPanelHolder = new Panel();
- BorderLayout borderLayout1 = new BorderLayout();
-
- BorderLayout borderLayout3 = new BorderLayout();
-
protected Panel scalePanelHolder = new Panel();
protected Panel idPanelHolder = new Panel();
- BorderLayout borderLayout5 = new BorderLayout();
-
protected Panel idSpaceFillerPanel1 = new Panel();
public Panel annotationSpaceFillerHolder = new Panel();
- BorderLayout borderLayout6 = new BorderLayout();
-
- BorderLayout borderLayout7 = new BorderLayout();
-
- Panel hscrollHolder = new Panel();
-
- BorderLayout borderLayout10 = new BorderLayout();
-
protected Panel hscrollFillerPanel = new Panel();
- BorderLayout borderLayout11 = new BorderLayout();
-
- BorderLayout borderLayout4 = new BorderLayout();
-
- BorderLayout borderLayout2 = new BorderLayout();
-
Panel annotationPanelHolder = new Panel();
protected Scrollbar apvscroll = new Scrollbar();
- BorderLayout borderLayout12 = new BorderLayout();
+ /*
+ * Flag set while scrolling to follow complementary cDNA/protein scroll. When
+ * false, suppresses invoking the same method recursively.
+ */
+ private boolean scrollComplementaryPanel = true;
private void jbInit() throws Exception
{
// idPanelHolder.setPreferredSize(new Dimension(70, 10));
- this.setLayout(borderLayout7);
+ this.setLayout(new BorderLayout());
// sequenceHolderPanel.setPreferredSize(new Dimension(150, 150));
- sequenceHolderPanel.setLayout(borderLayout3);
- seqPanelHolder.setLayout(borderLayout1);
+ sequenceHolderPanel.setLayout(new BorderLayout());
+ seqPanelHolder.setLayout(new BorderLayout());
scalePanelHolder.setBackground(Color.white);
// scalePanelHolder.setPreferredSize(new Dimension(10, 30));
- scalePanelHolder.setLayout(borderLayout6);
- idPanelHolder.setLayout(borderLayout5);
+ scalePanelHolder.setLayout(new BorderLayout());
+ idPanelHolder.setLayout(new BorderLayout());
idSpaceFillerPanel1.setBackground(Color.white);
// idSpaceFillerPanel1.setPreferredSize(new Dimension(10, 30));
- idSpaceFillerPanel1.setLayout(borderLayout11);
+ idSpaceFillerPanel1.setLayout(new BorderLayout());
annotationSpaceFillerHolder.setBackground(Color.white);
// annotationSpaceFillerHolder.setPreferredSize(new Dimension(10, 80));
- annotationSpaceFillerHolder.setLayout(borderLayout4);
+ annotationSpaceFillerHolder.setLayout(new BorderLayout());
hscroll.setOrientation(Scrollbar.HORIZONTAL);
- hscrollHolder.setLayout(borderLayout10);
+
+ Panel hscrollHolder = new Panel();
+ hscrollHolder.setLayout(new BorderLayout());
hscrollFillerPanel.setBackground(Color.white);
apvscroll.setOrientation(Scrollbar.VERTICAL);
apvscroll.setVisible(true);
apvscroll.addAdjustmentListener(this);
annotationPanelHolder.setBackground(Color.white);
- annotationPanelHolder.setLayout(borderLayout12);
+ annotationPanelHolder.setLayout(new BorderLayout());
annotationPanelHolder.add(apvscroll, BorderLayout.EAST);
// hscrollFillerPanel.setPreferredSize(new Dimension(70, 10));
hscrollHolder.setBackground(Color.white);
@@ -937,6 +1094,12 @@ public class AlignmentPanel extends Panel implements AdjustmentListener,
}
@Override
+ public String getViewName()
+ {
+ return getName();
+ }
+
+ @Override
public StructureSelectionManager getStructureSelectionManager()
{
return StructureSelectionManager
@@ -951,4 +1114,47 @@ public class AlignmentPanel extends Panel implements AdjustmentListener,
error.printStackTrace();
}
+ /**
+ * Set a flag to say we are scrolling to follow a (cDNA/protein) complement.
+ *
+ * @param b
+ */
+ protected void setToScrollComplementPanel(boolean b)
+ {
+ this.scrollComplementaryPanel = b;
+ }
+
+ /**
+ * Get whether to scroll complement panel
+ *
+ * @return true if cDNA/protein complement panels should be scrolled
+ */
+ protected boolean isSetToScrollComplementPanel()
+ {
+ return this.scrollComplementaryPanel;
+ }
+
+ @Override
+ /**
+ * Property change event fired when a change is made to the viewport ranges
+ * object associated with this alignment panel's viewport
+ */
+ public void propertyChange(PropertyChangeEvent evt)
+ {
+ // update this panel's scroll values based on the new viewport ranges values
+ int x = vpRanges.getStartRes();
+ int y = vpRanges.getStartSeq();
+ setScrollValues(x, y);
+
+ // now update any complementary alignment (its viewport ranges object
+ // is different so does not get automatically updated)
+ if (isSetToScrollComplementPanel())
+ {
+ setToScrollComplementPanel(false);
+ av.scrollComplementaryAlignment(getComplementPanel());
+ setToScrollComplementPanel(true);
+ }
+
+ }
+
}