JAL-2388 Unit test update
[jalview.git] / src / jalview / viewmodel / ViewportPositionProps.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  * Supplies and updates viewport properties relating to position such as: start
27  * and end residues and sequences
28  */
29 public class ViewportPositionProps extends ViewportProperties
30 {
31   // start residue of viewport
32   private int startRes;
33
34   // end residue of viewport
35   private int endRes;
36
37   // start sequence of viewport
38   private int startSeq;
39
40   // end sequence of viewport
41   private int endSeq;
42
43   // alignment
44   private AlignmentI al;
45
46   /**
47    * Constructor
48    * 
49    * @param alignment
50    *          the viewport's alignment
51    */
52   public ViewportPositionProps(AlignmentI alignment)
53   {
54     // initial values of viewport settings
55     this.startRes = 0;
56     this.endRes = alignment.getWidth() - 1;
57     this.startSeq = 0;
58     this.endSeq = alignment.getHeight() - 1;
59     this.al = alignment;
60   }
61
62   // ways to update values
63
64   // ways to notify of changes
65
66   // ways to supply positional information
67
68   /**
69    * Get alignment width in cols, including hidden cols
70    */
71   public int getAbsoluteAlignmentWidth()
72   {
73     return al.getWidth();
74   }
75
76   /**
77    * Get alignment height in rows, including hidden rows
78    */
79   public int getAbsoluteAlignmentHeight()
80   {
81     return al.getHeight() + al.getHiddenSequences().getSize();
82   }
83
84   /**
85    * Set first residue visible in the viewport
86    * 
87    * @param res
88    *          residue position
89    */
90   public void setStartRes(int res)
91   {
92     if (res > al.getWidth() - 1)
93     {
94       res = al.getWidth() - 1;
95     }
96     else if (res < 0)
97     {
98       res = 0;
99     }
100     this.startRes = res;
101   }
102
103   /**
104    * Set last residue visible in the viewport
105    * 
106    * @param res
107    *          residue position
108    */
109   public void setEndRes(int res)
110   {
111     if (res >= al.getWidth())
112     {
113       res = al.getWidth() - 1;
114     }
115     else if (res < 1)
116     {
117       res = 1;
118     }
119     this.endRes = res;
120   }
121
122   /**
123    * Set the first sequence visible in the viewport
124    * 
125    * @param seq
126    *          sequence position
127    */
128   public void setStartSeq(int seq)
129   {
130     if (seq > al.getHeight() - 1)
131     {
132       seq = al.getHeight() - 1;
133     }
134     else if (seq < 0)
135     {
136       seq = 0;
137     }
138     this.startSeq = seq;
139   }
140
141   /**
142    * Set the last sequence visible in the viewport
143    * 
144    * @param seq
145    *          sequence position
146    */
147   public void setEndSeq(int seq)
148   {
149     if (seq >= al.getHeight())
150     {
151       seq = al.getHeight() - 1;
152     }
153     else if (seq < 1)
154     {
155       seq = 1;
156     }
157     this.endSeq = seq;
158   }
159
160   /**
161    * Get start residue of viewport
162    */
163   public int getStartRes()
164   {
165     return startRes;
166   }
167
168   /**
169    * Get end residue of viewport
170    */
171   public int getEndRes()
172   {
173     return endRes;
174   }
175
176   /**
177    * Get start sequence of viewport
178    */
179   public int getStartSeq()
180   {
181     return startSeq;
182   }
183
184   /**
185    * Get end sequence of viewport
186    */
187   public int getEndSeq()
188   {
189     return endSeq;
190   }
191 }