1 package jalview.viewmodel;
3 import jalview.api.AlignmentColsCollectionI;
4 import jalview.api.AlignmentRowsCollectionI;
5 import jalview.datamodel.AlignmentI;
6 import jalview.datamodel.HiddenColumns;
7 import jalview.datamodel.HiddenSequences;
8 import jalview.datamodel.VisibleColsCollection;
9 import jalview.datamodel.VisibleRowsCollection;
11 public class OverviewDimensionsHideHidden extends OverviewDimensions
13 private ViewportRanges ranges;
15 public OverviewDimensionsHideHidden(ViewportRanges vpranges,
16 boolean showAnnotationPanel)
18 super(vpranges, showAnnotationPanel);
24 public void updateViewportFromMouse(int mousex, int mousey,
25 HiddenSequences hiddenSeqs, HiddenColumns hiddenCols)
27 int xAsRes = getLeftXFromCentreX(mousex, hiddenCols);
28 int yAsSeq = getTopYFromCentreY(mousey, hiddenSeqs);
30 updateViewportFromTopLeft(xAsRes, yAsSeq, hiddenSeqs, hiddenCols);
35 public void adjustViewportFromMouse(int mousex, int mousey,
36 HiddenSequences hiddenSeqs, HiddenColumns hiddenCols)
38 // calculate translation in pixel terms:
39 // get mouse location in viewport coords, add translation in viewport
40 // coords, and update viewport as usual
41 int vpx = Math.round((float) mousex * alwidth / width);
42 int vpy = Math.round((float) mousey * alheight / sequencesHeight);
44 updateViewportFromTopLeft(vpx + transX, vpy + transY, hiddenSeqs,
50 protected void updateViewportFromTopLeft(int xAsRes, int yAsSeq,
51 HiddenSequences hiddenSeqs, HiddenColumns hiddenCols)
67 // Convert x value to residue position
70 // need to determine where scrollCol should be, given x
71 // to do this also need to know width of viewport, and some hidden column
74 // convert x to residues - this is an absolute position
75 // int xAsRes = Math.round((float) x * alwidth / width);
77 // get viewport width in residues
78 int vpwidth = ranges.getViewportWidth();
80 if (xAsRes + vpwidth > alwidth)
82 // went past the end of the alignment, adjust backwards
84 // if last position was before the end of the alignment, need to update
85 if (ranges.getStartRes() < alwidth)
87 xAsRes = alwidth - vpwidth;
91 xAsRes = ranges.getStartRes();
97 // Convert y value to sequence position
100 // get viewport height in sequences
101 // add 1 because height includes both endSeq and startSeq
102 int vpheight = ranges.getViewportHeight();
104 if (yAsSeq + vpheight > alheight)
106 // went past the end of the alignment, adjust backwards
107 if (ranges.getEndSeq() < alheight)
109 yAsSeq = alheight - vpheight;
113 yAsSeq = ranges.getStartSeq();
118 ranges.setStartRes(xAsRes);
119 ranges.setStartSeq(yAsSeq);
124 public void setBoxPosition(HiddenSequences hiddenSeqs,
125 HiddenColumns hiddenCols)
127 setBoxPosition(ranges.getStartRes(), ranges.getStartSeq(),
128 ranges.getViewportWidth(), ranges.getViewportHeight());
132 public AlignmentColsCollectionI getColumns(AlignmentI al)
134 return new VisibleColsCollection(0,
135 ranges.getAbsoluteAlignmentWidth() - 1, al);
139 public AlignmentRowsCollectionI getRows(AlignmentI al)
141 return new VisibleRowsCollection(0,
142 ranges.getAbsoluteAlignmentHeight() - 1, al);
146 protected void resetAlignmentDims()
148 alwidth = ranges.getVisibleAlignmentWidth();
149 alheight = ranges.getVisibleAlignmentHeight();
153 protected int getLeftXFromCentreX(int mousex, HiddenColumns hidden)
155 int vpx = Math.round((float) mousex * alwidth / width);
156 return vpx - ranges.getViewportWidth() / 2;
160 protected int getTopYFromCentreY(int mousey, HiddenSequences hidden)
162 int vpy = Math.round((float) mousey * alheight / sequencesHeight);
163 return vpy - ranges.getViewportHeight() / 2;
167 public void setDragPoint(int x, int y, HiddenSequences hiddenSeqs,
168 HiddenColumns hiddenCols)
170 // get alignment position of x and box (can get directly from vpranges) and
172 int vpx = Math.round((float) x * alwidth / width);
174 int vpy = Math.round((float) y * alheight / sequencesHeight);
176 transX = ranges.getStartRes() - vpx;
177 transY = ranges.getStartSeq() - vpy;