JAL-4367 Limit right and top adjustments
[jalview.git] / src / jalview / gui / IdwidthAdjuster.java
index 0ebdfa1..029f184 100755 (executable)
@@ -30,6 +30,7 @@ import java.awt.event.MouseMotionListener;
 import javax.swing.JPanel;
 
 import jalview.api.AlignViewportI;
+import jalview.bin.Cache;
 
 /**
  * DOCUMENT ME!
@@ -131,11 +132,23 @@ public class IdwidthAdjuster extends JPanel
     /*
      * don't drag below minimum width
      */
-    if (newWidth < MIN_ID_WIDTH)
+    if (newWidth < MIN_ID_WIDTH || newWidth > this.ap.getWidth())
     {
       return;
     }
 
+    /*
+     * don't allow residue width to be < 1 in wrapped format
+     */
+    if (viewport.getWrapAlignment())
+    {
+      SeqCanvas sc = ap.getSeqPanel().seqCanvas;
+      if (sc != null && sc.getWrappedCanvasWidth(sc.getWidth() - dif) < 1)
+      {
+        return;
+      }
+    }
+
     oldX = evt.getX();
 
     /*
@@ -145,8 +158,19 @@ public class IdwidthAdjuster extends JPanel
     {
       return;
     }
+
+    // TODO JAL-4260 - work out how to trigger recomputation of wrapped pages !
+    int curCol = viewport.getRanges().getStartRes()
+            + viewport.getRanges().getViewportWidth();
+
     viewport.setIdWidth(newWidth);
+
     ap.validateAnnotationDimensions(false);
+    if (viewport.getWrapAlignment())
+    {
+      viewport.getRanges().scrollToWrappedVisible(
+              curCol - viewport.getRanges().getViewportWidth());
+    }
     ap.paintAlignment(true, false);
 
     ap.getIdPanel().getIdCanvas().setManuallyAdjusted(true);
@@ -154,7 +178,8 @@ public class IdwidthAdjuster extends JPanel
 
   public void setWidth(int newWidth)
   {
-    if (newWidth < MIN_ID_WIDTH)
+    if (newWidth < MIN_ID_WIDTH
+            || ap.getIdPanel().getIdCanvas().isManuallyAdjusted())
     {
       return;
     }
@@ -165,7 +190,7 @@ public class IdwidthAdjuster extends JPanel
 
   public boolean manuallyAdjusted()
   {
-    return ap.getIdPanel().getIdCanvas().manuallyAdjusted();
+    return ap.getIdPanel().getIdCanvas().isManuallyAdjusted();
   }
 
   @Override
@@ -186,8 +211,21 @@ public class IdwidthAdjuster extends JPanel
   @Override
   public void paintComponent(Graphics g)
   {
+    int width = getWidth();
+    int height = getHeight();
     g.setColor(Color.white);
-    g.fillRect(0, 0, getWidth(), getHeight());
+    g.fillRect(0, 0, width, height);
+
+    if (!Cache.getDefault(AnnotationLabels.RESIZE_MARGINS_MARK_PREF, false))
+    // && !ap.getAlignViewport().getWrapAlignment()) // now allowing adjustment
+    // in wrap mode
+    {
+      int spacer = Math.max(2, AnnotationLabels.HEIGHT_ADJUSTER_HEIGHT / 4);
+      g.setColor(Color.LIGHT_GRAY);
+      g.drawLine(width - 3 * spacer, 0, width - 3 * spacer, height / 2);
+      g.drawLine(width - spacer, 0, width - spacer, height / 2);
+    }
+
     setCursor(Cursor.getPredefinedCursor(Cursor.W_RESIZE_CURSOR));
   }
 }