X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fviewmodel%2FOverviewDimensions.java;h=c153dc1505545ecf79fc1a7d10c2a9e71a09a6d1;hb=51b0b157926ed477cb558ca5971126bf9fccbd31;hp=eb4a6e6e5ac79f9021f8320a428b9225335cd7f9;hpb=14985603cea28569e295ddabb219da8034f1c7b2;p=jalview.git diff --git a/src/jalview/viewmodel/OverviewDimensions.java b/src/jalview/viewmodel/OverviewDimensions.java index eb4a6e6..c153dc1 100644 --- a/src/jalview/viewmodel/OverviewDimensions.java +++ b/src/jalview/viewmodel/OverviewDimensions.java @@ -26,39 +26,68 @@ import jalview.datamodel.AlignmentI; import jalview.datamodel.HiddenColumns; import jalview.datamodel.HiddenSequences; +import java.awt.Dimension; import java.awt.Graphics; public abstract class OverviewDimensions { protected static final int MAX_WIDTH = 400; + protected static final int MIN_WIDTH = 120; + protected static final int MIN_SEQ_HEIGHT = 40; + protected static final int MAX_SEQ_HEIGHT = 300; private static final int DEFAULT_GRAPH_HEIGHT = 20; protected int width; + protected int sequencesHeight; + protected int graphHeight = DEFAULT_GRAPH_HEIGHT; + protected int boxX = -1; + protected int boxY = -1; + protected int boxWidth = -1; + protected int boxHeight = -1; - protected int scrollCol = -1; - protected int scrollRow = -1; + protected int alwidth; + protected int alheight; + protected float widthRatio; + + protected float heightRatio; + + /** + * Create an OverviewDimensions object + * + * @param ranges + * positional properties of the viewport + * @param showAnnotationPanel + * 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 @@ -97,16 +126,6 @@ public abstract class OverviewDimensions g.drawRect(boxX + 1, boxY + 1, boxWidth - 2, boxHeight - 2); } - public int getScrollCol() - { - return scrollCol; - } - - public int getScrollRow() - { - return scrollRow; - } - public int getBoxX() { return boxX; @@ -150,23 +169,25 @@ 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) { sequencesHeight = h - graphHeight; + heightRatio = (float) alheight / sequencesHeight; } /** @@ -185,6 +206,44 @@ public abstract class OverviewDimensions 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); + + /* + * 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); + + /** * Set the overview panel's box position to match the viewport * * @param hiddenSeqs @@ -202,8 +261,7 @@ public abstract class OverviewDimensions * the alignment's hidden columns * @return a column collection */ - public abstract AlignmentColsCollectionI getColumns( - HiddenColumns hiddenCols); + public abstract AlignmentColsCollectionI getColumns(AlignmentI al); /** * Get the collection of rows used by this overview dimensions object @@ -218,4 +276,52 @@ public abstract class OverviewDimensions * Updates overview dimensions to account for current alignment dimensions */ 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(); + + // boxX, boxY is the x,y location equivalent to startRes, startSeq + int xPos = Math.min(startRes, alwidth - vpwidth + 1); + boxX = Math.round(xPos / widthRatio); + boxY = Math.round(startSeq / heightRatio); + + // boxWidth is the width in residues translated to pixels + boxWidth = Math.round(vpwidth / widthRatio); + + // boxHeight is the height in sequences translated to pixels + boxHeight = Math.round(vpheight / heightRatio); + } + + /** + * Answers if a mouse position is in the overview's red box + * + * @param x + * mouse x position + * @param y + * mouse y position + * @return true if (x,y) is inside the box + */ + public boolean isPositionInBox(int x, int y) + { + return (x > boxX && y > boxY && x < boxX + boxWidth + && y < boxY + boxHeight); + } + + /* + * 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); + } \ No newline at end of file