Wrap alignment with annotations
[jalview.git] / src / jalview / gui / SeqPanel.java
index 8146be0..8486ac1 100755 (executable)
@@ -212,16 +212,26 @@ public class SeqPanel extends JPanel
 \r
     if (av.wrapAlignment)\r
     {\r
+\r
+      int hgap = av.charHeight;\r
+      if (av.scaleAboveWrapped)\r
+        hgap += av.charHeight;\r
+\r
+      int cHeight = av.getAlignment().getHeight() * av.charHeight\r
+          + hgap + seqCanvas.getAnnotationHeight();\r
+\r
         int y = evt.getY();\r
-        y -= (2 * av.charHeight);\r
+        y -= hgap;\r
         x -= seqCanvas.LABEL_WEST;\r
 \r
-        int chunkHeight = (av.getAlignment().getHeight() + 2) * av.charHeight;\r
+\r
         int cwidth = seqCanvas.getWrappedCanvasWidth(this.getWidth());\r
-        wrappedBlock = y/chunkHeight;\r
-        wrappedBlock += av.getStartRes()/cwidth;\r
 \r
-        res = wrappedBlock*cwidth   +   x / av.getCharWidth();\r
+        wrappedBlock = y / cHeight;\r
+        wrappedBlock += av.getStartRes() / cwidth;\r
+\r
+        res = wrappedBlock * cwidth + x / av.getCharWidth();\r
+\r
     }\r
     else\r
     {\r
@@ -234,14 +244,22 @@ public class SeqPanel extends JPanel
 \r
    int findSeq(MouseEvent evt)\r
    {\r
+\r
      int seq = 0;\r
      int y = evt.getY();\r
 \r
      if (av.wrapAlignment)\r
      {\r
-       y -= (2 * av.charHeight);\r
-       int chunkHeight = (av.getAlignment().getHeight() + 2) * av.charHeight;\r
-       seq = ( (y % chunkHeight) / av.getCharHeight());\r
+       int hgap = av.charHeight;\r
+       if (av.scaleAboveWrapped)\r
+         hgap += av.charHeight;\r
+\r
+       int cHeight = av.getAlignment().getHeight() * av.charHeight\r
+           + hgap + seqCanvas.getAnnotationHeight();\r
+\r
+         y -= hgap;\r
+\r
+       seq = ( (y % cHeight) / av.getCharHeight());\r
      }\r
      else\r
      {\r
@@ -602,8 +620,18 @@ public class SeqPanel extends JPanel
 \r
       startWrapBlock=wrappedBlock;\r
 \r
-      if(seq<0 || res<0)\r
+      if(av.wrapAlignment && seq>av.alignment.getHeight())\r
+      {\r
+          JOptionPane.showInternalMessageDialog(Desktop.desktop,\r
+              "Cannot edit annotations in wrapped view.",\r
+              "Wrapped view - no edit",\r
+              JOptionPane.WARNING_MESSAGE);\r
         return;\r
+      }\r
+\r
+      if(seq<0 || res<0)\r
+            return;\r
+\r
 \r
         SequenceI sequence = (Sequence) av.getAlignment().getSequenceAt(seq);\r
 \r