From: kiramt Date: Mon, 6 Mar 2017 16:20:18 +0000 (+0000) Subject: JAL-2388 Remove OverviewDimensions dependency on gui classes X-Git-Tag: Release_2_10_2~3^2~92^2~53 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=cb72ab56f740256004ad15c56514528b34d79b43;p=jalview.git JAL-2388 Remove OverviewDimensions dependency on gui classes --- diff --git a/src/jalview/appletgui/OverviewPanel.java b/src/jalview/appletgui/OverviewPanel.java index 0bb9392..8f91835 100755 --- a/src/jalview/appletgui/OverviewPanel.java +++ b/src/jalview/appletgui/OverviewPanel.java @@ -83,7 +83,7 @@ public class OverviewPanel extends Panel implements Runnable, showAnnotation = true; } - od = new OverviewDimensions(av, showAnnotation); + od = new OverviewDimensions(av.getPosProps(), showAnnotation); setSize(new Dimension(od.getWidth(), od.getHeight())); addComponentListener(new ComponentAdapter() @@ -148,7 +148,9 @@ public class OverviewPanel extends Panel implements Runnable, private void mouseAction(MouseEvent evt) { - od.updateViewportFromMouse(evt.getX(), evt.getY()); + od.updateViewportFromMouse(evt.getX(), evt.getY(), av.getAlignment() + .getHiddenSequences(), av.getColumnSelection(), av + .getPosProps()); ap.setScrollValues(od.getScrollCol(), od.getScrollRow()); ap.paintAlignment(false); } @@ -343,7 +345,8 @@ public class OverviewPanel extends Panel implements Runnable, */ public void setBoxPosition() { - od.setBoxPosition(); + od.setBoxPosition(av.getAlignment() + .getHiddenSequences(), av.getColumnSelection(), av.getPosProps()); repaint(); } diff --git a/src/jalview/gui/OverviewPanel.java b/src/jalview/gui/OverviewPanel.java index d15ec40..e399bc1 100755 --- a/src/jalview/gui/OverviewPanel.java +++ b/src/jalview/gui/OverviewPanel.java @@ -95,7 +95,7 @@ public class OverviewPanel extends JPanel implements Runnable { showAnnotation = true; } - od = new OverviewDimensions(av, showAnnotation); + od = new OverviewDimensions(av.getPosProps(), showAnnotation); addComponentListener(new ComponentAdapter() { @@ -119,7 +119,9 @@ public class OverviewPanel extends JPanel implements Runnable { // TODO: feature: jv2.5 detect shift drag and update selection from // it. - od.updateViewportFromMouse(evt.getX(), evt.getY()); + od.updateViewportFromMouse(evt.getX(), evt.getY(), av + .getAlignment().getHiddenSequences(), av + .getColumnSelection(), av.getPosProps()); ap.setScrollValues(od.getScrollCol(), od.getScrollRow()); } } @@ -132,7 +134,9 @@ public class OverviewPanel extends JPanel implements Runnable { if (!av.getWrapAlignment()) { - od.updateViewportFromMouse(evt.getX(), evt.getY()); + od.updateViewportFromMouse(evt.getX(), evt.getY(), av + .getAlignment().getHiddenSequences(), av + .getColumnSelection(), av.getPosProps()); ap.setScrollValues(od.getScrollCol(), od.getScrollRow()); } } @@ -331,7 +335,8 @@ public class OverviewPanel extends JPanel implements Runnable */ public void setBoxPosition() { - od.setBoxPosition(); + od.setBoxPosition(av.getAlignment() + .getHiddenSequences(), av.getColumnSelection(), av.getPosProps()); repaint(); } diff --git a/src/jalview/viewmodel/OverviewDimensions.java b/src/jalview/viewmodel/OverviewDimensions.java index ed9a155..34b7aff 100644 --- a/src/jalview/viewmodel/OverviewDimensions.java +++ b/src/jalview/viewmodel/OverviewDimensions.java @@ -20,7 +20,6 @@ */ package jalview.viewmodel; -import jalview.api.AlignViewportI; import jalview.datamodel.ColumnSelection; import jalview.datamodel.HiddenSequences; @@ -39,10 +38,6 @@ public class OverviewDimensions private static final int MAX_SEQ_HEIGHT = 300; - private AlignViewportI av; - - private ViewportPositionProps posProps; - // width of the overview panel private int width; @@ -65,26 +60,34 @@ public class OverviewDimensions // height of box private int boxHeight = -1; + // scroll position in viewport corresponding to boxX private int scrollCol = -1; + // scroll position in viewport corresponding to boxY private int scrollRow = -1; - public OverviewDimensions(AlignViewportI avi, boolean showAnnotationPanel) + /** + * Create an OverviewDimensions object + * + * @param props + * positional properties of the viewport + * @param showAnnotationPanel + * true if the annotation panel is to be shown, false otherwise + */ + public OverviewDimensions(ViewportPositionProps props, + boolean showAnnotationPanel) { - this.av = avi; - this.posProps = av.getPosProps(); - // scale the initial size of overviewpanel to shape of alignment - float initialScale = (float) posProps.getAlignmentWidthInCols() - / (float) posProps.getAlignmentHeightInRows(); + float initialScale = (float) props.getAbsoluteAlignmentWidth() + / (float) props.getAbsoluteAlignmentHeight(); if (!showAnnotationPanel) { graphHeight = 0; } - if (posProps.getAlignmentWidthInCols() > posProps - .getAlignmentHeightInRows()) + if (props.getAbsoluteAlignmentWidth() > props + .getAbsoluteAlignmentHeight()) { // wider width = MAX_WIDTH; @@ -109,14 +112,27 @@ public class OverviewDimensions /** * Check box dimensions and scroll positions and correct if necessary + * + * @param mousex + * x position in overview panel + * @param mousey + * y position in overview panel + * @param hiddenSeqs + * hidden sequences + * @param hiddenCols + * hidden columns + * @param props + * viewport position properties */ - public void updateViewportFromMouse(int x, int y) + public void updateViewportFromMouse(int mousex, int mousey, + HiddenSequences hiddenSeqs, ColumnSelection hiddenCols, + ViewportPositionProps props) { - int alwidth = av.getAlignment().getWidth(); - int alheight = av.getAlignment().getAbsoluteHeight(); + int x = mousex; + int y = mousey; - HiddenSequences hiddenSeqs = av.getAlignment().getHiddenSequences(); - ColumnSelection hiddenCols = av.getColumnSelection(); + int alwidth = props.getAbsoluteAlignmentWidth(); + int alheight = props.getAbsoluteAlignmentHeight(); if (x < 0) { @@ -148,8 +164,7 @@ public class OverviewDimensions int xAsRes = Math.round((float) x * alwidth / width); // get viewport width in residues - int vpwidth = av.getPosProps().getEndRes() - - av.getPosProps().getStartRes() + 1; + int vpwidth = props.getEndRes() - props.getStartRes() + 1; // get where x should be when accounting for hidden cols // if x is in a hidden col region, shift to left - but we still need @@ -178,8 +193,7 @@ public class OverviewDimensions int yAsSeq = Math.round((float) y * alheight / sequencesHeight); // get viewport height in sequences - int vpheight = av.getPosProps().getEndSeq() - - av.getPosProps().getStartSeq(); + int vpheight = props.getEndSeq() - props.getStartSeq(); // get where y should be when accounting for hidden rows // if y is in a hidden row region, shift up - but we still need absolute @@ -210,23 +224,35 @@ public class OverviewDimensions * Update the overview panel box when the associated alignment panel is * changed * + * @param hiddenSeqs + * hidden sequences + * @param hiddenCols + * hidden columns + * @param props + * viewport position properties */ - public void setBoxPosition() + public void setBoxPosition(HiddenSequences hiddenSeqs, + ColumnSelection hiddenCols, ViewportPositionProps props) { - int alwidth = av.getAlignment().getWidth(); - int alheight = av.getAlignment().getAbsoluteHeight(); + int alwidth = props.getAbsoluteAlignmentWidth(); + int alheight = props.getAbsoluteAlignmentHeight(); - int startRes = av.getPosProps().getAbsoluteStartRes(); - int endRes = av.getPosProps().getAbsoluteEndRes(); + // work with absolute values of startRes and endRes + int startRes = hiddenCols.adjustForHiddenColumns(props.getStartRes()); + int endRes = hiddenCols.adjustForHiddenColumns(props.getEndRes()); - int startSeq = av.getPosProps().getAbsoluteStartSeq(); - int endSeq = av.getPosProps().getAbsoluteEndSeq(); + // work with absolute values of startSeq and endSeq + int startSeq = hiddenSeqs.adjustForHiddenSeqs(props.getStartSeq()); + int endSeq = hiddenSeqs.adjustForHiddenSeqs(props.getEndSeq()); + // 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); + // boxWidth is the width in residues translated to pixels boxWidth = Math .round((float) (endRes - startRes + 1) * width / alwidth); + // boxHeight is the height in sequences translated to pixels boxHeight = Math.round((float) (endSeq - startSeq) * sequencesHeight / alheight); } @@ -280,16 +306,6 @@ public class OverviewDimensions return boxHeight; } - public void setBoxX(int x) - { - boxX = x; - } - - public void setBoxY(int y) - { - boxY = y; - } - public void setWidth(int w) { width = w; diff --git a/src/jalview/viewmodel/ViewportPositionProps.java b/src/jalview/viewmodel/ViewportPositionProps.java index 2789d77..176da8a 100644 --- a/src/jalview/viewmodel/ViewportPositionProps.java +++ b/src/jalview/viewmodel/ViewportPositionProps.java @@ -70,19 +70,19 @@ public class ViewportPositionProps extends ViewportProperties // ways to supply positional information /** - * Get alignment width + * Get alignment width in cols, including hidden cols */ - public int getAlignmentWidthInCols() + public int getAbsoluteAlignmentWidth() { return al.getWidth(); } /** - * Get alignment height + * Get alignment height in rows, including hidden rows */ - public int getAlignmentHeightInRows() + public int getAbsoluteAlignmentHeight() { - return al.getHeight(); + return al.getHeight() + al.getHiddenSequences().getSize(); } public void setStartRes(int res) diff --git a/test/jalview/viewmodel/OverviewDimensionsTest.java b/test/jalview/viewmodel/OverviewDimensionsTest.java index d470c35..be8154c 100644 --- a/test/jalview/viewmodel/OverviewDimensionsTest.java +++ b/test/jalview/viewmodel/OverviewDimensionsTest.java @@ -121,7 +121,7 @@ public class OverviewDimensionsTest { av = af.getViewport(); - od = new OverviewDimensions(av, true); + od = new OverviewDimensions(av.getPosProps(), true); while (av.isCalcInProgress()) { @@ -135,7 +135,8 @@ public class OverviewDimensionsTest { } // Initial box sizing - default path through code - od.setBoxPosition(); + od.setBoxPosition(av.getAlignment() + .getHiddenSequences(), av.getColumnSelection(), av.getPosProps()); init(); } @@ -167,6 +168,7 @@ public class OverviewDimensionsTest { viewWidth = av.getEndRes() - av.getStartRes(); // wait for gui to get set up + // this does actually appear to be necessary while (viewHeight != 17 || viewWidth != 62) { try @@ -232,7 +234,7 @@ public class OverviewDimensionsTest { al1.setDataset(null); AlignViewport av1 = new AlignViewport(al1); - OverviewDimensions od = new OverviewDimensions(av1, true); + OverviewDimensions od = new OverviewDimensions(av1.getPosProps(), true); int scaledHeight = 266; assertEquals(od.getGraphHeight(), defaultGraphHeight); assertEquals(od.getSequencesHeight(), scaledHeight); @@ -245,7 +247,7 @@ public class OverviewDimensionsTest { al2.setDataset(null); AlignViewport av2 = new AlignViewport(al2); - od = new OverviewDimensions(av2, true); + od = new OverviewDimensions(av2.getPosProps(), true); int scaledWidth = 300; assertEquals(od.getGraphHeight(), defaultGraphHeight); assertEquals(od.getSequencesHeight(), maxSeqHeight); @@ -259,7 +261,7 @@ public class OverviewDimensionsTest { al3.setDataset(null); AlignViewport av3 = new AlignViewport(al3); - od = new OverviewDimensions(av3, true); + od = new OverviewDimensions(av3.getPosProps(), true); assertEquals(od.getGraphHeight(), defaultGraphHeight); assertEquals(od.getSequencesHeight(), minSeqHeight); assertEquals(od.getWidth(), maxWidth); @@ -272,7 +274,7 @@ public class OverviewDimensionsTest { al4.setDataset(null); AlignViewport av4 = new AlignViewport(al4); - od = new OverviewDimensions(av4, true); + od = new OverviewDimensions(av4.getPosProps(), true); assertEquals(od.getGraphHeight(), defaultGraphHeight); assertEquals(od.getSequencesHeight(), maxSeqHeight); assertEquals(od.getWidth(), minWidth); @@ -282,7 +284,7 @@ public class OverviewDimensionsTest { al5.setDataset(null); AlignViewport av5 = new AlignViewport(al5); - od = new OverviewDimensions(av5, false); + od = new OverviewDimensions(av5.getPosProps(), false); assertEquals(od.getGraphHeight(), 0); assertEquals(od.getSequencesHeight(), maxSeqHeight); assertEquals(od.getWidth(), minWidth); @@ -302,7 +304,9 @@ public class OverviewDimensionsTest { @Test(groups = { "Functional" }) public void testSetBoxFromMouseClick() { - od.updateViewportFromMouse(0, 0); + od.updateViewportFromMouse(0, 0, + av.getAlignment().getHiddenSequences(), + av.getColumnSelection(), av.getPosProps()); assertEquals(od.getBoxX(), 0); assertEquals(od.getBoxY(), 0); assertEquals(od.getBoxWidth(), boxWidth); @@ -396,7 +400,9 @@ public class OverviewDimensionsTest { @Test(groups = { "Functional" }) public void testFromMouseWithHiddenColsAtStart() { - od.updateViewportFromMouse(0, 0); + od.updateViewportFromMouse(0, 0, + av.getAlignment().getHiddenSequences(), + av.getColumnSelection(), av.getPosProps()); assertEquals(od.getBoxX(), 0); assertEquals(od.getBoxY(), 0); assertEquals(od.getBoxWidth(), boxWidth); @@ -408,7 +414,8 @@ public class OverviewDimensionsTest { int lastHiddenCol = 30; hideColumns(0, lastHiddenCol); - od.setBoxPosition(); + od.setBoxPosition(av.getAlignment() + .getHiddenSequences(), av.getColumnSelection(), av.getPosProps()); assertEquals(od.getBoxX(), Math.round((float) (lastHiddenCol + 1) * od.getWidth() / alwidth)); @@ -460,7 +467,9 @@ public class OverviewDimensionsTest { @Test(groups = { "Functional" }) public void testFromMouseWithHiddenColsInMiddle() { - od.updateViewportFromMouse(0, 0); + od.updateViewportFromMouse(0, 0, + av.getAlignment().getHiddenSequences(), + av.getColumnSelection(), av.getPosProps()); assertEquals(od.getBoxX(), 0); assertEquals(od.getBoxY(), 0); assertEquals(od.getBoxWidth(), boxWidth); @@ -472,7 +481,8 @@ public class OverviewDimensionsTest { int lastHidden = 73; hideColumns(firstHidden, lastHidden); - od.setBoxPosition(); + od.setBoxPosition(av.getAlignment() + .getHiddenSequences(), av.getColumnSelection(), av.getPosProps()); assertEquals(od.getBoxX(), 0); assertEquals(od.getBoxY(), 0); assertEquals(od.getBoxWidth(), boxWidth); @@ -565,7 +575,9 @@ public class OverviewDimensionsTest { @Test(groups = { "Functional" }) public void testFromMouseWithHiddenColsAtEnd() { - od.updateViewportFromMouse(0, 0); + od.updateViewportFromMouse(0, 0, + av.getAlignment().getHiddenSequences(), + av.getColumnSelection(), av.getPosProps()); assertEquals(od.getBoxX(), 0); assertEquals(od.getBoxY(), 0); assertEquals(od.getBoxWidth(), boxWidth); @@ -576,7 +588,8 @@ public class OverviewDimensionsTest { int firstHidden = 140; int lastHidden = 157; hideColumns(firstHidden, lastHidden); - od.setBoxPosition(); + od.setBoxPosition(av.getAlignment() + .getHiddenSequences(), av.getColumnSelection(), av.getPosProps()); assertEquals(od.getBoxX(), 0); assertEquals(od.getBoxY(), 0); assertEquals(od.getBoxWidth(), boxWidth); @@ -909,7 +922,9 @@ public class OverviewDimensionsTest { @Test(groups = { "Functional" }) public void testFromMouseWithHiddenRowsAtStart() { - od.updateViewportFromMouse(0, 0); + od.updateViewportFromMouse(0, 0, + av.getAlignment().getHiddenSequences(), + av.getColumnSelection(), av.getPosProps()); assertEquals(od.getBoxX(), 0); assertEquals(od.getBoxY(), 0); assertEquals(od.getBoxHeight(), boxHeight); @@ -922,7 +937,8 @@ public class OverviewDimensionsTest { int lastHiddenRow = 30; hideSequences(0, lastHiddenRow + 1, lastHiddenRow + 1); - od.setBoxPosition(); + od.setBoxPosition(av.getAlignment() + .getHiddenSequences(), av.getColumnSelection(), av.getPosProps()); assertEquals(od.getBoxX(), 0); assertEquals(od.getBoxY(), Math.round((float) (lastHiddenRow + 1) @@ -955,7 +971,9 @@ public class OverviewDimensionsTest { @Test(groups = { "Functional" }) public void testFromMouseWithHiddenRowsInMiddle() { - od.updateViewportFromMouse(0, 0); + od.updateViewportFromMouse(0, 0, + av.getAlignment().getHiddenSequences(), + av.getColumnSelection(), av.getPosProps()); assertEquals(od.getBoxX(), 0); assertEquals(od.getBoxY(), 0); @@ -970,7 +988,8 @@ public class OverviewDimensionsTest { int lastHiddenRow = 60; hideSequences(firstHiddenRow, lastHiddenRow + 1, lastHiddenRow + 1); - od.setBoxPosition(); + od.setBoxPosition(av.getAlignment() + .getHiddenSequences(), av.getColumnSelection(), av.getPosProps()); assertEquals(od.getBoxX(), 0); assertEquals(od.getBoxY(), 0); @@ -1015,7 +1034,9 @@ public class OverviewDimensionsTest { @Test(groups = { "Functional" }) public void testFromMouseWithHiddenRowsAtEnd() { - od.updateViewportFromMouse(0, 0); + od.updateViewportFromMouse(0, 0, + av.getAlignment().getHiddenSequences(), + av.getColumnSelection(), av.getPosProps()); assertEquals(od.getBoxX(), 0); assertEquals(od.getBoxY(), 0); assertEquals(od.getBoxWidth(), boxWidth); @@ -1029,7 +1050,8 @@ public class OverviewDimensionsTest { int lastHidden = 524; hideSequences(firstHidden - 1, lastHidden, firstHidden - 1); - od.setBoxPosition(); + od.setBoxPosition(av.getAlignment() + .getHiddenSequences(), av.getColumnSelection(), av.getPosProps()); assertEquals(od.getBoxX(), 0); assertEquals(od.getBoxY(), 0); assertEquals(od.getBoxWidth(), boxWidth); @@ -1079,7 +1101,8 @@ public class OverviewDimensionsTest { { av.setStartRes(startRes); av.setEndRes(startRes + viewWidth); - od.setBoxPosition(); + od.setBoxPosition(av.getAlignment() + .getHiddenSequences(), av.getColumnSelection(), av.getPosProps()); } /* @@ -1089,7 +1112,8 @@ public class OverviewDimensionsTest { { av.setStartSeq(startSeq); av.setEndSeq(startSeq + viewHeight); - od.setBoxPosition(); + od.setBoxPosition(av.getAlignment() + .getHiddenSequences(), av.getColumnSelection(), av.getPosProps()); } /* @@ -1101,7 +1125,8 @@ public class OverviewDimensionsTest { av.setEndRes(startRes + viewWidth); av.setStartSeq(startSeq); av.setEndSeq(startSeq + viewHeight); - od.setBoxPosition(); + od.setBoxPosition(av.getAlignment() + .getHiddenSequences(), av.getColumnSelection(), av.getPosProps()); } /* @@ -1109,7 +1134,9 @@ public class OverviewDimensionsTest { */ private void mouseClick(OverviewDimensions od, int x, int y) { - od.updateViewportFromMouse(x, y); + od.updateViewportFromMouse(x, y, + av.getAlignment().getHiddenSequences(), + av.getColumnSelection(), av.getPosProps()); // updates require an OverviewPanel to exist which it doesn't here // so call setBoxPosition() as it would be called by the AlignmentPanel // normally @@ -1119,7 +1146,8 @@ public class OverviewDimensionsTest { av.setEndRes(od.getScrollCol() + viewWidth); av.setStartSeq(od.getScrollRow()); av.setEndSeq(od.getScrollRow() + viewHeight); - od.setBoxPosition(); + od.setBoxPosition(av.getAlignment() + .getHiddenSequences(), av.getColumnSelection(), av.getPosProps()); } private void testBoxIsAtClickPoint(int xpos, int ypos)