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.ViewStyleI;
24 import jalview.datamodel.AlignmentI;
27 * Supplies and updates viewport properties relating to position such as: start
28 * and end residues and sequences, hidden column/row adjustments, ratio of
29 * viewport to alignment etc
31 public class ViewportPositionProps extends ViewportProperties
33 // start residue of viewport
36 // end residue of viewport
39 // start sequence of viewport
42 // end sequence of viewport
46 private int charHeight;
49 private int charWidth;
52 private AlignmentI al;
55 private ViewStyleI viewstyle;
59 * @param alignment TODO
61 public ViewportPositionProps(AlignmentI alignment, ViewStyleI vstyle)
63 // initial values of viewport settings
65 this.endRes = alignment.getWidth() - 1;
67 this.endSeq = alignment.getHeight() - 1;
69 this.viewstyle = vstyle;
72 public void setCharHeight(int h)
74 viewstyle.setCharHeight(h);
77 public void setCharWidth(int w)
79 viewstyle.setCharWidth(w);
82 // ways to update values
84 // ways to notify of changes
86 // ways to supply positional information
91 public int getAlignmentWidthInCols()
97 * Get alignment height
99 public int getAlignmentHeightInRows()
101 return al.getHeight();
104 public void setStartRes(int res)
106 if (res > al.getWidth() - 1)
108 res = al.getWidth() - 1;
117 public void setEndRes(int res)
119 if (res > al.getWidth() - 1)
121 res = al.getWidth() - 1;
130 public void setStartSeq(int seq)
132 if (seq > al.getHeight())
134 seq = al.getHeight();
143 public void setEndSeq(int seq)
145 if (seq > al.getHeight())
147 seq = al.getHeight();
157 * Get start residue of viewport
159 public int getStartRes()
165 * Get end residue of viewport
167 public int getEndRes()
173 * Get start sequence of viewport
175 public int getStartSeq()
181 * Get end sequence of viewport
183 public int getEndSeq()
188 * Get start residue of viewport
190 public int getStartRes(boolean countHidden)
194 return 0; // av.getColumnSelection().adjustForHiddenColumns(startRes);
203 * Convert distance x in viewport pixels to a distance in number of residues
207 * @return number of residues
209 public int convertPixelsToResidues(int x)
211 return Math.round((float) x / viewstyle.getCharWidth());
212 // return (int) ((float) x / viewstyle.getCharWidth());
216 * Convert distance y in viewport pixels to a distance in number of sequences
220 * @return number of sequences
222 public int convertPixelsToSequences(int y)
224 return Math.round((float) y / viewstyle.getCharHeight());
225 // return (int) ((float) y / viewstyle.getCharHeight());
229 * Convert number of sequences s to a height in viewport pixels
232 * number of sequences
233 * @return number of pixels
235 public int convertSequencesToPixels(int s)
237 return (s * viewstyle.getCharHeight());
241 * Convert number of residues r to a width in viewport pixels
245 * @return number of pixels
247 public int convertResiduesToPixels(int r)
249 return (r * viewstyle.getCharWidth());