Clover icon

Coverage Report

  1. Project Clover database Thu Nov 28 2024 11:45:30 GMT
  2. Package jalview.viewmodel

File OverviewDimensionsHideHidden.java

 

Coverage histogram

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

Code metrics

14
46
11
1
214
133
18
0.39
4.18
11
1.64

Classes

Class Line # Actions
OverviewDimensionsHideHidden 31 46 18
0.9154929591.5%
 

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