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 import java.awt.Dimension;
33 public class OverviewDimensionsHideHidden extends OverviewDimensions
35 private ViewportRanges ranges;
37 private int xdiff; // when dragging, difference in alignment units between
38 // start residue and original mouse click position
40 private int ydiff; // when dragging, difference in alignment units between
41 // start sequence and original mouse click position
43 public OverviewDimensionsHideHidden(ViewportRanges vpranges,
44 boolean showAnnotationPanel)
46 this(vpranges, showAnnotationPanel, null);
49 public OverviewDimensionsHideHidden(ViewportRanges vpranges,
50 boolean showAnnotationPanel, Dimension dim)
52 super(vpranges, showAnnotationPanel, dim);
58 public void updateViewportFromMouse(int mousex, int mousey,
59 HiddenSequences hiddenSeqs, HiddenColumns hiddenCols)
63 int xAsRes = getLeftXFromCentreX(mousex, hiddenCols);
64 int yAsSeq = getTopYFromCentreY(mousey, hiddenSeqs);
66 updateViewportFromTopLeft(xAsRes, yAsSeq, hiddenSeqs, hiddenCols);
71 public void adjustViewportFromMouse(int mousex, int mousey,
72 HiddenSequences hiddenSeqs, HiddenColumns hiddenCols)
76 // calculate translation in pixel terms:
77 // get mouse location in viewport coords, add translation in viewport
78 // coords, and update viewport as usual
79 int vpx = Math.round(mousex * widthRatio);
80 int vpy = Math.round(mousey * heightRatio);
82 updateViewportFromTopLeft(vpx + xdiff, vpy + ydiff, hiddenSeqs,
88 * {@inheritDoc} Callers should have already called resetAlignmentDims to
89 * refresh alwidth, alheight and width/height ratios
92 protected void updateViewportFromTopLeft(int leftx, int topy,
93 HiddenSequences hiddenSeqs, HiddenColumns hiddenCols)
108 if (ranges.isWrappedMode())
110 yAsSeq = 0; // sorry, no vertical scroll when wrapped
113 // get viewport width in residues
114 int vpwidth = ranges.getViewportWidth();
116 if (xAsRes + vpwidth > alwidth)
118 // went past the end of the alignment, adjust backwards
120 // if last position was before the end of the alignment, need to update
121 if (ranges.getStartRes() < alwidth)
123 xAsRes = alwidth - vpwidth;
127 xAsRes = ranges.getStartRes();
131 // Determine where scrollRow should be, given visYAsSeq
133 // get viewport height in sequences
134 // add 1 because height includes both endSeq and startSeq
135 int vpheight = ranges.getViewportHeight();
137 if (yAsSeq + vpheight > alheight)
139 // went past the end of the alignment, adjust backwards
140 if (ranges.getEndSeq() < alheight)
142 yAsSeq = alheight - vpheight;
146 yAsSeq = ranges.getStartSeq();
150 ranges.setStartResAndSeq(xAsRes, yAsSeq);
154 public void setBoxPosition(HiddenSequences hiddenSeqs,
155 HiddenColumns hiddenCols)
157 setBoxPosition(ranges.getStartRes(), ranges.getStartSeq(),
158 ranges.getViewportWidth(), ranges.getViewportHeight());
162 public AlignmentColsCollectionI getColumns(AlignmentI al)
164 return new VisibleColsCollection(0,
165 ranges.getAbsoluteAlignmentWidth() - 1, al.getHiddenColumns());
169 public AlignmentRowsCollectionI getRows(AlignmentI al)
171 return new VisibleRowsCollection(0,
172 ranges.getAbsoluteAlignmentHeight() - 1, al);
176 protected void resetAlignmentDims()
178 alwidth = ranges.getVisibleAlignmentWidth();
179 alheight = ranges.getVisibleAlignmentHeight();
181 widthRatio = (float) alwidth / width;
182 heightRatio = (float) alheight / sequencesHeight;
186 * {@inheritDoc} Callers should have already called resetAlignmentDims to
190 protected int getLeftXFromCentreX(int mousex, HiddenColumns hidden)
192 int vpx = Math.round(mousex * widthRatio);
193 return vpx - ranges.getViewportWidth() / 2;
197 * {@inheritDoc} Callers should have already called resetAlignmentDims to
198 * refresh heightRatio
201 protected int getTopYFromCentreY(int mousey, HiddenSequences hidden)
203 int vpy = Math.round(mousey * heightRatio);
204 return vpy - ranges.getViewportHeight() / 2;
208 public void setDragPoint(int x, int y, HiddenSequences hiddenSeqs,
209 HiddenColumns hiddenCols)
211 resetAlignmentDims();
213 // get alignment position of x and box (can get directly from vpranges) and
214 // calculate difference between the positions
215 int vpx = Math.round(x * widthRatio);
216 int vpy = Math.round(y * heightRatio);
218 xdiff = ranges.getStartRes() - vpx;
219 ydiff = ranges.getStartSeq() - vpy;