/* * 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.ViewStyleI; import jalview.datamodel.AlignmentI; /** * Supplies and updates viewport properties relating to position such as: start * and end residues and sequences, hidden column/row adjustments, ratio of * viewport to alignment etc */ public class ViewportPositionProps 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; // character height private int charHeight; // character width private int charWidth; // alignment private AlignmentI al; // viewstyle private ViewStyleI viewstyle; /** * Constructor * @param alignment TODO */ public ViewportPositionProps(AlignmentI alignment, ViewStyleI vstyle) { // initial values of viewport settings this.startRes = 0; this.endRes = alignment.getWidth() - 1; this.startSeq = 0; this.endSeq = alignment.getHeight() - 1; this.al = alignment; this.viewstyle = vstyle; } public void setCharHeight(int h) { viewstyle.setCharHeight(h); } public void setCharWidth(int w) { viewstyle.setCharWidth(w); } // ways to update values // ways to notify of changes // ways to supply positional information /** * Get alignment width */ public int getAlignmentWidthInCols() { return al.getWidth(); } /** * Get alignment height */ public int getAlignmentHeightInRows() { return al.getHeight(); } public void setStartRes(int res) { if (res > al.getWidth() - 1) { res = al.getWidth() - 1; } else if (res < 0) { res = 0; } this.startRes = res; } public void setEndRes(int res) { if (res > al.getWidth() - 1) { res = al.getWidth() - 1; } else if (res < 0) { res = 0; } this.endRes = res; } public void setStartSeq(int seq) { if (seq > al.getHeight()) { seq = al.getHeight(); } else if (seq < 0) { seq = 0; } this.startSeq = seq; } public void setEndSeq(int seq) { if (seq > al.getHeight()) { seq = al.getHeight(); } else if (seq < 0) { seq = 0; } this.endSeq = 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 start residue of viewport */ public int getStartRes(boolean countHidden) { if (countHidden) { return 0; // av.getColumnSelection().adjustForHiddenColumns(startRes); } else { return startRes; } } /** * Convert distance x in viewport pixels to a distance in number of residues * * @param x * number of pixels * @return number of residues */ public int convertPixelsToResidues(int x) { return Math.round((float) x / viewstyle.getCharWidth()); // return (int) ((float) x / viewstyle.getCharWidth()); } /** * Convert distance y in viewport pixels to a distance in number of sequences * * @param y * number of pixels * @return number of sequences */ public int convertPixelsToSequences(int y) { return Math.round((float) y / viewstyle.getCharHeight()); // return (int) ((float) y / viewstyle.getCharHeight()); } /** * Convert number of sequences s to a height in viewport pixels * * @param s * number of sequences * @return number of pixels */ public int convertSequencesToPixels(int s) { return (s * viewstyle.getCharHeight()); } /** * Convert number of residues r to a width in viewport pixels * * @param r * number of residues * @return number of pixels */ public int convertResiduesToPixels(int r) { return (r * viewstyle.getCharWidth()); } }