JAL-3438 spotless for 2.11.2.0
[jalview.git] / src / jalview / gui / SequenceRenderer.java
index 0a1e8ef..43fef15 100755 (executable)
@@ -30,6 +30,9 @@ import java.awt.Color;
 import java.awt.FontMetrics;
 import java.awt.Graphics;
 
+import org.jfree.graphics2d.svg.SVGGraphics2D;
+import org.jibble.epsgraphics.EpsGraphics2D;
+
 public class SequenceRenderer implements jalview.api.SequenceRenderer
 {
   final static int CHAR_TO_UPPER = 'A' - 'a';
@@ -97,9 +100,7 @@ public class SequenceRenderer implements jalview.api.SequenceRenderer
   {
     allGroups = av.getAlignment().findAllGroups(seq);
     return resColourFinder.getResidueColour(av.getShowBoxes(),
-            av.getResidueShading(),
-            allGroups, seq, position,
-            finder);
+            av.getResidueShading(), allGroups, seq, position, finder);
   }
 
   /**
@@ -180,15 +181,13 @@ public class SequenceRenderer implements jalview.api.SequenceRenderer
       if (i < length)
       {
         SequenceGroup currentSequenceGroup = resColourFinder
-                .getCurrentSequenceGroup(
-                allGroups, i);
+                .getCurrentSequenceGroup(allGroups, i);
         if (currentSequenceGroup != null)
         {
           if (currentSequenceGroup.getDisplayBoxes())
           {
             resBoxColour = resColourFinder.getBoxColour(
-                    currentSequenceGroup.getGroupColourScheme(), seq,
-                    i);
+                    currentSequenceGroup.getGroupColourScheme(), seq, i);
           }
         }
         else if (av.getShowBoxes())
@@ -254,8 +253,20 @@ public class SequenceRenderer implements jalview.api.SequenceRenderer
     }
     graphics.setColor(av.getTextColour());
 
-    if (monospacedFont && av.getShowText() && allGroups.length == 0
-            && !av.getColourText() && av.getThresholdTextColour() == 0)
+    boolean drawAllText = monospacedFont && av.getShowText()
+            && allGroups.length == 0 && !av.getColourText()
+            && av.getThresholdTextColour() == 0;
+
+    /*
+     * EPS or SVG misaligns monospaced strings (JAL-3239)
+     * so always draw these one character at a time
+     */
+    if (graphics instanceof EpsGraphics2D
+            || graphics instanceof SVGGraphics2D)
+    {
+      drawAllText = false;
+    }
+    if (drawAllText)
     {
       if (av.isRenderGaps())
       {
@@ -289,8 +300,7 @@ public class SequenceRenderer implements jalview.api.SequenceRenderer
         }
 
         SequenceGroup currentSequenceGroup = resColourFinder
-                .getCurrentSequenceGroup(
-                allGroups, i);
+                .getCurrentSequenceGroup(allGroups, i);
         if (currentSequenceGroup != null)
         {
           if (!currentSequenceGroup.getDisplayText())
@@ -303,8 +313,7 @@ public class SequenceRenderer implements jalview.api.SequenceRenderer
           {
             getboxColour = true;
             resBoxColour = resColourFinder.getBoxColour(
-                    currentSequenceGroup.getGroupColourScheme(), seq,
-                    i);
+                    currentSequenceGroup.getGroupColourScheme(), seq, i);
 
             if (currentSequenceGroup.getColourText())
             {
@@ -326,7 +335,8 @@ public class SequenceRenderer implements jalview.api.SequenceRenderer
             graphics.setColor(currentSequenceGroup.textColour);
           }
           boolean isgrep = currentSequenceGroup != null
-                  ? currentSequenceGroup.getSeqrep() == seq : false;
+                  ? currentSequenceGroup.getSeqrep() == seq
+                  : false;
           if (!isarep && !isgrep
                   && currentSequenceGroup.getShowNonconserved()) // todo
                                                                  // optimize
@@ -481,21 +491,30 @@ public class SequenceRenderer implements jalview.api.SequenceRenderer
     }
   }
 
-  public void drawCursor(SequenceI seq, int res, int x1, int y1)
+  /**
+   * Draw a sequence canvas cursor
+   * 
+   * @param g
+   *          graphics context to draw on
+   * @param s
+   *          character to draw at cursor
+   * @param x1
+   *          x position of cursor in graphics context
+   * @param y1
+   *          y position of cursor in graphics context
+   */
+  public void drawCursor(Graphics g, char s, int x1, int y1)
   {
     int pady = av.getCharHeight() / 5;
     int charOffset = 0;
-    graphics.setColor(Color.black);
-    graphics.fillRect(x1, y1, av.getCharWidth(), av.getCharHeight());
+    g.setColor(Color.black);
+    g.fillRect(x1, y1, av.getCharWidth(), av.getCharHeight());
 
     if (av.isValidCharWidth())
     {
-      graphics.setColor(Color.white);
-
-      char s = seq.getCharAt(res);
-
+      g.setColor(Color.white);
       charOffset = (av.getCharWidth() - fm.charWidth(s)) / 2;
-      graphics.drawString(String.valueOf(s), charOffset + x1,
+      g.drawString(String.valueOf(s), charOffset + x1,
               (y1 + av.getCharHeight()) - pady);
     }