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;
35 private int xdiff; // when dragging, difference in alignment units between
36 // start residue and original mouse click position
38 private int ydiff; // when dragging, difference in alignment units between
39 // start sequence and original mouse click position
42 * Create an OverviewDimensions object
45 * positional properties of the viewport
46 * @param showAnnotationPanel
47 * true if the annotation panel is to be shown, false otherwise
49 public OverviewDimensionsShowHidden(ViewportRanges vpranges,
50 boolean showAnnotationPanel)
52 super(vpranges, showAnnotationPanel);
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, HiddenColumns hiddenCols)
75 // convert mousex and mousey to alignment units as well as
76 // translating to top left corner of viewport - this is an absolute position
77 int xAsRes = getLeftXFromCentreX(mousex, hiddenCols);
78 int yAsSeq = getTopYFromCentreY(mousey, hiddenSeqs);
80 // convert to visible positions
81 int visXAsRes = hiddenCols.findColumnPosition(xAsRes);
82 yAsSeq = hiddenSeqs.adjustForHiddenSeqs(
83 hiddenSeqs.findIndexWithoutHiddenSeqs(yAsSeq));
84 yAsSeq = Math.max(yAsSeq, 0); // -1 if before first visible sequence
85 int visYAsSeq = hiddenSeqs.findIndexWithoutHiddenSeqs(yAsSeq);
86 visYAsSeq = Math.max(visYAsSeq, 0); // -1 if before first visible sequence
88 // update viewport accordingly
89 updateViewportFromTopLeft(visXAsRes, visYAsSeq, hiddenSeqs, hiddenCols);
93 public void adjustViewportFromMouse(int mousex, int mousey,
94 HiddenSequences hiddenSeqs, HiddenColumns hiddenCols)
96 // calculate translation in pixel terms:
97 // get mouse location in viewport coords, add translation in viewport
99 // convert back to pixel coords
100 int vpx = Math.round((float) mousex * alwidth / width);
101 int visXAsRes = hiddenCols.findColumnPosition(vpx) + xdiff;
103 int vpy = Math.round((float) mousey * alheight / sequencesHeight);
104 int visYAsRes = hiddenSeqs.findIndexWithoutHiddenSeqs(vpy) + ydiff;
106 // update viewport accordingly
107 updateViewportFromTopLeft(visXAsRes, visYAsRes,
113 protected void updateViewportFromTopLeft(int leftx, int topy,
114 HiddenSequences hiddenSeqs, HiddenColumns hiddenCols)
116 int visXAsRes = leftx;
117 int visYAsSeq = topy;
118 resetAlignmentDims();
130 // Determine where scrollCol should be, given visXAsRes
132 // get viewport width in residues
133 int vpwidth = ranges.getViewportWidth();
135 // check in case we went off the edge of the alignment
136 int visAlignWidth = hiddenCols.findColumnPosition(alwidth - 1);
137 if (visXAsRes + vpwidth - 1 > visAlignWidth)
139 // went past the end of the alignment, adjust backwards
141 // if last position was before the end of the alignment, need to update
142 if (ranges.getEndRes() < visAlignWidth)
144 visXAsRes = hiddenCols.findColumnPosition(hiddenCols
145 .subtractVisibleColumns(vpwidth - 1, alwidth - 1));
149 visXAsRes = ranges.getStartRes();
153 // Determine where scrollRow should be, given visYAsSeq
155 // get viewport height in sequences
156 int vpheight = ranges.getViewportHeight();
158 // check in case we went off the edge of the alignment
159 int visAlignHeight = hiddenSeqs.findIndexWithoutHiddenSeqs(alheight);
161 if (visYAsSeq + vpheight - 1 > visAlignHeight)
163 // went past the end of the alignment, adjust backwards
164 if (ranges.getEndSeq() < visAlignHeight)
166 visYAsSeq = hiddenSeqs.findIndexWithoutHiddenSeqs(hiddenSeqs
167 .subtractVisibleRows(vpheight - 1, alheight - 1));
171 visYAsSeq = ranges.getStartSeq();
176 ranges.setStartRes(visXAsRes);
177 ranges.setStartSeq(visYAsSeq);
181 * Update the overview panel box when the associated alignment panel is
189 * viewport position properties
192 public void setBoxPosition(HiddenSequences hiddenSeqs,
193 HiddenColumns hiddenCols)
195 // work with absolute values of startRes and endRes
196 int startRes = hiddenCols.adjustForHiddenColumns(ranges.getStartRes());
197 int endRes = hiddenCols.adjustForHiddenColumns(ranges.getEndRes());
199 // work with absolute values of startSeq and endSeq
200 int startSeq = hiddenSeqs.adjustForHiddenSeqs(ranges.getStartSeq());
201 int endSeq = hiddenSeqs.adjustForHiddenSeqs(ranges.getEndSeq());
203 setBoxPosition(startRes, startSeq, endRes - startRes + 1, endSeq
208 public AlignmentColsCollectionI getColumns(AlignmentI al)
210 return new AllColsCollection(0,
211 ranges.getAbsoluteAlignmentWidth() - 1, al);
215 public AlignmentRowsCollectionI getRows(AlignmentI al)
217 return new AllRowsCollection(0,
218 ranges.getAbsoluteAlignmentHeight() - 1,
223 protected void resetAlignmentDims()
225 alwidth = ranges.getAbsoluteAlignmentWidth();
226 alheight = ranges.getAbsoluteAlignmentHeight();
230 protected int getLeftXFromCentreX(int mousex, HiddenColumns hidden)
232 int vpx = Math.round((float) mousex * alwidth / width);
233 return hidden.subtractVisibleColumns(ranges.getViewportWidth() / 2,
238 protected int getTopYFromCentreY(int mousey, HiddenSequences hidden)
240 int vpy = Math.round((float) mousey * alheight / sequencesHeight);
241 return hidden.subtractVisibleRows(ranges.getViewportHeight() / 2, vpy);
245 public void setDragPoint(int x, int y, HiddenSequences hiddenSeqs,
246 HiddenColumns hiddenCols)
248 // get alignment position of x and box (can get directly from vpranges) and
249 // calculate difference between the positions
250 int vpx = Math.round((float) x * alwidth / width);
251 int vpy = Math.round((float) y * alheight / sequencesHeight);
253 xdiff = ranges.getStartRes() - hiddenCols.findColumnPosition(vpx);
254 ydiff = ranges.getStartSeq()
255 - hiddenSeqs.findIndexWithoutHiddenSeqs(vpy);