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.datamodel.AlignmentI;
26 * Slightly less embryonic class which: Supplies and updates viewport properties
27 * relating to position such as: start and end residues and sequences; ideally
28 * will serve hidden columns/rows too. Intention also to support calculations
29 * for positioning, scrolling etc. such as finding the middle of the viewport,
30 * checking for scrolls off screen
32 public class ViewportRanges extends ViewportProperties
34 // start residue of viewport
37 // end residue of viewport
40 // start sequence of viewport
43 // end sequence of viewport
47 private AlignmentI al;
53 * the viewport's alignment
55 public ViewportRanges(AlignmentI alignment)
57 // initial values of viewport settings
59 this.endRes = alignment.getWidth() - 1;
61 this.endSeq = alignment.getHeight() - 1;
66 * Get alignment width in cols, including hidden cols
68 public int getAbsoluteAlignmentWidth()
74 * Get alignment height in rows, including hidden rows
76 public int getAbsoluteAlignmentHeight()
78 return al.getHeight() + al.getHiddenSequences().getSize();
82 * Set first residue visible in the viewport, and retain the current width.
87 public void setStartRes(int res)
89 int width = getViewportWidth();
90 setStartEndRes(res, res + width - 1);
94 * Set start and end residues at the same time. This method only fires one
95 * event for the two changes, and should be used in preference to separate
96 * calls to setStartRes and setEndRes.
103 public void setStartEndRes(int start, int end)
105 int oldres = this.startRes;
106 if (start > al.getWidth() - 1)
108 startRes = al.getWidth() - 1;
128 changeSupport.firePropertyChange("startres", oldres, start);
132 * Set last residue visible in the viewport
137 public void setEndRes(int res)
139 int width = getViewportWidth();
140 setStartEndRes(res - width + 1, res);
144 * Set the first sequence visible in the viewport
149 public void setStartSeq(int seq)
151 int height = getViewportHeight();
152 setStartEndSeq(seq, seq + height - 1);
156 * Set start and end sequences at the same time. This method only fires one
157 * event for the two changes, and should be used in preference to separate
158 * calls to setStartSeq and setEndSeq.
165 public void setStartEndSeq(int start, int end)
167 int oldseq = this.startSeq;
168 if (start > al.getHeight() - 1)
170 startSeq = al.getHeight() - 1;
181 if (end >= al.getHeight())
183 endSeq = al.getHeight() - 1;
194 changeSupport.firePropertyChange("startseq", oldseq, start);
198 * Set the last sequence visible in the viewport
203 public void setEndSeq(int seq)
205 int height = getViewportHeight();
206 setStartEndSeq(seq - height + 1, seq);
210 * Get start residue of viewport
212 public int getStartRes()
218 * Get end residue of viewport
220 public int getEndRes()
226 * Get start sequence of viewport
228 public int getStartSeq()
234 * Get end sequence of viewport
236 public int getEndSeq()
242 * Set viewport width in residues, without changing startRes. Use in
243 * preference to calculating endRes from the width, to avoid out by one
249 public void setViewportWidth(int w)
251 setStartEndRes(startRes, startRes + w - 1);
255 * Set viewport height in residues, without changing startSeq. Use in
256 * preference to calculating endSeq from the height, to avoid out by one
260 * height in sequences
262 public void setViewportHeight(int h)
264 setStartEndSeq(startSeq, startSeq + h - 1);
268 * Set viewport horizontal start position and width. Use in preference to
269 * calculating endRes from the width, to avoid out by one errors!
276 public void setViewportStartAndWidth(int start, int w)
278 setStartEndRes(start, start + w - 1);
282 * Set viewport vertical start position and height. Use in preference to
283 * calculating endSeq from the height, to avoid out by one errors!
288 * height in sequences
290 public void setViewportStartAndHeight(int start, int h)
292 setStartEndSeq(start, start + h - 1);
296 * Get width of viewport in residues
298 * @return width of viewport
300 public int getViewportWidth()
302 return (endRes - startRes + 1);
306 * Get height of viewport in residues
308 * @return height of viewport
310 public int getViewportHeight()
312 return (endSeq - startSeq + 1);
316 * Scroll the viewport range vertically
319 * true if scrolling up, false if down
321 * @return true if the scroll is valid
323 public boolean scrollUp(boolean up)
332 setStartSeq(startSeq - 1);
336 if (endSeq >= al.getHeight() - 1)
341 setStartSeq(startSeq + 1);
347 * Scroll the viewport range horizontally
350 * true if scrolling right, false if left
352 * @return true if the scroll is valid
354 public boolean scrollRight(boolean right)
363 setStartRes(startRes - 1);
367 if (endRes > al.getWidth() - 1)
372 setStartRes(startRes + 1);
379 * Scroll a wrapped alignment so that the specified residue is visible
382 * residue position to scroll to
384 public void scrollToWrappedVisible(int res)
386 // get the start residue of the wrapped row which res is in
387 // and set that as our start residue
388 int width = getViewportWidth();
389 setStartRes((res / width) * width);