import jalview.datamodel.HiddenColumns;
import jalview.datamodel.HiddenSequences;
+import java.awt.Dimension;
import java.awt.Graphics;
+import java.awt.Rectangle;
public abstract class OverviewDimensions
{
protected int alheight;
+ protected float widthRatio;
+
+ protected float heightRatio;
+
+ private Rectangle vpbox = new Rectangle();
+
/**
* Create an OverviewDimensions object
*
* true if the annotation panel is to be shown, false otherwise
*/
public OverviewDimensions(ViewportRanges ranges,
- boolean showAnnotationPanel)
+ boolean showAnnotationPanel, Dimension dim)
{
+ if (!showAnnotationPanel)
+ {
+ graphHeight = 0;
+ }
+
// scale the initial size of overviewpanel to shape of alignment
float initialScale = (float) ranges.getAbsoluteAlignmentWidth()
/ (float) ranges.getAbsoluteAlignmentHeight();
- if (!showAnnotationPanel)
+ if (dim != null)
{
- graphHeight = 0;
+ width = dim.width;
+ sequencesHeight = dim.height;
+ return;
}
-
if (ranges.getAbsoluteAlignmentWidth() > ranges
.getAbsoluteAlignmentHeight())
{
*/
public void drawBox(Graphics g)
{
+ // System.out.println("OD drawBox " + boxX + " " + boxY + " " + boxWidth
+ // + " " + boxHeight);
+ updateBox();
g.drawRect(boxX, boxY, boxWidth, boxHeight);
g.drawRect(boxX + 1, boxY + 1, boxWidth - 2, boxHeight - 2);
}
return boxHeight;
}
+ /**
+ * Returns the width of the Overview in pixels
+ *
+ * @return
+ */
public int getWidth()
{
return width;
}
+ /**
+ * Returns the height of the Overview in pixels
+ *
+ * @return
+ */
public int getHeight()
{
return sequencesHeight + graphHeight;
}
+ /**
+ * Returns the height of the sequence alignment in the Overview in pixels
+ *
+ * @return
+ */
public int getSequencesHeight()
{
return sequencesHeight;
public float getPixelsPerCol()
{
resetAlignmentDims();
- return (float) width / alwidth;
+ return 1 / widthRatio;
}
public float getPixelsPerSeq()
{
resetAlignmentDims();
- return (float) sequencesHeight / alheight;
+ return 1 / heightRatio;
}
public void setWidth(int w)
{
width = w;
+ widthRatio = (float) alwidth / width;
}
public void setHeight(int h)
{
+ // BH 2019 problem was that component.resize() can come
+ // after setBoxPosition().
+ // Solution was to move setting of box dimensions to paint
sequencesHeight = h - graphHeight;
+ heightRatio = (float) alheight / sequencesHeight;
}
/**
int vpheight)
{
resetAlignmentDims();
+ vpbox = new Rectangle(startRes, startSeq, vpwidth, vpheight);
+ updateBox();
+ }
+ public void updateBox()
+ {
// boxX, boxY is the x,y location equivalent to startRes, startSeq
- boxX = Math.round((float) startRes * width / alwidth);
- boxY = Math.round((float) startSeq * sequencesHeight / alheight);
+ int xPos = Math.min(vpbox.x, alwidth - vpbox.width + 1);
+ boxX = Math.round(xPos / widthRatio);
+ boxY = Math.round(vpbox.y / heightRatio);
// boxWidth is the width in residues translated to pixels
- boxWidth = Math.round((float) vpwidth * width / alwidth);
+ boxWidth = Math.max(1, Math.round(vpbox.width / widthRatio));
// boxHeight is the height in sequences translated to pixels
- boxHeight = Math.round((float) vpheight * sequencesHeight / alheight);
+ boxHeight = Math.max(1, Math.round(vpbox.height / heightRatio));
}
/**
/*
* Given the centre x position, calculate the box's left x position
*/
- protected abstract int getLeftXFromCentreX(int mousex, HiddenColumns hidden);
+ protected abstract int getLeftXFromCentreX(int mousex,
+ HiddenColumns hidden);
/*
* Given the centre y position, calculate the box's top y position