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.datamodel.AlignmentColsCollection;
24 import jalview.datamodel.AlignmentI;
25 import jalview.datamodel.AlignmentRowsCollection;
26 import jalview.datamodel.ColumnSelection;
27 import jalview.datamodel.HiddenSequences;
29 public class OverviewDimensionsWithHidden extends OverviewDimensions
31 private float pixelsPerCol;
33 private float pixelsPerSeq;
36 * Create an OverviewDimensions object
39 * positional properties of the viewport
40 * @param showAnnotationPanel
41 * true if the annotation panel is to be shown, false otherwise
43 public OverviewDimensionsWithHidden(ViewportRanges ranges,
44 boolean showAnnotationPanel)
46 super(ranges, showAnnotationPanel);
48 int alwidth = ranges.getAbsoluteAlignmentWidth();
49 int alheight = ranges.getAbsoluteAlignmentHeight();
51 pixelsPerCol = (float) width / alwidth;
52 pixelsPerSeq = (float) sequencesHeight / alheight;
56 * Check box dimensions and scroll positions and correct if necessary
59 * x position in overview panel
61 * y position in overview panel
67 * viewport position properties
70 public void updateViewportFromMouse(int mousex, int mousey,
71 HiddenSequences hiddenSeqs, ColumnSelection hiddenCols,
72 ViewportRanges ranges)
77 int alwidth = ranges.getAbsoluteAlignmentWidth();
78 int alheight = ranges.getAbsoluteAlignmentHeight();
91 // Convert x value to residue position
94 // need to determine where scrollCol should be, given x
95 // to do this also need to know width of viewport, and some hidden column
98 // convert x to residues - this is an absolute position
99 int xAsRes = Math.round((float) x * alwidth / width);
101 // get viewport width in residues
102 int vpwidth = ranges.getEndRes() - ranges.getStartRes() + 1;
104 // get where x should be when accounting for hidden cols
105 // if x is in a hidden col region, shift to left - but we still need
107 // so convert back after getting visible region position
108 int visXAsRes = hiddenCols.findColumnPosition(xAsRes);
110 // check in case we went off the edge of the alignment
111 int visAlignWidth = hiddenCols.findColumnPosition(alwidth - 1);
112 if (visXAsRes + vpwidth - 1 > visAlignWidth)
114 // went past the end of the alignment, adjust backwards
116 // if last position was before the end of the alignment, need to update
117 if ((scrollCol + vpwidth - 1) < visAlignWidth)
119 visXAsRes = hiddenCols.findColumnPosition(hiddenCols
120 .subtractVisibleColumns(vpwidth - 1, alwidth - 1));
124 visXAsRes = scrollCol;
129 // Convert y value to sequence position
132 // convert y to residues
133 int yAsSeq = Math.round((float) y * alheight / sequencesHeight);
135 // get viewport height in sequences
136 // add 1 because height includes both endSeq and startSeq
137 int vpheight = ranges.getEndSeq() - ranges.getStartSeq() + 1;
139 // get where y should be when accounting for hidden rows
140 // if y is in a hidden row region, shift up - but we still need absolute
142 // so convert back after getting visible region position
143 yAsSeq = hiddenSeqs.adjustForHiddenSeqs(hiddenSeqs
144 .findIndexWithoutHiddenSeqs(yAsSeq));
146 // check in case we went off the edge of the alignment
147 int visAlignHeight = hiddenSeqs.findIndexWithoutHiddenSeqs(alheight);
148 int visYAsSeq = hiddenSeqs.findIndexWithoutHiddenSeqs(yAsSeq);
149 if (visYAsSeq + vpheight - 1 > visAlignHeight)
151 // went past the end of the alignment, adjust backwards
152 if ((scrollRow + vpheight - 1) < visAlignHeight)
154 visYAsSeq = hiddenSeqs.findIndexWithoutHiddenSeqs(hiddenSeqs
155 .subtractVisibleRows(vpheight - 1, alheight - 1));
159 visYAsSeq = scrollRow;
163 // update scroll values
164 scrollCol = visXAsRes;
165 scrollRow = visYAsSeq;
170 * Update the overview panel box when the associated alignment panel is
178 * viewport position properties
181 public void setBoxPosition(HiddenSequences hiddenSeqs,
182 ColumnSelection hiddenCols, ViewportRanges ranges)
184 int alwidth = ranges.getAbsoluteAlignmentWidth();
185 int alheight = ranges.getAbsoluteAlignmentHeight();
187 // work with absolute values of startRes and endRes
188 int startRes = hiddenCols.adjustForHiddenColumns(ranges.getStartRes());
189 int endRes = hiddenCols.adjustForHiddenColumns(ranges.getEndRes());
191 // work with absolute values of startSeq and endSeq
192 int startSeq = hiddenSeqs.adjustForHiddenSeqs(ranges.getStartSeq());
193 int endSeq = hiddenSeqs.adjustForHiddenSeqs(ranges.getEndSeq());
195 // boxX, boxY is the x,y location equivalent to startRes, startSeq
196 boxX = Math.round((float) startRes * width / alwidth);
197 boxY = Math.round((float) startSeq * sequencesHeight / alheight);
199 // boxWidth is the width in residues translated to pixels
200 // since the box includes both the start and end residues, add 1 to the
203 .round((float) (endRes - startRes + 1) * width / alwidth);
204 // boxHeight is the height in sequences translated to pixels
205 boxHeight = Math.round((float) (endSeq - startSeq + 1)
211 public AlignmentColsCollection getColumns(ViewportRanges ranges,
212 ColumnSelection hiddenCols)
214 return new AlignmentColsCollection(0,
215 ranges.getAbsoluteAlignmentWidth() - 1,
220 public AlignmentRowsCollection getRows(ViewportRanges ranges,
223 return new AlignmentRowsCollection(0,
224 ranges.getAbsoluteAlignmentHeight() - 1,
229 public float getPixelsPerCol()
235 public float getPixelsPerSeq()