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;
25 import java.awt.Graphics;
27 public class OverviewDimensions
29 // Default width and height values
30 private static final int DEFAULT_GRAPH_HEIGHT = 20;
32 private static final int MAX_WIDTH = 400;
34 private static final int MIN_WIDTH = 120;
36 private static final int MIN_SEQ_HEIGHT = 40;
38 private static final int MAX_SEQ_HEIGHT = 300;
40 private AlignViewportI av;
42 private float scalew = 1f;
44 private float scaleh = 1f;
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)
76 // scale the initial size of overviewpanel to shape of alignment
77 float initialScale = (float) av.getAlignment().getWidth()
78 / (float) av.getAlignment().getHeight();
80 // TODO: in applet this was getSequenceConsensusHash()
81 // check if it makes any functional difference
82 if (av.getAlignmentConservationAnnotation() == null)
87 if (av.getAlignment().getWidth() > av.getAlignment().getHeight())
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 setBoxPositionByMouse(int x, int y)
121 else if (boxY > (sequencesHeight - boxHeight))
123 boxY = sequencesHeight - boxHeight + 1;
130 else if (boxX > (width - boxWidth))
132 if (av.hasHiddenColumns())
134 // Try smallest possible box
135 boxWidth = (int) ((av.getEndRes() - av.getStartRes() + 1)
136 * av.getCharWidth() * scalew);
138 boxX = width - boxWidth;
141 scrollCol = (int) (boxX / scalew / av.getCharWidth());
142 scrollRow = (int) (boxY / scaleh / av.getCharHeight());
144 if (av.hasHiddenColumns())
146 if (!av.getColumnSelection().isVisible(scrollCol))
151 scrollCol = av.getColumnSelection().findColumnPosition(scrollCol);
154 if (av.hasHiddenRows())
156 scrollRow = av.getAlignment().getHiddenSequences()
157 .findIndexWithoutHiddenSeqs(scrollRow);
162 * Update the overview panel box when the associated alignment panel is
166 public void setBoxPosition()
170 int startRes = av.getStartRes();
171 int endRes = av.getEndRes();
173 if (av.hasHiddenColumns())
175 startRes = av.getColumnSelection().adjustForHiddenColumns(startRes);
176 endRes = av.getColumnSelection().adjustForHiddenColumns(endRes);
179 int startSeq = av.getStartSeq();
180 int endSeq = av.getEndSeq();
182 if (av.hasHiddenRows())
184 startSeq = av.getAlignment().getHiddenSequences()
185 .adjustForHiddenSeqs(startSeq);
187 endSeq = av.getAlignment().getHiddenSequences()
188 .adjustForHiddenSeqs(endSeq);
191 boxX = (int) (startRes * av.getCharWidth() * scalew);
192 boxY = (int) (startSeq * av.getCharHeight() * scaleh);
194 boxWidth = (int) ((endRes - startRes + 1) * av.getCharWidth() * scalew);
195 boxHeight = (int) ((endSeq - startSeq) * av.getCharHeight() * scaleh);
199 * Update width and height scales in terms of the alignment width and height
201 public void updateScales()
203 int alwidth = av.getAlignment().getWidth();
204 int alheight = av.getAlignment().getHeight()
205 + av.getAlignment().getHiddenSequences().getSize();
207 int fullsizeWidth = alwidth * av.getCharWidth();
208 int fullsizeHeight = alheight * av.getCharHeight();
210 scalew = (float) width / fullsizeWidth;
211 scaleh = (float) sequencesHeight / fullsizeHeight;
215 * Draw the overview panel's viewport box on a graphics object
218 * the graphics object to draw on
220 public void drawBox(Graphics g)
222 g.drawRect(boxX, boxY, boxWidth, boxHeight);
223 g.drawRect(boxX + 1, boxY + 1, boxWidth - 2, boxHeight - 2);
226 // don't like this, scroll vals are separate from setting code
227 public int getScrollCol()
232 public int getScrollRow()
237 // TODO should be removed, when unit test has mock Graphics object available
238 // to check boxX/boxY
244 // TODO should be removed, when unit test has mock Graphics object available
245 // to check boxX/boxY
251 public int getBoxWidth()
256 public int getBoxHeight()
261 public void setBoxX(int x)
266 public void setBoxY(int y)
271 public void setWidth(int w)
276 public void setHeight(int h)
278 sequencesHeight = h - graphHeight;
281 public int getWidth()
286 public int getHeight()
288 return sequencesHeight + graphHeight;
291 public int getSequencesHeight()
293 return sequencesHeight;
296 public int getGraphHeight()