/* * 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.datamodel.AlignmentI; /** * Embryonic class which: Supplies and updates viewport properties relating to * position such as: start and end residues and sequences; ideally will serve * hidden columns/rows too. Intention also to support calculations for * positioning, scrolling etc. such as finding the middle of the viewport, * checking for scrolls off screen */ public class ViewportRanges extends ViewportProperties { // start residue of viewport private int startRes; // end residue of viewport private int endRes; // start sequence of viewport private int startSeq; // end sequence of viewport private int endSeq; // alignment private AlignmentI al; /** * Constructor * * @param alignment * the viewport's alignment */ public ViewportRanges(AlignmentI alignment) { // initial values of viewport settings this.startRes = 0; this.endRes = alignment.getWidth() - 1; this.startSeq = 0; this.endSeq = alignment.getHeight() - 1; this.al = alignment; } /** * Get alignment width in cols, including hidden cols */ public int getAbsoluteAlignmentWidth() { return al.getWidth(); } /** * Get alignment height in rows, including hidden rows */ public int getAbsoluteAlignmentHeight() { return al.getHeight() + al.getHiddenSequences().getSize(); } /** * Set first residue visible in the viewport, and retain the current width. * * @param res * residue position */ public void setStartRes(int res) { int width = getViewportWidth(); setStartEndRes(res, res + width - 1); } public void setStartEndRes(int startres, int endres) { int oldres = this.startRes; if (startres > al.getWidth() - 1) { startres = al.getWidth() - 1; } else if (startres < 0) { startres = 0; } this.startRes = startres; if (endres < 0) { endres = 0; } this.endRes = endres; changeSupport.firePropertyChange("startres", oldres, startres); } /** * Set last residue visible in the viewport * * @param res * residue position */ public void setEndRes(int res) { int width = getViewportWidth(); setStartEndRes(res - width + 1, res); } /** * Set the first sequence visible in the viewport * * @param seq * sequence position */ public void setStartSeq(int seq) { int height = getViewportHeight(); setStartEndSeq(seq, seq + height - 1); } public void setStartEndSeq(int startseq, int endseq) { int oldseq = this.startSeq; if (startseq > al.getHeight() - 1) { startseq = al.getHeight() - 1; } else if (startseq < 0) { startseq = 0; } this.startSeq = startseq; if (endseq >= al.getHeight()) { endseq = al.getHeight() - 1; } else if (endseq < 0) { endseq = 0; } this.endSeq = endseq; changeSupport.firePropertyChange("startseq", oldseq, startseq); } /** * Set the last sequence visible in the viewport * * @param seq * sequence position */ public void setEndSeq(int seq) { int height = getViewportHeight(); setStartEndSeq(seq - height + 1, seq); } /** * Get start residue of viewport */ public int getStartRes() { return startRes; } /** * Get end residue of viewport */ public int getEndRes() { return endRes; } /** * Get start sequence of viewport */ public int getStartSeq() { return startSeq; } /** * Get end sequence of viewport */ public int getEndSeq() { return endSeq; } /** * Get width of viewport in residues * * @return width of viewport */ public int getViewportWidth() { return (endRes - startRes + 1); // TODO get for wrapped alignments too } /** * Get height of viewport in residues * * @return height of viewport */ public int getViewportHeight() { return (endSeq - startSeq + 1); } // return value is true if the scroll is valid public boolean scrollUp(boolean up) { if (up) { if (startSeq < 1) { return false; } setStartSeq(startSeq - 1); } else { if (endSeq >= al.getHeight() - 1) { return false; } setStartSeq(startSeq + 1); } return true; } /** * DOCUMENT ME! * * @param right * DOCUMENT ME! * * @return DOCUMENT ME! */ public boolean scrollRight(boolean right) { if (!right) { if (startRes < 1) { return false; } setStartRes(startRes - 1); } else { if (endRes > al.getWidth() - 1) { return false; } setStartRes(startRes + 1); } return true; } public void scrollToWrappedVisible(int res) { setStartRes(res); } }