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;
32 public abstract class OverviewDimensions
34 protected static final int MAX_WIDTH = 400;
36 protected static final int MIN_WIDTH = 120;
38 protected static final int MIN_SEQ_HEIGHT = 40;
40 protected static final int MAX_SEQ_HEIGHT = 300;
42 private static final int DEFAULT_GRAPH_HEIGHT = 20;
46 protected int sequencesHeight;
48 protected int graphHeight = DEFAULT_GRAPH_HEIGHT;
50 protected int boxX = -1;
52 protected int boxY = -1;
54 protected int boxWidth = -1;
56 protected int boxHeight = -1;
58 protected int alwidth;
60 protected int alheight;
62 protected float widthRatio;
64 protected float heightRatio;
67 * Create an OverviewDimensions object
70 * positional properties of the viewport
71 * @param showAnnotationPanel
72 * true if the annotation panel is to be shown, false otherwise
74 public OverviewDimensions(ViewportRanges ranges,
75 boolean showAnnotationPanel, Dimension dim)
77 if (!showAnnotationPanel)
82 // scale the initial size of overviewpanel to shape of alignment
83 float initialScale = (float) ranges.getAbsoluteAlignmentWidth()
84 / (float) ranges.getAbsoluteAlignmentHeight();
89 sequencesHeight = dim.height;
93 if (ranges.getAbsoluteAlignmentWidth() > ranges
94 .getAbsoluteAlignmentHeight())
98 sequencesHeight = Math.round(MAX_WIDTH / initialScale);
99 if (sequencesHeight < MIN_SEQ_HEIGHT)
101 sequencesHeight = MIN_SEQ_HEIGHT;
107 width = Math.round(MAX_WIDTH * initialScale);
108 sequencesHeight = MAX_SEQ_HEIGHT;
110 if (width < MIN_WIDTH)
118 * Draw the overview panel's viewport box on a graphics object
121 * the graphics object to draw on
123 public void drawBox(Graphics g)
125 g.drawRect(boxX, boxY, boxWidth, boxHeight);
126 g.drawRect(boxX + 1, boxY + 1, boxWidth - 2, boxHeight - 2);
139 public int getBoxWidth()
144 public int getBoxHeight()
149 public int getWidth()
154 public int getHeight()
156 return sequencesHeight + graphHeight;
159 public int getSequencesHeight()
161 return sequencesHeight;
164 public int getGraphHeight()
169 public float getPixelsPerCol()
171 resetAlignmentDims();
172 return 1 / widthRatio;
175 public float getPixelsPerSeq()
177 resetAlignmentDims();
178 return 1 / heightRatio;
181 public void setWidth(int w)
184 widthRatio = (float) alwidth / width;
187 public void setHeight(int h)
189 sequencesHeight = h - graphHeight;
190 heightRatio = (float) alheight / sequencesHeight;
194 * Update the viewport location from a mouse click in the overview panel
197 * x location of mouse
199 * y location of mouse
201 * the alignment's hidden sequences
203 * the alignment's hidden columns
205 public abstract void updateViewportFromMouse(int mousex, int mousey,
206 HiddenSequences hiddenSeqs, HiddenColumns hiddenCols);
209 * Update the viewport location from a mouse drag within the overview's box
212 * x location of mouse
214 * y location of mouse
216 * the alignment's hidden sequences
218 * the alignment's hidden columns
220 public abstract void adjustViewportFromMouse(int mousex, int mousey,
221 HiddenSequences hiddenSeqs, HiddenColumns hiddenCols);
224 * Initialise dragging from the mouse - must be called on initial mouse click
225 * before using adjustViewportFromMouse in drag operations
228 * x location of mouse
230 * y location of mouse
232 * the alignment's hidden sequences
234 * the alignment's hidden columns
236 public abstract void setDragPoint(int x, int y,
237 HiddenSequences hiddenSeqs, HiddenColumns hiddenCols);
240 * Move the viewport so that the top left corner of the overview's box
241 * is at the mouse position (leftx, topy)
243 protected abstract void updateViewportFromTopLeft(int leftx, int topy,
244 HiddenSequences hiddenSeqs, HiddenColumns hiddenCols);
247 * Set the overview panel's box position to match the viewport
250 * the alignment's hidden sequences
252 * the alignment's hidden columns
254 public abstract void setBoxPosition(HiddenSequences hiddenSeqs,
255 HiddenColumns hiddenCols);
258 * Get the collection of columns used by this overview dimensions object
261 * the alignment's hidden columns
262 * @return a column collection
264 public abstract AlignmentColsCollectionI getColumns(AlignmentI al);
267 * Get the collection of rows used by this overview dimensions object
271 * @return a row collection
273 public abstract AlignmentRowsCollectionI getRows(AlignmentI al);
276 * Updates overview dimensions to account for current alignment dimensions
278 protected abstract void resetAlignmentDims();
281 * Given the box coordinates in residues and sequences, set the box dimensions in the overview window
283 protected void setBoxPosition(int startRes, int startSeq, int vpwidth,
286 resetAlignmentDims();
288 // boxX, boxY is the x,y location equivalent to startRes, startSeq
289 int xPos = Math.min(startRes, alwidth - vpwidth + 1);
290 boxX = Math.round(xPos / widthRatio);
291 boxY = Math.round(startSeq / heightRatio);
293 // boxWidth is the width in residues translated to pixels
294 boxWidth = Math.round(vpwidth / widthRatio);
296 // boxHeight is the height in sequences translated to pixels
297 boxHeight = Math.round(vpheight / heightRatio);
301 * Answers if a mouse position is in the overview's red box
307 * @return true if (x,y) is inside the box
309 public boolean isPositionInBox(int x, int y)
311 return (x > boxX && y > boxY && x < boxX + boxWidth
312 && y < boxY + boxHeight);
316 * Given the centre x position, calculate the box's left x position
318 protected abstract int getLeftXFromCentreX(int mousex,
319 HiddenColumns hidden);
322 * Given the centre y position, calculate the box's top y position
324 protected abstract int getTopYFromCentreY(int mousey,
325 HiddenSequences hidden);