JAL-2388 Renamed viewport position props to viewport ranges
[jalview.git] / src / jalview / viewmodel / ViewportRanges.java
1 /*
2  * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3  * Copyright (C) $$Year-Rel$$ The Jalview Authors
4  * 
5  * This file is part of Jalview.
6  * 
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.
11  *  
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.
16  * 
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.
20  */
21 package jalview.viewmodel;
22
23 import jalview.datamodel.AlignmentI;
24
25 /**
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
29  */
30 public class ViewportRanges extends ViewportProperties
31 {
32   // start residue of viewport
33   private int startRes;
34
35   // end residue of viewport
36   private int endRes;
37
38   // start sequence of viewport
39   private int startSeq;
40
41   // end sequence of viewport
42   private int endSeq;
43
44   // alignment
45   private AlignmentI al;
46
47   /**
48    * Constructor
49    * 
50    * @param alignment
51    *          the viewport's alignment
52    */
53   public ViewportRanges(AlignmentI alignment)
54   {
55     // initial values of viewport settings
56     this.startRes = 0;
57     this.endRes = alignment.getWidth() - 1;
58     this.startSeq = 0;
59     this.endSeq = alignment.getHeight() - 1;
60     this.al = alignment;
61   }
62
63   /**
64    * Get alignment width in cols, including hidden cols
65    */
66   public int getAbsoluteAlignmentWidth()
67   {
68     return al.getWidth();
69   }
70
71   /**
72    * Get alignment height in rows, including hidden rows
73    */
74   public int getAbsoluteAlignmentHeight()
75   {
76     return al.getHeight() + al.getHiddenSequences().getSize();
77   }
78
79   /**
80    * Set first residue visible in the viewport
81    * 
82    * @param res
83    *          residue position
84    */
85   public void setStartRes(int res)
86   {
87     if (res > al.getWidth() - 1)
88     {
89       res = al.getWidth() - 1;
90     }
91     else if (res < 0)
92     {
93       res = 0;
94     }
95     this.startRes = res;
96   }
97
98   /**
99    * Set last residue visible in the viewport
100    * 
101    * @param res
102    *          residue position
103    */
104   public void setEndRes(int res)
105   {
106     if (res >= al.getWidth())
107     {
108       res = al.getWidth() - 1;
109     }
110     else if (res < 0)
111     {
112       res = 0;
113     }
114     this.endRes = res;
115   }
116
117   /**
118    * Set the first sequence visible in the viewport
119    * 
120    * @param seq
121    *          sequence position
122    */
123   public void setStartSeq(int seq)
124   {
125     if (seq > al.getHeight() - 1)
126     {
127       seq = al.getHeight() - 1;
128     }
129     else if (seq < 0)
130     {
131       seq = 0;
132     }
133     this.startSeq = seq;
134   }
135
136   /**
137    * Set the last sequence visible in the viewport
138    * 
139    * @param seq
140    *          sequence position
141    */
142   public void setEndSeq(int seq)
143   {
144     if (seq >= al.getHeight())
145     {
146       seq = al.getHeight() - 1;
147     }
148     else if (seq < 0)
149     {
150       seq = 0;
151     }
152     this.endSeq = seq;
153   }
154
155   /**
156    * Get start residue of viewport
157    */
158   public int getStartRes()
159   {
160     return startRes;
161   }
162
163   /**
164    * Get end residue of viewport
165    */
166   public int getEndRes()
167   {
168     return endRes;
169   }
170
171   /**
172    * Get start sequence of viewport
173    */
174   public int getStartSeq()
175   {
176     return startSeq;
177   }
178
179   /**
180    * Get end sequence of viewport
181    */
182   public int getEndSeq()
183   {
184     return endSeq;
185   }
186 }