2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
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.
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.
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.
21 package jalview.viewmodel;
23 import jalview.api.AlignViewportI;
24 import jalview.datamodel.ColumnSelection;
25 import jalview.datamodel.HiddenSequences;
27 import java.awt.Graphics;
29 public class OverviewDimensions
31 // Default width and height values
32 private static final int DEFAULT_GRAPH_HEIGHT = 20;
34 private static final int MAX_WIDTH = 400;
36 private static final int MIN_WIDTH = 120;
38 private static final int MIN_SEQ_HEIGHT = 40;
40 private static final int MAX_SEQ_HEIGHT = 300;
42 private AlignViewportI av;
44 private ViewportPositionProps posProps;
46 // width of the overview panel
49 // height of sequences part of the overview panel
50 private int sequencesHeight;
52 // height of the graphs part of the overview panel
53 private int graphHeight = DEFAULT_GRAPH_HEIGHT;
55 // dimensions of box outlining current extent of view in alignment panel
56 // location of left side of box
57 private int boxX = -1;
59 // location of bottom of box
60 private int boxY = -1;
63 private int boxWidth = -1;
66 private int boxHeight = -1;
68 private int scrollCol = -1;
70 private int scrollRow = -1;
72 public OverviewDimensions(AlignViewportI avi, boolean showAnnotationPanel)
75 this.posProps = av.getPosProps();
77 // scale the initial size of overviewpanel to shape of alignment
78 float initialScale = (float) posProps.getAlignmentWidthInCols()
79 / (float) posProps.getAlignmentHeightInRows();
81 if (!showAnnotationPanel)
86 if (posProps.getAlignmentWidthInCols() > posProps
87 .getAlignmentHeightInRows())
91 sequencesHeight = (int) (MAX_WIDTH / initialScale);
92 if (sequencesHeight < MIN_SEQ_HEIGHT)
94 sequencesHeight = MIN_SEQ_HEIGHT;
100 width = (int) (MAX_WIDTH * initialScale);
101 sequencesHeight = MAX_SEQ_HEIGHT;
103 if (width < MIN_WIDTH)
111 * Check box dimensions and scroll positions and correct if necessary
113 public void updateViewportFromMouse(int x, int y)
115 int alwidth = av.getAlignment().getWidth();
116 int alheight = av.getAlignment().getAbsoluteHeight();
118 HiddenSequences hiddenSeqs = av.getAlignment().getHiddenSequences();
119 ColumnSelection hiddenCols = av.getColumnSelection();
125 else if (x >= alwidth)
134 else if (y >= alheight)
140 // Convert x value to residue position
143 // need to determine where scrollCol should be, given x
144 // to do this also need to know width of viewport, and some hidden column
147 // convert x to residues - this is an absolute position
148 int xAsRes = Math.round((float) x * alwidth / width);
150 // get viewport width in residues
151 int vpwidth = av.getPosProps().getEndRes()
152 - av.getPosProps().getStartRes() + 1;
154 // get where x should be when accounting for hidden cols
155 // if x is in a hidden col region, shift to left - but we still need
157 // so convert back after getting visible region position
158 xAsRes = hiddenCols.adjustForHiddenColumns(hiddenCols
159 .findColumnPosition(xAsRes));
161 // get where end res should be by adding the viewport width on
162 int endRes = xAsRes + vpwidth;
164 // check in case we went off the edge of the alignment
165 if (endRes > alwidth)
167 // went past the end of the alignment, adjust backwards
169 // recalc xAsRes backwards from endRes
170 xAsRes = endRes - vpwidth;
174 // Convert y value to sequence position
177 // convert y to residues
178 int yAsSeq = Math.round((float) y * alheight / sequencesHeight);
180 // get viewport height in sequences
181 int vpheight = av.getPosProps().getEndSeq()
182 - av.getPosProps().getStartSeq();
184 // get where y should be when accounting for hidden rows
185 // if y is in a hidden row region, shift up - but we still need absolute
187 // so convert back after getting visible region position
188 yAsSeq = hiddenSeqs.adjustForHiddenSeqs(hiddenSeqs
189 .findIndexWithoutHiddenSeqs(yAsSeq));
191 // get where end seq should be by adding the viewport height on
192 int endSeq = yAsSeq + vpheight;
194 // check in case we went off the edge of the alignment
195 if (endSeq > alheight)
197 // went past the end of the alignment, adjust backwards
199 // recalc yAsSeq backwards from endSeq
200 yAsSeq = endSeq - vpheight;
203 // convert absolute positions back to visible alignment positions for
204 // viewport scrolling
205 scrollCol = hiddenCols.findColumnPosition(xAsRes);
206 scrollRow = hiddenSeqs.findIndexWithoutHiddenSeqs(yAsSeq);
210 * Update the overview panel box when the associated alignment panel is
214 public void setBoxPosition()
216 int alwidth = av.getAlignment().getWidth();
217 int alheight = av.getAlignment().getAbsoluteHeight();
219 int startRes = av.getPosProps().getAbsoluteStartRes();
220 int endRes = av.getPosProps().getAbsoluteEndRes();
222 int startSeq = av.getPosProps().getAbsoluteStartSeq();
223 int endSeq = av.getPosProps().getAbsoluteEndSeq();
225 boxX = Math.round((float) startRes * width / alwidth);
226 boxY = Math.round((float) startSeq * sequencesHeight / alheight);
229 .round((float) (endRes - startRes + 1) * width / alwidth);
230 boxHeight = Math.round((float) (endSeq - startSeq) * sequencesHeight
235 * Draw the overview panel's viewport box on a graphics object
238 * the graphics object to draw on
240 public void drawBox(Graphics g)
242 g.drawRect(boxX, boxY, boxWidth, boxHeight);
243 g.drawRect(boxX + 1, boxY + 1, boxWidth - 2, boxHeight - 2);
246 // don't like this, scroll vals are separate from setting code
247 public int getScrollCol()
252 public int getScrollRow()
257 // TODO should be removed, when unit test has mock Graphics object available
258 // to check boxX/boxY
264 // TODO should be removed, when unit test has mock Graphics object available
265 // to check boxX/boxY
271 // TODO should be removed, when unit test has mock Graphics object available
272 public int getBoxWidth()
277 // TODO should be removed, when unit test has mock Graphics object available
278 public int getBoxHeight()
283 public void setBoxX(int x)
288 public void setBoxY(int y)
293 public void setWidth(int w)
298 public void setHeight(int h)
300 sequencesHeight = h - graphHeight;
303 public int getWidth()
308 public int getHeight()
310 return sequencesHeight + graphHeight;
313 public int getSequencesHeight()
315 return sequencesHeight;
318 public int getGraphHeight()