--- /dev/null
+/*
+ * 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 <http://www.gnu.org/licenses/>.
+ * 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
+ *
+ * @param res
+ * residue position
+ */
+ public void setStartRes(int res)
+ {
+ if (res > al.getWidth() - 1)
+ {
+ res = al.getWidth() - 1;
+ }
+ else if (res < 0)
+ {
+ res = 0;
+ }
+ this.startRes = res;
+ }
+
+ /**
+ * Set last residue visible in the viewport
+ *
+ * @param res
+ * residue position
+ */
+ public void setEndRes(int res)
+ {
+ if (res >= al.getWidth())
+ {
+ res = al.getWidth() - 1;
+ }
+ else if (res < 0)
+ {
+ res = 0;
+ }
+ this.endRes = res;
+ }
+
+ /**
+ * Set the first sequence visible in the viewport
+ *
+ * @param seq
+ * sequence position
+ */
+ public void setStartSeq(int seq)
+ {
+ if (seq > al.getHeight() - 1)
+ {
+ seq = al.getHeight() - 1;
+ }
+ else if (seq < 0)
+ {
+ seq = 0;
+ }
+ this.startSeq = seq;
+ }
+
+ /**
+ * Set the last sequence visible in the viewport
+ *
+ * @param seq
+ * sequence position
+ */
+ public void setEndSeq(int seq)
+ {
+ if (seq >= al.getHeight())
+ {
+ seq = al.getHeight() - 1;
+ }
+ 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;
+ }
+}