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 ViewportPositionProps posProps;
44 private float scalew = 1f;
46 private float scaleh = 1f;
48 // width of the overview panel
51 // height of sequences part of the overview panel
52 private int sequencesHeight;
54 // height of the graphs part of the overview panel
55 private int graphHeight = DEFAULT_GRAPH_HEIGHT;
57 // dimensions of box outlining current extent of view in alignment panel
58 // location of left side of box
59 private int boxX = -1;
61 // location of bottom of box
62 private int boxY = -1;
65 private int boxWidth = -1;
68 private int boxHeight = -1;
70 private int scrollCol = -1;
72 private int scrollRow = -1;
74 public OverviewDimensions(AlignViewportI avi)
77 this.posProps = av.getPosProps();
79 // scale the initial size of overviewpanel to shape of alignment
80 float initialScale = (float) posProps.getAlignmentWidthInCols()
81 / (float) posProps.getAlignmentHeightInRows();
83 // TODO: in applet this was getSequenceConsensusHash()
84 // check if it makes any functional difference
85 if (av.getAlignmentConservationAnnotation() == null)
90 if (posProps.getAlignmentWidthInCols() > posProps
91 .getAlignmentHeightInRows())
95 sequencesHeight = (int) (MAX_WIDTH / initialScale);
96 if (sequencesHeight < MIN_SEQ_HEIGHT)
98 sequencesHeight = MIN_SEQ_HEIGHT;
104 width = (int) (MAX_WIDTH * initialScale);
105 sequencesHeight = MAX_SEQ_HEIGHT;
107 if (width < MIN_WIDTH)
115 * Check box dimensions and scroll positions and correct if necessary
117 public void setBoxPositionByMouse(int x, int y)
119 int alwidth = av.getAlignment().getWidth();
120 int alheight = av.getAlignment().getAbsoluteHeight();
128 else if (boxY > (sequencesHeight - boxHeight))
130 boxY = sequencesHeight - boxHeight;
137 else if (boxX > (width - boxWidth))
139 if (av.hasHiddenColumns())
141 // Try smallest possible box
142 boxWidth = Math.round((float) (posProps.getEndRes()
143 - posProps.getStartRes() + 1)
146 boxX = width - boxWidth;
149 scrollCol = Math.round((float) boxX * alwidth / width);
150 scrollRow = Math.round((float) boxY * alheight / sequencesHeight);
152 if (av.hasHiddenColumns())
154 // doesn't seem to do anything useful
155 /*if (!av.getColumnSelection().isVisible(scrollCol))
160 scrollCol = av.getColumnSelection().findColumnPosition(scrollCol);
163 if (av.hasHiddenRows())
165 scrollRow = av.getAlignment().getHiddenSequences()
166 .findIndexWithoutHiddenSeqs(scrollRow);
171 * Update the overview panel box when the associated alignment panel is
175 public void setBoxPosition()
177 int alwidth = av.getAlignment().getWidth();
178 int alheight = av.getAlignment().getAbsoluteHeight();
180 int startRes = av.getPosProps().getAbsoluteStartRes();
181 int endRes = av.getPosProps().getAbsoluteEndRes();
183 int startSeq = av.getPosProps().getAbsoluteStartSeq();
184 int endSeq = av.getPosProps().getAbsoluteEndSeq();
186 boxX = Math.round((float) startRes * width / alwidth);
187 boxY = Math.round((float) startSeq * sequencesHeight / alheight);
190 .round((float) (endRes - startRes + 1) * width / alwidth);
191 boxHeight = Math.round((float) (endSeq - startSeq) * sequencesHeight
196 * Draw the overview panel's viewport box on a graphics object
199 * the graphics object to draw on
201 public void drawBox(Graphics g)
203 g.drawRect(boxX, boxY, boxWidth, boxHeight);
204 g.drawRect(boxX + 1, boxY + 1, boxWidth - 2, boxHeight - 2);
207 // don't like this, scroll vals are separate from setting code
208 public int getScrollCol()
213 public int getScrollRow()
218 // TODO should be removed, when unit test has mock Graphics object available
219 // to check boxX/boxY
225 // TODO should be removed, when unit test has mock Graphics object available
226 // to check boxX/boxY
232 // TODO should be removed, when unit test has mock Graphics object available
233 public int getBoxWidth()
238 // TODO should be removed, when unit test has mock Graphics object available
239 public int getBoxHeight()
244 public void setBoxX(int x)
249 public void setBoxY(int y)
254 public void setWidth(int w)
259 public void setHeight(int h)
261 sequencesHeight = h - graphHeight;
264 public int getWidth()
269 public int getHeight()
271 return sequencesHeight + graphHeight;
274 public int getSequencesHeight()
276 return sequencesHeight;
279 public int getGraphHeight()