JAL-4476 Reformat secondary structure consensus annotation labels feature/JAL-4476_reformat_ss_consensus_annotation_labels
authorRenia Correya <rcorreya001@dundee.ac.uk>
Tue, 8 Oct 2024 11:45:54 +0000 (12:45 +0100)
committerRenia Correya <rcorreya001@dundee.ac.uk>
Tue, 8 Oct 2024 11:45:54 +0000 (12:45 +0100)
src/jalview/gui/AnnotationLabels.java

index db4e654..df07e91 100755 (executable)
@@ -1620,7 +1620,24 @@ public class AnnotationLabels extends JPanel
               // g.drawLine(20, y + offset, x - 20, y + offset);
 
             }
-            g.drawString(label, x, y + offset);
+            if(label.contains("Secondary Structure Consensus")) {
+              //label.replace("Secondary Structure Consensus", "Secondary Structure Consensus" + "\n");
+              // Split the string into lines using the newline character
+              String[] lines = label.split("(?<=Secondary Structure Consensus)", 2);
+              
+              // Set the starting y position
+              int lineHeight = g.getFontMetrics().getHeight();
+              labelWidth = Math.max(fm.stringWidth(lines[0]), fm.stringWidth(lines[1])) + 3; 
+
+              x = width - labelWidth;
+              for (int k = 0; k < lines.length; k++) {
+                  // Draw each line, offsetting the y position by lineHeight for each line
+                  g.drawString(lines[k].trim(), x, y + offset +(k * lineHeight));
+              }
+            }
+            else {
+              g.drawString(label, x, y + offset);
+            }
           }
         }
         lastSeqRef = aa[i].sequenceRef;