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.ColumnSelection;
29 import jalview.datamodel.HiddenSequences;
31 public class OverviewDimensionsWithHidden extends OverviewDimensions
33 private float pixelsPerCol;
35 private float pixelsPerSeq;
38 * Create an OverviewDimensions object
41 * positional properties of the viewport
42 * @param showAnnotationPanel
43 * true if the annotation panel is to be shown, false otherwise
45 public OverviewDimensionsWithHidden(ViewportRanges ranges,
46 boolean showAnnotationPanel)
48 super(ranges, showAnnotationPanel);
50 int alwidth = ranges.getAbsoluteAlignmentWidth();
51 int alheight = ranges.getAbsoluteAlignmentHeight();
53 pixelsPerCol = (float) width / alwidth;
54 pixelsPerSeq = (float) sequencesHeight / alheight;
58 * Check box dimensions and scroll positions and correct if necessary
61 * x position in overview panel
63 * y position in overview panel
69 * viewport position properties
72 public void updateViewportFromMouse(int mousex, int mousey,
73 HiddenSequences hiddenSeqs, ColumnSelection hiddenCols,
74 ViewportRanges ranges)
79 int alwidth = ranges.getAbsoluteAlignmentWidth();
80 int alheight = ranges.getAbsoluteAlignmentHeight();
93 // Convert x value to residue position
96 // need to determine where scrollCol should be, given x
97 // to do this also need to know width of viewport, and some hidden column
100 // convert x to residues - this is an absolute position
101 int xAsRes = Math.round((float) x * alwidth / width);
103 // get viewport width in residues
104 int vpwidth = ranges.getEndRes() - ranges.getStartRes() + 1;
106 // get where x should be when accounting for hidden cols
107 // if x is in a hidden col region, shift to left - but we still need
109 // so convert back after getting visible region position
110 int visXAsRes = hiddenCols.findColumnPosition(xAsRes);
112 // check in case we went off the edge of the alignment
113 int visAlignWidth = hiddenCols.findColumnPosition(alwidth - 1);
114 if (visXAsRes + vpwidth - 1 > visAlignWidth)
116 // went past the end of the alignment, adjust backwards
118 // if last position was before the end of the alignment, need to update
119 if ((scrollCol + vpwidth - 1) < visAlignWidth)
121 visXAsRes = hiddenCols.findColumnPosition(hiddenCols
122 .subtractVisibleColumns(vpwidth - 1, alwidth - 1));
126 visXAsRes = scrollCol;
131 // Convert y value to sequence position
134 // convert y to residues
135 int yAsSeq = Math.round((float) y * alheight / sequencesHeight);
137 // get viewport height in sequences
138 // add 1 because height includes both endSeq and startSeq
139 int vpheight = ranges.getEndSeq() - ranges.getStartSeq() + 1;
141 // get where y should be when accounting for hidden rows
142 // if y is in a hidden row region, shift up - but we still need absolute
144 // so convert back after getting visible region position
145 yAsSeq = hiddenSeqs.adjustForHiddenSeqs(hiddenSeqs
146 .findIndexWithoutHiddenSeqs(yAsSeq));
148 // check in case we went off the edge of the alignment
149 int visAlignHeight = hiddenSeqs.findIndexWithoutHiddenSeqs(alheight);
150 int visYAsSeq = hiddenSeqs.findIndexWithoutHiddenSeqs(yAsSeq);
151 if (visYAsSeq + vpheight - 1 > visAlignHeight)
153 // went past the end of the alignment, adjust backwards
154 if ((scrollRow + vpheight - 1) < visAlignHeight)
156 visYAsSeq = hiddenSeqs.findIndexWithoutHiddenSeqs(hiddenSeqs
157 .subtractVisibleRows(vpheight - 1, alheight - 1));
161 visYAsSeq = scrollRow;
165 // update scroll values
166 scrollCol = visXAsRes;
167 scrollRow = visYAsSeq;
172 * Update the overview panel box when the associated alignment panel is
180 * viewport position properties
183 public void setBoxPosition(HiddenSequences hiddenSeqs,
184 ColumnSelection hiddenCols, ViewportRanges ranges)
186 int alwidth = ranges.getAbsoluteAlignmentWidth();
187 int alheight = ranges.getAbsoluteAlignmentHeight();
189 // work with absolute values of startRes and endRes
190 int startRes = hiddenCols.adjustForHiddenColumns(ranges.getStartRes());
191 int endRes = hiddenCols.adjustForHiddenColumns(ranges.getEndRes());
193 // work with absolute values of startSeq and endSeq
194 int startSeq = hiddenSeqs.adjustForHiddenSeqs(ranges.getStartSeq());
195 int endSeq = hiddenSeqs.adjustForHiddenSeqs(ranges.getEndSeq());
197 // boxX, boxY is the x,y location equivalent to startRes, startSeq
198 boxX = Math.round((float) startRes * width / alwidth);
199 boxY = Math.round((float) startSeq * sequencesHeight / alheight);
201 // boxWidth is the width in residues translated to pixels
202 // since the box includes both the start and end residues, add 1 to the
205 .round((float) (endRes - startRes + 1) * width / alwidth);
206 // boxHeight is the height in sequences translated to pixels
207 boxHeight = Math.round((float) (endSeq - startSeq + 1)
213 public AlignmentColsCollectionI getColumns(ViewportRanges ranges,
214 ColumnSelection hiddenCols)
216 return new AllColsCollection(0,
217 ranges.getAbsoluteAlignmentWidth() - 1,
222 public AlignmentRowsCollectionI getRows(ViewportRanges ranges,
225 return new AllRowsCollection(0,
226 ranges.getAbsoluteAlignmentHeight() - 1,
231 public float getPixelsPerCol()
237 public float getPixelsPerSeq()