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) av.getAlignment().getWidth()
81 / (float) av.getAlignment().getHeight();
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)
125 else if (boxY > (sequencesHeight - boxHeight))
127 boxY = sequencesHeight - boxHeight + 1;
134 else if (boxX > (width - boxWidth))
136 if (av.hasHiddenColumns())
138 // Try smallest possible box
139 boxWidth = (int) (posProps.convertResiduesToPixels(posProps
140 .getEndRes() - posProps.getStartRes() + 1) * scalew);
142 // boxWidth = (int) ((av.getEndRes() - av.getStartRes() + 1)
143 // * av.getCharWidth() * scalew);
145 boxX = width - boxWidth;
148 scrollCol = posProps.convertPixelsToResidues(Math.round(boxX / scalew));
150 .convertPixelsToSequences(Math.round(boxY / scaleh));
152 // scrollCol = (int) (boxX / scalew / av.getCharWidth());
153 // scrollRow = (int) (boxY / scaleh / av.getCharHeight());
155 if (av.hasHiddenColumns())
157 if (!av.getColumnSelection().isVisible(scrollCol))
162 scrollCol = av.getColumnSelection().findColumnPosition(scrollCol);
165 if (av.hasHiddenRows())
167 scrollRow = av.getAlignment().getHiddenSequences()
168 .findIndexWithoutHiddenSeqs(scrollRow);
173 * Update the overview panel box when the associated alignment panel is
177 public void setBoxPosition()
181 int startRes = av.getStartRes();
182 int endRes = av.getEndRes();
184 if (av.hasHiddenColumns())
186 startRes = av.getColumnSelection().adjustForHiddenColumns(startRes);
187 endRes = av.getColumnSelection().adjustForHiddenColumns(endRes);
190 int startSeq = av.getStartSeq();
191 int endSeq = av.getEndSeq();
193 if (av.hasHiddenRows())
195 startSeq = av.getAlignment().getHiddenSequences()
196 .adjustForHiddenSeqs(startSeq);
198 endSeq = av.getAlignment().getHiddenSequences()
199 .adjustForHiddenSeqs(endSeq);
202 boxX = Math.round(posProps.convertResiduesToPixels(startRes) * scalew);
203 boxY = Math.round(posProps.convertSequencesToPixels(startSeq) * scaleh);
205 // boxX = (int) (startRes * av.getCharWidth() * scalew);
206 // boxY = (int) (startSeq * av.getCharHeight() * scaleh);
208 boxWidth = Math.round(posProps.convertResiduesToPixels(endRes
211 boxHeight = Math.round(posProps.convertSequencesToPixels(endSeq
215 // boxWidth = (int) ((endRes - startRes + 1) * av.getCharWidth() * scalew);
216 // boxHeight = (int) ((endSeq - startSeq) * av.getCharHeight() * scaleh);
220 * Update width and height scales in terms of the alignment width and height
222 public void updateScales()
224 int alwidth = av.getAlignment().getWidth();
225 int alheight = av.getAlignment().getHeight()
226 + av.getAlignment().getHiddenSequences().getSize();
228 int fullsizeWidth = alwidth * av.getCharWidth();
229 int fullsizeHeight = alheight * av.getCharHeight();
231 scalew = (float) width / fullsizeWidth;
232 scaleh = (float) sequencesHeight / fullsizeHeight;
236 * Draw the overview panel's viewport box on a graphics object
239 * the graphics object to draw on
241 public void drawBox(Graphics g)
243 g.drawRect(boxX, boxY, boxWidth, boxHeight);
244 g.drawRect(boxX + 1, boxY + 1, boxWidth - 2, boxHeight - 2);
247 // don't like this, scroll vals are separate from setting code
248 public int getScrollCol()
253 public int getScrollRow()
258 // TODO should be removed, when unit test has mock Graphics object available
259 // to check boxX/boxY
265 // TODO should be removed, when unit test has mock Graphics object available
266 // to check boxX/boxY
272 public int getBoxWidth()
277 public int getBoxHeight()
282 public void setBoxX(int x)
287 public void setBoxY(int y)
292 public void setWidth(int w)
297 public void setHeight(int h)
299 sequencesHeight = h - graphHeight;
302 public int getWidth()
307 public int getHeight()
309 return sequencesHeight + graphHeight;
312 public int getSequencesHeight()
314 return sequencesHeight;
317 public int getGraphHeight()