2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
21 package jalview.viewmodel;
23 import jalview.api.AlignmentColsCollectionI;
24 import jalview.api.AlignmentRowsCollectionI;
25 import jalview.datamodel.AlignmentI;
26 import jalview.datamodel.AllColsCollection;
27 import jalview.datamodel.AllRowsCollection;
28 import jalview.datamodel.HiddenColumns;
29 import jalview.datamodel.HiddenSequences;
31 public class OverviewDimensionsWithHidden extends OverviewDimensions
34 * Create an OverviewDimensions object
37 * positional properties of the viewport
38 * @param showAnnotationPanel
39 * true if the annotation panel is to be shown, false otherwise
41 public OverviewDimensionsWithHidden(ViewportRanges ranges,
42 boolean showAnnotationPanel)
44 super(ranges, showAnnotationPanel);
46 alwidth = ranges.getAbsoluteAlignmentWidth();
47 alheight = ranges.getAbsoluteAlignmentHeight();
51 * Check box dimensions and scroll positions and correct if necessary
54 * x position in overview panel
56 * y position in overview panel
62 * viewport position properties
65 public void updateViewportFromMouse(int mousex, int mousey,
66 HiddenSequences hiddenSeqs, HiddenColumns hiddenCols,
67 ViewportRanges ranges)
72 alwidth = ranges.getAbsoluteAlignmentWidth();
73 alheight = ranges.getAbsoluteAlignmentHeight();
86 // Convert x value to residue position
89 // need to determine where scrollCol should be, given x
90 // to do this also need to know width of viewport, and some hidden column
93 // convert x to residues - this is an absolute position
94 int xAsRes = Math.round((float) x * alwidth / width);
96 // get viewport width in residues
97 int vpwidth = ranges.getEndRes() - ranges.getStartRes() + 1;
99 // get where x should be when accounting for hidden cols
100 // if x is in a hidden col region, shift to left - but we still need
102 // so convert back after getting visible region position
103 int visXAsRes = hiddenCols.findColumnPosition(xAsRes);
105 // check in case we went off the edge of the alignment
106 int visAlignWidth = hiddenCols.findColumnPosition(alwidth - 1);
107 if (visXAsRes + vpwidth - 1 > visAlignWidth)
109 // went past the end of the alignment, adjust backwards
111 // if last position was before the end of the alignment, need to update
112 if ((scrollCol + vpwidth - 1) < visAlignWidth)
114 visXAsRes = hiddenCols.findColumnPosition(hiddenCols
115 .subtractVisibleColumns(vpwidth - 1, alwidth - 1));
119 visXAsRes = scrollCol;
124 // Convert y value to sequence position
127 // convert y to residues
128 int yAsSeq = Math.round((float) y * alheight / sequencesHeight);
130 // get viewport height in sequences
131 // add 1 because height includes both endSeq and startSeq
132 int vpheight = ranges.getEndSeq() - ranges.getStartSeq() + 1;
134 // get where y should be when accounting for hidden rows
135 // if y is in a hidden row region, shift up - but we still need absolute
137 // so convert back after getting visible region position
138 yAsSeq = hiddenSeqs.adjustForHiddenSeqs(hiddenSeqs
139 .findIndexWithoutHiddenSeqs(yAsSeq));
141 // check in case we went off the edge of the alignment
142 int visAlignHeight = hiddenSeqs.findIndexWithoutHiddenSeqs(alheight);
143 int visYAsSeq = hiddenSeqs.findIndexWithoutHiddenSeqs(yAsSeq);
144 if (visYAsSeq + vpheight - 1 > visAlignHeight)
146 // went past the end of the alignment, adjust backwards
147 if ((scrollRow + vpheight - 1) < visAlignHeight)
149 visYAsSeq = hiddenSeqs.findIndexWithoutHiddenSeqs(hiddenSeqs
150 .subtractVisibleRows(vpheight - 1, alheight - 1));
154 visYAsSeq = scrollRow;
158 // update scroll values
159 scrollCol = visXAsRes;
160 scrollRow = visYAsSeq;
165 * Update the overview panel box when the associated alignment panel is
173 * viewport position properties
176 public void setBoxPosition(HiddenSequences hiddenSeqs,
177 HiddenColumns hiddenCols, ViewportRanges ranges)
179 alwidth = ranges.getAbsoluteAlignmentWidth();
180 alheight = ranges.getAbsoluteAlignmentHeight();
182 // work with absolute values of startRes and endRes
183 int startRes = hiddenCols.adjustForHiddenColumns(ranges.getStartRes());
184 int endRes = hiddenCols.adjustForHiddenColumns(ranges.getEndRes());
186 // work with absolute values of startSeq and endSeq
187 int startSeq = hiddenSeqs.adjustForHiddenSeqs(ranges.getStartSeq());
188 int endSeq = hiddenSeqs.adjustForHiddenSeqs(ranges.getEndSeq());
190 // boxX, boxY is the x,y location equivalent to startRes, startSeq
191 boxX = Math.round((float) startRes * width / alwidth);
192 boxY = Math.round((float) startSeq * sequencesHeight / alheight);
194 // boxWidth is the width in residues translated to pixels
195 // since the box includes both the start and end residues, add 1 to the
198 .round((float) (endRes - startRes + 1) * width / alwidth);
199 // boxHeight is the height in sequences translated to pixels
200 boxHeight = Math.round((float) (endSeq - startSeq + 1)
206 public AlignmentColsCollectionI getColumns(ViewportRanges ranges,
207 HiddenColumns hiddenCols)
209 return new AllColsCollection(0,
210 ranges.getAbsoluteAlignmentWidth() - 1,
215 public AlignmentRowsCollectionI getRows(ViewportRanges ranges,
218 return new AllRowsCollection(0,
219 ranges.getAbsoluteAlignmentHeight() - 1,