get annotation by label string
[jalview.git] / src / jalview / appletgui / SequenceRenderer.java
index 9103c1d..daf971d 100755 (executable)
@@ -1,6 +1,6 @@
 /*\r
  * Jalview - A Sequence Alignment Editor and Viewer\r
- * Copyright (C) 2005 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle\r
+ * Copyright (C) 2007 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle\r
  *\r
  * This program is free software; you can redistribute it and/or\r
  * modify it under the terms of the GNU General Public License\r
@@ -47,11 +47,11 @@ public class SequenceRenderer
    */\r
   public void prepare(Graphics g, boolean renderGaps)\r
   {\r
-      graphics = g;\r
-      fm = g.getFontMetrics();\r
+    graphics = g;\r
+    fm = g.getFontMetrics();\r
 \r
-      this.renderGaps = renderGaps;\r
-    }\r
+    this.renderGaps = renderGaps;\r
+  }\r
 \r
   public Color getResidueBoxColour(SequenceI seq, int i)\r
   {\r
@@ -66,21 +66,21 @@ public class SequenceRenderer
     }\r
     else if (av.getShowBoxes())\r
     {\r
-        getBoxColour(av.globalColourScheme, seq, i);\r
+      getBoxColour(av.globalColourScheme, seq, i);\r
     }\r
 \r
     return resBoxColour;\r
-    }\r
+  }\r
 \r
   void getBoxColour(ColourSchemeI cs, SequenceI seq, int i)\r
   {\r
     if (cs != null)\r
     {\r
-      resBoxColour = cs.findColour(seq.getSequence(i, i + 1), i);\r
+      resBoxColour = cs.findColour(seq.getCharAt(i), i);\r
     }\r
-    else if(forOverview && !jalview.util.Comparison.isGap(seq.getCharAt(i)))\r
+    else if (forOverview && !jalview.util.Comparison.isGap(seq.getCharAt(i)))\r
     {\r
-        resBoxColour = Color.lightGray;\r
+      resBoxColour = Color.lightGray;\r
     }\r
     else\r
     {\r
@@ -92,24 +92,29 @@ public class SequenceRenderer
   public Color findSequenceColour(SequenceI seq, int i)\r
   {\r
     allGroups = av.alignment.findAllGroups(seq);\r
-    drawBoxes(seq, i,i, 0);\r
+    drawBoxes(seq, i, i, 0);\r
     return resBoxColour;\r
   }\r
 \r
   public void drawSequence(SequenceI seq, SequenceGroup[] sg,\r
-                           int start, int end,  int y1)\r
+                           int start, int end, int y1)\r
   {\r
+    if (seq == null)\r
+    {\r
+      return;\r
+    }\r
+\r
     allGroups = sg;\r
 \r
-    drawBoxes(seq, start, end,  y1);\r
+    drawBoxes(seq, start, end, y1);\r
 \r
-    if(av.validCharWidth)\r
+    if (av.validCharWidth)\r
     {\r
       drawText(seq, start, end, y1);\r
     }\r
   }\r
 \r
-  public void drawBoxes(SequenceI seq, int start, int end,  int y1)\r
+  public void drawBoxes(SequenceI seq, int start, int end, int y1)\r
   {\r
     int i = start;\r
     int length = seq.getLength();\r
@@ -121,7 +126,7 @@ public class SequenceRenderer
     while (i <= end)\r
     {\r
       resBoxColour = Color.white;\r
-      if(i < length)\r
+      if (i < length)\r
       {\r
         if (inCurrentSequenceGroup(i))\r
         {\r
@@ -136,7 +141,6 @@ public class SequenceRenderer
         }\r
       }\r
 \r
-\r
       if (resBoxColour != tempColour)\r
       {\r
         if (tempColour != null)\r
@@ -159,19 +163,30 @@ public class SequenceRenderer
       i++;\r
     }\r
 \r
-    graphics.fillRect(av.charWidth * (curStart - start), y1, curWidth, av.charHeight);\r
+    graphics.fillRect(av.charWidth * (curStart - start), y1, curWidth,\r
+                      av.charHeight);\r
   }\r
 \r
   public void drawText(SequenceI seq, int start, int end, int y1)\r
   {\r
+    Font boldFont = null;\r
+    boolean bold = false;\r
+    if (av.upperCasebold)\r
+    {\r
+      boldFont = new Font(av.getFont().getName(), Font.BOLD, av.charHeight);\r
 \r
-    y1 += av.charHeight - av.charHeight / 5;  // height/5 replaces pady\r
+      graphics.setFont(av.getFont());\r
+    }\r
+\r
+    y1 += av.charHeight - av.charHeight / 5; // height/5 replaces pady\r
 \r
     int charOffset = 0;\r
 \r
     // Need to find the sequence position here.\r
-    if(end+1>=seq.getLength())\r
-          end = seq.getLength()-1;\r
+    if (end + 1 >= seq.getLength())\r
+    {\r
+      end = seq.getLength() - 1;\r
+    }\r
 \r
     char s = ' ';\r
 \r
@@ -219,10 +234,30 @@ public class SequenceRenderer
         }\r
       }\r
 \r
+      if (av.upperCasebold)\r
+      {\r
+        fm = graphics.getFontMetrics();\r
+        if ('A' <= s && s <= 'Z')\r
+        {\r
+          if (!bold)\r
+          {\r
+\r
+            graphics.setFont(boldFont);\r
+          }\r
+          bold = true;\r
+        }\r
+        else if (bold)\r
+        {\r
+          graphics.setFont(av.font);\r
+          bold = false;\r
+        }\r
+\r
+      }\r
+\r
       charOffset = (av.charWidth - fm.charWidth(s)) / 2;\r
       graphics.drawString(String.valueOf(s),\r
-                         charOffset + av.charWidth * (i - start),\r
-                        y1 );\r
+                          charOffset + av.charWidth * (i - start),\r
+                          y1);\r
     }\r
 \r
   }\r
@@ -246,7 +281,8 @@ public class SequenceRenderer
     return false;\r
   }\r
 \r
-  public void drawHighlightedText(SequenceI seq, int start, int end, int x1, int y1)\r
+  public void drawHighlightedText(SequenceI seq, int start, int end, int x1,\r
+                                  int y1)\r
   {\r
     int pady = av.charHeight / 5;\r
     int charOffset = 0;\r
@@ -256,13 +292,13 @@ public class SequenceRenderer
 \r
     char s = '~';\r
     // Need to find the sequence position here.\r
-    if(av.validCharWidth)\r
+    if (av.validCharWidth)\r
     {\r
       for (int i = start; i <= end; i++)\r
       {\r
         if (i < seq.getLength())\r
         {\r
-          s = seq.getSequence().charAt(i);\r
+          s = seq.getCharAt(i);\r
         }\r
 \r
         charOffset = (av.charWidth - fm.charWidth(s)) / 2;\r
@@ -292,6 +328,6 @@ public class SequenceRenderer
                           charOffset + x1,\r
                           (y1 + av.charHeight) - pady);\r
     }\r
-    }\r
+  }\r
 \r
 }\r