@Override
public void mousePressed(MouseEvent evt)
{
- od.setBoxX(evt.getX());
- od.setBoxY(evt.getY());
- checkValid();
+ od.setBoxPositionByMouse(evt.getX(), evt.getY());
+ ap.setScrollValues(od.getScrollCol(), od.getScrollRow());
+ ap.paintAlignment(false);
}
@Override
public void mouseReleased(MouseEvent evt)
{
- od.setBoxX(evt.getX());
- od.setBoxY(evt.getY());
- checkValid();
+ od.setBoxPositionByMouse(evt.getX(), evt.getY());
+ ap.setScrollValues(od.getScrollCol(), od.getScrollRow());
+ ap.paintAlignment(false);
}
@Override
public void mouseDragged(MouseEvent evt)
{
- od.setBoxX(evt.getX());
- od.setBoxY(evt.getY());
- checkValid();
- }
-
- /**
- * Check box dimensions and scroll positions and correct if necessary
- */
- private void checkValid()
- {
- od.checkValid();
+ od.setBoxPositionByMouse(evt.getX(), evt.getY());
ap.setScrollValues(od.getScrollCol(), od.getScrollRow());
ap.paintAlignment(false);
}
{
og.drawImage(miniMe, 0, 0, this);
og.setColor(Color.red);
- og.drawRect(od.getBoxX(), od.getBoxY(), od.getBoxWidth(),
- od.getBoxHeight());
- og.drawRect(od.getBoxX() + 1, od.getBoxY() + 1, od.getBoxWidth() - 2,
- od.getBoxHeight() - 2);
+ od.drawBox(og);
g.drawImage(offscreen, 0, 0, this);
}
}
import javax.swing.JPanel;
/**
- * DOCUMENT ME!
+ * Panel displaying an overview of the full alignment, with an interactive box
+ * representing the viewport onto the alignment.
*
* @author $author$
* @version $Revision$
/**
* Creates a new OverviewPanel object.
*
- * @param ap
+ * @param alPanel
* The alignment panel which is shown in the overview panel
*/
- public OverviewPanel(AlignmentPanel ap)
+ public OverviewPanel(AlignmentPanel alPanel)
{
- this.av = ap.av;
- this.ap = ap;
+ this.av = alPanel.av;
+ this.ap = alPanel;
setLayout(null);
sr = new SequenceRenderer(av);
sr.renderGaps = false;
sr.forOverview = true;
- fr = new FeatureRenderer(ap);
+ fr = new FeatureRenderer(alPanel);
od = new OverviewDimensions(av);
{
// TODO: feature: jv2.5 detect shift drag and update selection from
// it.
- od.setBoxX(evt.getX());
- od.setBoxY(evt.getY());
- checkValid();
+ od.setBoxPositionByMouse(evt.getX(), evt.getY());
+ ap.setScrollValues(od.getScrollCol(), od.getScrollRow());
}
}
});
{
if (!av.getWrapAlignment())
{
- od.setBoxX(evt.getX());
- od.setBoxY(evt.getY());
- checkValid();
+ od.setBoxPositionByMouse(evt.getX(), evt.getY());
+ ap.setScrollValues(od.getScrollCol(), od.getScrollRow());
}
}
});
}
/**
- * Check box dimensions and scroll positions and correct if necessary
- */
- private void checkValid()
- {
- od.checkValid();
- ap.setScrollValues(od.getScrollCol(), od.getScrollRow());
-
- }
-
- /**
* Updates the overview image when the related alignment panel is updated
*/
public void updateOverviewImage()
}
// TODO: render selected regions
g.setColor(Color.red);
- g.drawRect(od.getBoxX(), od.getBoxY(), od.getBoxWidth(),
- od.getBoxHeight());
- g.drawRect(od.getBoxX() + 1, od.getBoxY() + 1, od.getBoxWidth() - 2,
- od.getBoxHeight() - 2);
+ od.drawBox(g);
}
}
import jalview.api.AlignViewportI;
+import java.awt.Graphics;
+
public class OverviewDimensions
{
// Default width and height values
/**
* Check box dimensions and scroll positions and correct if necessary
*/
- public void checkValid()
+ public void setBoxPositionByMouse(int x, int y)
{
+ boxX = x;
+ boxY = y;
if (boxY < 0)
{
boxY = 0;
}
-
- if (boxY > (sequencesHeight - boxHeight))
+ else if (boxY > (sequencesHeight - boxHeight))
{
boxY = sequencesHeight - boxHeight + 1;
}
{
boxX = 0;
}
-
- if (boxX > (width - boxWidth))
+ else if (boxX > (width - boxWidth))
{
if (av.hasHiddenColumns())
{
endSeq = av.getAlignment().getHiddenSequences()
.adjustForHiddenSeqs(endSeq);
-
}
boxX = (int) (startRes * av.getCharWidth() * scalew);
boxY = (int) (startSeq * av.getCharHeight() * scaleh);
- if (av.hasHiddenColumns())
- {
- boxWidth = (int) ((endRes - startRes + 1) * av.getCharWidth() * scalew);
- }
- else
- {
- boxWidth = (int) ((endRes - startRes + 1) * av.getCharWidth() * scalew);
- }
-
+ boxWidth = (int) ((endRes - startRes + 1) * av.getCharWidth() * scalew);
boxHeight = (int) ((endSeq - startSeq) * av.getCharHeight() * scaleh);
}
scaleh = (float) sequencesHeight / fullsizeHeight;
}
+ /**
+ * Draw the overview panel's viewport box on a graphics object
+ *
+ * @param g
+ * the graphics object to draw on
+ */
+ public void drawBox(Graphics g)
+ {
+ 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
public int getScrollCol()
{
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;
@Test(groups = { "Functional" })
public void testSetBoxFromMouseClick()
{
- od.checkValid();
+ od.setBoxPositionByMouse(0, 0);
assertEquals(od.getBoxX(), 0);
assertEquals(od.getBoxY(), 0);
assertEquals(od.getBoxWidth(), boxWidth);
@Test(groups = { "Functional" })
public void testFromMouseWithHiddenColsAtStart()
{
- od.checkValid();
+ od.setBoxPositionByMouse(0, 0);
assertEquals(od.getBoxX(), 0);
assertEquals(od.getBoxY(), 0);
assertEquals(od.getBoxWidth(), boxWidth);
@Test(groups = { "Functional" })
public void testFromMouseWithHiddenColsInMiddle()
{
- od.checkValid();
+ od.setBoxPositionByMouse(0, 0);
assertEquals(od.getBoxX(), 0);
assertEquals(od.getBoxY(), 0);
assertEquals(od.getBoxWidth(), boxWidth);
@Test(groups = { "Functional" })
public void testFromMouseWithHiddenColsAtEnd()
{
- od.checkValid();
+ od.setBoxPositionByMouse(0, 0);
assertEquals(od.getBoxX(), 0);
assertEquals(od.getBoxY(), 0);
assertEquals(od.getBoxWidth(), boxWidth);
@Test(groups = { "Functional" })
public void testFromMouseWithHiddenRowsAtStart()
{
- od.checkValid();
+ od.setBoxPositionByMouse(0, 0);
assertEquals(od.getBoxX(), 0);
assertEquals(od.getBoxY(), 0);
assertEquals(od.getBoxWidth(), boxWidth);
@Test(groups = { "Functional" })
public void testFromMouseWithHiddenRowsInMiddle()
{
- od.checkValid();
+ od.setBoxPositionByMouse(0, 0);
assertEquals(od.getBoxX(), 0);
assertEquals(od.getBoxY(), 0);
assertEquals(od.getBoxWidth(), boxWidth);
@Test(groups = { "Functional" })
public void testFromMouseWithHiddenRowsAtEnd()
{
- od.checkValid();
+ od.setBoxPositionByMouse(0, 0);
assertEquals(od.getBoxX(), 0);
assertEquals(od.getBoxY(), 0);
assertEquals(od.getBoxWidth(), boxWidth);
*/
private void mouseClick(OverviewDimensions od, int x, int y)
{
- od.setBoxX(x);
- od.setBoxY(y);
- od.checkValid();
+ od.setBoxPositionByMouse(x, y);
// updates require an OverviewPanel to exist which it doesn't here
// so call setBoxPosition() as it would be called by the AlignmentPanel
// normally