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.HiddenColumns;
27 import jalview.datamodel.HiddenSequences;
28 import jalview.datamodel.VisibleColsCollection;
29 import jalview.datamodel.VisibleRowsCollection;
31 public class OverviewDimensionsHideHidden 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
41 public OverviewDimensionsHideHidden(ViewportRanges vpranges,
42 boolean showAnnotationPanel)
44 super(vpranges, showAnnotationPanel);
50 public void updateViewportFromMouse(int mousex, int mousey,
51 HiddenSequences hiddenSeqs, HiddenColumns hiddenCols)
53 int xAsRes = getLeftXFromCentreX(mousex, hiddenCols);
54 int yAsSeq = getTopYFromCentreY(mousey, hiddenSeqs);
56 updateViewportFromTopLeft(xAsRes, yAsSeq, hiddenSeqs, hiddenCols);
61 public void adjustViewportFromMouse(int mousex, int mousey,
62 HiddenSequences hiddenSeqs, HiddenColumns hiddenCols)
64 // calculate translation in pixel terms:
65 // get mouse location in viewport coords, add translation in viewport
66 // coords, and update viewport as usual
67 int vpx = Math.round((float) mousex * alwidth / width);
68 int vpy = Math.round((float) mousey * alheight / sequencesHeight);
70 updateViewportFromTopLeft(vpx + xdiff, vpy + ydiff, hiddenSeqs,
76 protected void updateViewportFromTopLeft(int leftx, int topy,
77 HiddenSequences hiddenSeqs, HiddenColumns hiddenCols)
93 if (ranges.isWrappedMode())
95 yAsSeq = 0; // sorry, no vertical scroll when wrapped
98 // get viewport width in residues
99 int vpwidth = ranges.getViewportWidth();
101 if (xAsRes + vpwidth > alwidth)
103 // went past the end of the alignment, adjust backwards
105 // if last position was before the end of the alignment, need to update
106 if (ranges.getStartRes() < alwidth)
108 xAsRes = alwidth - vpwidth;
112 xAsRes = ranges.getStartRes();
116 // Determine where scrollRow should be, given visYAsSeq
118 // get viewport height in sequences
119 // add 1 because height includes both endSeq and startSeq
120 int vpheight = ranges.getViewportHeight();
122 if (yAsSeq + vpheight > alheight)
124 // went past the end of the alignment, adjust backwards
125 if (ranges.getEndSeq() < alheight)
127 yAsSeq = alheight - vpheight;
131 yAsSeq = ranges.getStartSeq();
135 ranges.setStartResAndSeq(xAsRes, yAsSeq);
139 public void setBoxPosition(HiddenSequences hiddenSeqs,
140 HiddenColumns hiddenCols)
142 setBoxPosition(ranges.getStartRes(), ranges.getStartSeq(),
143 ranges.getViewportWidth(), ranges.getViewportHeight());
147 public AlignmentColsCollectionI getColumns(AlignmentI al)
149 return new VisibleColsCollection(0,
150 ranges.getAbsoluteAlignmentWidth() - 1, al);
154 public AlignmentRowsCollectionI getRows(AlignmentI al)
156 return new VisibleRowsCollection(0,
157 ranges.getAbsoluteAlignmentHeight() - 1, al);
161 protected void resetAlignmentDims()
163 alwidth = ranges.getVisibleAlignmentWidth();
164 alheight = ranges.getVisibleAlignmentHeight();
168 protected int getLeftXFromCentreX(int mousex, HiddenColumns hidden)
170 int vpx = Math.round((float) mousex * alwidth / width);
171 return vpx - ranges.getViewportWidth() / 2;
175 protected int getTopYFromCentreY(int mousey, HiddenSequences hidden)
177 int vpy = Math.round((float) mousey * alheight / sequencesHeight);
178 return vpy - ranges.getViewportHeight() / 2;
182 public void setDragPoint(int x, int y, HiddenSequences hiddenSeqs,
183 HiddenColumns hiddenCols)
185 // get alignment position of x and box (can get directly from vpranges) and
186 // calculate difference between the positions
187 int vpx = Math.round((float) x * alwidth / width);
188 int vpy = Math.round((float) y * alheight / sequencesHeight);
190 xdiff = ranges.getStartRes() - vpx;
191 ydiff = ranges.getStartSeq() - vpy;