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