Clover icon

Coverage Report

  1. Project Clover database Thu Dec 4 2025 14:43:25 GMT
  2. Package jalview.viewmodel

File OverviewDimensions.java

 

Coverage histogram

../../img/srcFileCovDistChart10.png
0% of files have more coverage

Code metrics

14
41
16
1
328
150
23
0.56
2.56
16
1.44

Classes

Class Line # Actions
OverviewDimensions 33 41 23
0.9154929591.5%
 

Contributing tests

This file is covered by 49 tests. .

Source view

1    /*
2    * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3    * Copyright (C) $$Year-Rel$$ The Jalview Authors
4    *
5    * This file is part of Jalview.
6    *
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.
11    *
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.
16    *
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.
20    */
21    package jalview.viewmodel;
22   
23    import java.awt.Dimension;
24    import java.awt.Graphics;
25   
26    import jalview.api.AlignmentColsCollectionI;
27    import jalview.api.AlignmentRowsCollectionI;
28    import jalview.datamodel.AlignmentI;
29    import jalview.datamodel.HiddenColumns;
30    import jalview.datamodel.HiddenSequences;
31   
32   
 
33    public abstract class OverviewDimensions
34    {
35    protected static final int MAX_WIDTH = 400;
36   
37    protected static final int MIN_WIDTH = 120;
38   
39    protected static final int MIN_SEQ_HEIGHT = 40;
40   
41    protected static final int MAX_SEQ_HEIGHT = 300;
42   
43    private static final int DEFAULT_GRAPH_HEIGHT = 20;
44   
45    protected int width;
46   
47    protected int sequencesHeight;
48   
49    protected int graphHeight = DEFAULT_GRAPH_HEIGHT;
50   
51    protected int boxX = -1;
52   
53    protected int boxY = -1;
54   
55    protected int boxWidth = -1;
56   
57    protected int boxHeight = -1;
58   
59    protected int alwidth;
60   
61    protected int alheight;
62   
63    protected float widthRatio;
64   
65    protected float heightRatio;
66   
67    /**
68    * Create an OverviewDimensions object
69    *
70    * @param ranges
71    * positional properties of the viewport
72    * @param showAnnotationPanel
73    * true if the annotation panel is to be shown, false otherwise
74    */
 
75  88 toggle public OverviewDimensions(ViewportRanges ranges,
76    boolean showAnnotationPanel, Dimension dim)
77    {
78  88 if (!showAnnotationPanel)
79    {
80  2 graphHeight = 0;
81    }
82   
83    // scale the initial size of overviewpanel to shape of alignment
84  88 float initialScale = (float) ranges.getAbsoluteAlignmentWidth()
85    / (float) ranges.getAbsoluteAlignmentHeight();
86   
87  88 if (dim != null)
88    {
89  0 width = dim.width;
90  0 sequencesHeight = dim.height;
91  0 return;
92    }
93   
94  88 if (ranges.getAbsoluteAlignmentWidth() > ranges
95    .getAbsoluteAlignmentHeight())
96    {
97    // wider
98  47 width = MAX_WIDTH;
99  47 sequencesHeight = Math.round(MAX_WIDTH / initialScale);
100  47 if (sequencesHeight < MIN_SEQ_HEIGHT)
101    {
102  25 sequencesHeight = MIN_SEQ_HEIGHT;
103    }
104    }
105    else
106    {
107    // taller
108  41 width = Math.round(MAX_WIDTH * initialScale);
109  41 sequencesHeight = MAX_SEQ_HEIGHT;
110   
111  41 if (width < MIN_WIDTH)
112    {
113  4 width = MIN_WIDTH;
114    }
115    }
116    }
117   
118    /**
119    * Draw the overview panel's viewport box on a graphics object
120    *
121    * @param g
122    * the graphics object to draw on
123    */
 
124  281 toggle public void drawBox(Graphics g)
125    {
126  281 g.drawRect(boxX, boxY, boxWidth, boxHeight);
127  281 g.drawRect(boxX + 1, boxY + 1, boxWidth - 2, boxHeight - 2);
128    }
129   
 
130  306 toggle public int getBoxX()
131    {
132  306 return boxX;
133    }
134   
 
135  297 toggle public int getBoxY()
136    {
137  297 return boxY;
138    }
139   
 
140  301 toggle public int getBoxWidth()
141    {
142  301 return boxWidth;
143    }
144   
 
145  283 toggle public int getBoxHeight()
146    {
147  283 return boxHeight;
148    }
149   
 
150  1663 toggle public int getWidth()
151    {
152  1663 return width;
153    }
154   
 
155  1549 toggle public int getHeight()
156    {
157  1549 return sequencesHeight + graphHeight;
158    }
159   
 
160  607 toggle public int getSequencesHeight()
161    {
162  607 return sequencesHeight;
163    }
164   
 
165  531 toggle public int getGraphHeight()
166    {
167  531 return graphHeight;
168    }
169   
 
170  263 toggle public float getPixelsPerCol()
171    {
172  263 resetAlignmentDims();
173  263 return 1 / widthRatio;
174    }
175   
 
176  263 toggle public float getPixelsPerSeq()
177    {
178  263 resetAlignmentDims();
179  263 return 1 / heightRatio;
180    }
181   
 
182  648 toggle public void setWidth(int w)
183    {
184  648 width = w < 1 ? 1 : w;
185  648 widthRatio = (float) alwidth / width;
186    }
187   
 
188  648 toggle public void setHeight(int h)
189    {
190  648 sequencesHeight = (h < 1 ? 1 : h) - graphHeight;
191  648 heightRatio = (float) alheight / sequencesHeight;
192    }
193   
194    /**
195    * Update the viewport location from a mouse click in the overview panel
196    *
197    * @param mousex
198    * x location of mouse
199    * @param mousey
200    * y location of mouse
201    * @param hiddenSeqs
202    * the alignment's hidden sequences
203    * @param hiddenCols
204    * the alignment's hidden columns
205    */
206    public abstract void updateViewportFromMouse(int mousex, int mousey,
207    HiddenSequences hiddenSeqs, HiddenColumns hiddenCols);
208   
209    /**
210    * Update the viewport location from a mouse drag within the overview's box
211    *
212    * @param mousex
213    * x location of mouse
214    * @param mousey
215    * y location of mouse
216    * @param hiddenSeqs
217    * the alignment's hidden sequences
218    * @param hiddenCols
219    * the alignment's hidden columns
220    */
221    public abstract void adjustViewportFromMouse(int mousex, int mousey,
222    HiddenSequences hiddenSeqs, HiddenColumns hiddenCols);
223   
224    /**
225    * Initialise dragging from the mouse - must be called on initial mouse click
226    * before using adjustViewportFromMouse in drag operations
227    *
228    * @param mousex
229    * x location of mouse
230    * @param mousey
231    * y location of mouse
232    * @param hiddenSeqs
233    * the alignment's hidden sequences
234    * @param hiddenCols
235    * the alignment's hidden columns
236    */
237    public abstract void setDragPoint(int x, int y,
238    HiddenSequences hiddenSeqs, HiddenColumns hiddenCols);
239   
240    /*
241    * Move the viewport so that the top left corner of the overview's box
242    * is at the mouse position (leftx, topy)
243    */
244    protected abstract void updateViewportFromTopLeft(int leftx, int topy,
245    HiddenSequences hiddenSeqs, HiddenColumns hiddenCols);
246   
247    /**
248    * Set the overview panel's box position to match the viewport
249    *
250    * @param hiddenSeqs
251    * the alignment's hidden sequences
252    * @param hiddenCols
253    * the alignment's hidden columns
254    */
255    public abstract void setBoxPosition(HiddenSequences hiddenSeqs,
256    HiddenColumns hiddenCols);
257   
258    /**
259    * Get the collection of columns used by this overview dimensions object
260    *
261    * @param hiddenCols
262    * the alignment's hidden columns
263    * @return a column collection
264    */
265    public abstract AlignmentColsCollectionI getColumns(AlignmentI al);
266   
267    /**
268    * Get the collection of rows used by this overview dimensions object
269    *
270    * @param al
271    * the alignment
272    * @return a row collection
273    */
274    public abstract AlignmentRowsCollectionI getRows(AlignmentI al);
275   
276    /**
277    * Updates overview dimensions to account for current alignment dimensions
278    */
279    protected abstract void resetAlignmentDims();
280   
281    /*
282    * Given the box coordinates in residues and sequences, set the box dimensions in the overview window
283    */
 
284  406 toggle protected void setBoxPosition(int startRes, int startSeq, int vpwidth,
285    int vpheight)
286    {
287  406 resetAlignmentDims();
288   
289    // boxX, boxY is the x,y location equivalent to startRes, startSeq
290  406 int xPos = Math.min(startRes, alwidth - vpwidth + 1);
291  406 boxX = Math.round(xPos / widthRatio);
292  406 boxY = Math.round(startSeq / heightRatio);
293   
294    // boxWidth is the width in residues translated to pixels
295  406 boxWidth = Math.round(vpwidth / widthRatio);
296   
297    // boxHeight is the height in sequences translated to pixels
298  406 boxHeight = Math.round(vpheight / heightRatio);
299    }
300   
301    /**
302    * Answers if a mouse position is in the overview's red box
303    *
304    * @param x
305    * mouse x position
306    * @param y
307    * mouse y position
308    * @return true if (x,y) is inside the box
309    */
 
310  42 toggle public boolean isPositionInBox(int x, int y)
311    {
312  42 return (x > boxX && y > boxY && x < boxX + boxWidth
313    && y < boxY + boxHeight);
314    }
315   
316    /*
317    * Given the centre x position, calculate the box's left x position
318    */
319    protected abstract int getLeftXFromCentreX(int mousex,
320    HiddenColumns hidden);
321   
322    /*
323    * Given the centre y position, calculate the box's top y position
324    */
325    protected abstract int getTopYFromCentreY(int mousey,
326    HiddenSequences hidden);
327   
328    }