- * Check box dimensions and scroll positions and correct if necessary
- *
- * @param mousex
- * x position in overview panel
- * @param mousey
- * y position in overview panel
- * @param hiddenSeqs
- * hidden sequences
- * @param hiddenCols
- * hidden columns
- * @param props
- * viewport position properties
- */
- public void updateViewportFromMouse(int mousex, int mousey,
- HiddenSequences hiddenSeqs, ColumnSelection hiddenCols,
- ViewportPositionProps props)
- {
- int x = mousex;
- int y = mousey;
-
- int alwidth = props.getAbsoluteAlignmentWidth();
- int alheight = props.getAbsoluteAlignmentHeight();
-
- 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 = props.getEndRes() - props.getStartRes() + 1;
-
- // get where x should be when accounting for hidden cols
- // if x is in a hidden col region, shift to left - but we still need
- // absolute position
- // so convert back after getting visible region position
- xAsRes = hiddenCols.adjustForHiddenColumns(hiddenCols
- .findColumnPosition(xAsRes));
-
- // get where end res should be by adding the viewport width on
- // subtract 1 because the width includes endRes
- int endRes = xAsRes + vpwidth - 1;
-
- // check in case we went off the edge of the alignment
- int visAlignWidth = hiddenCols.findColumnPosition(alwidth);
- if (endRes > visAlignWidth - 1)
- {
- // went past the end of the alignment, adjust backwards
- endRes = visAlignWidth - 1;
- // recalc xAsRes backwards from endRes
- // add 1 because width includes xAsRes
- xAsRes = hiddenCols.adjustForHiddenColumns(endRes - vpwidth + 1);
- }
-
- //
- // 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 = props.getEndSeq() - props.getStartSeq() + 1;
-
- // get where y should be when accounting for hidden rows
- // if y is in a hidden row region, shift up - but we still need absolute
- // position,
- // so convert back after getting visible region position
- yAsSeq = hiddenSeqs.adjustForHiddenSeqs(hiddenSeqs
- .findIndexWithoutHiddenSeqs(yAsSeq));
-
- // get where end seq should be by adding the viewport height on
- int endSeq = yAsSeq + vpheight - 1;
-
- // check in case we went off the edge of the alignment
- int visAlignHeight = hiddenSeqs.findIndexWithoutHiddenSeqs(alheight);
- if (hiddenSeqs.findIndexWithoutHiddenSeqs(endSeq) > visAlignHeight - 1)
- {
- // went past the end of the alignment, adjust backwards
- endSeq = visAlignHeight - 1;
- // recalc yAsSeq backwards from endSeq
- yAsSeq = endSeq - vpheight + 1;
- }
-
- // convert absolute positions back to visible alignment positions for
- // viewport scrolling
- scrollCol = hiddenCols.findColumnPosition(xAsRes);
- scrollRow = hiddenSeqs.findIndexWithoutHiddenSeqs(yAsSeq);
- }
-
- /**
- * Update the overview panel box when the associated alignment panel is
- * changed
- *
- * @param hiddenSeqs
- * hidden sequences
- * @param hiddenCols
- * hidden columns
- * @param props
- * viewport position properties
- */
- public void setBoxPosition(HiddenSequences hiddenSeqs,
- ColumnSelection hiddenCols, ViewportPositionProps props)
- {
- int alwidth = props.getAbsoluteAlignmentWidth();
- int alheight = props.getAbsoluteAlignmentHeight();
-
- // work with absolute values of startRes and endRes
- int startRes = hiddenCols.adjustForHiddenColumns(props.getStartRes());
- int endRes = hiddenCols.adjustForHiddenColumns(props.getEndRes());
-
- // work with absolute values of startSeq and endSeq
- int startSeq = hiddenSeqs.adjustForHiddenSeqs(props.getStartSeq());
- int endSeq = hiddenSeqs.adjustForHiddenSeqs(props.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
- // since the box includes both the start and end sequences, add 1 to the
- // difference
- boxHeight = Math.round((float) (endSeq - startSeq + 1)
- * sequencesHeight
- / alheight);
- }
-
- /**