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;
62 * Create an OverviewDimensions object
65 * positional properties of the viewport
66 * @param showAnnotationPanel
67 * true if the annotation panel is to be shown, false otherwise
69 public OverviewDimensions(ViewportRanges ranges,
70 boolean showAnnotationPanel)
72 // scale the initial size of overviewpanel to shape of alignment
73 float initialScale = (float) ranges.getAbsoluteAlignmentWidth()
74 / (float) ranges.getAbsoluteAlignmentHeight();
76 if (!showAnnotationPanel)
81 if (ranges.getAbsoluteAlignmentWidth() > ranges
82 .getAbsoluteAlignmentHeight())
86 sequencesHeight = Math.round(MAX_WIDTH / initialScale);
87 if (sequencesHeight < MIN_SEQ_HEIGHT)
89 sequencesHeight = MIN_SEQ_HEIGHT;
95 width = Math.round(MAX_WIDTH * initialScale);
96 sequencesHeight = MAX_SEQ_HEIGHT;
98 if (width < MIN_WIDTH)
106 * Draw the overview panel's viewport box on a graphics object
109 * the graphics object to draw on
111 public void drawBox(Graphics g)
113 g.drawRect(boxX, boxY, boxWidth, boxHeight);
114 g.drawRect(boxX + 1, boxY + 1, boxWidth - 2, boxHeight - 2);
127 public int getBoxWidth()
132 public int getBoxHeight()
137 public int getWidth()
142 public int getHeight()
144 return sequencesHeight + graphHeight;
147 public int getSequencesHeight()
149 return sequencesHeight;
152 public int getGraphHeight()
157 public float getPixelsPerCol()
159 resetAlignmentDims();
160 return (float) width / alwidth;
163 public float getPixelsPerSeq()
165 resetAlignmentDims();
166 return (float) sequencesHeight / alheight;
169 public void setWidth(int w)
174 public void setHeight(int h)
176 sequencesHeight = h - graphHeight;
180 * Update the viewport location from a mouse click in the overview panel
183 * x location of mouse
185 * y location of mouse
187 * the alignment's hidden sequences
189 * the alignment's hidden columns
191 public abstract void updateViewportFromMouse(int mousex, int mousey,
192 HiddenSequences hiddenSeqs, HiddenColumns hiddenCols);
195 * Set the overview panel's box position to match the viewport
198 * the alignment's hidden sequences
200 * the alignment's hidden columns
202 public abstract void setBoxPosition(HiddenSequences hiddenSeqs,
203 HiddenColumns hiddenCols);
206 * Get the collection of columns used by this overview dimensions object
209 * the alignment's hidden columns
210 * @return a column collection
212 public abstract AlignmentColsCollectionI getColumns(AlignmentI al);
215 * Get the collection of rows used by this overview dimensions object
219 * @return a row collection
221 public abstract AlignmentRowsCollectionI getRows(AlignmentI al);
224 * Updates overview dimensions to account for current alignment dimensions
226 protected abstract void resetAlignmentDims();
228 protected void setBoxPosition(int startRes, int startSeq, int vpwidth,
231 resetAlignmentDims();
233 // boxX, boxY is the x,y location equivalent to startRes, startSeq
234 int xPos = Math.min(startRes, alwidth - vpwidth + 1);
235 boxX = Math.round((float) xPos * width / alwidth);
236 boxY = Math.round((float) startSeq * sequencesHeight / alheight);
238 // boxWidth is the width in residues translated to pixels
239 boxWidth = Math.round((float) vpwidth * width / alwidth);
241 // boxHeight is the height in sequences translated to pixels
242 boxHeight = Math.round((float) vpheight * sequencesHeight / alheight);