X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2Fjalview%2Fviewmodel%2FOverviewDimensionsShowHidden.java;fp=src%2Fjalview%2Fviewmodel%2FOverviewDimensionsShowHidden.java;h=4f7d6c25bf70fff51eb6e1e9ff84930c4e5d491b;hb=c2e5d3d1ebe3b283bdde15637c590721cd6c5637;hp=0000000000000000000000000000000000000000;hpb=557859a3ea9a1e86899ef2033de90eadb6d87118;p=jalview.git diff --git a/src/jalview/viewmodel/OverviewDimensionsShowHidden.java b/src/jalview/viewmodel/OverviewDimensionsShowHidden.java new file mode 100644 index 0000000..4f7d6c2 --- /dev/null +++ b/src/jalview/viewmodel/OverviewDimensionsShowHidden.java @@ -0,0 +1,210 @@ +/* + * 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 . + * The Jalview Authors are detailed in the 'AUTHORS' file. + */ +package jalview.viewmodel; + +import jalview.api.AlignmentColsCollectionI; +import jalview.api.AlignmentRowsCollectionI; +import jalview.datamodel.AlignmentI; +import jalview.datamodel.AllColsCollection; +import jalview.datamodel.AllRowsCollection; +import jalview.datamodel.HiddenColumns; +import jalview.datamodel.HiddenSequences; + +public class OverviewDimensionsShowHidden extends OverviewDimensions +{ + private ViewportRanges ranges; + + /** + * Create an OverviewDimensions object + * + * @param ranges + * positional properties of the viewport + * @param showAnnotationPanel + * true if the annotation panel is to be shown, false otherwise + */ + public OverviewDimensionsShowHidden(ViewportRanges vpranges, + boolean showAnnotationPanel) + { + super(vpranges, showAnnotationPanel); + ranges = vpranges; + resetAlignmentDims(); + } + + /** + * 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 ranges + * viewport position properties + */ + @Override + public void updateViewportFromMouse(int mousex, int mousey, + HiddenSequences hiddenSeqs, HiddenColumns hiddenCols) + { + int x = mousex; + int y = mousey; + + resetAlignmentDims(); + + 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 = ranges.getViewportWidth(); + + // 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 + int visXAsRes = hiddenCols.findColumnPosition(xAsRes); + + // check in case we went off the edge of the alignment + int visAlignWidth = hiddenCols.findColumnPosition(alwidth - 1); + if (visXAsRes + vpwidth - 1 > visAlignWidth) + { + // went past the end of the alignment, adjust backwards + + // if last position was before the end of the alignment, need to update + if ((ranges.getEndRes() + vpwidth - 1) < visAlignWidth) + { + visXAsRes = hiddenCols.findColumnPosition(hiddenCols + .subtractVisibleColumns(vpwidth - 1, alwidth - 1)); + } + else + { + visXAsRes = ranges.getEndRes(); + } + } + + // + // Convert y value to sequence position + // + + // convert y to residues + int yAsSeq = Math.round((float) y * alheight / sequencesHeight); + + // get viewport height in sequences + int vpheight = ranges.getViewportHeight(); + + // 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)); + + // check in case we went off the edge of the alignment + int visAlignHeight = hiddenSeqs.findIndexWithoutHiddenSeqs(alheight); + int visYAsSeq = hiddenSeqs.findIndexWithoutHiddenSeqs(yAsSeq); + if (visYAsSeq + vpheight - 1 > visAlignHeight) + { + // went past the end of the alignment, adjust backwards + if ((ranges.getEndSeq() + vpheight - 1) < visAlignHeight) + { + visYAsSeq = hiddenSeqs.findIndexWithoutHiddenSeqs(hiddenSeqs + .subtractVisibleRows(vpheight - 1, alheight - 1)); + } + else + { + visYAsSeq = ranges.getEndSeq(); + } + } + + // update viewport + ranges.setStartRes(xAsRes); + ranges.setStartSeq(yAsSeq); + + } + + /** + * Update the overview panel box when the associated alignment panel is + * changed + * + * @param hiddenSeqs + * hidden sequences + * @param hiddenCols + * hidden columns + * @param ranges + * viewport position properties + */ + @Override + public void setBoxPosition(HiddenSequences hiddenSeqs, + HiddenColumns hiddenCols) + { + // work with absolute values of startRes and endRes + int startRes = hiddenCols + .adjustForHiddenColumns(ranges.getStartRes()); + int endRes = hiddenCols.adjustForHiddenColumns(ranges.getEndRes()); + + // work with absolute values of startSeq and endSeq + int startSeq = hiddenSeqs.adjustForHiddenSeqs(ranges.getStartSeq()); + int endSeq = hiddenSeqs.adjustForHiddenSeqs(ranges.getEndSeq()); + + setBoxPosition(startRes, endRes, startSeq, endSeq); + } + + @Override + public AlignmentColsCollectionI getColumns(AlignmentI al) + { + return new AllColsCollection(0, + ranges.getAbsoluteAlignmentWidth() - 1, al); + } + + @Override + public AlignmentRowsCollectionI getRows(AlignmentI al) + { + return new AllRowsCollection(0, + ranges.getAbsoluteAlignmentHeight() - 1, + al); + } + + @Override + protected void resetAlignmentDims() + { + alwidth = ranges.getAbsoluteAlignmentWidth(); + alheight = ranges.getAbsoluteAlignmentHeight(); + } +}