JAL-2491 first addition of new event
[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    * Set first residue visible in the viewport, and retain the current width.
83    * 
84    * @param res
85    *          residue position
86    */
87   public void setStartRes(int res)
88   {
89     if (res > al.getWidth() - 1)
90     {
91       res = al.getWidth() - 1;
92     }
93     else if (res < 0)
94     {
95       res = 0;
96     }
97
98     int oldres = this.startRes;
99     this.startRes = res;
100     // changeSupport.firePropertyChange("startres", oldres, res);
101   }
102
103   public void setStartEndRes(int startres, int endres)
104   {
105     int oldres = this.startRes;
106     setStartRes(startres);
107     setEndRes(endres);
108     changeSupport.firePropertyChange("startres", oldres, startres);
109   }
110
111   /**
112    * Set last residue visible in the viewport
113    * 
114    * @param res
115    *          residue position
116    */
117   public void setEndRes(int res)
118   {
119     if (res >= al.getWidth())
120     {
121       res = al.getWidth() - 1;
122     }
123     else if (res < 0)
124     {
125       res = 0;
126     }
127     int oldres = this.endRes;
128     this.endRes = res;
129
130     // changeSupport.firePropertyChange("endres", oldres, res);
131   }
132
133   /**
134    * Set the first sequence visible in the viewport
135    * 
136    * @param seq
137    *          sequence position
138    */
139   public void setStartSeq(int seq)
140   {
141     if (seq > al.getHeight() - 1)
142     {
143       seq = al.getHeight() - 1;
144     }
145     else if (seq < 0)
146     {
147       seq = 0;
148     }
149
150     int oldseq = this.startSeq;
151     this.startSeq = seq;
152     // changeSupport.firePropertyChange("startseq", oldseq, seq);
153   }
154
155   public void setStartEndSeq(int startseq, int endseq)
156   {
157     int oldseq = this.startSeq;
158     setStartSeq(startseq);
159     setEndSeq(endseq);
160     changeSupport.firePropertyChange("startseq", oldseq, startseq);
161   }
162
163   /**
164    * Set the last sequence visible in the viewport
165    * 
166    * @param seq
167    *          sequence position
168    */
169   public void setEndSeq(int seq)
170   {
171     if (seq >= al.getHeight())
172     {
173       seq = al.getHeight() - 1;
174     }
175     else if (seq < 0)
176     {
177       seq = 0;
178     }
179     int oldseq = this.endSeq;
180     this.endSeq = seq;
181
182     // changeSupport.firePropertyChange("endseq", oldseq, seq);
183   }
184
185   /**
186    * Get start residue of viewport
187    */
188   public int getStartRes()
189   {
190     return startRes;
191   }
192
193   /**
194    * Get end residue of viewport
195    */
196   public int getEndRes()
197   {
198     return endRes;
199   }
200
201   /**
202    * Get start sequence of viewport
203    */
204   public int getStartSeq()
205   {
206     return startSeq;
207   }
208
209   /**
210    * Get end sequence of viewport
211    */
212   public int getEndSeq()
213   {
214     return endSeq;
215   }
216 }