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 * Embryonic class which: Supplies and updates viewport properties relating to
27 * position such as: start and end residues and sequences; ideally will serve
28 * hidden columns/rows too. Intention also to support calculations for
29 * 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);
93 public void setStartEndRes(int startres, int endres)
95 int oldres = this.startRes;
96 if (startres > al.getWidth() - 1)
98 startres = al.getWidth() - 1;
100 else if (startres < 0)
104 this.startRes = startres;
110 this.endRes = endres;
112 changeSupport.firePropertyChange("startres", oldres, startres);
116 * Set last residue visible in the viewport
121 public void setEndRes(int res)
123 int width = getViewportWidth();
124 setStartEndRes(res - width + 1, res);
128 * Set the first sequence visible in the viewport
133 public void setStartSeq(int seq)
135 int height = getViewportHeight();
136 setStartEndSeq(seq, seq + height - 1);
139 public void setStartEndSeq(int startseq, int endseq)
141 int oldseq = this.startSeq;
142 if (startseq > al.getHeight() - 1)
144 startseq = al.getHeight() - 1;
146 else if (startseq < 0)
150 this.startSeq = startseq;
152 if (endseq >= al.getHeight())
154 endseq = al.getHeight() - 1;
160 this.endSeq = endseq;
161 changeSupport.firePropertyChange("startseq", oldseq, startseq);
165 * Set the last sequence visible in the viewport
170 public void setEndSeq(int seq)
172 int height = getViewportHeight();
173 setStartEndSeq(seq - height + 1, seq);
177 * Get start residue of viewport
179 public int getStartRes()
185 * Get end residue of viewport
187 public int getEndRes()
193 * Get start sequence of viewport
195 public int getStartSeq()
201 * Get end sequence of viewport
203 public int getEndSeq()
209 * Get width of viewport in residues
211 * @return width of viewport
213 public int getViewportWidth()
215 return (endRes - startRes + 1); // TODO get for wrapped alignments too
219 * Get height of viewport in residues
221 * @return height of viewport
223 public int getViewportHeight()
225 return (endSeq - startSeq + 1);
228 // return value is true if the scroll is valid
229 public boolean scrollUp(boolean up)
238 setStartSeq(startSeq - 1);
242 if (endSeq >= al.getHeight() - 1)
247 setStartSeq(startSeq + 1);
258 * @return DOCUMENT ME!
260 public boolean scrollRight(boolean right)
269 setStartRes(startRes - 1);
273 if (endRes > al.getWidth() - 1)
278 setStartRes(startRes + 1);
284 public void scrollToWrappedVisible(int res)