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 OverviewDimensionsShowHidden extends OverviewDimensions
33 private ViewportRanges ranges;
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 OverviewDimensionsShowHidden(ViewportRanges vpranges,
44 boolean showAnnotationPanel)
46 super(vpranges, showAnnotationPanel);
52 * Check box dimensions and scroll positions and correct if necessary
55 * x position in overview panel
57 * y position in overview panel
63 * viewport position properties
66 public void updateViewportFromMouse(int mousex, int mousey,
67 HiddenSequences hiddenSeqs, HiddenColumns hiddenCols)
69 int xAsRes = getLeftXFromCentreX(mousex, hiddenCols);
70 int yAsSeq = getTopYFromCentreY(mousey, hiddenSeqs);
72 updateViewportFromTopLeft(xAsRes, yAsSeq, hiddenSeqs, hiddenCols);
76 public void adjustViewportFromMouse(int mousex, int mousey,
77 HiddenSequences hiddenSeqs, HiddenColumns hiddenCols)
79 // calculate translation in pixel terms:
80 // get mouse location in viewport coords, add translation in viewport
82 // convert back to pixel coords
83 int vpx = Math.round((float) mousex * alwidth / width);
84 int visXAsRes = hiddenCols.findColumnPosition(vpx);
86 int vpy = Math.round((float) mousey * alheight / sequencesHeight);
87 int visYAsRes = hiddenSeqs.findIndexWithoutHiddenSeqs(vpy);
89 updateViewportFromTopLeft(visXAsRes + transX, visYAsRes + transY,
95 protected void updateViewportFromTopLeft(int xAsRes, int yAsSeq,
96 HiddenSequences hiddenSeqs, HiddenColumns hiddenCols)
112 // Convert x value to residue position
115 // need to determine where scrollCol should be, given x
116 // to do this also need to know width of viewport, and some hidden column
119 // convert x to residues - this is an absolute position
120 // int xAsRes = Math.round((float) x * alwidth / width);
122 // get viewport width in residues
123 int vpwidth = ranges.getViewportWidth();
125 // get where x should be when accounting for hidden cols
126 // if x is in a hidden col region, shift to left - but we still need
128 // so convert back after getting visible region position
129 int visXAsRes = hiddenCols.findColumnPosition(xAsRes);
131 // check in case we went off the edge of the alignment
132 int visAlignWidth = hiddenCols.findColumnPosition(alwidth - 1);
133 if (visXAsRes + vpwidth - 1 > visAlignWidth)
135 // went past the end of the alignment, adjust backwards
137 // if last position was before the end of the alignment, need to update
138 if (ranges.getEndRes() < visAlignWidth)
140 visXAsRes = hiddenCols.findColumnPosition(hiddenCols
141 .subtractVisibleColumns(vpwidth - 1, alwidth - 1));
145 visXAsRes = ranges.getStartRes();
150 // Convert y value to sequence position
153 // convert y to residues
154 // int yAsSeq = Math.round((float) y * alheight / sequencesHeight);
156 // get viewport height in sequences
157 int vpheight = ranges.getViewportHeight();
159 // get where y should be when accounting for hidden rows
160 // if y is in a hidden row region, shift up - but we still need absolute
162 // so convert back after getting visible region position
163 yAsSeq = hiddenSeqs.adjustForHiddenSeqs(hiddenSeqs
164 .findIndexWithoutHiddenSeqs(yAsSeq));
166 // check in case we went off the edge of the alignment
167 int visAlignHeight = hiddenSeqs.findIndexWithoutHiddenSeqs(alheight);
168 int visYAsSeq = hiddenSeqs.findIndexWithoutHiddenSeqs(yAsSeq);
169 if (visYAsSeq + vpheight - 1 > visAlignHeight)
171 // went past the end of the alignment, adjust backwards
172 if (ranges.getEndSeq() < visAlignHeight)
174 visYAsSeq = hiddenSeqs.findIndexWithoutHiddenSeqs(hiddenSeqs
175 .subtractVisibleRows(vpheight - 1, alheight - 1));
179 visYAsSeq = ranges.getStartSeq();
184 ranges.setStartRes(visXAsRes);
185 ranges.setStartSeq(visYAsSeq);
190 * Update the overview panel box when the associated alignment panel is
198 * viewport position properties
201 public void setBoxPosition(HiddenSequences hiddenSeqs,
202 HiddenColumns hiddenCols)
205 // work with absolute values of startRes and endRes
206 int startRes = hiddenCols.adjustForHiddenColumns(ranges.getStartRes());
207 int endRes = hiddenCols.adjustForHiddenColumns(ranges.getEndRes());
209 // work with absolute values of startSeq and endSeq
210 int startSeq = hiddenSeqs.adjustForHiddenSeqs(ranges.getStartSeq());
211 int endSeq = hiddenSeqs.adjustForHiddenSeqs(ranges.getEndSeq());
213 setBoxPosition(startRes, startSeq, endRes - startRes + 1, endSeq
218 public AlignmentColsCollectionI getColumns(AlignmentI al)
220 return new AllColsCollection(0,
221 ranges.getAbsoluteAlignmentWidth() - 1, al);
225 public AlignmentRowsCollectionI getRows(AlignmentI al)
227 return new AllRowsCollection(0,
228 ranges.getAbsoluteAlignmentHeight() - 1,
233 protected void resetAlignmentDims()
235 alwidth = ranges.getAbsoluteAlignmentWidth();
236 alheight = ranges.getAbsoluteAlignmentHeight();
240 protected int getLeftXFromCentreX(int mousex, HiddenColumns hidden)
242 int vpx = Math.round((float) mousex * alwidth / width);
243 return hidden.subtractVisibleColumns(ranges.getViewportWidth() / 2,
248 protected int getTopYFromCentreY(int mousey, HiddenSequences hidden)
250 int vpy = Math.round((float) mousey * alheight / sequencesHeight);
251 return hidden.subtractVisibleRows(ranges.getViewportHeight() / 2, vpy);
255 public void setDragPoint(int x, int y, HiddenSequences hiddenSeqs,
256 HiddenColumns hiddenCols)
259 // get alignment position of x and box (can get directly from vpranges) and calc difference
260 int vpx = Math.round((float) x * alwidth / width);
261 int visXAsRes = hiddenCols.findColumnPosition(vpx);
263 int vpy = Math.round((float) y * alheight / sequencesHeight);
264 int visYAsRes = hiddenSeqs.findIndexWithoutHiddenSeqs(vpy);
266 transX = ranges.getStartRes() - visXAsRes;
267 transY = ranges.getStartSeq() - visYAsRes;