Alignment Annotation added
authoramwaterhouse <Andrew Waterhouse>
Fri, 1 Apr 2005 16:46:10 +0000 (16:46 +0000)
committeramwaterhouse <Andrew Waterhouse>
Fri, 1 Apr 2005 16:46:10 +0000 (16:46 +0000)
14 files changed:
src/jalview/datamodel/Alignment.java
src/jalview/datamodel/AlignmentAnnotation.java [new file with mode: 0755]
src/jalview/datamodel/AlignmentI.java
src/jalview/datamodel/Annotation.java [new file with mode: 0755]
src/jalview/gui/AlignFrame.java
src/jalview/gui/AlignViewport.java
src/jalview/gui/AlignmentPanel.java
src/jalview/gui/AnnotationLabels.java [new file with mode: 0755]
src/jalview/gui/AnnotationPanel.java [new file with mode: 0755]
src/jalview/gui/ColumnSelection.java
src/jalview/gui/ScorePanel.java [deleted file]
src/jalview/gui/SecondaryStructurePanel.java [deleted file]
src/jalview/jbgui/GAlignFrame.java
src/jalview/jbgui/GAlignmentPanel.java

index 5adb70d..10e2766 100755 (executable)
@@ -13,6 +13,9 @@ public class Alignment implements AlignmentI
   protected Vector      groups = new Vector();\r
   protected ArrayList   superGroup = new ArrayList();\r
   protected char        gapCharacter = '-';\r
+  public AlignmentAnnotation [] annotations;\r
+  public Conservation conservation;\r
+\r
   public boolean featuresAdded = false;\r
 \r
   /** Make an alignment from an array of Sequences.\r
@@ -504,8 +507,52 @@ public class Alignment implements AlignmentI
         return false;\r
 \r
     return true;\r
+  }\r
+\r
+   public void deleteAnnotation(AlignmentAnnotation aa)\r
+   {\r
+     int aSize = 1;\r
+     if(annotations!=null)\r
+       aSize = annotations.length;\r
+\r
+     AlignmentAnnotation [] temp = new AlignmentAnnotation [aSize-1];\r
+\r
+     int tIndex = 0;\r
+     for (int i = 0; i < aSize; i++)\r
+      {\r
+        if(annotations[i]==aa)\r
+          continue;\r
+\r
+\r
+        temp[tIndex] = annotations[i];\r
+        tIndex++;\r
+      }\r
+\r
+     annotations = temp;\r
 \r
+   }\r
+\r
+  public void addAnnotation(AlignmentAnnotation aa)\r
+  {\r
+    int aSize = 1;\r
+    if(annotations!=null)\r
+      aSize = annotations.length+1;\r
+\r
+    AlignmentAnnotation [] temp = new AlignmentAnnotation [aSize];\r
+    int i=0;\r
+    if (aSize > 1)\r
+      for (i = 0; i < aSize-1; i++)\r
+        temp[i] = annotations[i];\r
+\r
+    temp[i] = aa;\r
+\r
+    annotations = temp;\r
   }\r
+  public AlignmentAnnotation[] getAlignmentAnnotation()\r
+  {\r
+    return annotations;\r
+  }\r
+\r
 }\r
 \r
 \r
diff --git a/src/jalview/datamodel/AlignmentAnnotation.java b/src/jalview/datamodel/AlignmentAnnotation.java
new file mode 100755 (executable)
index 0000000..43ebf38
--- /dev/null
@@ -0,0 +1,62 @@
+package jalview.datamodel;\r
+\r
+public class AlignmentAnnotation\r
+{\r
+  public String label;\r
+  public String description;\r
+  public Annotation  [] annotations;\r
+  public boolean isGraph = false;\r
+  public float graphMin, graphMax;\r
+  public int windowLength;\r
+\r
+  // Graphical hints and tips\r
+  public boolean editable = false;\r
+  public boolean hasIcons; //\r
+  public boolean hasText;\r
+  public boolean visible = true;\r
+  public int height=0;\r
+\r
+  public AlignmentAnnotation(String label, String description, Annotation [] annotations)\r
+  {\r
+    // always editable?\r
+    editable = true;\r
+    this.label = label;\r
+    this.description = description;\r
+    this.annotations = annotations;\r
+    for(int i=0; i<annotations.length; i++)\r
+    {\r
+      if (annotations[i]!=null &&(\r
+          annotations[i].secondaryStructure == 'H' ||\r
+          annotations[i].secondaryStructure == 'E'))\r
+        hasIcons = true;\r
+\r
+      if (annotations[i]!=null && annotations[i].displayCharacter.length()>0)\r
+        hasText = true;\r
+    }\r
+  }\r
+\r
+  public AlignmentAnnotation(String label, String description, Annotation [] annotations, float min, float max, int winLength)\r
+  {\r
+    // graphs are not editable\r
+    this.label = label;\r
+    this.description = description;\r
+    this.annotations = annotations;\r
+    isGraph = true;\r
+    graphMin = min;\r
+    graphMax = max;\r
+    windowLength = winLength;\r
+    for(int i=0; i<annotations.length; i++)\r
+    {\r
+      if (annotations[i]!=null &&(\r
+          annotations[i].secondaryStructure == 'H' ||\r
+          annotations[i].secondaryStructure == 'E'))\r
+        hasIcons = true;\r
+\r
+      if (annotations[i]!=null && annotations[i].displayCharacter.length()>0)\r
+        hasText = true;\r
+    }\r
+\r
+\r
+  }\r
+\r
+}\r
index 182b687..b46a1a7 100755 (executable)
@@ -1,6 +1,5 @@
 package jalview.datamodel;\r
 \r
-import jalview.jbgui.*;\r
 import java.util.*;\r
 \r
 /** Data structure to hold and manipulate a multiple sequence alignment\r
@@ -63,10 +62,15 @@ public interface AlignmentI {
   public void          sortByPID(SequenceI s) ;\r
   public void          sortByID() ;\r
 \r
+  //Annotations\r
+  public void addAnnotation(AlignmentAnnotation aa);\r
+  public void deleteAnnotation(AlignmentAnnotation aa);\r
+  public AlignmentAnnotation [] getAlignmentAnnotation();\r
+\r
   public void          setGapCharacter(char gc);\r
   public char          getGapCharacter();\r
 \r
-    public Vector        getAAFrequency();\r
+  public Vector        getAAFrequency();\r
 }\r
 \r
 \r
diff --git a/src/jalview/datamodel/Annotation.java b/src/jalview/datamodel/Annotation.java
new file mode 100755 (executable)
index 0000000..6179cfa
--- /dev/null
@@ -0,0 +1,21 @@
+package jalview.datamodel;
+import java.awt.*;
+
+public class Annotation
+{
+  public String displayCharacter="";
+  public String description="";       // currently used as mouse over
+  public char secondaryStructure=' '; // recognises H and E
+  public float value;
+
+  // add visual cues here
+  public Color colour = Color.black;
+
+  public Annotation(String displayChar, String desc, char ss, float val)
+  {
+    displayCharacter = displayChar;
+    description = desc;
+    secondaryStructure = ss;
+    value = val;
+  }
+}
index 00961d6..8c7c9be 100755 (executable)
@@ -32,7 +32,6 @@ public class AlignFrame extends GAlignFrame
   final AlignViewport viewport;\r
   public AlignFrame(AlignmentI al)\r
   {\r
-    super();\r
     viewport = new AlignViewport(al,true,true,false);\r
 \r
     String fontName = jalview.bin.Cache.getProperty("FONT_NAME");\r
@@ -45,6 +44,15 @@ public class AlignFrame extends GAlignFrame
     alignPanel = new AlignmentPanel(this, viewport);\r
     getContentPane().add(alignPanel, java.awt.BorderLayout.CENTER);\r
 \r
+    // add conservation graph to alignment\r
+    viewport.updateConservation();\r
+    viewport.updateConsensus();\r
+\r
+    alignPanel.annotationPanel.adjustPanelHeight();\r
+    alignPanel.annotationSpaceFillerHolder.setPreferredSize(alignPanel.annotationPanel.getPreferredSize());\r
+    alignPanel.annotationScroller.setPreferredSize(alignPanel.annotationPanel.getPreferredSize());\r
+\r
+\r
     addInternalFrameListener(new InternalFrameAdapter()\r
    {\r
      public void internalFrameActivated(InternalFrameEvent evt)\r
@@ -227,6 +235,8 @@ public class AlignFrame extends GAlignFrame
       seq = (SequenceI[]) history[1];\r
       viewport.setAlignment( new Alignment(seq) );\r
       updateEditMenuBar();\r
+      viewport.updateConsensus();\r
+      alignPanel.RefreshPanels();\r
       alignPanel.RefreshPanels();\r
   }\r
 \r
@@ -339,12 +349,14 @@ public class AlignFrame extends GAlignFrame
         int newHeight = newSeqs.length * af.viewport.getCharHeight() + 200;\r
         if (newHeight > 500)\r
           newHeight = 500;\r
-        Desktop.addInternalFrame(af, "Copied sequences", 700, newHeight);\r
+        Desktop.addInternalFrame(af, "Copied sequences", 700, 500);\r
       }\r
       else\r
       {\r
         viewport.setEndSeq(viewport.alignment.getHeight());\r
         viewport.alignment.getWidth();\r
+        viewport.updateConservation();\r
+        viewport.updateConsensus();\r
         alignPanel.RefreshPanels();\r
       }\r
 \r
@@ -386,6 +398,8 @@ public class AlignFrame extends GAlignFrame
      {\r
        this.setClosed(true);\r
      }catch(Exception ex){}\r
+   viewport.updateConservation();\r
+   viewport.updateConsensus();\r
      alignPanel.RefreshPanels();\r
 \r
   }\r
@@ -398,6 +412,8 @@ public class AlignFrame extends GAlignFrame
      SequenceI[] seq = (SequenceI[]) history[1];\r
      viewport.setAlignment( new Alignment(seq) );\r
      updateEditMenuBar();\r
+     viewport.updateConsensus();\r
+     alignPanel.RefreshPanels();\r
      alignPanel.RefreshPanels();\r
   }\r
 \r
@@ -508,6 +524,8 @@ public class AlignFrame extends GAlignFrame
   {\r
     addHistoryItem("delete gapped columns");\r
     viewport.getAlignment().removeGaps();\r
+    viewport.updateConservation();\r
+    viewport.updateConsensus();\r
     alignPanel.RefreshPanels();\r
   }\r
 \r
@@ -528,7 +546,8 @@ public class AlignFrame extends GAlignFrame
           jSize--;\r
         }\r
     }\r
-\r
+    viewport.updateConservation();\r
+    viewport.updateConsensus();\r
     alignPanel.RefreshPanels();\r
   }\r
 \r
@@ -616,9 +635,9 @@ public class AlignFrame extends GAlignFrame
     alignPanel.RefreshPanels();\r
   }\r
 \r
-  public void consensusGraphMenuItem_actionPerformed(ActionEvent e)\r
+  public void annotationPanelMenuItem_actionPerformed(ActionEvent e)\r
   {\r
-    alignPanel.setGraphPanelVisible( consensusGraphMenuItem.isSelected() );\r
+    alignPanel.setAnnotationVisible( annotationPanelMenuItem.isSelected() );\r
   }\r
 \r
   public void overviewMenuItem_actionPerformed(ActionEvent e)\r
@@ -1109,11 +1128,13 @@ if ( viewport.getConservationSelected() )
          g.drawString("Clustal Alignment Web Service running", 30,30);\r
        }\r
   }\r
-  public void jpredMenuItem_actionPerformed(ActionEvent e)\r
-    {\r
-    //  JInternalFrame frame = new JInternalFrame();\r
-//      JPredClient ct = new JPredClient((SequenceI)\r
-    ///                                   viewport.getAlignment().getSequences().elementAt(0));\r
+  protected void jpred_actionPerformed(ActionEvent e)\r
+{\r
+\r
+\r
+      JInternalFrame frame = new JInternalFrame();\r
+      JPredClient ct = new JPredClient((SequenceI)\r
+                                       viewport.getAlignment().getSequences().elementAt(0));\r
     }\r
 \r
     protected void LoadtreeMenuItem_actionPerformed(ActionEvent e) {\r
index 71427ca..19a206d 100755 (executable)
@@ -1,7 +1,7 @@
 package jalview.gui;\r
 \r
 import java.awt.*;\r
-import jalview.io.*;\r
+import jalview.analysis.*;\r
 import jalview.analysis.NJTree;\r
 import jalview.datamodel.*;\r
 import jalview.schemes.*;\r
@@ -42,7 +42,6 @@ public class AlignViewport
 \r
   ColumnSelection colSel = new ColumnSelection();\r
 \r
-  String visibleConsensus;\r
 \r
   int threshold;\r
   int increment;\r
@@ -50,32 +49,20 @@ public class AlignViewport
   NJTree currentTree = null;\r
 \r
 \r
-  public AlignViewport(AlignmentI da,\r
+  public AlignViewport(AlignmentI al,\r
                        boolean showText,\r
                        boolean showBoxes,\r
                        boolean wrapAlignment) {\r
-    this(0,da.getWidth()-1,0,da.getHeight()-1,\r
-         showText,\r
-         showBoxes,\r
-         wrapAlignment);\r
-\r
-    setAlignment(da);\r
-  }\r
 \r
-  public AlignViewport(int startRes, int endRes,\r
-                       int startSeq, int endSeq,\r
-                       boolean showText,\r
-                       boolean showBoxes,\r
-                       boolean wrapAlignment) {\r
-\r
-    this.startRes = startRes;\r
-    this.endRes   = endRes;\r
-    this.startSeq = startSeq;\r
-    this.endSeq   = endSeq;\r
-    this.showText      = showText;\r
-    this.showBoxes     = showBoxes;\r
+    this.startRes = 0;\r
+    this.endRes = al.getWidth()-1;\r
+    this.startSeq = 0;\r
+    this.endSeq = al.getHeight()-1;\r
+    this.showText = showText;\r
+    this.showBoxes = showBoxes;\r
     this.wrapAlignment = wrapAlignment;\r
 \r
+    setAlignment(al);\r
     setFont( font );\r
  }\r
 \r
@@ -84,31 +71,112 @@ public class AlignViewport
    showSequenceFeatures = b;\r
  }\r
 \r
+  AlignmentAnnotation consensus;\r
+  AlignmentAnnotation conservation;\r
+  public void updateConservation()\r
+  {\r
+    Annotation [] annotations = new Annotation[alignment.getWidth()];\r
+\r
+    Conservation cons = new jalview.analysis.Conservation("All",\r
+        jalview.schemes.ResidueProperties.propHash, 3,\r
+        alignment.getSequences(), 0,\r
+        alignment.getWidth());\r
+    cons.calculate();\r
+    cons.verdict(false, 100);\r
+\r
+    String sequence = cons.getConsSequence().getSequence();\r
+    for (int i = 0; i < alignment.getWidth(); i++)\r
+    {\r
+      int value = 0;\r
+      try\r
+      {\r
+        value = Integer.parseInt(sequence.charAt(i) + "");\r
+      }\r
+      catch (Exception ex)\r
+      {\r
+        if (sequence.charAt(i) == '*') value = 10;\r
+      }\r
+\r
+      annotations[i] = new Annotation(sequence.charAt(i) + "",\r
+                                      "Conservation graph", ' ', value);\r
+    }\r
+\r
+    if(conservation==null)\r
+    {\r
+      conservation = new AlignmentAnnotation("Conservation",\r
+                                             "Conservation of total alignment",\r
+                                             annotations, 0, 10, 1);\r
+      alignment.addAnnotation(conservation);\r
+    }\r
+    else\r
+      conservation.annotations = annotations;\r
+\r
+  }\r
+\r
+  public void updateConsensus()\r
+  {\r
+    Annotation [] annotations = new Annotation[alignment.getWidth()];\r
+\r
+    Vector cons = alignment.getAAFrequency();\r
+    Hashtable hash = null;\r
+    for (int i = 0; i < alignment.getWidth(); i++)\r
+    {\r
+        hash = (Hashtable) cons.elementAt(i);\r
+        float value = Float.parseFloat(hash.get("maxCount").toString());\r
+        value /= Float.parseFloat(hash.get("size").toString());\r
+\r
+        value *= 100;\r
+        String maxRes = hash.get("maxResidue")+" ";\r
+        String mouseOver = hash.get("maxResidue")+" ";\r
+        if(maxRes.length()>2)\r
+        {\r
+          mouseOver = "["+maxRes+"] ";\r
+          maxRes = "+ ";\r
+        }\r
+\r
+        mouseOver += value+"%";\r
+        annotations[i] = new Annotation(maxRes, mouseOver, ' ', value);\r
+\r
+    }\r
+\r
+     if(consensus==null)\r
+     {\r
+       consensus = new AlignmentAnnotation("% Identity",\r
+                                           "PID", annotations, 0f, 100f, 1);\r
+       alignment.addAnnotation(consensus);\r
+     }\r
+     else\r
+       consensus.annotations = annotations;\r
+\r
+  }\r
+\r
   public String getVisibleConsensus()\r
   {\r
     return visibleConsensus;\r
   }\r
 \r
-  Vector consensus = new Vector();\r
+  String visibleConsensus;\r
+  Vector consensusV = new Vector();\r
   public Vector getConsensus(boolean recalculate)\r
   {\r
-    if(recalculate || consensus.size()<1)\r
+    if(recalculate || consensusV.size()<1)\r
     {\r
-      consensus = alignment.getAAFrequency();\r
+      consensusV = alignment.getAAFrequency();\r
       StringBuffer sb = new StringBuffer();\r
       Hashtable hash = null;\r
-      for (int i = 0; i < consensus.size(); i++)\r
+      for (int i = 0; i < consensusV.size(); i++)\r
       {\r
-        hash = (Hashtable) consensus.elementAt(i);\r
+        hash = (Hashtable) consensusV.elementAt(i);\r
         sb.append(hash.get("maxResidue").toString().charAt(0));\r
       }\r
       visibleConsensus = sb.toString();\r
     }\r
 \r
 \r
-    return consensus;\r
+    return consensusV;\r
   }\r
 \r
+\r
   public SequenceGroup getSelectionGroup()\r
   {\r
     return selectionGroup;\r
index d8131b4..248fb3d 100755 (executable)
@@ -22,10 +22,10 @@ public class AlignmentPanel extends GAlignmentPanel implements AdjustmentListene
   SeqPanel   seqPanel;\r
   IdPanel    idPanel;\r
   IdwidthAdjuster idwidthAdjuster;\r
-  SecondaryStructurePanel ssPanel;\r
   public AlignFrame alignFrame;\r
   ScalePanel scalePanel;\r
-  ScorePanel scorePanel;\r
+  AnnotationPanel annotationPanel;\r
+  AnnotationLabels alabels;\r
 \r
   public AlignmentPanel(AlignFrame af, final AlignViewport av)\r
   {\r
@@ -35,22 +35,25 @@ public class AlignmentPanel extends GAlignmentPanel implements AdjustmentListene
     idPanel         = new IdPanel   (av, this);\r
 \r
     scalePanel = new ScalePanel(av, this);\r
-    scorePanel = new ScorePanel(av);\r
-    ssPanel = new SecondaryStructurePanel(av);\r
-\r
-    secondaryPanelHolder.add(ssPanel, BorderLayout.CENTER);\r
 \r
     idPanelHolder.add(idPanel, BorderLayout.CENTER);\r
     idwidthAdjuster = new IdwidthAdjuster(this);\r
     idSpaceFillerPanel1.add(idwidthAdjuster, BorderLayout.CENTER);\r
 \r
+    annotationPanel = new AnnotationPanel(this);\r
+    alabels = new AnnotationLabels(this);\r
+\r
+    annotationSpaceFillerHolder.setPreferredSize(annotationPanel.getPreferredSize());\r
+    annotationScroller.setPreferredSize(annotationPanel.getPreferredSize());\r
+    annotationScroller.setViewportView(annotationPanel);\r
+    annotationSpaceFillerHolder.add(alabels, BorderLayout.CENTER);\r
+\r
     Dimension d = calculateIdWidth();\r
     d.setSize( d.width+4, d.height);\r
     idPanel.idCanvas.setPreferredSize( d );\r
     hscrollFillerPanel.setPreferredSize( d );\r
 \r
     scalePanelHolder.add(scalePanel, BorderLayout.CENTER);\r
-    scorePanelHolder.add(scorePanel, BorderLayout.CENTER);\r
     seqPanelHolder.add(seqPanel, BorderLayout.CENTER);\r
 \r
 \r
@@ -63,7 +66,6 @@ public class AlignmentPanel extends GAlignmentPanel implements AdjustmentListene
          Dimension d = calculateIdWidth();\r
          d.setSize( d.width+4, d.height);\r
          idPanel.idCanvas.setPreferredSize( d );\r
-         hscrollFillerPanel.setPreferredSize( d );\r
          RefreshPanels();\r
        }\r
     });\r
@@ -92,15 +94,19 @@ public class AlignmentPanel extends GAlignmentPanel implements AdjustmentListene
            RefreshPanels();\r
            break;\r
          case KeyEvent.VK_X:\r
+           if(evt.isControlDown())\r
            alignFrame.cut_actionPerformed(null);\r
            break;\r
          case KeyEvent.VK_C:\r
+         if(evt.isControlDown())\r
            alignFrame.copy_actionPerformed(null);\r
            break;\r
          case KeyEvent.VK_V:\r
+          if(evt.isControlDown())\r
            alignFrame.paste(true);\r
            break;\r
          case KeyEvent.VK_A:\r
+         if(evt.isControlDown())\r
            alignFrame.selectAllSequenceMenuItem_actionPerformed(null);\r
            break;\r
         case KeyEvent.VK_DOWN:\r
@@ -110,6 +116,7 @@ public class AlignmentPanel extends GAlignmentPanel implements AdjustmentListene
           alignFrame.moveSelectedSequences(true);\r
           break;\r
         case KeyEvent.VK_F:\r
+         if(evt.isControlDown())\r
           alignFrame.findMenuItem_actionPerformed(null);\r
           break;\r
        }\r
@@ -176,32 +183,28 @@ public class AlignmentPanel extends GAlignmentPanel implements AdjustmentListene
  }\r
 \r
 \r
-  public void setGraphPanelVisible(boolean b)\r
+  public void setAnnotationVisible(boolean b)\r
   {\r
-    idSpaceFillerPanel.setVisible(b);\r
-    scorePanelHolder.setVisible(b);\r
+    annotationSpaceFillerHolder.setVisible(b);\r
+    annotationScroller.setVisible(b);\r
+    javax.swing.SwingUtilities.invokeLater(new Runnable()\r
+     {\r
+       public void run()\r
+       {\r
+         RefreshPanels();\r
+       }\r
+    });\r
 \r
-    RefreshPanels();\r
-    // bit annoying to call this twice, can you do better?\r
-    RefreshPanels();\r
   }\r
 \r
-  public void setSecondaryStructureVisible(boolean b)\r
-  {\r
-    secondaryPanelHolder.setVisible(b);\r
-    RefreshPanels();\r
-  }\r
 \r
   public void setWrapAlignment(boolean wrap)\r
   {\r
-    scorePanelHolder.setVisible(!wrap);\r
     scalePanelHolder.setVisible(!wrap);\r
-    secondaryPanelHolder.setVisible(!wrap);\r
-\r
     hscroll.setVisible(!wrap);\r
-\r
     idwidthAdjuster.setVisible(!wrap);\r
-    idSpaceFillerPanel.setVisible(!wrap);\r
+    annotationScroller.setVisible(!wrap);\r
+    annotationSpaceFillerHolder.setVisible(!wrap);\r
     idSpaceFillerPanel1.setVisible(!wrap);\r
 \r
     RefreshPanels();\r
@@ -232,35 +235,31 @@ public class AlignmentPanel extends GAlignmentPanel implements AdjustmentListene
     RefreshPanels();\r
   }\r
 \r
+\r
   public void RefreshPanels()\r
   {\r
+    requestFocus();\r
+    invalidate();\r
+\r
+    Dimension d = idPanel.idCanvas.getPreferredSize();\r
+    idPanelHolder.setPreferredSize(d);\r
+    hscrollFillerPanel.setPreferredSize(new Dimension(d.width, 12));\r
 \r
-              requestFocus();\r
-              invalidate();\r
-              idPanelHolder.setPreferredSize(idPanel.idCanvas.getPreferredSize());\r
-              if(idPanel.idCanvas.getPreferredSize()!=null)\r
-                hscrollFillerPanel.setPreferredSize(new Dimension(idPanel.idCanvas.getPreferredSize().width, 12));\r
-              idSpaceFillerPanel1.setPreferredSize(new Dimension(500,\r
-                  av.charHeight / 2 + 12));\r
-              scalePanelHolder.setPreferredSize(new Dimension(500,\r
-                  av.charHeight / 2 + 12));\r
-\r
-              if (av.getWrapAlignment())\r
-              {\r
-                int max = av.alignment.getWidth() /\r
-                    (seqPanel.seqCanvas.getWidth() / av.charWidth)+1 ;\r
-\r
-                vscroll.setValues(0, 1, 0, max);\r
-              }\r
-              else\r
-              {\r
-                av.getConsensus(true);\r
-                if (overviewPanel != null)\r
-                  overviewPanel.updateOverviewImage();\r
-                 setScrollValues(av.getStartRes(), av.getStartSeq());\r
-              }\r
-\r
-          repaint();\r
+    if (av.getWrapAlignment())\r
+    {\r
+      int max = av.alignment.getWidth() /\r
+          (seqPanel.seqCanvas.getWidth() / av.charWidth) + 1;\r
+      vscroll.setValues(0, 1, 0, max);\r
+    }\r
+    else\r
+    {\r
+      if (overviewPanel != null)\r
+        overviewPanel.updateOverviewImage();\r
+      setScrollValues(av.getStartRes(), av.getStartSeq());\r
+    }\r
+\r
+    validate();\r
+    repaint();\r
   }\r
 \r
   int hextent = 0;\r
@@ -329,8 +328,6 @@ public class AlignmentPanel extends GAlignmentPanel implements AdjustmentListene
     hscroll.setValues(x,hextent,0,av.getAlignment().getWidth());\r
     vscroll.setValues(y,vextent,0,av.getAlignment().getHeight() );\r
 \r
-    repaint();\r
-\r
   }\r
 \r
 \r
@@ -363,6 +360,7 @@ public class AlignmentPanel extends GAlignmentPanel implements AdjustmentListene
       overviewPanel.setBoxPosition();\r
 \r
     repaint();\r
+\r
   }\r
 \r
   public int print(Graphics pg, PageFormat pf, int pi) throws PrinterException\r
diff --git a/src/jalview/gui/AnnotationLabels.java b/src/jalview/gui/AnnotationLabels.java
new file mode 100755 (executable)
index 0000000..c600b82
--- /dev/null
@@ -0,0 +1,213 @@
+\r
+package jalview.gui;\r
+\r
+import javax.swing.*;\r
+import java.awt.event.*;\r
+import java.awt.*;\r
+import java.awt.image.*;\r
+import jalview.datamodel.*;\r
+\r
+public class AnnotationLabels extends JPanel implements MouseListener, MouseMotionListener, ActionListener\r
+{\r
+  boolean active = false;\r
+  Image image;\r
+  AlignmentPanel ap ;\r
+  boolean resizing = false;\r
+  int oldY, mouseX;\r
+  static String ADDNEW = "Add new row";\r
+  static String HIDE = "Hide this row";\r
+  static String DELETE = "Delete this row";\r
+  static String SHOWALL="Show all hidden rows";\r
+  int selectedRow = 0;\r
+  int scrollOffset = 0;\r
+\r
+  public AnnotationLabels(AlignmentPanel ap)\r
+  {\r
+    this.ap = ap;\r
+\r
+    java.net.URL url = getClass().getResource("/images/idwidth.gif");\r
+    Image temp = null;\r
+    if (url != null)\r
+      temp = java.awt.Toolkit.getDefaultToolkit().createImage(url);\r
+\r
+    try\r
+    {\r
+      MediaTracker mt = new MediaTracker(this);\r
+      mt.addImage(temp, 0);\r
+      mt.waitForID(0);\r
+    }\r
+    catch (Exception ex) {}\r
+\r
+    BufferedImage bi = new BufferedImage(temp.getHeight(this), temp.getWidth(this),\r
+                                         BufferedImage.TYPE_INT_RGB);\r
+    Graphics2D g = (Graphics2D) bi.getGraphics();\r
+    g.rotate(Math.toRadians(90));\r
+    g.drawImage(temp, 0, -bi.getWidth(this), this);\r
+    image = (Image) bi;\r
+\r
+    addMouseListener(this);\r
+    addMouseMotionListener(this);\r
+  }\r
+\r
+  public void setScrollOffset(int y)\r
+  {\r
+    scrollOffset = y;\r
+    repaint();\r
+  }\r
+\r
+  public void actionPerformed(ActionEvent evt)\r
+  {\r
+    AlignmentAnnotation[] aa = ap.av.alignment.getAlignmentAnnotation();\r
+\r
+    if(evt.getActionCommand().equals(ADDNEW))\r
+    {\r
+      String label = JOptionPane.showInputDialog(this, "Label for annotation");\r
+      if(label==null)\r
+        label = "";\r
+      ap.av.alignment.addAnnotation(new AlignmentAnnotation\r
+                                      (label,\r
+                                       "New description",\r
+                                       new Annotation[ap.av.alignment.getWidth()]));\r
+    }\r
+   else if(evt.getActionCommand().equals(HIDE))\r
+   {\r
+     aa[selectedRow].visible = false;\r
+   }\r
+   else if(evt.getActionCommand().equals(DELETE))\r
+   {\r
+     ap.av.alignment.deleteAnnotation(aa[selectedRow]);\r
+   }\r
+   else if(evt.getActionCommand().equals(SHOWALL))\r
+   {\r
+       for(int i=0; i<aa.length; i++)\r
+         aa[i].visible = true;\r
+   }\r
+\r
+   ap.annotationPanel.adjustPanelHeight();\r
+   ap.RefreshPanels();\r
+\r
+  }\r
+\r
+  public void mousePressed(MouseEvent evt)\r
+  {\r
+    int y = evt.getY() - scrollOffset;\r
+\r
+    if (SwingUtilities.isRightMouseButton(evt))\r
+    {\r
+       AlignmentAnnotation[] aa = ap.av.alignment.getAlignmentAnnotation();\r
+       if(aa==null || aa.length==0)\r
+       {\r
+            JPopupMenu pop = new JPopupMenu("Annotations");\r
+            JMenuItem item = new JMenuItem(ADDNEW);\r
+            item.addActionListener(this);\r
+            pop.add(item);\r
+            pop.show(this, evt.getX(), evt.getY());\r
+            return;\r
+       }\r
+\r
+       int height = 0;\r
+       for (int i = 0; i < aa.length; i++)\r
+       {\r
+         if(!aa[i].visible)\r
+           continue;\r
+\r
+         height += aa[i].height;\r
+         if(y<height)\r
+         {\r
+           selectedRow = i;\r
+           break;\r
+         }\r
+       }\r
+\r
+      JPopupMenu pop = new JPopupMenu("Annotations");\r
+      JMenuItem item = new JMenuItem(ADDNEW);\r
+      item.addActionListener(this);\r
+      pop.add(item);\r
+      item = new JMenuItem(HIDE);\r
+      item.addActionListener(this);\r
+      pop.add(item);\r
+      item = new JMenuItem(DELETE);\r
+      item.addActionListener(this);\r
+      pop.add(item);\r
+      item = new JMenuItem(SHOWALL);\r
+      item.addActionListener(this);\r
+      pop.add(item);\r
+      pop.show(this, evt.getX(), evt.getY());\r
+      return;\r
+    }\r
+\r
+    oldY = evt.getY();\r
+  }\r
+\r
+  public void mouseReleased(MouseEvent evt){ active = false; repaint(); }\r
+  public void mouseEntered(MouseEvent evt) { active = true;  repaint();}\r
+  public void mouseExited(MouseEvent evt)  { active = false; repaint();}\r
+  public void mouseDragged(MouseEvent evt)\r
+  {\r
+    active = true;\r
+    Dimension d = ap.annotationScroller.getPreferredSize();\r
+    int dif = evt.getY() - oldY;\r
+\r
+    dif /= ap.av.charHeight;\r
+    dif *= ap.av.charHeight;\r
+\r
+    if(d.height-dif>20)\r
+    {\r
+      ap.annotationScroller.setPreferredSize(new Dimension(d.width,d.height - dif));\r
+      d = ap.annotationSpaceFillerHolder.getPreferredSize();\r
+      ap.annotationSpaceFillerHolder.setPreferredSize(new Dimension(d.width,d.height - dif));\r
+      ap.RefreshPanels();\r
+    }\r
+    ap.addNotify();\r
+  }\r
+\r
+  public void mouseMoved(MouseEvent evt)   {}\r
+  public void mouseClicked(MouseEvent evt) {}\r
+\r
+  public void paintComponent(Graphics g1)\r
+  {\r
+    Graphics2D g = (Graphics2D)g1;\r
+    g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);\r
+\r
+    FontMetrics fm = g.getFontMetrics(g.getFont());\r
+\r
+    g.setColor(Color.white);\r
+    g.fillRect(0,0, getWidth(), getHeight());\r
+\r
+    g.translate(0, scrollOffset);\r
+    g.setColor(Color.black);\r
+\r
+   AlignmentAnnotation[] aa = ap.av.alignment.getAlignmentAnnotation();\r
+   int y = g.getFont().getSize();\r
+   int x = 0;\r
+\r
+   if(aa!=null)\r
+   for(int i=0; i<aa.length; i++)\r
+   {\r
+     if(!aa[i].visible)\r
+       continue;\r
+\r
+     x = getWidth() - fm.stringWidth(aa[i].label)-3;\r
+\r
+     g.drawString(aa[i].label, x, y);\r
+\r
+     y+=aa[i].height;\r
+   }\r
+\r
+   if (active)\r
+   {\r
+     if (image != null)\r
+       g.drawImage(image, 2, 0, this);\r
+   }\r
+\r
+   if (aa == null || aa.length<1)\r
+   {\r
+     g.drawString("Right click", 2, 8);\r
+     g.drawString("to add annotation", 2, 18);\r
+   }\r
+\r
+\r
+\r
+  }\r
+\r
+}\r
diff --git a/src/jalview/gui/AnnotationPanel.java b/src/jalview/gui/AnnotationPanel.java
new file mode 100755 (executable)
index 0000000..2874494
--- /dev/null
@@ -0,0 +1,523 @@
+package jalview.gui;\r
+\r
+import jalview.datamodel.*;\r
+\r
+import javax.swing.*;\r
+import java.awt.*;\r
+import java.awt.event.*;\r
+import java.util.*;\r
+import java.awt.image.*;\r
+\r
+public class AnnotationPanel extends JPanel implements MouseListener, MouseMotionListener, ActionListener, AdjustmentListener\r
+{\r
+  AlignViewport av;\r
+  AlignmentPanel ap;\r
+  int activeRow =-1;\r
+\r
+  ArrayList activeRes;\r
+  static String HELIX ="Helix";\r
+  static String SHEET ="Sheet";\r
+  static String LABEL ="Label";\r
+  static String REMOVE="Remove Annotation";\r
+  static String COLOUR="Colour";\r
+  static Color HELIX_COLOUR = Color.red.darker();\r
+  static Color SHEET_COLOUR = Color.green.darker().darker();\r
+\r
+  BufferedImage bi;\r
+\r
+\r
+\r
+  public AnnotationPanel(AlignmentPanel ap)\r
+  {\r
+    this.ap = ap;\r
+    av = ap.av;\r
+    this.setLayout(null);\r
+    addMouseListener(this);\r
+    addMouseMotionListener(this);\r
+    adjustPanelHeight();\r
+\r
+\r
+    ap.annotationScroller.getVerticalScrollBar().addAdjustmentListener( this );\r
+  }\r
+\r
+  public void adjustmentValueChanged(AdjustmentEvent evt)\r
+  {\r
+    ap.alabels.setScrollOffset( -evt.getValue() );\r
+  }\r
+\r
+  public void adjustPanelHeight()\r
+  {\r
+    // setHeight of panels\r
+    AlignmentAnnotation[] aa = av.alignment.getAlignmentAnnotation();\r
+    int height = 0;\r
+    if(aa!=null)\r
+    for (int i = 0; i < aa.length; i++)\r
+    {\r
+      if(!aa[i].visible)\r
+        continue;\r
+\r
+      aa[i].height = 0;\r
+\r
+      if(aa[i].hasText)\r
+        aa[i].height += av.charHeight;\r
+      if (aa[i].hasIcons)\r
+        aa[i].height += 16;\r
+\r
+      if (aa[i].isGraph)\r
+        aa[i].height += 50;\r
+\r
+      if(aa[i].height==0)\r
+        aa[i].height = 20;\r
+      height += aa[i].height;\r
+    }\r
+  else height=20;\r
+    this.setPreferredSize(new Dimension(1, height));\r
+\r
+  }\r
+\r
+  public void addEditableColumn(int i)\r
+  {\r
+    if(activeRow==-1)\r
+    {\r
+      AlignmentAnnotation [] aa = av.alignment.getAlignmentAnnotation();\r
+      for(int j=0; j<aa.length; j++)\r
+        if(aa[j].editable)\r
+        {\r
+          activeRow = j;\r
+          break;\r
+        }\r
+    }\r
+\r
+    if(activeRes==null)\r
+    {\r
+      activeRes = new ArrayList();\r
+      activeRes.add(String.valueOf(i));\r
+      return;\r
+    }\r
+\r
+    activeRes.add(String.valueOf(i));\r
+\r
+  }\r
+\r
+\r
+  public void actionPerformed(ActionEvent evt)\r
+  {\r
+\r
+    AlignmentAnnotation [] aa = av.alignment.getAlignmentAnnotation();\r
+    Annotation [] anot = aa[activeRow].annotations;\r
+\r
+    if(evt.getActionCommand().equals(REMOVE))\r
+    {\r
+      for(int i=0; i<activeRes.size(); i++)\r
+      {\r
+        anot[Integer.parseInt(activeRes.get(i).toString())] = null;\r
+        anot[Integer.parseInt(activeRes.get(i).toString())] = null;\r
+      }\r
+    }\r
+    else if(evt.getActionCommand().equals(LABEL))\r
+    {\r
+      String label = JOptionPane.showInputDialog(this, "Enter Label ", "Enter label", JOptionPane.QUESTION_MESSAGE );\r
+      if(label==null)\r
+        label = "";\r
+\r
+      if(label.length()>0 && !aa[activeRow].hasText)\r
+       aa[activeRow].hasText = true;\r
+\r
+      for(int i=0; i<activeRes.size(); i++)\r
+      {\r
+        int index = Integer.parseInt(activeRes.get(i).toString());\r
+        if(anot[index]==null)\r
+          anot[index] = new Annotation(label, "", ' ',0);\r
+        anot[index].displayCharacter = label;\r
+      }\r
+    }\r
+    else if(evt.getActionCommand().equals(COLOUR))\r
+    {\r
+     Color col = JColorChooser.showDialog(this, "Choose foreground colour", Color.black);\r
+     for (int i = 0; i < activeRes.size(); i++)\r
+     {\r
+       int index = Integer.parseInt(activeRes.get(i).toString());\r
+       if (anot[index] == null)\r
+         anot[index] = new Annotation("", "", ' ', 0);\r
+       anot[index].colour = col;\r
+     }\r
+    }\r
+    else // HELIX OR SHEET\r
+    {\r
+    char type = 0;\r
+    String symbol = "\u03B1";\r
+    if(evt.getActionCommand().equals(HELIX))\r
+       type = 'H';\r
+    else if(evt.getActionCommand().equals(SHEET))\r
+    {\r
+      type = 'E';\r
+      symbol = "\u03B2";\r
+    }\r
+\r
+    if(!aa[activeRow].hasIcons)\r
+      aa[activeRow].hasIcons = true;\r
+\r
+\r
+    String label = JOptionPane.showInputDialog("Enter a label for the structure?", symbol );\r
+    if(label==null)\r
+       label="";\r
+\r
+    if(label.length()>0 && !aa[activeRow].hasText)\r
+       aa[activeRow].hasText = true;\r
+\r
+    for(int i=0; i<activeRes.size(); i++)\r
+    {\r
+      int index = Integer.parseInt(activeRes.get(i).toString());\r
+      if (anot[index] == null)\r
+      {\r
+        anot[index] = new Annotation(label, "", type, 0);\r
+      }\r
+\r
+        anot[ index ].secondaryStructure = type;\r
+        anot[ index ].displayCharacter = label;\r
+    }\r
+    }\r
+\r
+    adjustPanelHeight();\r
+    activeRes = null;\r
+    repaint();\r
+    return;\r
+\r
+\r
+  }\r
+\r
+  public void mousePressed(MouseEvent evt)\r
+  {\r
+    if (SwingUtilities.isRightMouseButton(evt))\r
+    {\r
+      if(activeRes==null)\r
+        return;\r
+\r
+      JPopupMenu pop = new JPopupMenu("Structure type");\r
+      JMenuItem item = new JMenuItem(HELIX);\r
+      item.addActionListener(this);\r
+      pop.add(item);\r
+      item = new JMenuItem(SHEET);\r
+      item.addActionListener(this);\r
+      pop.add(item);\r
+      item = new JMenuItem(LABEL);\r
+      item.addActionListener(this);\r
+      pop.add(item);\r
+      item = new JMenuItem(COLOUR);\r
+      item.addActionListener(this);\r
+      pop.add(item);\r
+      item = new JMenuItem(REMOVE);\r
+      item.addActionListener(this);\r
+      pop.add(item);\r
+      pop.show(this, evt.getX(), evt.getY());\r
+      return;\r
+    }\r
+\r
+\r
+    AlignmentAnnotation [] aa = av.alignment.getAlignmentAnnotation();\r
+    if(aa==null)\r
+      return;\r
+\r
+    int height = 0;\r
+    activeRow = -1;\r
+    for(int i=0; i<aa.length; i++)\r
+    {\r
+      height+= aa[i].height;\r
+\r
+      if(evt.getY()<height)\r
+      {\r
+        if(!aa[i].editable)\r
+        {\r
+          activeRes = null;\r
+          continue;\r
+        }\r
+\r
+        activeRow = i;\r
+        break;\r
+      }\r
+    }\r
+\r
+\r
+    int res = evt.getX() / av.getCharWidth() + av.getStartRes();\r
+\r
+    if(evt.isControlDown() || evt.isAltDown())\r
+      addEditableColumn(res);\r
+\r
+    else if(evt.isShiftDown())\r
+    {\r
+\r
+      if(activeRes==null)\r
+        activeRes=new ArrayList();\r
+      else\r
+      {\r
+          int start =  Integer.parseInt( activeRes.get( activeRes.size()-1 ).toString() );\r
+          int end = res;\r
+          if(end<start)\r
+          {\r
+            int temp = end;\r
+            end = start;\r
+            start = temp;\r
+          }\r
+          for(int n=start; n<=end; n++)\r
+            addEditableColumn(n);\r
+\r
+      }\r
+    }\r
+    else\r
+    {\r
+        activeRes = new ArrayList();\r
+        activeRes.add( String.valueOf(res) );\r
+    }\r
+\r
+    repaint();\r
+\r
+  }\r
+  public void mouseReleased(MouseEvent evt)\r
+  {  }\r
+  public void mouseEntered(MouseEvent evt)\r
+  {  }\r
+  public void mouseExited(MouseEvent evt)\r
+  {  }\r
+  public void mouseDragged(MouseEvent evt)\r
+  {  }\r
+  public void mouseMoved(MouseEvent evt)\r
+  {\r
+    ToolTipManager.sharedInstance().registerComponent(this);\r
+    AlignmentAnnotation [] aa = av.alignment.getAlignmentAnnotation();\r
+    if(aa==null)\r
+      return;\r
+\r
+    int row = -1;\r
+    int height=0;\r
+    for(int i=0; i<aa.length; i++)\r
+    {\r
+\r
+      if( aa[i].visible )\r
+        height += aa[i].height;\r
+\r
+      if(evt.getY()<height)\r
+      {\r
+        row = i;\r
+        break;\r
+      }\r
+    }\r
+\r
+    int res = evt.getX() / av.getCharWidth() + av.getStartRes();\r
+    if(row>-1 && aa[row].annotations[res]!=null)\r
+      this.setToolTipText(aa[row].annotations[res].description);\r
+\r
+  }\r
+  public void mouseClicked(MouseEvent evt) {}\r
+\r
+\r
+  public void paintComponent(Graphics g)\r
+  {\r
+    if(bi==null\r
+       || bi.getWidth()!=ap.annotationPanel.getWidth()\r
+       || bi.getHeight()!=ap.annotationPanel.getHeight())\r
+    {\r
+      bi = new BufferedImage(ap.annotationPanel.getWidth(),\r
+                           ap.annotationPanel.getHeight(),\r
+                           BufferedImage.TYPE_INT_RGB);\r
+    }\r
+\r
+    drawComponent( (Graphics2D)bi.getGraphics() );\r
+    g.drawImage( bi, 0, 0, this);\r
+  }\r
+\r
+  public void drawComponent(Graphics2D g)\r
+  {\r
+    g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);\r
+    FontMetrics fm = g.getFontMetrics();\r
+    g.setFont(av.getFont());\r
+    g.setColor(Color.white);\r
+    g.fillRect(0,0,getWidth(),getHeight());\r
+\r
+    if(av.alignment.getAlignmentAnnotation()==null || av.alignment.getAlignmentAnnotation().length<1)\r
+    {\r
+      g.setColor(Color.black);\r
+      g.drawString("Alignment has no annotations",20,15);\r
+      return;\r
+    }\r
+\r
+    AlignmentAnnotation [] aa = av.alignment.getAlignmentAnnotation();\r
+\r
+    int j, x=0, y=0;\r
+    char [] lastSS = new char[aa.length];\r
+    int  [] lastSSX= new int[aa.length] ;\r
+    int iconOffset = av.charHeight/2;\r
+    boolean validRes = false;\r
+    //\u03B2 \u03B1\r
+    for(int i=0; i<aa.length; i++)\r
+    {\r
+      AlignmentAnnotation row = aa[i];\r
+      if(!row.visible)\r
+        continue;\r
+\r
+      if(row.isGraph)\r
+      {\r
+        // this is so that we draw the characters below the graph\r
+        y += row.height;\r
+        if(row.hasText)\r
+          y -= av.charHeight;\r
+      }\r
+      if(row.hasText)\r
+        iconOffset = av.charHeight/2;\r
+      else\r
+        iconOffset = 0;\r
+\r
+      for(j=av.startRes; j<av.endRes+1; j++)\r
+      {\r
+        validRes = row.annotations[j]==null?false:true;\r
+\r
+       x = (j-av.getStartRes())*av.charWidth;\r
+\r
+\r
+       if(activeRow==i)\r
+       {\r
+\r
+         g.setColor(Color.red);\r
+\r
+         if(activeRes!=null)\r
+           for (int n = 0; n < activeRes.size(); n++)\r
+           {\r
+             int v = Integer.parseInt(activeRes.get(n).toString()) ;\r
+             if (v == j)\r
+               g.fillRect( (j-av.getStartRes()) * av.charWidth, y, av.charWidth, row.height);\r
+           }\r
+       }\r
+\r
+\r
+\r
+       if(validRes && row.annotations[j].displayCharacter.length()>0)\r
+       {\r
+         int charOffset = (av.charWidth -\r
+                            fm.charWidth(row.annotations[j].displayCharacter.\r
+                                         charAt(0))) / 2;\r
+         g.setColor( row.annotations[j].colour);\r
+          if(j==0)\r
+          {\r
+            if (row.annotations[0].secondaryStructure == 'H'\r
+                || row.annotations[0].secondaryStructure == 'E')\r
+              g.drawString(row.annotations[j].displayCharacter, x,\r
+                           y + iconOffset + 2);\r
+          }\r
+         else if( (row.annotations[j].secondaryStructure=='H'\r
+               || row.annotations[j].secondaryStructure=='E') &&\r
+               (row.annotations[j-1]==null ||\r
+                row.annotations[j].secondaryStructure!=row.annotations[j-1].secondaryStructure))\r
+\r
+        g.drawString(row.annotations[j].displayCharacter, x, y + iconOffset + 2);\r
+\r
+        if(!row.hasIcons)\r
+            g.drawString(row.annotations[j].displayCharacter, x + charOffset,\r
+                         y + iconOffset + 2);\r
+       }\r
+\r
+       if(row.hasIcons)\r
+       if(!validRes || row.annotations[j].secondaryStructure!=lastSS[i])\r
+       {\r
+         switch (lastSS[i])\r
+         {\r
+           case 'H':\r
+             g.setColor(HELIX_COLOUR);\r
+             g.fillRoundRect(lastSSX[i], y+4 + iconOffset, x-lastSSX[i], 7, 8, 8);\r
+             break;\r
+           case 'E':\r
+             g.setColor(SHEET_COLOUR);\r
+             g.fillRect(lastSSX[i], y + 4 + iconOffset, x-lastSSX[i]-4, 7);\r
+             g.fillPolygon(new int[] {x - 4, x- 4, x }\r
+                           , new int[]{y+ iconOffset, y + 14+ iconOffset, y + 8+ iconOffset}, 3);\r
+             break;\r
+           case 'C':\r
+             break;\r
+           default :\r
+             g.setColor(Color.gray);\r
+             g.fillRect(lastSSX[i], y+6+ iconOffset, x-lastSSX[i], 2);\r
+             break;\r
+         }\r
+\r
+         if(validRes)\r
+           lastSS[i] = row.annotations[j].secondaryStructure;\r
+          else\r
+            lastSS[i] = ' ';\r
+         lastSSX[i] = x;\r
+       }\r
+\r
+       if (validRes && row.isGraph)\r
+       {\r
+         g.setColor(new Color(0,0,180));\r
+         int height = (int)((row.annotations[j].value / row.graphMax)*50);\r
+\r
+         if(row.windowLength>1)\r
+         {\r
+           int total =0;\r
+           for(int i2=j- (row.windowLength/2); i2<j+(row.windowLength/2); i2++)\r
+           {\r
+             if(i2<0 || i2>=av.alignment.getWidth())\r
+               continue;\r
+\r
+             total += row.annotations[i2].value;\r
+           }\r
+\r
+           total/=row.windowLength;\r
+           height = (int)( (total / row.graphMax) *50);\r
+\r
+         }\r
+\r
+         g.fillRect(x, y-height, av.charWidth, height );\r
+       }\r
+\r
+\r
+      }\r
+\r
+      x+=av.charWidth;\r
+\r
+      if(row.hasIcons)\r
+      switch (lastSS[i])\r
+      {\r
+        case 'H':\r
+          g.setColor(HELIX_COLOUR);\r
+          g.fillRoundRect(lastSSX[i], y+4+ iconOffset, x - lastSSX[i], 7, 8, 8);\r
+          break;\r
+        case 'E':\r
+          g.setColor(SHEET_COLOUR);\r
+          g.fillRect(lastSSX[i], y + 4+ iconOffset, x - lastSSX[i] - 4, 7);\r
+          g.fillPolygon(new int[]\r
+                        {x - 4, x - 4, x}\r
+                        , new int[]\r
+                        {y + iconOffset, y + 14+ iconOffset, y + 7+ iconOffset}\r
+                        , 3);\r
+          break;\r
+        case 'C':\r
+          break;\r
+        default:\r
+          g.setColor(Color.gray);\r
+          g.fillRect(lastSSX[i], y+6+ iconOffset, x-lastSSX[i], 2);\r
+          break;\r
+\r
+      }\r
+\r
+       if(row.isGraph && row.hasText)\r
+         y+=av.charHeight;\r
+       if(!row.isGraph)\r
+          y+=aa[i].height;\r
+    }\r
+  }\r
+\r
+  // used by overview window\r
+  public void drawGraph(Graphics g, AlignmentAnnotation aa,int width, int y)\r
+  {\r
+    g.setColor(Color.white);\r
+    g.fillRect(0,0,width, y);\r
+    g.setColor(new Color(0,0,180));\r
+    int x = 0;\r
+    for(int j=0; j<aa.annotations.length; j++)\r
+    {\r
+      g.setColor(new Color(0, 0, 180));\r
+      int height = (int) ( (aa.annotations[j].value / aa.graphMax) * 50);\r
+      g.fillRect(x, y - height, av.charWidth, height);\r
+      x+=av.charWidth;\r
+    }\r
+  }\r
+}\r
index 9b25550..7d1e474 100755 (executable)
@@ -67,9 +67,8 @@ public class ColumnSelection{
     for (int i=0; i < size();i++) {\r
       int temp = columnAt(i);\r
 \r
-      if (temp >= start) {\r
+      if (temp >= start)\r
         selected.setElementAt(new Integer(temp-change),i);\r
-      }\r
     }\r
   }\r
 }\r
diff --git a/src/jalview/gui/ScorePanel.java b/src/jalview/gui/ScorePanel.java
deleted file mode 100755 (executable)
index e6ba4b3..0000000
+++ /dev/null
@@ -1,104 +0,0 @@
-package jalview.gui;\r
-\r
-import jalview.jbgui.*;\r
-import java.util.*;\r
-import javax.swing.*;\r
-import java.awt.*;\r
-import java.awt.event.*;\r
-\r
-public class ScorePanel extends JPanel\r
-{\r
-  AlignViewport av;\r
-\r
-  public ScorePanel(AlignViewport a)\r
-  {\r
-    av = a;\r
-    setPreferredSize(new Dimension(500,80));\r
-    addMouseMotionListener(new MouseMotionAdapter()\r
-    { public void mouseMoved(MouseEvent evt)\r
-      {\r
-        doMouseMoved(evt);\r
-      }\r
-    });\r
-\r
-    ToolTipManager.sharedInstance().registerComponent(this);\r
-  }\r
-\r
-  public void doMouseMoved(MouseEvent evt)\r
-  {\r
-     Vector freq = av.getConsensus(false);\r
-\r
-     int col = (int)(evt.getX()/av.charWidth) +av.getStartRes();\r
-\r
-     if(col >= av.getEndRes() || col >= freq.size())\r
-       return;\r
-\r
-     Hashtable hash = (Hashtable) freq.elementAt( col );\r
-\r
-     String characters = hash.get("maxResidue").toString();\r
-\r
-     if (characters.length()>1)\r
-       this.setToolTipText(characters);\r
-     else\r
-       this.setToolTipText(null);\r
-  }\r
-\r
-\r
-\r
-  public void paintComponent(Graphics g)\r
-  {\r
-   setPreferredSize(new Dimension( this.getWidth(), 80));\r
-   drawScorePanel(g, getWidth(), av.getStartRes(),  av.getChunkWidth());\r
-  }\r
-\r
-  public void drawScorePanel(Graphics g, int width, int startRes, int length)\r
-  {\r
-   g.setColor(Color.white);\r
-   g.fillRect(0, 0,width, 80);\r
-   g.setColor(Color.blue);\r
-   g.setFont(av.getFont());\r
-\r
-   Vector freq = av.getConsensus(false);\r
-\r
-   int value, charOffset;\r
-   String characters;\r
-   char character;\r
-\r
-\r
-   int i=0, iSize = length;\r
-   if(iSize > freq.size())\r
-     iSize=freq.size();\r
-\r
-   for (i = 0; i < iSize; i++)\r
-   {\r
-     g.setColor(Color.blue);\r
-\r
-     Hashtable hash = (Hashtable) freq.elementAt(i+startRes);\r
-     if(hash.containsKey("maxResidue"))\r
-            characters = hash.get("maxResidue").toString();\r
-     else\r
-       characters="@";\r
-     character = characters.charAt(0);\r
-     value = Integer.parseInt(hash.get("maxCount").toString());\r
-\r
-     if (characters.length() > 1)\r
-       character = '+';\r
-\r
-     charOffset = (int) (av.charWidth -\r
-                         g.getFontMetrics().charWidth(character)) / 2;\r
-     g.drawString(character + "", charOffset + (int) (i * av.charWidth),\r
-                  60 + (int) av.charWidth);\r
-\r
-     value = (int) ( (float) value /\r
-                    Float.parseFloat(hash.get("size").toString()) * 55);\r
-\r
-     if ( !jalview.util.Comparison.isGap(character))\r
-       g.fillRect( (int) (i * av.charWidth),\r
-                  60 - value,\r
-                  (int) av.charWidth,\r
-                  value\r
-                  );\r
-   }\r
-  }\r
-\r
-}\r
diff --git a/src/jalview/gui/SecondaryStructurePanel.java b/src/jalview/gui/SecondaryStructurePanel.java
deleted file mode 100755 (executable)
index 1c8bd36..0000000
+++ /dev/null
@@ -1,194 +0,0 @@
-package jalview.gui;\r
-\r
-import javax.swing.JPanel;\r
-import java.awt.event.*;\r
-import java.awt.*;\r
-import java.util.*;\r
-import javax.swing.*;\r
-import jalview.datamodel.*;\r
-\r
-public class SecondaryStructurePanel extends JPanel implements ActionListener\r
-{\r
-  AlignViewport av;\r
-  Vector structures;\r
-\r
-  SecondaryStructure amend;\r
-\r
-  public SecondaryStructurePanel(AlignViewport av)\r
-  {\r
-    this.av = av;\r
-    structures = new Vector();\r
-    setPreferredSize(new Dimension(500,30));\r
-\r
-    addMouseListener(new MouseAdapter()\r
-    {\r
-      public void mousePressed(MouseEvent evt)\r
-      { doMousePressed(evt); }\r
-      public void mouseReleased(MouseEvent evt)\r
-      { doMouseReleased(evt); }\r
-    });\r
-    addMouseMotionListener(new MouseMotionAdapter()\r
-    {\r
-      public void mouseDragged(MouseEvent evt)\r
-      { doMouseDragged(evt);  }\r
-    });\r
-  }\r
-\r
-  int startRes = 0;\r
-  int endRes = 0;\r
-  boolean amendStart = false;\r
-  boolean amendEnd = false;\r
-\r
-  public void doMousePressed(MouseEvent evt)\r
-  {\r
-    amend = null;\r
-    amendStart =false;\r
-    amendEnd = false;\r
-\r
-    startRes = evt.getX() / av.getCharWidth() + av.getStartRes();\r
-    for(int i=0; i<structures.size(); i++)\r
-    {\r
-      SecondaryStructure ss = (SecondaryStructure) structures.get(i);\r
-      if(startRes>=ss.start && startRes<=ss.end)\r
-      {\r
-        amend = ss;\r
-        if(startRes==ss.start)\r
-          amendStart = true;\r
-\r
-        if(startRes==ss.end)\r
-          amendEnd = true;\r
-\r
-        if(evt.getClickCount()==2)\r
-        {\r
-          String label = JOptionPane.showInputDialog(this, "Amend label", "Amend label", JOptionPane.QUESTION_MESSAGE );\r
-          if(label==null)\r
-            label = "";\r
-          ss.label = label;\r
-        }\r
-        break;\r
-      }\r
-    }\r
-    repaint();\r
-\r
-  }\r
-\r
-  public void doMouseReleased(MouseEvent evt)\r
-  {\r
-    endRes = evt.getX() / av.getCharWidth() + av.getStartRes();\r
-\r
-    if(amend!=null)\r
-    {\r
-      if(amendStart)\r
-        amend.start = endRes;\r
-      if(amendEnd)\r
-        amend.end = endRes;\r
-\r
-      amend=null;\r
-      repaint();\r
-      return;\r
-    }\r
-\r
-    endRes = evt.getX() / av.getCharWidth() + av.getStartRes();\r
-\r
-    JPopupMenu pop = new JPopupMenu("Structure type");\r
-    JMenuItem item = new JMenuItem("Helix");\r
-    item.addActionListener(this);\r
-    pop.add(item);\r
-    item = new JMenuItem("Sheet");\r
-    item.addActionListener(this);\r
-    pop.add(item);\r
-    pop.show(this, evt.getX(), evt.getY());\r
-\r
-  }\r
-\r
-  public void actionPerformed(ActionEvent evt)\r
-  {\r
-\r
-    int type = 0;\r
-    if(evt.getActionCommand().equals("Helix"))\r
-       type = SecondaryStructure.HELIX;\r
-    else if(evt.getActionCommand().equals("Sheet"))\r
-      type = SecondaryStructure.SHEET;\r
-\r
-    String label = JOptionPane.showInputDialog(this, "Enter a label for the structure?", "Enter label", JOptionPane.QUESTION_MESSAGE );\r
-    if(label==null)\r
-      label = "";\r
-\r
-    SecondaryStructure ss = new SecondaryStructure(startRes, endRes, type, label);\r
-    structures.add(ss);\r
-    repaint();\r
-\r
-  }\r
-\r
-  public void doMouseDragged(MouseEvent evt)\r
-  {\r
-    paintNow(getGraphics());\r
-  }\r
-\r
-  void paintNow(Graphics g)\r
-  {\r
-    g.setColor(Color.white);\r
-    g.setFont(new Font("Verdana", Font.PLAIN, 10));\r
-    g.fillRect(0,0,getWidth(),getHeight());\r
-    for(int i=0; i<structures.size(); i++)\r
-    {\r
-      SecondaryStructure ss = (SecondaryStructure)structures.get(i);\r
-\r
-\r
-      if(ss.type==SecondaryStructure.SHEET)\r
-      {\r
-        g.setColor(Color.orange);\r
-        if(ss==amend)\r
-          g.setColor(Color.red);\r
-\r
-        g.fillRect( (  ss.start - av.startRes) * av.charWidth,          4,\r
-                    (ss.end - ss.start) * av.charWidth, 7);\r
-\r
-        g.fillPolygon( new int[]{ (ss.end - av.startRes )* av.charWidth,\r
-                       ( ss.end - av.startRes )* av.charWidth,\r
-                       ( ss.end - av.startRes )* av.charWidth+7},\r
-                       new int[]{0,14,7}, 3);\r
-      }\r
-\r
-      if(ss.type==SecondaryStructure.HELIX)\r
-      {\r
-        g.setColor(Color.magenta);\r
-        if(ss==amend)\r
-          g.setColor(Color.red);\r
-        g.fillRoundRect((ss.start -av.startRes)* av.charWidth, 4,\r
-                   (ss.end - ss.start) * av.charWidth, 7, 8,8);\r
-      }\r
-\r
-\r
-\r
-      g.setColor(Color.black);\r
-\r
-      int labelWidth = g.getFontMetrics().stringWidth(ss.label);\r
-\r
-      g.drawString( ss.label,  (ss.start +(ss.end-ss.start)/2 -av.startRes)*av.charWidth - labelWidth/2, 24);\r
-    }\r
-  }\r
-\r
-  public void paintComponent(Graphics g)\r
-  {\r
-    paintNow(g);\r
-  }\r
-}\r
-\r
-class SecondaryStructure\r
-{\r
-  public static int HELIX = 1;\r
-  public static int SHEET = 2;\r
-  public String label="";\r
-  public int start= 20;\r
-  public int end  = 40;\r
-  public int type = HELIX;\r
-\r
-  public SecondaryStructure(int s, int e, int t, String l)\r
-  {\r
-    start = s; end = e; type = t; label = l;\r
-  }\r
-\r
-}\r
-\r
-\r
index a256133..8b68899 100755 (executable)
@@ -61,7 +61,7 @@ public class GAlignFrame extends JInternalFrame
   protected JRadioButtonMenuItem BLOSUM62Colour = new JRadioButtonMenuItem();
   JMenuItem njTreeBlosumMenuItem = new JMenuItem();
   JMenuItem avDistanceTreeBlosumMenuItem = new JMenuItem();
-  protected JCheckBoxMenuItem consensusGraphMenuItem = new JCheckBoxMenuItem();
+  protected JCheckBoxMenuItem annotationPanelMenuItem = new JCheckBoxMenuItem();
   protected JCheckBoxMenuItem colourTextMenuItem = new JCheckBoxMenuItem();
   JMenuItem htmlMenuItem = new JMenuItem();
   JMenuItem overviewMenuItem = new JMenuItem();
@@ -90,6 +90,7 @@ public class GAlignFrame extends JInternalFrame
   protected JCheckBoxMenuItem fullSeqId = new JCheckBoxMenuItem();
   JMenuItem epsFile = new JMenuItem();
   JMenuItem LoadtreeMenuItem = new JMenuItem();
+  JMenuItem jpred = new JMenuItem();
   public GAlignFrame()
   {
 
@@ -457,14 +458,14 @@ public class GAlignFrame extends JInternalFrame
         njTreeBlosumMenuItem_actionPerformed(e);
       }
     });
-    consensusGraphMenuItem.setActionCommand("");
-    consensusGraphMenuItem.setText("Consensus graph");
-    consensusGraphMenuItem.setState(true);
-    consensusGraphMenuItem.addActionListener(new java.awt.event.ActionListener()
+    annotationPanelMenuItem.setActionCommand("");
+    annotationPanelMenuItem.setText("Annotation Panel");
+    annotationPanelMenuItem.setState(true);
+    annotationPanelMenuItem.addActionListener(new java.awt.event.ActionListener()
     {
       public void actionPerformed(ActionEvent e)
       {
-        consensusGraphMenuItem_actionPerformed(e);
+        annotationPanelMenuItem_actionPerformed(e);
       }
     });
     colourTextMenuItem.setText("Colour text");
@@ -689,6 +690,14 @@ public class GAlignFrame extends JInternalFrame
         LoadtreeMenuItem_actionPerformed(e);
       }
     });
+    jpred.setText("JPred");
+    jpred.addActionListener(new java.awt.event.ActionListener()
+    {
+      public void actionPerformed(ActionEvent e)
+      {
+        jpred_actionPerformed(e);
+      }
+    });
     alignFrameMenuBar.add(fileMenu);
     alignFrameMenuBar.add(editMenu);
     alignFrameMenuBar.add(searchMenu);
@@ -735,7 +744,7 @@ public class GAlignFrame extends JInternalFrame
     viewMenu.add(viewTextMenuItem);
     viewMenu.add(colourTextMenuItem);
     viewMenu.add(renderGapsMenuItem);
-    viewMenu.add(consensusGraphMenuItem);
+    viewMenu.add(annotationPanelMenuItem);
     viewMenu.add(overviewMenuItem);
     viewMenu.add(sequenceFeatures);
     colourMenu.add(applyToAllGroups);
@@ -769,6 +778,7 @@ public class GAlignFrame extends JInternalFrame
     calculateMenu.add(avDistanceTreeBlosumMenuItem);
     calculateMenu.add(njTreeBlosumMenuItem);
     alignMenu.add(clustalAlignMenuItem);
+    alignMenu.add(jpred);
     this.getContentPane().add(statusBar, BorderLayout.SOUTH);
     jMenu1.add(pasteNew);
     jMenu1.add(pasteThis);
@@ -889,7 +899,7 @@ public class GAlignFrame extends JInternalFrame
 
 
 
-  protected void consensusGraphMenuItem_actionPerformed(ActionEvent e)
+  protected void annotationPanelMenuItem_actionPerformed(ActionEvent e)
   {
 
   }
@@ -1125,4 +1135,9 @@ public class GAlignFrame extends JInternalFrame
 
   }
 
+  protected void jpred_actionPerformed(ActionEvent e)
+  {
+
+  }
+
 }
index bbbb1ab..d9e576a 100755 (executable)
@@ -10,6 +10,7 @@ package jalview.jbgui;
 
 import java.awt.*;
 import javax.swing.*;
+import javax.swing.border.*;
 
 public class GAlignmentPanel extends JPanel
 {
@@ -19,26 +20,21 @@ public class GAlignmentPanel extends JPanel
   protected JPanel seqPanelHolder = new JPanel();
   BorderLayout borderLayout1 = new BorderLayout();
   BorderLayout borderLayout3 = new BorderLayout();
-  JPanel jPanel2 = new JPanel();
-  BorderLayout borderLayout2 = new BorderLayout();
-  protected JPanel scorePanelHolder = new JPanel();
   protected JPanel scalePanelHolder = new JPanel();
   protected JPanel idPanelHolder = new JPanel();
   BorderLayout borderLayout5 = new BorderLayout();
   protected JPanel idSpaceFillerPanel1 = new JPanel();
-  protected JPanel idSpaceFillerPanel = new JPanel();
-  BorderLayout borderLayout4 = new BorderLayout();
+  public JPanel annotationSpaceFillerHolder = new JPanel();
   BorderLayout borderLayout6 = new BorderLayout();
   ButtonGroup buttonGroup1 = new ButtonGroup();
   BorderLayout borderLayout7 = new BorderLayout();
-  JPanel jPanel3 = new JPanel();
-  protected JPanel secondaryPanelHolder = new JPanel();
-  BorderLayout borderLayout8 = new BorderLayout();
-  BorderLayout borderLayout9 = new BorderLayout();
-  JPanel jPanel1 = new JPanel();
+  JPanel hscrollHolder = new JPanel();
   BorderLayout borderLayout10 = new BorderLayout();
   protected JPanel hscrollFillerPanel = new JPanel();
   BorderLayout borderLayout11 = new BorderLayout();
+  public JScrollPane annotationScroller = new JScrollPane();
+  Border border1;
+  BorderLayout borderLayout4 = new BorderLayout();
 
   public GAlignmentPanel()
   {
@@ -53,6 +49,7 @@ public class GAlignmentPanel extends JPanel
   }
   private void jbInit() throws Exception
   {
+    border1 = BorderFactory.createLineBorder(Color.gray,1);
     idPanelHolder.setBorder(null);
     idPanelHolder.setPreferredSize(new Dimension(70, 10));
     this.setLayout(borderLayout7);
@@ -61,42 +58,38 @@ public class GAlignmentPanel extends JPanel
     sequenceHolderPanel.setPreferredSize(new Dimension(150, 150));
     sequenceHolderPanel.setLayout(borderLayout3);
     seqPanelHolder.setLayout(borderLayout1);
-    jPanel2.setBackground(new Color(212, 208, 230));
-    jPanel2.setBorder(null);
-    jPanel2.setLayout(borderLayout2);
     scalePanelHolder.setBackground(Color.white);
     scalePanelHolder.setMinimumSize(new Dimension(10, 80));
     scalePanelHolder.setPreferredSize(new Dimension(10, 30));
     scalePanelHolder.setLayout(borderLayout6);
-    scorePanelHolder.setBackground(Color.white);
-    scorePanelHolder.setPreferredSize(new Dimension(10, 80));
-    scorePanelHolder.setLayout(borderLayout4);
     idPanelHolder.setLayout(borderLayout5);
     idSpaceFillerPanel1.setBackground(Color.white);
     idSpaceFillerPanel1.setPreferredSize(new Dimension(10, 30));
     idSpaceFillerPanel1.setLayout(borderLayout11);
-    idSpaceFillerPanel.setBackground(Color.white);
-    idSpaceFillerPanel.setPreferredSize(new Dimension(10, 80));
+    annotationSpaceFillerHolder.setBackground(Color.white);
+    annotationSpaceFillerHolder.setPreferredSize(new Dimension(10, 80));
+    annotationSpaceFillerHolder.setLayout(borderLayout4);
     hscroll.setOrientation(JScrollBar.HORIZONTAL);
-    jPanel3.setLayout(borderLayout9);
-    secondaryPanelHolder.setLayout(borderLayout8);
-    jPanel1.setLayout(borderLayout10);
+    hscrollHolder.setLayout(borderLayout10);
     hscrollFillerPanel.setBackground(Color.white);
-    jPanel1.setBackground(Color.white);
+    hscrollFillerPanel.setPreferredSize(new Dimension(70, 10));
+    hscrollHolder.setBackground(Color.white);
+    annotationScroller.setBorder(null);
+    annotationScroller.setPreferredSize(new Dimension(10, 80));
+    this.setPreferredSize(new Dimension(220, 166));
+    this.setRequestFocusEnabled(true);
     sequenceHolderPanel.add(scalePanelHolder,  BorderLayout.NORTH);
     sequenceHolderPanel.add(seqPanelHolder,  BorderLayout.CENTER);
     seqPanelHolder.add(vscroll, BorderLayout.EAST);
-    this.add(jPanel2, BorderLayout.CENTER);
-    jPanel2.add(sequenceHolderPanel, BorderLayout.CENTER);
-    sequenceHolderPanel.add(jPanel3,  BorderLayout.SOUTH);
-    jPanel3.add(scorePanelHolder, BorderLayout.CENTER);
+    sequenceHolderPanel.add(annotationScroller, BorderLayout.SOUTH);
   //  jPanel3.add(secondaryPanelHolder,  BorderLayout.SOUTH);
     this.add(idPanelHolder, BorderLayout.WEST);
     idPanelHolder.add(idSpaceFillerPanel1,  BorderLayout.NORTH);
-    idPanelHolder.add(idSpaceFillerPanel,  BorderLayout.SOUTH);
-    this.add(jPanel1,  BorderLayout.SOUTH);
-    jPanel1.add(hscroll, BorderLayout.CENTER);
-    jPanel1.add(hscrollFillerPanel,  BorderLayout.WEST);
+    idPanelHolder.add(annotationSpaceFillerHolder, BorderLayout.SOUTH);
+    this.add(hscrollHolder,  BorderLayout.SOUTH);
+    hscrollHolder.add(hscroll, BorderLayout.CENTER);
+    hscrollHolder.add(hscrollFillerPanel,  BorderLayout.WEST);
+    this.add(sequenceHolderPanel,  BorderLayout.CENTER);
   }