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 java.awt.Dimension;
25 import jalview.api.AlignmentColsCollectionI;
26 import jalview.api.AlignmentRowsCollectionI;
27 import jalview.datamodel.AlignmentI;
28 import jalview.datamodel.HiddenColumns;
29 import jalview.datamodel.HiddenSequences;
30 import jalview.datamodel.VisibleColsCollection;
31 import jalview.datamodel.VisibleRowsCollection;
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
47 * @param showAnnotationPanel
50 public OverviewDimensionsHideHidden(ViewportRanges vpranges, boolean showAnnotationPanel) {
51 this(vpranges, showAnnotationPanel, null);
54 public OverviewDimensionsHideHidden(ViewportRanges vpranges,
55 boolean showAnnotationPanel, Dimension dim)
57 super(vpranges, showAnnotationPanel, dim);
63 public void updateViewportFromMouse(int mousex, int mousey,
64 HiddenSequences hiddenSeqs, HiddenColumns hiddenCols)
68 int xAsRes = getLeftXFromCentreX(mousex, hiddenCols);
69 int yAsSeq = getTopYFromCentreY(mousey, hiddenSeqs);
71 updateViewportFromTopLeft(xAsRes, yAsSeq, hiddenSeqs, hiddenCols);
76 public void adjustViewportFromMouse(int mousex, int mousey,
77 HiddenSequences hiddenSeqs, HiddenColumns hiddenCols)
81 // calculate translation in pixel terms:
82 // get mouse location in viewport coords, add translation in viewport
83 // coords, and update viewport as usual
84 int vpx = Math.round(mousex * widthRatio);
85 int vpy = Math.round(mousey * heightRatio);
87 updateViewportFromTopLeft(vpx + xdiff, vpy + ydiff, hiddenSeqs,
93 * {@inheritDoc} Callers should have already called resetAlignmentDims to
94 * refresh alwidth, alheight and width/height ratios
97 protected void updateViewportFromTopLeft(int leftx, int topy,
98 HiddenSequences hiddenSeqs, HiddenColumns hiddenCols)
113 if (ranges.isWrappedMode())
115 yAsSeq = 0; // sorry, no vertical scroll when wrapped
118 // get viewport width in residues
119 int vpwidth = ranges.getViewportWidth();
121 if (xAsRes + vpwidth > alwidth)
123 // went past the end of the alignment, adjust backwards
125 // if last position was before the end of the alignment, need to update
126 if (ranges.getStartRes() < alwidth)
128 xAsRes = alwidth - vpwidth;
132 xAsRes = ranges.getStartRes();
136 // Determine where scrollRow should be, given visYAsSeq
138 // get viewport height in sequences
139 // add 1 because height includes both endSeq and startSeq
140 int vpheight = ranges.getViewportHeight();
142 if (yAsSeq + vpheight > alheight)
144 // went past the end of the alignment, adjust backwards
145 if (ranges.getEndSeq() < alheight)
147 yAsSeq = alheight - vpheight;
151 yAsSeq = ranges.getStartSeq();
155 ranges.setStartResAndSeq(xAsRes, yAsSeq);
159 public void setBoxPosition(HiddenSequences hiddenSeqs,
160 HiddenColumns hiddenCols)
162 setBoxPosition(ranges.getStartRes(), ranges.getStartSeq(),
163 ranges.getViewportWidth(), ranges.getViewportHeight());
167 public AlignmentColsCollectionI getColumns(AlignmentI al)
169 return new VisibleColsCollection(0,
170 ranges.getAbsoluteAlignmentWidth() - 1, al.getHiddenColumns());
174 public AlignmentRowsCollectionI getRows(AlignmentI al)
176 return new VisibleRowsCollection(0,
177 ranges.getAbsoluteAlignmentHeight() - 1, al);
181 protected void resetAlignmentDims()
183 alwidth = ranges.getVisibleAlignmentWidth();
184 alheight = ranges.getVisibleAlignmentHeight();
186 widthRatio = (float) alwidth / width;
187 heightRatio = (float) alheight / sequencesHeight;
191 * {@inheritDoc} Callers should have already called resetAlignmentDims to
195 protected int getLeftXFromCentreX(int mousex, HiddenColumns hidden)
197 int vpx = Math.round(mousex * widthRatio);
198 return vpx - ranges.getViewportWidth() / 2;
202 * {@inheritDoc} Callers should have already called resetAlignmentDims to
203 * refresh heightRatio
206 protected int getTopYFromCentreY(int mousey, HiddenSequences hidden)
208 int vpy = Math.round(mousey * heightRatio);
209 return vpy - ranges.getViewportHeight() / 2;
213 public void setDragPoint(int x, int y, HiddenSequences hiddenSeqs,
214 HiddenColumns hiddenCols)
216 resetAlignmentDims();
218 // get alignment position of x and box (can get directly from vpranges) and
219 // calculate difference between the positions
220 int vpx = Math.round(x * widthRatio);
221 int vpy = Math.round(y * heightRatio);
223 xdiff = ranges.getStartRes() - vpx;
224 ydiff = ranges.getStartSeq() - vpy;