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;
34 protected static final int MIN_WIDTH = 120;
35 protected static final int MIN_SEQ_HEIGHT = 40;
36 protected static final int MAX_SEQ_HEIGHT = 300;
38 private static final int DEFAULT_GRAPH_HEIGHT = 20;
41 protected int sequencesHeight;
42 protected int graphHeight = DEFAULT_GRAPH_HEIGHT;
43 protected int boxX = -1;
44 protected int boxY = -1;
45 protected int boxWidth = -1;
46 protected int boxHeight = -1;
47 protected int scrollCol = -1;
48 protected int scrollRow = -1;
49 protected int alwidth;
50 protected int alheight;
52 public OverviewDimensions(ViewportRanges ranges,
53 boolean showAnnotationPanel)
55 // scale the initial size of overviewpanel to shape of alignment
56 float initialScale = (float) ranges.getAbsoluteAlignmentWidth()
57 / (float) ranges.getAbsoluteAlignmentHeight();
59 if (!showAnnotationPanel)
64 if (ranges.getAbsoluteAlignmentWidth() > ranges
65 .getAbsoluteAlignmentHeight())
69 sequencesHeight = Math.round(MAX_WIDTH / initialScale);
70 if (sequencesHeight < MIN_SEQ_HEIGHT)
72 sequencesHeight = MIN_SEQ_HEIGHT;
78 width = Math.round(MAX_WIDTH * initialScale);
79 sequencesHeight = MAX_SEQ_HEIGHT;
81 if (width < MIN_WIDTH)
89 * Draw the overview panel's viewport box on a graphics object
92 * the graphics object to draw on
94 public void drawBox(Graphics g)
96 g.drawRect(boxX, boxY, boxWidth, boxHeight);
97 g.drawRect(boxX + 1, boxY + 1, boxWidth - 2, boxHeight - 2);
100 public int getScrollCol()
105 public int getScrollRow()
120 public int getBoxWidth()
125 public int getBoxHeight()
130 public int getWidth()
135 public int getHeight()
137 return sequencesHeight + graphHeight;
140 public int getSequencesHeight()
142 return sequencesHeight;
145 public int getGraphHeight()
150 public float getPixelsPerCol()
152 resetAlignmentDims();
153 return (float) width / alwidth;
156 public float getPixelsPerSeq()
158 resetAlignmentDims();
159 return (float) sequencesHeight / alheight;
162 public void setWidth(int w)
167 public void setHeight(int h)
169 sequencesHeight = h - graphHeight;
173 * Update the viewport location from a mouse click in the overview panel
176 * x location of mouse
178 * y location of mouse
180 * the alignment's hidden sequences
182 * the alignment's hidden columns
184 public abstract void updateViewportFromMouse(int mousex, int mousey,
185 HiddenSequences hiddenSeqs, HiddenColumns hiddenCols);
188 * Set the overview panel's box position to match the viewport
191 * the alignment's hidden sequences
193 * the alignment's hidden columns
195 public abstract void setBoxPosition(HiddenSequences hiddenSeqs,
196 HiddenColumns hiddenCols);
199 * Get the collection of columns used by this overview dimensions object
202 * the alignment's hidden columns
203 * @return a column collection
205 public abstract AlignmentColsCollectionI getColumns(AlignmentI al);
208 * Get the collection of rows used by this overview dimensions object
212 * @return a row collection
214 public abstract AlignmentRowsCollectionI getRows(AlignmentI al);
217 * Updates overview dimensions to account for current alignment dimensions
219 protected abstract void resetAlignmentDims();
221 protected void setBoxPosition(int startRes, int endRes, int startSeq,
224 resetAlignmentDims();
226 // boxX, boxY is the x,y location equivalent to startRes, startSeq
227 boxX = Math.round((float) startRes * width / alwidth);
228 boxY = Math.round((float) startSeq * sequencesHeight / alheight);
230 // boxWidth is the width in residues translated to pixels
231 // since the box includes both the start and end residues, add 1 to the
234 .round((float) (endRes - startRes + 1) * width / alwidth);
235 // boxHeight is the height in sequences translated to pixels
236 boxHeight = Math.round((float) (endSeq - startSeq + 1)
237 * sequencesHeight / alheight);