JAL-2600 updates following review
[jalview.git] / src / jalview / viewmodel / ViewportRanges.java
index 743d212..c2bcf3f 100644 (file)
@@ -32,6 +32,14 @@ import jalview.datamodel.HiddenColumns;
  */
 public class ViewportRanges extends ViewportProperties
 {
+  public static final String STARTRES = "startres";
+
+  public static final String ENDRES = "endres";
+
+  public static final String STARTSEQ = "startseq";
+
+  public static final String ENDSEQ = "endseq";
+
   // start residue of viewport
   private int startRes;
 
@@ -123,7 +131,7 @@ public class ViewportRanges extends ViewportProperties
     int oldstartres = this.startRes;
     if (start > getVisibleAlignmentWidth() - 1)
     {
-      startRes = getVisibleAlignmentWidth() - 1;
+      startRes = Math.max(getVisibleAlignmentWidth() - 1, 0);
     }
     else if (start < 0)
     {
@@ -141,19 +149,19 @@ public class ViewportRanges extends ViewportProperties
     }
     else if (end > getVisibleAlignmentWidth() - 1)
     {
-      endRes = getVisibleAlignmentWidth() - 1;
+      endRes = Math.max(getVisibleAlignmentWidth() - 1, 0);
     }
     else
     {
       endRes = end;
     }
 
-    changeSupport.firePropertyChange("startres", oldstartres, startRes);
+    changeSupport.firePropertyChange(STARTRES, oldstartres, startRes);
     if (oldstartres == startRes)
     {
       // event won't be fired if start positions are same
       // fire an event for the end positions in case they changed
-      changeSupport.firePropertyChange("endres", oldendres, endRes);
+      changeSupport.firePropertyChange(ENDRES, oldendres, endRes);
     }
   }
 
@@ -208,7 +216,7 @@ public class ViewportRanges extends ViewportProperties
     int oldstartseq = this.startSeq;
     if (start > getVisibleAlignmentHeight() - 1)
     {
-      startSeq = getVisibleAlignmentHeight() - 1;
+      startSeq = Math.max(getVisibleAlignmentHeight() - 1, 0);
     }
     else if (start < 0)
     {
@@ -222,7 +230,7 @@ public class ViewportRanges extends ViewportProperties
     int oldendseq = this.endSeq;
     if (end >= getVisibleAlignmentHeight())
     {
-      endSeq = getVisibleAlignmentHeight() - 1;
+      endSeq = Math.max(getVisibleAlignmentHeight() - 1, 0);
     }
     else if (end < 0)
     {
@@ -233,12 +241,12 @@ public class ViewportRanges extends ViewportProperties
       endSeq = end;
     }
 
-    changeSupport.firePropertyChange("startseq", oldstartseq, startSeq);
+    changeSupport.firePropertyChange(STARTSEQ, oldstartseq, startSeq);
     if (oldstartseq == startSeq)
     {
       // event won't be fired if start positions are the same
       // fire in case the end positions changed
-      changeSupport.firePropertyChange("endseq", oldendseq, endSeq);
+      changeSupport.firePropertyChange(ENDSEQ, oldendseq, endSeq);
     }
   }