import jalview.api.AlignViewportI;
+import java.awt.Graphics;
+
public class OverviewDimensions
{
// Default width and height values
private AlignViewportI av;
+ private ViewportPositionProps posProps;
+
private float scalew = 1f;
private float scaleh = 1f;
public OverviewDimensions(AlignViewportI avi)
{
this.av = avi;
+ this.posProps = av.getPosProps();
// scale the initial size of overviewpanel to shape of alignment
- float initialScale = (float) av.getAlignment().getWidth()
- / (float) av.getAlignment().getHeight();
+ float initialScale = (float) posProps.getAlignmentWidthInCols()
+ / (float) posProps.getAlignmentHeightInRows();
// TODO: in applet this was getSequenceConsensusHash()
// check if it makes any functional difference
graphHeight = 0;
}
- if (av.getAlignment().getWidth() > av.getAlignment().getHeight())
+ if (posProps.getAlignmentWidthInCols() > posProps
+ .getAlignmentHeightInRows())
{
// wider
width = MAX_WIDTH;
/**
* Check box dimensions and scroll positions and correct if necessary
*/
- public void checkValid()
+ public void setBoxPositionByMouse(int x, int y)
{
+ int alwidth = av.getAlignment().getWidth();
+ int alheight = av.getAlignment().getAbsoluteHeight();
+
+ boxX = x;
+ boxY = y;
if (boxY < 0)
{
boxY = 0;
}
-
- if (boxY > (sequencesHeight - boxHeight))
+ else if (boxY > (sequencesHeight - boxHeight))
{
- boxY = sequencesHeight - boxHeight + 1;
+ boxY = sequencesHeight - boxHeight;
}
if (boxX < 0)
{
boxX = 0;
}
-
- if (boxX > (width - boxWidth))
+ else if (boxX > (width - boxWidth))
{
if (av.hasHiddenColumns())
{
// Try smallest possible box
- boxWidth = (int) ((av.getEndRes() - av.getStartRes() + 1)
- * av.getCharWidth() * scalew);
+ boxWidth = Math.round((float) (posProps.getEndRes()
+ - posProps.getStartRes() + 1)
+ * width / alwidth);
}
boxX = width - boxWidth;
}
- scrollCol = (int) (boxX / scalew / av.getCharWidth());
- scrollRow = (int) (boxY / scaleh / av.getCharHeight());
+ scrollCol = Math.round((float) boxX * alwidth / width);
+ scrollRow = Math.round((float) boxY * alheight / sequencesHeight);
if (av.hasHiddenColumns())
{
- if (!av.getColumnSelection().isVisible(scrollCol))
+ // doesn't seem to do anything useful
+ /*if (!av.getColumnSelection().isVisible(scrollCol))
{
return;
- }
+ }*/
scrollCol = av.getColumnSelection().findColumnPosition(scrollCol);
}
*/
public void setBoxPosition()
{
- updateScales();
-
- int startRes = av.getStartRes();
- int endRes = av.getEndRes();
-
- if (av.hasHiddenColumns())
- {
- startRes = av.getColumnSelection().adjustForHiddenColumns(startRes);
- endRes = av.getColumnSelection().adjustForHiddenColumns(endRes);
- }
-
- int startSeq = av.getStartSeq();
- int endSeq = av.getEndSeq();
-
- if (av.hasHiddenRows())
- {
- startSeq = av.getAlignment().getHiddenSequences()
- .adjustForHiddenSeqs(startSeq);
+ int alwidth = av.getAlignment().getWidth();
+ int alheight = av.getAlignment().getAbsoluteHeight();
- endSeq = av.getAlignment().getHiddenSequences()
- .adjustForHiddenSeqs(endSeq);
+ int startRes = av.getPosProps().getAbsoluteStartRes();
+ int endRes = av.getPosProps().getAbsoluteEndRes();
- }
+ int startSeq = av.getPosProps().getAbsoluteStartSeq();
+ int endSeq = av.getPosProps().getAbsoluteEndSeq();
- boxX = (int) (startRes * av.getCharWidth() * scalew);
- boxY = (int) (startSeq * av.getCharHeight() * scaleh);
+ boxX = Math.round((float) startRes * width / alwidth);
+ boxY = Math.round((float) startSeq * sequencesHeight / alheight);
- if (av.hasHiddenColumns())
- {
- boxWidth = (int) ((endRes - startRes + 1) * av.getCharWidth() * scalew);
- }
- else
- {
- boxWidth = (int) ((endRes - startRes + 1) * av.getCharWidth() * scalew);
- }
-
- boxHeight = (int) ((endSeq - startSeq) * av.getCharHeight() * scaleh);
+ boxWidth = Math
+ .round((float) (endRes - startRes + 1) * width / alwidth);
+ boxHeight = Math.round((float) (endSeq - startSeq) * sequencesHeight
+ / alheight);
}
/**
- * Update width and height scales in terms of the alignment width and height
+ * Draw the overview panel's viewport box on a graphics object
+ *
+ * @param g
+ * the graphics object to draw on
*/
- public void updateScales()
+ public void drawBox(Graphics g)
{
- int alwidth = av.getAlignment().getWidth();
- int alheight = av.getAlignment().getHeight()
- + av.getAlignment().getHiddenSequences().getSize();
-
- int fullsizeWidth = alwidth * av.getCharWidth();
- int fullsizeHeight = alheight * av.getCharHeight();
-
- scalew = (float) width / fullsizeWidth;
- scaleh = (float) sequencesHeight / fullsizeHeight;
+ g.drawRect(boxX, boxY, boxWidth, boxHeight);
+ g.drawRect(boxX + 1, boxY + 1, boxWidth - 2, boxHeight - 2);
}
// don't like this, scroll vals are separate from setting code
return scrollRow;
}
+ // TODO should be removed, when unit test has mock Graphics object available
+ // to check boxX/boxY
public int getBoxX()
{
return boxX;
}
+ // TODO should be removed, when unit test has mock Graphics object available
+ // to check boxX/boxY
public int getBoxY()
{
return boxY;
}
+ // TODO should be removed, when unit test has mock Graphics object available
public int getBoxWidth()
{
return boxWidth;
}
+ // TODO should be removed, when unit test has mock Graphics object available
public int getBoxHeight()
{
return boxHeight;