Clover icon

Coverage Report

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

File OverviewDimensionsHideHidden.java

 

Coverage histogram

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

Code metrics

14
47
12
1
227
138
19
0.4
3.92
12
1.58

Classes

Class Line # Actions
OverviewDimensionsHideHidden 33 47 19
0.9178082391.8%
 

Contributing tests

This file is covered by 26 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.HiddenColumns;
29    import jalview.datamodel.HiddenSequences;
30    import jalview.datamodel.VisibleColsCollection;
31    import jalview.datamodel.VisibleRowsCollection;
32   
 
33    public class OverviewDimensionsHideHidden 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    * for testng only
45    *
46    * @param vpranges
47    * @param showAnnotationPanel
48    */
 
49  22 toggle @Deprecated
50    public OverviewDimensionsHideHidden(ViewportRanges vpranges, boolean showAnnotationPanel) {
51  22 this(vpranges, showAnnotationPanel, null);
52    }
53   
 
54  59 toggle public OverviewDimensionsHideHidden(ViewportRanges vpranges,
55    boolean showAnnotationPanel, Dimension dim)
56    {
57  59 super(vpranges, showAnnotationPanel, dim);
58  59 ranges = vpranges;
59  59 resetAlignmentDims();
60    }
61   
 
62  56 toggle @Override
63    public void updateViewportFromMouse(int mousex, int mousey,
64    HiddenSequences hiddenSeqs, HiddenColumns hiddenCols)
65    {
66  56 resetAlignmentDims();
67   
68  56 int xAsRes = getLeftXFromCentreX(mousex, hiddenCols);
69  56 int yAsSeq = getTopYFromCentreY(mousey, hiddenSeqs);
70   
71  56 updateViewportFromTopLeft(xAsRes, yAsSeq, hiddenSeqs, hiddenCols);
72   
73    }
74   
 
75  3 toggle @Override
76    public void adjustViewportFromMouse(int mousex, int mousey,
77    HiddenSequences hiddenSeqs, HiddenColumns hiddenCols)
78    {
79  3 resetAlignmentDims();
80   
81    // calculate translation in pixel terms:
82    // get mouse location in viewport coords, add translation in viewport
83    // coords, and update viewport as usual
84  3 int vpx = Math.round(mousex * widthRatio);
85  3 int vpy = Math.round(mousey * heightRatio);
86   
87  3 updateViewportFromTopLeft(vpx + xdiff, vpy + ydiff, hiddenSeqs,
88    hiddenCols);
89   
90    }
91   
92    /**
93    * {@inheritDoc} Callers should have already called resetAlignmentDims to
94    * refresh alwidth, alheight and width/height ratios
95    */
 
96  59 toggle @Override
97    protected void updateViewportFromTopLeft(int leftx, int topy,
98    HiddenSequences hiddenSeqs, HiddenColumns hiddenCols)
99    {
100  59 int xAsRes = leftx;
101  59 int yAsSeq = topy;
102   
103  59 if (xAsRes < 0)
104    {
105  37 xAsRes = 0;
106    }
107   
108  59 if (yAsSeq < 0)
109    {
110  31 yAsSeq = 0;
111    }
112   
113  59 if (ranges.isWrappedMode())
114    {
115  0 yAsSeq = 0; // sorry, no vertical scroll when wrapped
116    }
117   
118    // get viewport width in residues
119  59 int vpwidth = ranges.getViewportWidth();
120   
121  59 if (xAsRes + vpwidth > alwidth)
122    {
123    // went past the end of the alignment, adjust backwards
124   
125    // if last position was before the end of the alignment, need to update
126  5 if (ranges.getStartRes() < alwidth)
127    {
128  5 xAsRes = alwidth - vpwidth;
129    }
130    else
131    {
132  0 xAsRes = ranges.getStartRes();
133    }
134    }
135   
136    // Determine where scrollRow should be, given visYAsSeq
137   
138    // get viewport height in sequences
139    // add 1 because height includes both endSeq and startSeq
140  59 int vpheight = ranges.getViewportHeight();
141   
142  59 if (yAsSeq + vpheight > alheight)
143    {
144    // went past the end of the alignment, adjust backwards
145  2 if (ranges.getEndSeq() < alheight)
146    {
147  2 yAsSeq = alheight - vpheight;
148    }
149    else
150    {
151  0 yAsSeq = ranges.getStartSeq();
152    }
153    }
154   
155  59 ranges.setStartResAndSeq(xAsRes, yAsSeq);
156    }
157   
 
158  283 toggle @Override
159    public void setBoxPosition(HiddenSequences hiddenSeqs,
160    HiddenColumns hiddenCols)
161    {
162  283 setBoxPosition(ranges.getStartRes(), ranges.getStartSeq(),
163    ranges.getViewportWidth(), ranges.getViewportHeight());
164    }
165   
 
166  492 toggle @Override
167    public AlignmentColsCollectionI getColumns(AlignmentI al)
168    {
169  492 return new VisibleColsCollection(0,
170    ranges.getAbsoluteAlignmentWidth() - 1, al.getHiddenColumns());
171    }
172   
 
173  249 toggle @Override
174    public AlignmentRowsCollectionI getRows(AlignmentI al)
175    {
176  249 return new VisibleRowsCollection(0,
177    ranges.getAbsoluteAlignmentHeight() - 1, al);
178    }
179   
 
180  902 toggle @Override
181    protected void resetAlignmentDims()
182    {
183  902 alwidth = ranges.getVisibleAlignmentWidth();
184  902 alheight = ranges.getVisibleAlignmentHeight();
185   
186  902 widthRatio = (float) alwidth / width;
187  902 heightRatio = (float) alheight / sequencesHeight;
188    }
189   
190    /**
191    * {@inheritDoc} Callers should have already called resetAlignmentDims to
192    * refresh widthRatio
193    */
 
194  56 toggle @Override
195    protected int getLeftXFromCentreX(int mousex, HiddenColumns hidden)
196    {
197  56 int vpx = Math.round(mousex * widthRatio);
198  56 return vpx - ranges.getViewportWidth() / 2;
199    }
200   
201    /**
202    * {@inheritDoc} Callers should have already called resetAlignmentDims to
203    * refresh heightRatio
204    */
 
205  56 toggle @Override
206    protected int getTopYFromCentreY(int mousey, HiddenSequences hidden)
207    {
208  56 int vpy = Math.round(mousey * heightRatio);
209  56 return vpy - ranges.getViewportHeight() / 2;
210    }
211   
 
212  3 toggle @Override
213    public void setDragPoint(int x, int y, HiddenSequences hiddenSeqs,
214    HiddenColumns hiddenCols)
215    {
216  3 resetAlignmentDims();
217   
218    // get alignment position of x and box (can get directly from vpranges) and
219    // calculate difference between the positions
220  3 int vpx = Math.round(x * widthRatio);
221  3 int vpy = Math.round(y * heightRatio);
222   
223  3 xdiff = ranges.getStartRes() - vpx;
224  3 ydiff = ranges.getStartSeq() - vpy;
225    }
226   
227    }