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.Graphics;
31 public abstract class OverviewDimensions
33 protected static final int MAX_WIDTH = 400;
35 protected static final int MIN_WIDTH = 120;
37 protected static final int MIN_SEQ_HEIGHT = 40;
39 protected static final int MAX_SEQ_HEIGHT = 300;
41 private static final int DEFAULT_GRAPH_HEIGHT = 20;
45 protected int sequencesHeight;
47 protected int graphHeight = DEFAULT_GRAPH_HEIGHT;
49 protected int boxX = -1;
51 protected int boxY = -1;
53 protected int boxWidth = -1;
55 protected int boxHeight = -1;
57 protected int alwidth;
59 protected int alheight;
61 protected float widthRatio;
63 protected float heightRatio;
66 * Create an OverviewDimensions object
69 * positional properties of the viewport
70 * @param showAnnotationPanel
71 * true if the annotation panel is to be shown, false otherwise
73 public OverviewDimensions(ViewportRanges ranges,
74 boolean showAnnotationPanel)
76 // scale the initial size of overviewpanel to shape of alignment
77 float initialScale = (float) ranges.getAbsoluteAlignmentWidth()
78 / (float) ranges.getAbsoluteAlignmentHeight();
80 if (!showAnnotationPanel)
85 if (ranges.getAbsoluteAlignmentWidth() > ranges
86 .getAbsoluteAlignmentHeight())
90 sequencesHeight = Math.round(MAX_WIDTH / initialScale);
91 if (sequencesHeight < MIN_SEQ_HEIGHT)
93 sequencesHeight = MIN_SEQ_HEIGHT;
99 width = Math.round(MAX_WIDTH * initialScale);
100 sequencesHeight = MAX_SEQ_HEIGHT;
102 if (width < MIN_WIDTH)
110 * Draw the overview panel's viewport box on a graphics object
113 * the graphics object to draw on
115 public void drawBox(Graphics g)
117 g.drawRect(boxX, boxY, boxWidth, boxHeight);
118 g.drawRect(boxX + 1, boxY + 1, boxWidth - 2, boxHeight - 2);
131 public int getBoxWidth()
136 public int getBoxHeight()
141 public int getWidth()
146 public int getHeight()
148 return sequencesHeight + graphHeight;
151 public int getSequencesHeight()
153 return sequencesHeight;
156 public int getGraphHeight()
161 public float getPixelsPerCol()
163 resetAlignmentDims();
164 return 1 / widthRatio;
167 public float getPixelsPerSeq()
169 resetAlignmentDims();
170 return 1 / heightRatio;
173 public void setWidth(int w)
176 widthRatio = (float) alwidth / width;
179 public void setHeight(int h)
181 sequencesHeight = h - graphHeight;
182 heightRatio = (float) alheight / sequencesHeight;
186 * Update the viewport location from a mouse click in the overview panel
189 * x location of mouse
191 * y location of mouse
193 * the alignment's hidden sequences
195 * the alignment's hidden columns
197 public abstract void updateViewportFromMouse(int mousex, int mousey,
198 HiddenSequences hiddenSeqs, HiddenColumns hiddenCols);
201 * Update the viewport location from a mouse drag within the overview's box
204 * x location of mouse
206 * y location of mouse
208 * the alignment's hidden sequences
210 * the alignment's hidden columns
212 public abstract void adjustViewportFromMouse(int mousex, int mousey,
213 HiddenSequences hiddenSeqs, HiddenColumns hiddenCols);
216 * Initialise dragging from the mouse - must be called on initial mouse click
217 * before using adjustViewportFromMouse in drag operations
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 setDragPoint(int x, int y,
229 HiddenSequences hiddenSeqs, HiddenColumns hiddenCols);
232 * Move the viewport so that the top left corner of the overview's box
233 * is at the mouse position (leftx, topy)
235 protected abstract void updateViewportFromTopLeft(int leftx, int topy,
236 HiddenSequences hiddenSeqs, HiddenColumns hiddenCols);
239 * Set the overview panel's box position to match the viewport
242 * the alignment's hidden sequences
244 * the alignment's hidden columns
246 public abstract void setBoxPosition(HiddenSequences hiddenSeqs,
247 HiddenColumns hiddenCols);
250 * Get the collection of columns used by this overview dimensions object
253 * the alignment's hidden columns
254 * @return a column collection
256 public abstract AlignmentColsCollectionI getColumns(AlignmentI al);
259 * Get the collection of rows used by this overview dimensions object
263 * @return a row collection
265 public abstract AlignmentRowsCollectionI getRows(AlignmentI al);
268 * Updates overview dimensions to account for current alignment dimensions
270 protected abstract void resetAlignmentDims();
273 * Given the box coordinates in residues and sequences, set the box dimensions in the overview window
275 protected void setBoxPosition(int startRes, int startSeq, int vpwidth,
278 resetAlignmentDims();
280 // boxX, boxY is the x,y location equivalent to startRes, startSeq
281 int xPos = Math.min(startRes, alwidth - vpwidth + 1);
282 boxX = Math.round(xPos / widthRatio);
283 boxY = Math.round(startSeq / heightRatio);
285 // boxWidth is the width in residues translated to pixels
286 boxWidth = Math.round(vpwidth / widthRatio);
288 // boxHeight is the height in sequences translated to pixels
289 boxHeight = Math.round(vpheight / heightRatio);
293 * Answers if a mouse position is in the overview's red box
299 * @return true if (x,y) is inside the box
301 public boolean isPositionInBox(int x, int y)
303 return (x > boxX && y > boxY && x < boxX + boxWidth
304 && y < boxY + boxHeight);
308 * Given the centre x position, calculate the box's left x position
310 protected abstract int getLeftXFromCentreX(int mousex,
311 HiddenColumns hidden);
314 * Given the centre y position, calculate the box's top y position
316 protected abstract int getTopYFromCentreY(int mousey,
317 HiddenSequences hidden);