JAL-2388 New rendering code, extensions to support hiding hidden cols
[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. Intention also to support calculations for
29  * positioning, scrolling etc. such as finding the middle of the viewport,
30  * checking for scrolls off screen
31  */
32 public class ViewportRanges extends ViewportProperties
33 {
34   // start residue of viewport
35   private int startRes;
36
37   // end residue of viewport
38   private int endRes;
39
40   // start sequence of viewport
41   private int startSeq;
42
43   // end sequence of viewport
44   private int endSeq;
45
46   // alignment
47   private AlignmentI al;
48
49   /**
50    * Constructor
51    * 
52    * @param alignment
53    *          the viewport's alignment
54    */
55   public ViewportRanges(AlignmentI alignment)
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   }
64
65   /**
66    * Get alignment width in cols, including hidden cols
67    */
68   public int getAbsoluteAlignmentWidth()
69   {
70     return al.getWidth();
71   }
72
73   /**
74    * Get alignment height in rows, including hidden rows
75    */
76   public int getAbsoluteAlignmentHeight()
77   {
78     return al.getHeight() + al.getHiddenSequences().getSize();
79   }
80
81   /**
82    * Get alignment width in cols, excluding hidden cols
83    */
84   public int getVisibleAlignmentWidth()
85   {
86     // TODO need access to hidden columns here
87     return al.getWidth(); // - hidden columns
88   }
89
90   /**
91    * Get alignment height in rows, excluding hidden rows
92    */
93   public int getVisibleAlignmentHeight()
94   {
95     return al.getHeight();
96   }
97
98   /**
99    * Set first residue visible in the viewport
100    * 
101    * @param res
102    *          residue position
103    */
104   public void setStartRes(int res)
105   {
106     if (res > al.getWidth() - 1)
107     {
108       res = al.getWidth() - 1;
109     }
110     else if (res < 0)
111     {
112       res = 0;
113     }
114     this.startRes = res;
115   }
116
117   /**
118    * Set last residue visible in the viewport
119    * 
120    * @param res
121    *          residue position
122    */
123   public void setEndRes(int res)
124   {
125     if (res >= al.getWidth())
126     {
127       res = al.getWidth() - 1;
128     }
129     else if (res < 0)
130     {
131       res = 0;
132     }
133     this.endRes = res;
134   }
135
136   /**
137    * Set the first sequence visible in the viewport
138    * 
139    * @param seq
140    *          sequence position
141    */
142   public void setStartSeq(int seq)
143   {
144     if (seq > al.getHeight() - 1)
145     {
146       seq = al.getHeight() - 1;
147     }
148     else if (seq < 0)
149     {
150       seq = 0;
151     }
152     this.startSeq = seq;
153   }
154
155   /**
156    * Set the last sequence visible in the viewport
157    * 
158    * @param seq
159    *          sequence position
160    */
161   public void setEndSeq(int seq)
162   {
163     if (seq >= al.getHeight())
164     {
165       seq = al.getHeight() - 1;
166     }
167     else if (seq < 0)
168     {
169       seq = 0;
170     }
171     this.endSeq = seq;
172   }
173
174   /**
175    * Get start residue of viewport
176    */
177   public int getStartRes()
178   {
179     return startRes;
180   }
181
182   /**
183    * Get end residue of viewport
184    */
185   public int getEndRes()
186   {
187     return endRes;
188   }
189
190   /**
191    * Get start sequence of viewport
192    */
193   public int getStartSeq()
194   {
195     return startSeq;
196   }
197
198   /**
199    * Get end sequence of viewport
200    */
201   public int getEndSeq()
202   {
203     return endSeq;
204   }
205 }