JAL-2388 Corrected overview panel behaviour, updated tests
[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.api.AlignViewportI;
24 import jalview.datamodel.AlignmentI;
25
26 /**
27  * Supplies and updates viewport properties relating to position such as: start
28  * and end residues and sequences, hidden column/row adjustments, etc
29  */
30 public class ViewportPositionProps 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   // viewport
48   private AlignViewportI av; // this is a bad dependency, viewmodel should not
49                              // depend on api
50
51   /**
52    * Constructor
53    * @param alignment TODO
54    */
55   public ViewportPositionProps(AlignmentI alignment, AlignViewportI viewport)
56   {
57     // initial values of viewport settings
58     this.startRes = 0;
59     this.endRes = alignment.getWidth() - 1;
60     this.startSeq = 0;
61     this.endSeq = alignment.getHeight() - 1;
62     this.al = alignment;
63     this.av = viewport;
64   }
65
66   // ways to update values
67
68   // ways to notify of changes
69
70   // ways to supply positional information
71
72   /**
73    * Get alignment width
74    */
75   public int getAlignmentWidthInCols()
76   {
77     return al.getWidth();
78   }
79
80   /**
81    * Get alignment height
82    */
83   public int getAlignmentHeightInRows()
84   {
85     return al.getHeight();
86   }
87
88   public void setStartRes(int res)
89   {
90     if (res > al.getWidth() - 1)
91     {
92       res = al.getWidth() - 1;
93     }
94     else if (res < 0)
95     {
96       res = 0;
97     }
98     this.startRes = res;
99   }
100
101   public void setEndRes(int res)
102   {
103     if (res > al.getWidth())
104     {
105       res = al.getWidth();
106     }
107     else if (res < 1)
108     {
109       res = 1;
110     }
111     this.endRes = res;
112   }
113
114   public void setStartSeq(int seq)
115   {
116     if (seq > al.getHeight() - 1)
117     {
118       seq = al.getHeight() - 1;
119     }
120     else if (seq < 0)
121     {
122       seq = 0;
123     }
124     this.startSeq = seq;
125   }
126
127   public void setEndSeq(int seq)
128   {
129     if (seq > al.getHeight())
130     {
131       seq = al.getHeight();
132     }
133     else if (seq < 1)
134     {
135       seq = 1;
136     }
137     this.endSeq = seq;
138   }
139
140   /**
141    * Get start residue of viewport
142    */
143   public int getStartRes()
144   {
145     return startRes;
146   }
147
148   /**
149    * Get end residue of viewport
150    */
151   public int getEndRes()
152   {
153     return endRes;
154   }
155
156   /**
157    * Get start sequence of viewport
158    */
159   public int getStartSeq()
160   {
161     return startSeq;
162   }
163
164   /**
165    * Get end sequence of viewport
166    */
167   public int getEndSeq()
168   {
169     return endSeq;
170   }
171
172   /**
173    * Get absolute start residue of viewport
174    */
175   public int getAbsoluteStartRes()
176   {
177     int start = startRes;
178
179     if (av.hasHiddenColumns())
180     {
181       start = av.getColumnSelection().adjustForHiddenColumns(start);
182     }
183     return start;
184   }
185
186   /**
187    * Get absolute start residue of viewport
188    */
189   public int getAbsoluteEndRes()
190   {
191     int end = endRes;
192
193     if (av.hasHiddenColumns())
194     {
195       end = av.getColumnSelection().adjustForHiddenColumns(end);
196     }
197     return end;
198   }
199
200   /**
201    * Get absolute start sequence of viewport
202    */
203   public int getAbsoluteStartSeq()
204   {
205     int start = startSeq;
206
207     if (av.hasHiddenRows())
208     {
209       start = av.getAlignment().getHiddenSequences()
210               .adjustForHiddenSeqs(start);
211     }
212     return start;
213   }
214
215   /**
216    * Get absolute end sequence of viewport
217    */
218   public int getAbsoluteEndSeq()
219   {
220     int end = endSeq;
221
222     if (av.hasHiddenRows())
223     {
224       end = av.getAlignment().getHiddenSequences().adjustForHiddenSeqs(end);
225     }
226     return end;
227   }
228
229 }