/* * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$) * Copyright (C) $$Year-Rel$$ The Jalview Authors * * This file is part of Jalview. * * Jalview is free software: you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation, either version 3 * of the License, or (at your option) any later version. * * Jalview is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty * of MERCHANTABILITY or FITNESS FOR A PARTICULAR * PURPOSE. See the GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with Jalview. If not, see . * The Jalview Authors are detailed in the 'AUTHORS' file. */ package jalview.viewmodel; import jalview.api.AlignViewportI; import jalview.datamodel.ColumnSelection; import jalview.datamodel.HiddenSequences; import java.awt.Graphics; public class OverviewDimensions { // Default width and height values private static final int DEFAULT_GRAPH_HEIGHT = 20; private static final int MAX_WIDTH = 400; private static final int MIN_WIDTH = 120; private static final int MIN_SEQ_HEIGHT = 40; private static final int MAX_SEQ_HEIGHT = 300; private AlignViewportI av; private ViewportPositionProps posProps; // width of the overview panel private int width; // height of sequences part of the overview panel private int sequencesHeight; // height of the graphs part of the overview panel private int graphHeight = DEFAULT_GRAPH_HEIGHT; // dimensions of box outlining current extent of view in alignment panel // location of left side of box private int boxX = -1; // location of bottom of box private int boxY = -1; // width of box private int boxWidth = -1; // height of box private int boxHeight = -1; private int scrollCol = -1; private int scrollRow = -1; public OverviewDimensions(AlignViewportI avi, 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(); if (!showAnnotationPanel) { graphHeight = 0; } if (posProps.getAlignmentWidthInCols() > posProps .getAlignmentHeightInRows()) { // wider width = MAX_WIDTH; sequencesHeight = (int) (MAX_WIDTH / initialScale); if (sequencesHeight < MIN_SEQ_HEIGHT) { sequencesHeight = MIN_SEQ_HEIGHT; } } else { // taller width = (int) (MAX_WIDTH * initialScale); sequencesHeight = MAX_SEQ_HEIGHT; if (width < MIN_WIDTH) { width = MIN_WIDTH; } } } /** * Check box dimensions and scroll positions and correct if necessary */ public void updateViewportFromMouse(int x, int y) { int alwidth = av.getAlignment().getWidth(); int alheight = av.getAlignment().getAbsoluteHeight(); HiddenSequences hiddenSeqs = av.getAlignment().getHiddenSequences(); ColumnSelection hiddenCols = av.getColumnSelection(); if (x < 0) { x = 0; } else if (x >= alwidth) { x = alwidth - 1; } if (y < 0) { y = 0; } else if (y >= alheight) { y = alheight - 1; } // // Convert x value to residue position // // need to determine where scrollCol should be, given x // to do this also need to know width of viewport, and some hidden column // correction // convert x to residues - this is an absolute position int xAsRes = Math.round((float) x * alwidth / width); // get viewport width in residues int vpwidth = av.getPosProps().getEndRes() - av.getPosProps().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 // absolute position // so convert back after getting visible region position xAsRes = hiddenCols.adjustForHiddenColumns(hiddenCols .findColumnPosition(xAsRes)); // get where end res should be by adding the viewport width on int endRes = xAsRes + vpwidth; // check in case we went off the edge of the alignment if (endRes > alwidth) { // went past the end of the alignment, adjust backwards endRes = alwidth; // recalc xAsRes backwards from endRes xAsRes = endRes - vpwidth; } // // Convert y value to sequence position // // convert y to residues int yAsSeq = Math.round((float) y * alheight / sequencesHeight); // get viewport height in sequences int vpheight = av.getPosProps().getEndSeq() - av.getPosProps().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 // position, // so convert back after getting visible region position yAsSeq = hiddenSeqs.adjustForHiddenSeqs(hiddenSeqs .findIndexWithoutHiddenSeqs(yAsSeq)); // get where end seq should be by adding the viewport height on int endSeq = yAsSeq + vpheight; // check in case we went off the edge of the alignment if (endSeq > alheight) { // went past the end of the alignment, adjust backwards endSeq = alheight; // recalc yAsSeq backwards from endSeq yAsSeq = endSeq - vpheight; } // convert absolute positions back to visible alignment positions for // viewport scrolling scrollCol = hiddenCols.findColumnPosition(xAsRes); scrollRow = hiddenSeqs.findIndexWithoutHiddenSeqs(yAsSeq); } /** * Update the overview panel box when the associated alignment panel is * changed * */ public void setBoxPosition() { int alwidth = av.getAlignment().getWidth(); int alheight = av.getAlignment().getAbsoluteHeight(); int startRes = av.getPosProps().getAbsoluteStartRes(); int endRes = av.getPosProps().getAbsoluteEndRes(); int startSeq = av.getPosProps().getAbsoluteStartSeq(); int endSeq = av.getPosProps().getAbsoluteEndSeq(); boxX = Math.round((float) startRes * width / alwidth); boxY = Math.round((float) startSeq * sequencesHeight / alheight); boxWidth = Math .round((float) (endRes - startRes + 1) * width / alwidth); boxHeight = Math.round((float) (endSeq - startSeq) * sequencesHeight / alheight); } /** * 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 scrollCol; } public int getScrollRow() { 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; } // TODO should be removed, when unit test has mock Graphics object available public int getBoxWidth() { return boxWidth; } // TODO should be removed, when unit test has mock Graphics object available public int getBoxHeight() { return boxHeight; } public void setBoxX(int x) { boxX = x; } public void setBoxY(int y) { boxY = y; } public void setWidth(int w) { width = w; } public void setHeight(int h) { sequencesHeight = h - graphHeight; } public int getWidth() { return width; } public int getHeight() { return sequencesHeight + graphHeight; } public int getSequencesHeight() { return sequencesHeight; } public int getGraphHeight() { return graphHeight; } }