package jalview.viewmodel; import jalview.api.AlignmentColsCollectionI; import jalview.api.AlignmentRowsCollectionI; import jalview.datamodel.AlignmentI; import jalview.datamodel.HiddenColumns; import jalview.datamodel.HiddenSequences; import jalview.datamodel.VisibleColsCollection; import jalview.datamodel.VisibleRowsCollection; public class OverviewDimensionsAllVisible extends OverviewDimensions { private ViewportRanges alRanges; public OverviewDimensionsAllVisible(ViewportRanges ranges, boolean showAnnotationPanel) { super(ranges, showAnnotationPanel); alRanges = ranges; resetAlignmentDims(); } @Override public void updateViewportFromMouse(int mousex, int mousey, HiddenSequences hiddenSeqs, HiddenColumns hiddenCols) { resetAlignmentDims(); int x = mousex; int y = mousey; if (x < 0) { x = 0; } if (y < 0) { y = 0; } // // Convert x value to residue position // // need to determine where scrollCol should be, given x // to do this also need to know width of viewport, and some hidden column // correction // convert x to residues - this is an absolute position int xAsRes = Math.round((float) x * alwidth / width); // get viewport width in residues int vpwidth = alRanges.getEndRes() - alRanges.getStartRes() + 1; if (xAsRes + vpwidth > alwidth) { // went past the end of the alignment, adjust backwards // if last position was before the end of the alignment, need to update if ((scrollCol + vpwidth - 1) < alwidth) { xAsRes = alwidth - vpwidth; } else { xAsRes = scrollCol; } } // // Convert y value to sequence position // // convert y to residues int yAsSeq = Math.round((float) y * alheight / sequencesHeight); // get viewport height in sequences // add 1 because height includes both endSeq and startSeq int vpheight = alRanges.getEndSeq() - alRanges.getStartSeq() + 1; if (yAsSeq + vpheight > alheight) { // went past the end of the alignment, adjust backwards if ((scrollRow + vpheight - 1) < alheight) { yAsSeq = alheight - vpheight; } else { yAsSeq = scrollRow; } } // update scroll values scrollCol = xAsRes; scrollRow = yAsSeq; } @Override public void setBoxPosition(HiddenSequences hiddenSeqs, HiddenColumns hiddenCols) { resetAlignmentDims(); // work with visible values of startRes and endRes int startRes = alRanges.getStartRes(); int endRes = alRanges.getEndRes(); // work with visible values of startSeq and endSeq int startSeq = alRanges.getStartSeq(); int endSeq = alRanges.getEndSeq(); // boxX, boxY is the x,y location equivalent to startRes, startSeq boxX = Math.round((float) startRes * width / alwidth); boxY = Math.round((float) startSeq * sequencesHeight / alheight); // boxWidth is the width in residues translated to pixels // since the box includes both the start and end residues, add 1 to the // difference boxWidth = Math .round((float) (endRes - startRes + 1) * width / alwidth); // boxHeight is the height in sequences translated to pixels boxHeight = Math.round((float) (endSeq - startSeq + 1) * sequencesHeight / alheight); } @Override public AlignmentColsCollectionI getColumns(HiddenColumns hiddenCols) { return new VisibleColsCollection(0, alRanges.getAbsoluteAlignmentWidth() - 1, hiddenCols); } @Override public AlignmentRowsCollectionI getRows(AlignmentI al) { return new VisibleRowsCollection(0, alRanges.getAbsoluteAlignmentHeight() - 1, al); } @Override protected void resetAlignmentDims() { alwidth = alRanges.getVisibleAlignmentWidth(); alheight = alRanges.getVisibleAlignmentHeight(); } }