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