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 public class OverviewDimensions
27 // Default width and height values
28 private static final int DEFAULT_GRAPH_HEIGHT = 20;
30 private static final int MAX_WIDTH = 400;
32 private static final int MIN_WIDTH = 120;
34 private static final int MIN_SEQ_HEIGHT = 40;
36 private static final int MAX_SEQ_HEIGHT = 300;
38 private AlignViewportI av;
40 private float scalew = 1f;
42 private float scaleh = 1f;
44 // width of the overview panel
47 // height of sequences part of the overview panel
48 private int sequencesHeight;
50 // height of the graphs part of the overview panel
51 private int graphHeight = DEFAULT_GRAPH_HEIGHT;
53 // dimensions of box outlining current extent of view in alignment panel
54 // location of left side of box
55 private int boxX = -1;
57 // location of bottom of box
58 private int boxY = -1;
61 private int boxWidth = -1;
64 private int boxHeight = -1;
66 private int scrollCol = -1;
68 private int scrollRow = -1;
70 public OverviewDimensions(AlignViewportI avi)
74 // scale the initial size of overviewpanel to shape of alignment
75 float initialScale = (float) av.getAlignment().getWidth()
76 / (float) av.getAlignment().getHeight();
78 // TODO: in applet this was getSequenceConsensusHash()
79 // check if it makes any functional difference
80 if (av.getAlignmentConservationAnnotation() == null)
85 if (av.getAlignment().getWidth() > av.getAlignment().getHeight())
89 sequencesHeight = (int) (MAX_WIDTH / initialScale);
90 if (sequencesHeight < MIN_SEQ_HEIGHT)
92 sequencesHeight = MIN_SEQ_HEIGHT;
98 width = (int) (MAX_WIDTH * initialScale);
99 sequencesHeight = MAX_SEQ_HEIGHT;
101 if (width < MIN_WIDTH)
109 * Check box dimensions and scroll positions and correct if necessary
111 public void checkValid()
118 if (boxY > (sequencesHeight - boxHeight))
120 boxY = sequencesHeight - boxHeight + 1;
128 if (boxX > (width - boxWidth))
130 if (av.hasHiddenColumns())
132 // Try smallest possible box
133 boxWidth = (int) ((av.getEndRes() - av.getStartRes() + 1)
134 * av.getCharWidth() * scalew);
136 boxX = width - boxWidth;
139 scrollCol = (int) (boxX / scalew / av.getCharWidth());
140 scrollRow = (int) (boxY / scaleh / av.getCharHeight());
142 if (av.hasHiddenColumns())
144 if (!av.getColumnSelection().isVisible(scrollCol))
149 scrollCol = av.getColumnSelection().findColumnPosition(scrollCol);
152 if (av.hasHiddenRows())
154 scrollRow = av.getAlignment().getHiddenSequences()
155 .findIndexWithoutHiddenSeqs(scrollRow);
160 * Update the overview panel box when the associated alignment panel is
164 public void setBoxPosition()
168 int startRes = av.getStartRes();
169 int endRes = av.getEndRes();
171 if (av.hasHiddenColumns())
173 startRes = av.getColumnSelection().adjustForHiddenColumns(startRes);
174 endRes = av.getColumnSelection().adjustForHiddenColumns(endRes);
177 int startSeq = av.getStartSeq();
178 int endSeq = av.getEndSeq();
180 if (av.hasHiddenRows())
182 startSeq = av.getAlignment().getHiddenSequences()
183 .adjustForHiddenSeqs(startSeq);
185 endSeq = av.getAlignment().getHiddenSequences()
186 .adjustForHiddenSeqs(endSeq);
190 boxX = (int) (startRes * av.getCharWidth() * scalew);
191 boxY = (int) (startSeq * av.getCharHeight() * scaleh);
193 if (av.hasHiddenColumns())
195 boxWidth = (int) ((endRes - startRes + 1) * av.getCharWidth() * scalew);
199 boxWidth = (int) ((endRes - startRes + 1) * av.getCharWidth() * scalew);
202 boxHeight = (int) ((endSeq - startSeq) * av.getCharHeight() * scaleh);
206 * Update width and height scales in terms of the alignment width and height
208 public void updateScales()
210 int alwidth = av.getAlignment().getWidth();
211 int alheight = av.getAlignment().getHeight()
212 + av.getAlignment().getHiddenSequences().getSize();
214 int fullsizeWidth = alwidth * av.getCharWidth();
215 int fullsizeHeight = alheight * av.getCharHeight();
217 scalew = (float) width / fullsizeWidth;
218 scaleh = (float) sequencesHeight / fullsizeHeight;
221 // don't like this, scroll vals are separate from setting code
222 public int getScrollCol()
227 public int getScrollRow()
242 public int getBoxWidth()
247 public int getBoxHeight()
252 public void setBoxX(int x)
257 public void setBoxY(int y)
262 public void setWidth(int w)
267 public void setHeight(int h)
269 sequencesHeight = h - graphHeight;
272 public int getWidth()
277 public int getHeight()
279 return sequencesHeight + graphHeight;
282 public int getSequencesHeight()
284 return sequencesHeight;
287 public int getGraphHeight()