Clover icon

Coverage Report

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

File OverviewDimensionsShowHidden.java

 

Coverage histogram

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

Code metrics

14
60
12
1
293
155
19
0.32
5
12
1.58

Classes

Class Line # Actions
OverviewDimensionsShowHidden 33 60 19
0.930232693%
 

Contributing tests

This file is covered by 20 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   
25    import jalview.api.AlignmentColsCollectionI;
26    import jalview.api.AlignmentRowsCollectionI;
27    import jalview.datamodel.AlignmentI;
28    import jalview.datamodel.AllColsCollection;
29    import jalview.datamodel.AllRowsCollection;
30    import jalview.datamodel.HiddenColumns;
31    import jalview.datamodel.HiddenSequences;
32   
 
33    public class OverviewDimensionsShowHidden extends OverviewDimensions
34    {
35    private ViewportRanges ranges;
36   
37    private int xdiff; // when dragging, difference in alignment units between
38    // start residue and original mouse click position
39   
40    private int ydiff; // when dragging, difference in alignment units between
41    // start sequence and original mouse click position
42   
43   
44    /**
45    * for testng only
46    *
47    * @param vpranges
48    * @param showAnnotationPanel
49    */
 
50  23 toggle @Deprecated
51    public OverviewDimensionsShowHidden(ViewportRanges vpranges, boolean showAnnotationPanel) {
52  23 this(vpranges, showAnnotationPanel, null);
53    }
54   
55    /**
56    * Create an OverviewDimensions object
57    *
58    * @param ranges
59    * positional properties of the viewport
60    * @param showAnnotationPanel
61    * true if the annotation panel is to be shown, false otherwise
62    */
 
63  29 toggle public OverviewDimensionsShowHidden(ViewportRanges vpranges,
64    boolean showAnnotationPanel, Dimension dim)
65    {
66  29 super(vpranges, showAnnotationPanel, dim);
67  29 ranges = vpranges;
68  29 resetAlignmentDims();
69    }
70   
71    /**
72    * Check box dimensions and scroll positions and correct if necessary
73    *
74    * @param mousex
75    * x position in overview panel
76    * @param mousey
77    * y position in overview panel
78    * @param hiddenSeqs
79    * hidden sequences
80    * @param hiddenCols
81    * hidden columns
82    * @param ranges
83    * viewport position properties
84    */
 
85  54 toggle @Override
86    public void updateViewportFromMouse(int mousex, int mousey,
87    HiddenSequences hiddenSeqs, HiddenColumns hiddenCols)
88    {
89  54 resetAlignmentDims();
90   
91    // convert mousex and mousey to alignment units as well as
92    // translating to top left corner of viewport - this is an absolute position
93  54 int xAsRes = getLeftXFromCentreX(mousex, hiddenCols);
94  54 int yAsSeq = getTopYFromCentreY(mousey, hiddenSeqs);
95   
96    // convert to visible positions
97  54 int visXAsRes = hiddenCols.absoluteToVisibleColumn(xAsRes);
98  54 yAsSeq = hiddenSeqs.adjustForHiddenSeqs(
99    hiddenSeqs.findIndexWithoutHiddenSeqs(yAsSeq));
100  54 yAsSeq = Math.max(yAsSeq, 0); // -1 if before first visible sequence
101  54 int visYAsSeq = hiddenSeqs.findIndexWithoutHiddenSeqs(yAsSeq);
102  54 visYAsSeq = Math.max(visYAsSeq, 0); // -1 if before first visible sequence
103   
104    // update viewport accordingly
105  54 updateViewportFromTopLeft(visXAsRes, visYAsSeq, hiddenSeqs, hiddenCols);
106    }
107   
 
108  3 toggle @Override
109    public void adjustViewportFromMouse(int mousex, int mousey,
110    HiddenSequences hiddenSeqs, HiddenColumns hiddenCols)
111    {
112  3 resetAlignmentDims();
113   
114    // calculate translation in pixel terms:
115    // get mouse location in viewport coords, add translation in viewport
116    // coords,
117    // convert back to pixel coords
118  3 int vpx = Math.round((float) mousex * alwidth / width);
119  3 int visXAsRes = hiddenCols.absoluteToVisibleColumn(vpx) + xdiff;
120   
121  3 int vpy = Math.round(mousey * heightRatio);
122  3 int visYAsRes = hiddenSeqs.findIndexWithoutHiddenSeqs(vpy) + ydiff;
123   
124    // update viewport accordingly
125  3 updateViewportFromTopLeft(visXAsRes, visYAsRes, hiddenSeqs, hiddenCols);
126    }
127   
128    /**
129    * {@inheritDoc} Callers should have already called resetAlignmentDims to
130    * refresh alwidth, alheight and width/height ratios
131    */
 
132  57 toggle @Override
133    protected void updateViewportFromTopLeft(int leftx, int topy,
134    HiddenSequences hiddenSeqs, HiddenColumns hiddenCols)
135    {
136  57 int visXAsRes = leftx;
137  57 int visYAsSeq = topy;
138   
139  57 if (visXAsRes < 0)
140    {
141  43 visXAsRes = 0;
142    }
143   
144  57 if (visYAsSeq < 0)
145    {
146  0 visYAsSeq = 0;
147    }
148   
149  57 if (ranges.isWrappedMode())
150    {
151  3 visYAsSeq = 0; // sorry, no vertical scroll when wrapped
152    }
153   
154    // Determine where scrollCol should be, given visXAsRes
155   
156    // get viewport width in residues
157  57 int vpwidth = ranges.getViewportWidth();
158   
159    // check in case we went off the edge of the alignment
160  57 int visAlignWidth = hiddenCols.absoluteToVisibleColumn(alwidth - 1);
161  57 if (visXAsRes + vpwidth - 1 > visAlignWidth)
162    {
163    // went past the end of the alignment, adjust backwards
164   
165    // if last position was before the end of the alignment, need to update
166  5 if (ranges.getEndRes() < visAlignWidth)
167    {
168  5 visXAsRes = hiddenCols.absoluteToVisibleColumn(hiddenCols
169    .offsetByVisibleColumns(-(vpwidth - 1), alwidth - 1));
170    }
171    else
172    {
173  0 visXAsRes = ranges.getStartRes();
174    }
175    }
176   
177    // Determine where scrollRow should be, given visYAsSeq
178   
179    // get viewport height in sequences
180  57 int vpheight = ranges.getViewportHeight();
181   
182    // check in case we went off the edge of the alignment
183  57 int visAlignHeight = hiddenSeqs.findIndexWithoutHiddenSeqs(alheight);
184   
185  57 if (visYAsSeq + vpheight - 1 > visAlignHeight)
186    {
187    // went past the end of the alignment, adjust backwards
188  3 if (ranges.getEndSeq() < visAlignHeight)
189    {
190  3 visYAsSeq = hiddenSeqs.findIndexWithoutHiddenSeqs(
191    hiddenSeqs.subtractVisibleRows(vpheight - 1, alheight - 1));
192    }
193    else
194    {
195  0 visYAsSeq = ranges.getStartSeq();
196    }
197    }
198   
199    // update viewport
200  57 ranges.setStartResAndSeq(visXAsRes, visYAsSeq);
201    }
202   
203    /**
204    * Update the overview panel box when the associated alignment panel is
205    * changed
206    *
207    * @param hiddenSeqs
208    * hidden sequences
209    * @param hiddenCols
210    * hidden columns
211    * @param ranges
212    * viewport position properties
213    */
 
214  123 toggle @Override
215    public void setBoxPosition(HiddenSequences hiddenSeqs,
216    HiddenColumns hiddenCols)
217    {
218    // work with absolute values of startRes and endRes
219  123 int startRes = hiddenCols.visibleToAbsoluteColumn(ranges.getStartRes());
220  123 int endRes = hiddenCols.visibleToAbsoluteColumn(ranges.getEndRes());
221   
222    // work with absolute values of startSeq and endSeq
223  123 int startSeq = hiddenSeqs.adjustForHiddenSeqs(ranges.getStartSeq());
224  123 int endSeq = hiddenSeqs.adjustForHiddenSeqs(ranges.getEndSeq());
225   
226  123 setBoxPosition(startRes, startSeq, endRes - startRes + 1,
227    endSeq - startSeq + 1);
228    }
229   
 
230  26 toggle @Override
231    public AlignmentColsCollectionI getColumns(AlignmentI al)
232    {
233  26 return new AllColsCollection(0, ranges.getAbsoluteAlignmentWidth() - 1,
234    al);
235    }
236   
 
237  14 toggle @Override
238    public AlignmentRowsCollectionI getRows(AlignmentI al)
239    {
240  14 return new AllRowsCollection(0, ranges.getAbsoluteAlignmentHeight() - 1,
241    al);
242    }
243   
 
244  240 toggle @Override
245    protected void resetAlignmentDims()
246    {
247  240 alwidth = ranges.getAbsoluteAlignmentWidth();
248  240 alheight = ranges.getAbsoluteAlignmentHeight();
249   
250  240 widthRatio = (float) alwidth / width;
251  240 heightRatio = (float) alheight / sequencesHeight;
252    }
253   
254    /**
255    * {@inheritDoc} Callers should have already called resetAlignmentDims to
256    * refresh widthRatio
257    */
 
258  54 toggle @Override
259    protected int getLeftXFromCentreX(int mousex, HiddenColumns hidden)
260    {
261  54 int vpx = Math.round((float) mousex * alwidth / width);
262  54 return hidden.offsetByVisibleColumns(-ranges.getViewportWidth() / 2,
263    vpx);
264    }
265   
266    /**
267    * {@inheritDoc} Callers should have already called resetAlignmentDims to
268    * refresh heightRatio
269    */
 
270  54 toggle @Override
271    protected int getTopYFromCentreY(int mousey, HiddenSequences hidden)
272    {
273  54 int vpy = Math.round(mousey * heightRatio);
274  54 return hidden.subtractVisibleRows(ranges.getViewportHeight() / 2, vpy);
275    }
276   
 
277  3 toggle @Override
278    public void setDragPoint(int x, int y, HiddenSequences hiddenSeqs,
279    HiddenColumns hiddenCols)
280    {
281  3 resetAlignmentDims();
282   
283    // get alignment position of x and box (can get directly from vpranges) and
284    // calculate difference between the positions
285  3 int vpx = Math.round(x * widthRatio);
286  3 int vpy = Math.round(y * heightRatio);
287   
288  3 xdiff = ranges.getStartRes() - hiddenCols.absoluteToVisibleColumn(vpx);
289  3 ydiff = ranges.getStartSeq()
290    - hiddenSeqs.findIndexWithoutHiddenSeqs(vpy);
291    }
292   
293    }