JAL-2388 Tidies
[jalview.git] / src / jalview / viewmodel / OverviewDimensions.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.AlignmentColsCollectionI;
24 import jalview.api.AlignmentRowsCollectionI;
25 import jalview.datamodel.AlignmentI;
26 import jalview.datamodel.ColumnSelection;
27 import jalview.datamodel.HiddenSequences;
28
29 import java.awt.Graphics;
30
31 public abstract class OverviewDimensions
32 {
33   protected static final int MAX_WIDTH = 400;
34   protected static final int MIN_WIDTH = 120;
35   protected static final int MIN_SEQ_HEIGHT = 40;
36   protected static final int MAX_SEQ_HEIGHT = 300;
37
38   private static final int DEFAULT_GRAPH_HEIGHT = 20;
39
40   protected int width;
41   protected int sequencesHeight;
42   protected int graphHeight = DEFAULT_GRAPH_HEIGHT;
43   protected int boxX = -1;
44   protected int boxY = -1;
45   protected int boxWidth = -1;
46   protected int boxHeight = -1;
47   protected int scrollCol = -1;
48   protected int scrollRow = -1;
49   protected int alwidth;
50   protected int alheight;
51
52   public OverviewDimensions(ViewportRanges ranges,
53           boolean showAnnotationPanel)
54   {
55     // scale the initial size of overviewpanel to shape of alignment
56     float initialScale = (float) ranges.getAbsoluteAlignmentWidth()
57             / (float) ranges.getAbsoluteAlignmentHeight();
58
59     if (!showAnnotationPanel)
60     {
61       graphHeight = 0;
62     }
63
64     if (ranges.getAbsoluteAlignmentWidth() > ranges
65             .getAbsoluteAlignmentHeight())
66     {
67       // wider
68       width = MAX_WIDTH;
69       sequencesHeight = Math.round(MAX_WIDTH / initialScale);
70       if (sequencesHeight < MIN_SEQ_HEIGHT)
71       {
72         sequencesHeight = MIN_SEQ_HEIGHT;
73       }
74     }
75     else
76     {
77       // taller
78       width = Math.round(MAX_WIDTH * initialScale);
79       sequencesHeight = MAX_SEQ_HEIGHT;
80
81       if (width < MIN_WIDTH)
82       {
83         width = MIN_WIDTH;
84       }
85     }
86   }
87
88   /**
89    * Draw the overview panel's viewport box on a graphics object
90    * 
91    * @param g
92    *          the graphics object to draw on
93    */
94   public void drawBox(Graphics g)
95   {
96     g.drawRect(boxX, boxY, boxWidth, boxHeight);
97     g.drawRect(boxX + 1, boxY + 1, boxWidth - 2, boxHeight - 2);
98   }
99
100   public int getScrollCol()
101   {
102     return scrollCol;
103   }
104
105   public int getScrollRow()
106   {
107     return scrollRow;
108   }
109
110   public int getBoxX()
111   {
112     return boxX;
113   }
114
115   public int getBoxY()
116   {
117     return boxY;
118   }
119
120   public int getBoxWidth()
121   {
122     return boxWidth;
123   }
124
125   public int getBoxHeight()
126   {
127     return boxHeight;
128   }
129
130   public int getWidth()
131   {
132     return width;
133   }
134
135   public int getHeight()
136   {
137     return sequencesHeight + graphHeight;
138   }
139
140   public int getSequencesHeight()
141   {
142     return sequencesHeight;
143   }
144
145   public int getGraphHeight()
146   {
147     return graphHeight;
148   }
149
150   public float getPixelsPerCol()
151   {
152     return (float) width / alwidth;
153   }
154
155   public float getPixelsPerSeq()
156   {
157     return (float) sequencesHeight / alheight;
158   }
159
160   public void setWidth(int w)
161   {
162     width = w;
163   }
164
165   public void setHeight(int h)
166   {
167     sequencesHeight = h - graphHeight;
168   }
169
170   /**
171    * Update the viewport location from a mouse click in the overview panel
172    * 
173    * @param mousex
174    *          x location of mouse
175    * @param mousey
176    *          y location of mouse
177    * @param hiddenSeqs
178    *          the alignment's hidden sequences
179    * @param hiddenCols
180    *          the alignment's hidden columns
181    * @param ranges
182    *          the alignment's width and height ranges
183    */
184   public abstract void updateViewportFromMouse(int mousex, int mousey,
185           HiddenSequences hiddenSeqs, ColumnSelection hiddenCols,
186           ViewportRanges ranges);
187
188   /**
189    * Set the overview panel's box position to match the viewport
190    * 
191    * @param hiddenSeqs
192    *          the alignment's hidden sequences
193    * @param hiddenCols
194    *          the alignment's hidden columns
195    * @param ranges
196    *          the alignment's width and height ranges
197    */
198   public abstract void setBoxPosition(HiddenSequences hiddenSeqs,
199           ColumnSelection hiddenCols, ViewportRanges ranges);
200
201   /**
202    * Get the collection of columns used by this overview dimensions object
203    * 
204    * @param ranges
205    *          the alignment's width and height ranges
206    * @param hiddenCols
207    *          the alignment's hidden columns
208    * @return a column collection
209    */
210   public abstract AlignmentColsCollectionI getColumns(
211           ViewportRanges ranges, ColumnSelection hiddenCols);
212
213   /**
214    * Get the collection of rows used by this overview dimensions object
215    * 
216    * @param ranges
217    *          the alignment's width and height ranges
218    * @param al
219    *          the alignment
220    * @return a row collection
221    */
222   public abstract AlignmentRowsCollectionI getRows(
223           ViewportRanges ranges, AlignmentI al);
224 }