import jalview.datamodel.SearchResultsI;
import jalview.datamodel.SequenceI;
import jalview.structure.StructureSelectionManager;
+import jalview.viewmodel.ViewportListenerI;
import jalview.viewmodel.ViewportRanges;
import java.awt.BorderLayout;
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
+ AlignmentViewPanel, ViewportListenerI
{
public AlignViewport av;
@Override
public void componentResized(ComponentEvent evt)
{
- setScrollValues(vpRanges.getStartRes(), vpRanges.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)
{
}
}
});
+ av.getRanges().addPropertyChangeListener(this);
}
@Override
annotationPanel.repaint();
validate();
repaint();
-
- if (overviewPanel != null)
- {
- overviewPanel.updateOverviewImage();
- }
}
public void setIdWidth(int w, int h)
}
else
{
- scrollToWrappedVisible(start);
- }
- if (redrawOverview && overviewPanel != null)
- {
- overviewPanel.setBoxPosition();
+ vpRanges.scrollToWrappedVisible(start);
}
+
paintAlignment(redrawOverview);
return true;
}
- void scrollToWrappedVisible(int res)
- {
- int cwidth = seqPanel.seqCanvas
- .getWrappedCanvasWidth(seqPanel.seqCanvas.getSize().width);
- if (res <= vpRanges.getStartRes()
- || res >= (vpRanges.getStartRes() + cwidth))
- {
- vscroll.setValue(res / cwidth);
- vpRanges.setStartRes(vscroll.getValue() * cwidth);
- }
- }
-
public OverviewPanel getOverviewPanel()
{
return overviewPanel;
int vextent = 0;
- // return value is true if the scroll is valid
- public boolean scrollUp(boolean up)
+ public void setScrollValues(int x, int y)
{
- if (up)
+ 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())
- {
- return false;
- }
- setScrollValues(hscroll.getValue(), vscroll.getValue() + 1);
- }
- repaint();
- return true;
- }
+ int width = av.getAlignment().getWidth();
+ int height = av.getAlignment().getHeight();
- public boolean scrollRight(boolean right)
- {
- if (!right)
- {
- if (hscroll.getValue() < 1)
+ if (av.hasHiddenColumns())
{
- return false;
+ width = av.getColumnSelection().findColumnPosition(width);
}
- setScrollValues(hscroll.getValue() - 1, vscroll.getValue());
- }
- else
- {
- if (hextent + hscroll.getValue() >= av.getAlignment().getWidth())
+ if (x < 0)
{
- return false;
+ x = 0;
}
- setScrollValues(hscroll.getValue() + 1, vscroll.getValue());
- }
- repaint();
- return true;
- }
-
- public void setScrollValues(int x, int y)
- {
- int width = av.getAlignment().getWidth();
- int height = av.getAlignment().getHeight();
-
- if (av.hasHiddenColumns())
- {
- width = av.getColumnSelection().findColumnPosition(width);
- }
- if (x < 0)
- {
- x = 0;
- }
-
-
- hextent = seqPanel.seqCanvas.getSize().width / av.getCharWidth();
- vextent = seqPanel.seqCanvas.getSize().height / av.getCharHeight();
-
- if (hextent > width)
- {
- hextent = width;
- }
+ hextent = seqPanel.seqCanvas.getSize().width / av.getCharWidth();
+ vextent = seqPanel.seqCanvas.getSize().height / av.getCharHeight();
- if (vextent > height)
- {
- vextent = height;
- }
+ if (hextent > width)
+ {
+ hextent = width;
+ }
- if ((hextent + x) > width)
- {
- System.err.println("hextent was " + hextent + " and x was " + x);
+ if (vextent > height)
+ {
+ vextent = height;
+ }
- x = width - hextent;
- }
+ if ((hextent + x) > width)
+ {
+ System.err.println("hextent was " + hextent + " and x was " + x);
- if ((vextent + y) > height)
- {
- y = height - vextent;
- }
+ x = width - hextent;
+ }
- if (y < 0)
- {
- y = 0;
- }
+ if ((vextent + y) > height)
+ {
+ y = height - vextent;
+ }
- if (x < 0)
- {
- System.err.println("x was " + x);
- x = 0;
- }
+ if (y < 0)
+ {
+ y = 0;
+ }
- vpRanges.setStartSeq(y);
- vpRanges.setEndSeq(y + vextent);
- vpRanges.setStartRes(x);
- vpRanges.setEndRes((x + (seqPanel.seqCanvas.getSize().width / av
- .getCharWidth())) - 1);
+ if (x < 0)
+ {
+ System.err.println("x was " + x);
+ x = 0;
+ }
- hscroll.setValues(x, hextent, 0, width);
- vscroll.setValues(y, vextent, 0, height);
+ hscroll.setValues(x, hextent, 0, width);
+ vscroll.setValues(y, vextent, 0, height);
- if (overviewPanel != null)
- {
- overviewPanel.setBoxPosition();
+ sendViewPosition();
}
- sendViewPosition();
-
}
@Override
public void adjustmentValueChanged(AdjustmentEvent evt)
{
int oldX = vpRanges.getStartRes();
+ int oldwidth = vpRanges.getViewportWidth();
int oldY = vpRanges.getStartSeq();
+ int oldheight = vpRanges.getViewportHeight();
if (evt == null || evt.getSource() == apvscroll)
{
if (evt == null || evt.getSource() == hscroll)
{
int x = hscroll.getValue();
- vpRanges.setStartRes(x);
- vpRanges.setEndRes(x + seqPanel.seqCanvas.getSize().width
- / av.getCharWidth() - 1);
+ 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))
+ {
+ return;
+ }
+ vpRanges.setViewportStartAndWidth(x, width);
}
if (evt == null || evt.getSource() == vscroll)
if (av.getWrapAlignment())
{
int rowSize = seqPanel.seqCanvas
- .getWrappedCanvasWidth(seqPanel.seqCanvas.getSize().width);
- vpRanges.setStartRes(vscroll.getValue() * rowSize);
- vpRanges.setEndRes((vscroll.getValue() + 1) * rowSize);
+ .getWrappedCanvasWidth(seqPanel.seqCanvas.getWidth());
+
+ // 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 ((offy * rowSize == oldX) && (oldwidth == rowSize))
+ {
+ return;
+ }
+ else if (offy > -1)
+ {
+ vpRanges.setViewportStartAndWidth(offy * rowSize, rowSize);
+ }
}
else
{
- vpRanges.setStartSeq(offy);
- vpRanges.setEndSeq(offy + seqPanel.seqCanvas.getSize().height
- / av.getCharHeight() - 1);
- }
- }
+ int height = seqPanel.seqCanvas.getHeight() / av.getCharHeight();
- if (overviewPanel != null)
- {
- overviewPanel.setBoxPosition();
+ // 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 ((offy == oldY) && (height == oldheight))
+ {
+ return;
+ }
+ vpRanges.setViewportStartAndHeight(offy, height);
+ }
}
- int scrollX = vpRanges.getStartRes() - oldX;
- int scrollY = vpRanges.getStartSeq() - oldY;
+ /* if (overviewPanel != null)
+ {
+ overviewPanel.setBoxPosition();
+ }
+ int scrollX = vpRanges.getStartRes() - oldX;
+ int scrollY = vpRanges.getStartSeq() - oldY;
+ */
if (av.getWrapAlignment() || !fastPaint || av.MAC)
{
repaint();
}
- else
- {
- // Make sure we're not trying to draw a panel
- // larger than the visible window
- if (scrollX > vpRanges.getEndRes() - vpRanges.getStartRes())
- {
- scrollX = vpRanges.getEndRes() - vpRanges.getStartRes();
- }
- else if (scrollX < vpRanges.getStartRes() - vpRanges.getEndRes())
- {
- scrollX = vpRanges.getStartRes() - vpRanges.getEndRes();
- }
-
- idPanel.idCanvas.fastPaint(scrollY);
- seqPanel.seqCanvas.fastPaint(scrollX, scrollY);
-
- scalePanel.repaint();
- if (av.isShowAnnotation())
- {
- annotationPanel.fastPaint(vpRanges.getStartRes() - oldX);
- }
- }
+ /* else
+ {
+ // Make sure we're not trying to draw a panel
+ // larger than the visible window
+ if (scrollX > vpRanges.getEndRes() - vpRanges.getStartRes())
+ {
+ scrollX = vpRanges.getEndRes() - vpRanges.getStartRes();
+ }
+ else if (scrollX < vpRanges.getStartRes() - vpRanges.getEndRes())
+ {
+ scrollX = vpRanges.getStartRes() - vpRanges.getEndRes();
+ }
+
+ idPanel.idCanvas.fastPaint(scrollY);
+ seqPanel.seqCanvas.fastPaint(scrollX, scrollY);
+
+ scalePanel.repaint();
+ if (av.isShowAnnotation())
+ {
+ annotationPanel.fastPaint(vpRanges.getStartRes() - oldX);
+ }
+ }*/
sendViewPosition();
/*
* If there is one, scroll the (Protein/cDNA) complementary alignment to
* match, unless we are ourselves doing that.
*/
- if (isFollowingComplementScroll())
- {
- setFollowingComplementScroll(false);
- }
- else
- {
- AlignmentPanel ap = getComplementPanel();
- av.scrollComplementaryAlignment(ap);
- }
+ /* if (isFollowingComplementScroll())
+ {
+ setFollowingComplementScroll(false);
+ }
+ else
+ {
+ AlignmentPanel ap = getComplementPanel();
+ av.scrollComplementaryAlignment(ap);
+ }*/
}
* This is like AlignmentI.findIndex(seq) but here we are matching the
* dataset sequence not the aligned sequence
*/
- int sequenceIndex = 0;
boolean matched = false;
for (SequenceI seq : seqs)
{
matched = true;
break;
}
- sequenceIndex++;
}
if (!matched)
{
idPanel.idCanvas.setSize(d.width, canvasHeight);
}
- if (av.getWrapAlignment())
- {
- int maxwidth = av.getAlignment().getWidth();
-
- if (av.hasHiddenColumns())
- {
- maxwidth = av.getColumnSelection().findColumnPosition(maxwidth) - 1;
- }
-
- int canvasWidth = seqPanel.seqCanvas
- .getWrappedCanvasWidth(seqPanel.seqCanvas.getSize().width);
-
- if (canvasWidth > 0)
- {
- int max = maxwidth / canvasWidth;
- vscroll.setMaximum(1 + max);
- vscroll.setUnitIncrement(1);
- vscroll.setVisibleAmount(1);
- }
- }
- else
- {
- setScrollValues(vpRanges.getStartRes(), vpRanges.getStartSeq());
- }
+ setScrollValues(vpRanges.getStartRes(), vpRanges.getStartSeq());
seqPanel.seqCanvas.repaint();
idPanel.idCanvas.repaint();
}
+ /*
+ * Set vertical scroll bar parameters for wrapped panel
+ * @param res
+ * the residue to scroll to
+ */
+ private void setScrollingForWrappedPanel(int res)
+ {
+ // get the width of the alignment in residues
+ int maxwidth = av.getAlignment().getWidth();
+ if (av.hasHiddenColumns())
+ {
+ maxwidth = av.getColumnSelection().findColumnPosition(maxwidth) - 1;
+ }
+
+ // get the width of the canvas in residues
+ int canvasWidth = seqPanel.seqCanvas
+ .getWrappedCanvasWidth(seqPanel.seqCanvas.getSize().width);
+ if (canvasWidth > 0)
+ {
+ // position we want to scroll to is number of canvasWidth's to get there
+ int current = res / canvasWidth;
+
+ // max scroll position: add one because extent is 1 and scrollbar value
+ // can only be set to at most max - extent
+ int max = maxwidth / canvasWidth + 1;
+ vscroll.setUnitIncrement(1);
+ vscroll.setValues(current, 1, 0, max);
+ }
+ }
+
protected Panel sequenceHolderPanel = new Panel();
protected Scrollbar vscroll = new Scrollbar();
return this.followingComplementScroll;
}
+ @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 (isFollowingComplementScroll())
+ {
+ setFollowingComplementScroll(false);
+ av.scrollComplementaryAlignment(getComplementPanel());
+ setFollowingComplementScroll(true);
+ }
+
+ }
+
}