X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fviewmodel%2FOverviewDimensions.java;h=8dc7dd86aa0c8b15d1a920c1b17721a75ea73b4e;hb=b3a111ba6d4c239f39d430997fc470ef9008748d;hp=caa36fc3b77a661bbce9dcd2d74047c6437b488d;hpb=24b3db7a46158fe7bf82c208472740f8b7c76448;p=jalview.git diff --git a/src/jalview/viewmodel/OverviewDimensions.java b/src/jalview/viewmodel/OverviewDimensions.java index caa36fc..8dc7dd8 100644 --- a/src/jalview/viewmodel/OverviewDimensions.java +++ b/src/jalview/viewmodel/OverviewDimensions.java @@ -26,7 +26,9 @@ import jalview.datamodel.AlignmentI; import jalview.datamodel.HiddenColumns; import jalview.datamodel.HiddenSequences; +import java.awt.Dimension; import java.awt.Graphics; +import java.awt.Rectangle; public abstract class OverviewDimensions { @@ -58,9 +60,11 @@ public abstract class OverviewDimensions protected int alheight; - protected int fixedX; + protected float widthRatio; - protected int fixedY; + protected float heightRatio; + + private Rectangle vpbox = new Rectangle(); /** * Create an OverviewDimensions object @@ -71,17 +75,23 @@ public abstract class OverviewDimensions * 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()) { @@ -114,6 +124,9 @@ public abstract class OverviewDimensions */ 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); } @@ -161,23 +174,28 @@ public abstract class OverviewDimensions 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; } /** @@ -195,13 +213,42 @@ public abstract class OverviewDimensions public abstract void updateViewportFromMouse(int mousex, int mousey, HiddenSequences hiddenSeqs, HiddenColumns hiddenCols); + /** + * Update the viewport location from a mouse drag within the overview's box + * + * @param mousex + * x location of mouse + * @param mousey + * y location of mouse + * @param hiddenSeqs + * the alignment's hidden sequences + * @param hiddenCols + * the alignment's hidden columns + */ public abstract void adjustViewportFromMouse(int mousex, int mousey, HiddenSequences hiddenSeqs, HiddenColumns hiddenCols); + /** + * Initialise dragging from the mouse - must be called on initial mouse click + * before using adjustViewportFromMouse in drag operations + * + * @param mousex + * x location of mouse + * @param mousey + * y location of mouse + * @param hiddenSeqs + * the alignment's hidden sequences + * @param hiddenCols + * the alignment's hidden columns + */ public abstract void setDragPoint(int x, int y, HiddenSequences hiddenSeqs, HiddenColumns hiddenCols); - protected abstract void updateViewportFromTopLeft(int mousex, int mousey, + /* + * Move the viewport so that the top left corner of the overview's box + * is at the mouse position (leftx, topy) + */ + protected abstract void updateViewportFromTopLeft(int leftx, int topy, HiddenSequences hiddenSeqs, HiddenColumns hiddenCols); /** @@ -238,22 +285,29 @@ public abstract class OverviewDimensions */ protected abstract void resetAlignmentDims(); + /* + * Given the box coordinates in residues and sequences, set the box dimensions in the overview window + */ protected void setBoxPosition(int startRes, int startSeq, int vpwidth, 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); - - System.out.println("Update box: x: " + boxX); + boxHeight = Math.max(1, Math.round(vpbox.height / heightRatio)); } /** @@ -271,8 +325,15 @@ public abstract class OverviewDimensions && y < boxY + boxHeight); } - protected abstract int getLeftXFromCentreX(int mousex, HiddenColumns hidden); + /* + * Given the centre x position, calculate the box's left x position + */ + protected abstract int getLeftXFromCentreX(int mousex, + HiddenColumns hidden); + /* + * Given the centre y position, calculate the box's top y position + */ protected abstract int getTopYFromCentreY(int mousey, HiddenSequences hidden);