Start merging of Laurens Code
[jalview.git] / src / jalview / gui / AnnotationPanel.java
index 8a93f79..60d3e06 100755 (executable)
@@ -26,6 +26,8 @@ import java.util.Hashtable;
 
 import javax.swing.*;
 
+import com.stevesoft.pat.Regex;
+
 import jalview.analysis.AAFrequency;
 import jalview.datamodel.*;
 import jalview.schemes.ColourSchemeI;
@@ -43,6 +45,11 @@ public class AnnotationPanel extends JPanel implements MouseListener,
 
   final String SHEET = "Sheet";
 
+  /**
+   * For RNA secondary structure "stems" aka helices
+   */
+  final String STEM = "RNA Helix";
+
   final String LABEL = "Label";
 
   final String REMOVE = "Remove Annotation";
@@ -53,6 +60,8 @@ public class AnnotationPanel extends JPanel implements MouseListener,
 
   final Color SHEET_COLOUR = Color.green.darker().darker();
 
+  final Color STEM_COLOUR = Color.blue.darker();
+
   /** DOCUMENT ME!! */
   AlignViewport av;
 
@@ -303,6 +312,13 @@ public class AnnotationPanel extends JPanel implements MouseListener,
         symbol = "\u03B2";
       }
 
+      // Added by LML to color stems
+      else if (evt.getActionCommand().equals(STEM))
+      {
+        type = 'S';
+        symbol = "\u03C3";
+      }
+
       if (!aa[activeRow].hasIcons)
       {
         aa[activeRow].hasIcons = true;
@@ -357,14 +373,15 @@ public class AnnotationPanel extends JPanel implements MouseListener,
         continue;
       String tlabel = null;
       if (anot[index] != null)
-      {
+      { // LML added stem code
         if (label2.equals(HELIX) || label2.equals(SHEET)
-                || label2.equals(LABEL))
+                || label2.equals(STEM) || label2.equals(LABEL))
         {
           tlabel = anot[index].description;
           if (tlabel == null || tlabel.length() < 1)
           {
-            if (label2.equals(HELIX) || label2.equals(SHEET))
+            if (label2.equals(HELIX) || label2.equals(SHEET)
+                    || label2.equals(STEM))
             {
               tlabel = "" + anot[index].secondaryStructure;
             }
@@ -443,6 +460,9 @@ public class AnnotationPanel extends JPanel implements MouseListener,
       item = new JMenuItem(SHEET);
       item.addActionListener(this);
       pop.add(item);
+      item = new JMenuItem(STEM);
+      item.addActionListener(this);
+      pop.add(item);
       item = new JMenuItem(LABEL);
       item.addActionListener(this);
       pop.add(item);
@@ -1045,6 +1065,38 @@ public class AnnotationPanel extends JPanel implements MouseListener,
 
               break;
 
+            case 'S': // Stem case for RNA secondary structure
+              g.setColor(STEM_COLOUR); // row.annotations[column].colour for By
+                                       // RNA Helices colouring
+              // System.out.println("last SSX displayx" +
+              // row.annotations[column-1].displayCharacter +"x");
+              Regex closeparen = new Regex("(\\))");
+              
+              //If a closing base pair half of the stem, display a backward arrow
+              if (closeparen
+                      .search(row.annotations[column - 1].displayCharacter))// row.annotations[column-1].displayCharacter))
+              {
+                g.fillPolygon(new int[]
+                { lastSSX + 5, lastSSX + 5, lastSSX },
+                        new int[]
+                        { y + iconOffset, y + 14 + iconOffset,
+                            y + 8 + iconOffset }, 3);
+                g.fillRect(lastSSX + 2, y + 4 + iconOffset,
+                        (x * av.charWidth) - lastSSX - 2, 7);
+              }
+              else //display a forward arrow
+              {
+                g.fillRect(lastSSX, y + 4 + iconOffset, (x * av.charWidth)
+                        - lastSSX - 4, 7);
+                g.fillPolygon(new int[]
+                { (x * av.charWidth) - 5, (x * av.charWidth) - 5,
+                    (x * av.charWidth) },
+                        new int[]
+                        { y + iconOffset, y + 14 + iconOffset,
+                            y + 8 + iconOffset }, 3);
+              }
+              break;
+
             default:
               g.setColor(Color.gray);
               g.fillRect(lastSSX, y + 6 + iconOffset, (x * av.charWidth)