JAL-244 Added light grey marks to indicate regions to resize the margins
[jalview.git] / src / jalview / gui / AnnotationLabels.java
index c4a40d8..6006026 100755 (executable)
@@ -88,7 +88,7 @@ public class AnnotationLabels extends JPanel
   /**
    * height in pixels for allowing height adjuster to be active
    */
-  private static int HEIGHT_ADJUSTER_HEIGHT = 10;
+  public static int HEIGHT_ADJUSTER_HEIGHT = 10;
 
   private static final Font font = new Font("Arial", Font.PLAIN, 11);
 
@@ -138,6 +138,8 @@ public class AnnotationLabels extends JPanel
 
   private int annotationIdWidth = -1;
 
+  public static final String RESIZE_MARGINS_MARK_PREF = "RESIZE_MARGINS_MARK";
+
   /**
    * Creates a new AnnotationLabels object
    * 
@@ -1167,7 +1169,6 @@ public class AnnotationLabels extends JPanel
     }
 
     drawComponent(g2, true, width);
-
   }
 
   /**
@@ -1218,7 +1219,13 @@ public class AnnotationLabels extends JPanel
         {
           // If no manual adjustment to ID column with has been made then adjust
           // width match widest of alignment or annotation id widths
+          boolean allowShrink = Cache.getDefault("ALLOW_SHRINK_ID_WIDTH",
+                  false);
           width = Math.max(alignmentIdWidth, newAnnotationIdWidth);
+          if (clip && width < givenWidth && !allowShrink)
+          {
+            width = givenWidth;
+          }
         }
         else if (newAnnotationIdWidth != annotationIdWidth
                 && newAnnotationIdWidth > givenWidth
@@ -1238,10 +1245,7 @@ public class AnnotationLabels extends JPanel
     }
     else
     {
-      Graphics2D g2d = (Graphics2D) g;
-      Graphics dummy = g2d.create();
-      int newAnnotationIdWidth = drawLabels(dummy, clip, width, false,
-              null);
+      int newAnnotationIdWidth = drawLabels(g, clip, width, false, null);
       width = Math.max(newAnnotationIdWidth, givenWidth);
     }
     drawLabels(g, clip, width, true, null);
@@ -1265,9 +1269,28 @@ public class AnnotationLabels extends JPanel
    * @param fmetrics
    *          FontMetrics if Graphics object g is null
    */
-  public int drawLabels(Graphics g, boolean clip, int width,
+  public int drawLabels(Graphics g0, boolean clip, int width,
           boolean actuallyDraw, FontMetrics fmetrics)
   {
+    if (clip)
+    {
+      clip = Cache.getDefault("MOVE_SEQUENCE_ID_WITH_VISIBLE_ANNOTATIONS",
+              true);
+    }
+    Graphics g = null;
+    // create a dummy Graphics object if not drawing and one is supplied
+    if (g0 != null)
+    {
+      if (!actuallyDraw)
+      {
+        Graphics2D g2d = (Graphics2D) g0;
+        g = g2d.create();
+      }
+      else
+      {
+        g = g0;
+      }
+    }
     int actualWidth = 0;
     if (g != null)
     {
@@ -1287,6 +1310,17 @@ public class AnnotationLabels extends JPanel
     {
       g.setColor(Color.white);
       g.fillRect(0, 0, getWidth(), getHeight());
+
+      if (!Cache.getDefault(RESIZE_MARGINS_MARK_PREF, false)
+              && !av.getWrapAlignment())
+      {
+        g.setColor(Color.LIGHT_GRAY);
+        g.drawLine(0, HEIGHT_ADJUSTER_HEIGHT / 4, HEIGHT_ADJUSTER_WIDTH / 4,
+                HEIGHT_ADJUSTER_HEIGHT / 4);
+        g.drawLine(0, 3 * HEIGHT_ADJUSTER_HEIGHT / 4,
+                HEIGHT_ADJUSTER_WIDTH / 4, 3 * HEIGHT_ADJUSTER_HEIGHT / 4);
+
+      }
     }
 
     if (actuallyDraw)