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.AlignmentColsCollectionI;
24 import jalview.api.AlignmentRowsCollectionI;
25 import jalview.datamodel.AlignmentI;
26 import jalview.datamodel.HiddenColumns;
27 import jalview.datamodel.HiddenSequences;
29 import java.awt.Dimension;
30 import java.awt.Graphics;
31 import java.awt.Rectangle;
33 public abstract class OverviewDimensions
35 protected static final int MAX_WIDTH = 400;
37 protected static final int MIN_WIDTH = 120;
39 protected static final int MIN_SEQ_HEIGHT = 40;
41 protected static final int MAX_SEQ_HEIGHT = 300;
43 private static final int DEFAULT_GRAPH_HEIGHT = 20;
47 protected int sequencesHeight;
49 protected int graphHeight = DEFAULT_GRAPH_HEIGHT;
51 protected int boxX = -1;
53 protected int boxY = -1;
55 protected int boxWidth = -1;
57 protected int boxHeight = -1;
59 protected int alwidth;
61 protected int alheight;
63 protected float widthRatio;
65 protected float heightRatio;
67 private Rectangle vpbox = new Rectangle();
70 * Create an OverviewDimensions object
73 * positional properties of the viewport
74 * @param showAnnotationPanel
75 * true if the annotation panel is to be shown, false otherwise
77 public OverviewDimensions(ViewportRanges ranges,
78 boolean showAnnotationPanel, Dimension dim)
80 if (!showAnnotationPanel)
85 // scale the initial size of overviewpanel to shape of alignment
86 float initialScale = (float) ranges.getAbsoluteAlignmentWidth()
87 / (float) ranges.getAbsoluteAlignmentHeight();
92 sequencesHeight = dim.height;
95 if (ranges.getAbsoluteAlignmentWidth() > ranges
96 .getAbsoluteAlignmentHeight())
100 sequencesHeight = Math.round(MAX_WIDTH / initialScale);
101 if (sequencesHeight < MIN_SEQ_HEIGHT)
103 sequencesHeight = MIN_SEQ_HEIGHT;
109 width = Math.round(MAX_WIDTH * initialScale);
110 sequencesHeight = MAX_SEQ_HEIGHT;
112 if (width < MIN_WIDTH)
120 * Draw the overview panel's viewport box on a graphics object
123 * the graphics object to draw on
125 public void drawBox(Graphics g)
127 // System.out.println("OD drawBox " + boxX + " " + boxY + " " + boxWidth
128 // + " " + boxHeight);
130 g.drawRect(boxX, boxY, boxWidth, boxHeight);
131 g.drawRect(boxX + 1, boxY + 1, boxWidth - 2, boxHeight - 2);
144 public int getBoxWidth()
149 public int getBoxHeight()
155 * Returns the width of the Overview in pixels
159 public int getWidth()
165 * Returns the height of the Overview in pixels
169 public int getHeight()
171 return sequencesHeight + graphHeight;
175 * Returns the height of the sequence alignment in the Overview in pixels
179 public int getSequencesHeight()
181 return sequencesHeight;
184 public int getGraphHeight()
189 public float getPixelsPerCol()
191 resetAlignmentDims();
192 return 1 / widthRatio;
195 public float getPixelsPerSeq()
197 resetAlignmentDims();
198 return 1 / heightRatio;
201 public void setWidth(int w)
204 widthRatio = (float) alwidth / width;
207 public void setHeight(int h)
209 // BH 2019 problem was that component.resize() can come
210 // after setBoxPosition().
211 // Solution was to move setting of box dimensions to paint
212 sequencesHeight = h - graphHeight;
213 heightRatio = (float) alheight / sequencesHeight;
217 * Update the viewport location from a mouse click in the overview panel
220 * x location of mouse
222 * y location of mouse
224 * the alignment's hidden sequences
226 * the alignment's hidden columns
228 public abstract void updateViewportFromMouse(int mousex, int mousey,
229 HiddenSequences hiddenSeqs, HiddenColumns hiddenCols);
232 * Update the viewport location from a mouse drag within the overview's box
235 * x location of mouse
237 * y location of mouse
239 * the alignment's hidden sequences
241 * the alignment's hidden columns
243 public abstract void adjustViewportFromMouse(int mousex, int mousey,
244 HiddenSequences hiddenSeqs, HiddenColumns hiddenCols);
247 * Initialise dragging from the mouse - must be called on initial mouse click
248 * before using adjustViewportFromMouse in drag operations
251 * x location of mouse
253 * y location of mouse
255 * the alignment's hidden sequences
257 * the alignment's hidden columns
259 public abstract void setDragPoint(int x, int y,
260 HiddenSequences hiddenSeqs, HiddenColumns hiddenCols);
263 * Move the viewport so that the top left corner of the overview's box
264 * is at the mouse position (leftx, topy)
266 protected abstract void updateViewportFromTopLeft(int leftx, int topy,
267 HiddenSequences hiddenSeqs, HiddenColumns hiddenCols);
270 * Set the overview panel's box position to match the viewport
273 * the alignment's hidden sequences
275 * the alignment's hidden columns
277 public abstract void setBoxPosition(HiddenSequences hiddenSeqs,
278 HiddenColumns hiddenCols);
281 * Get the collection of columns used by this overview dimensions object
284 * the alignment's hidden columns
285 * @return a column collection
287 public abstract AlignmentColsCollectionI getColumns(AlignmentI al);
290 * Get the collection of rows used by this overview dimensions object
294 * @return a row collection
296 public abstract AlignmentRowsCollectionI getRows(AlignmentI al);
299 * Updates overview dimensions to account for current alignment dimensions
301 protected abstract void resetAlignmentDims();
304 * Given the box coordinates in residues and sequences, set the box dimensions in the overview window
306 protected void setBoxPosition(int startRes, int startSeq, int vpwidth,
309 resetAlignmentDims();
310 vpbox = new Rectangle(startRes, startSeq, vpwidth, vpheight);
314 public void updateBox()
316 // boxX, boxY is the x,y location equivalent to startRes, startSeq
317 int xPos = Math.min(vpbox.x, alwidth - vpbox.width + 1);
318 boxX = Math.round(xPos / widthRatio);
319 boxY = Math.round(vpbox.y / heightRatio);
321 // boxWidth is the width in residues translated to pixels
322 boxWidth = Math.max(1, Math.round(vpbox.width / widthRatio));
324 // boxHeight is the height in sequences translated to pixels
325 boxHeight = Math.max(1, Math.round(vpbox.height / heightRatio));
329 * Answers if a mouse position is in the overview's red box
335 * @return true if (x,y) is inside the box
337 public boolean isPositionInBox(int x, int y)
339 return (x > boxX && y > boxY && x < boxX + boxWidth
340 && y < boxY + boxHeight);
344 * Given the centre x position, calculate the box's left x position
346 protected abstract int getLeftXFromCentreX(int mousex,
347 HiddenColumns hidden);
350 * Given the centre y position, calculate the box's top y position
352 protected abstract int getTopYFromCentreY(int mousey,
353 HiddenSequences hidden);