JAL-2388 Tidies
[jalview.git] / src / jalview / viewmodel / OverviewDimensionsAllVisible.java
1 package jalview.viewmodel;
2
3 import jalview.api.AlignmentColsCollectionI;
4 import jalview.api.AlignmentRowsCollectionI;
5 import jalview.datamodel.AlignmentI;
6 import jalview.datamodel.ColumnSelection;
7 import jalview.datamodel.HiddenSequences;
8 import jalview.datamodel.VisibleColsCollection;
9 import jalview.datamodel.VisibleRowsCollection;
10
11 public class OverviewDimensionsAllVisible extends OverviewDimensions
12 {
13   public OverviewDimensionsAllVisible(ViewportRanges ranges,
14           boolean showAnnotationPanel)
15   {
16     super(ranges, showAnnotationPanel);
17
18     alwidth = ranges.getVisibleAlignmentWidth();
19     alheight = ranges.getVisibleAlignmentHeight();
20   }
21
22   @Override
23   public void updateViewportFromMouse(int mousex, int mousey,
24           HiddenSequences hiddenSeqs, ColumnSelection hiddenCols,
25           ViewportRanges ranges)
26   {
27     int x = mousex;
28     int y = mousey;
29
30     alwidth = ranges.getVisibleAlignmentWidth();
31     alheight = ranges.getVisibleAlignmentHeight();
32
33     if (x < 0)
34     {
35       x = 0;
36     }
37
38     if (y < 0)
39     {
40       y = 0;
41     }
42
43     //
44     // Convert x value to residue position
45     //
46
47     // need to determine where scrollCol should be, given x
48     // to do this also need to know width of viewport, and some hidden column
49     // correction
50
51     // convert x to residues - this is an absolute position
52     int xAsRes = Math.round((float) x * alwidth / width);
53
54     // get viewport width in residues
55     int vpwidth = ranges.getEndRes() - ranges.getStartRes() + 1;
56
57     if (xAsRes + vpwidth > alwidth)
58     {
59       // went past the end of the alignment, adjust backwards
60
61       // if last position was before the end of the alignment, need to update
62       if ((scrollCol + vpwidth - 1) < alwidth)
63       {
64         xAsRes = alwidth - vpwidth;
65       }
66       else
67       {
68         xAsRes = scrollCol;
69       }
70     }
71
72
73     //
74     // Convert y value to sequence position
75     //
76
77     // convert y to residues
78     int yAsSeq = Math.round((float) y * alheight / sequencesHeight);
79
80     // get viewport height in sequences
81     // add 1 because height includes both endSeq and startSeq
82     int vpheight = ranges.getEndSeq() - ranges.getStartSeq() + 1;
83
84     if (yAsSeq + vpheight > alheight)
85     {
86       // went past the end of the alignment, adjust backwards
87       if ((scrollRow + vpheight - 1) < alheight)
88       {
89         yAsSeq = alheight - vpheight;
90       }
91       else
92       {
93         yAsSeq = scrollRow;
94       }
95     }
96
97     // update scroll values
98     scrollCol = xAsRes;
99     scrollRow = yAsSeq;
100
101   }
102
103   @Override
104   public void setBoxPosition(HiddenSequences hiddenSeqs,
105           ColumnSelection hiddenCols, ViewportRanges ranges)
106   {
107     alwidth = ranges.getVisibleAlignmentWidth();
108     alheight = ranges.getVisibleAlignmentHeight();
109
110     // work with visible values of startRes and endRes
111     int startRes = ranges.getStartRes();
112     int endRes = ranges.getEndRes();
113
114     // work with visible values of startSeq and endSeq
115     int startSeq = ranges.getStartSeq();
116     int endSeq = ranges.getEndSeq();
117
118     // boxX, boxY is the x,y location equivalent to startRes, startSeq
119     boxX = Math.round((float) startRes * width / alwidth);
120     boxY = Math.round((float) startSeq * sequencesHeight / alheight);
121
122     // boxWidth is the width in residues translated to pixels
123     // since the box includes both the start and end residues, add 1 to the
124     // difference
125     boxWidth = Math
126             .round((float) (endRes - startRes + 1) * width / alwidth);
127     // boxHeight is the height in sequences translated to pixels
128     boxHeight = Math.round((float) (endSeq - startSeq + 1)
129             * sequencesHeight / alheight);
130
131   }
132
133   @Override
134   public AlignmentColsCollectionI getColumns(ViewportRanges ranges,
135           ColumnSelection hiddenCols)
136   {
137     return new VisibleColsCollection(0,
138             ranges.getVisibleAlignmentWidth() - 1, hiddenCols);
139   }
140
141   @Override
142   public AlignmentRowsCollectionI getRows(ViewportRanges ranges,
143           AlignmentI al)
144   {
145     return new VisibleRowsCollection(0,
146             ranges.getVisibleAlignmentHeight() - 1, al);
147   }
148 }