Clover icon

Coverage Report

  1. Project Clover database Mon Nov 11 2024 17:27:16 GMT
  2. Package jalview.viewmodel

File OverviewDimensionsShowHidden.java

 

Coverage histogram

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

Code metrics

14
59
11
1
279
150
18
0.31
5.36
11
1.64

Classes

Class Line # Actions
OverviewDimensionsShowHidden 31 59 18
0.928571492.9%
 

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