CursoMode added
authoramwaterhouse <Andrew Waterhouse>
Fri, 24 Mar 2006 15:33:20 +0000 (15:33 +0000)
committeramwaterhouse <Andrew Waterhouse>
Fri, 24 Mar 2006 15:33:20 +0000 (15:33 +0000)
src/jalview/gui/AlignViewport.java
src/jalview/gui/AlignmentPanel.java
src/jalview/gui/SeqCanvas.java
src/jalview/gui/SeqPanel.java

index 23d7612..a92517c 100755 (executable)
@@ -74,6 +74,8 @@ public class AlignViewport
     boolean hasHiddenColumns = false;\r
     boolean hasHiddenRows = false;\r
 \r
+    boolean cursorMode = false;\r
+\r
     // The following vector holds the features which are\r
     // currently visible, in the correct order or rendering\r
     Hashtable featuresDisplayed = null;\r
index 7ef6763..a04c5bf 100755 (executable)
@@ -106,6 +106,13 @@ public class AlignmentPanel extends GAlignmentPanel
     {\r
       public void keyPressed(KeyEvent evt)\r
       {\r
+        if(av.cursorMode\r
+           && evt.getKeyCode()>=KeyEvent.VK_0\r
+           && evt.getKeyCode()<=KeyEvent.VK_9)\r
+        {\r
+          seqPanel.numberPressed(evt.getKeyChar());\r
+        }\r
+\r
         switch (evt.getKeyCode())\r
         {\r
           case 27: // escape key\r
@@ -115,26 +122,101 @@ public class AlignmentPanel extends GAlignmentPanel
             break;\r
 \r
           case KeyEvent.VK_DOWN:\r
-            alignFrame.moveSelectedSequences(false);\r
-\r
+            if(av.cursorMode)\r
+            {\r
+              seqPanel.moveCursor(0,1);\r
+            }\r
+            else\r
+              alignFrame.moveSelectedSequences(false);\r
             break;\r
 \r
           case KeyEvent.VK_UP:\r
-            alignFrame.moveSelectedSequences(true);\r
+            if (av.cursorMode)\r
+            {\r
+              seqPanel.moveCursor(0,-1);\r
+            }\r
+            else\r
+              alignFrame.moveSelectedSequences(true);\r
+            break;\r
 \r
+          case KeyEvent.VK_LEFT:\r
+            if(av.cursorMode)\r
+            {\r
+              seqPanel.moveCursor(-1,0);\r
+            }\r
+            break;\r
+\r
+          case KeyEvent.VK_RIGHT:\r
+            if (av.cursorMode)\r
+            {\r
+              seqPanel.moveCursor(1,0);\r
+            }\r
+            break;\r
+\r
+          case KeyEvent.VK_SPACE:\r
+            if(av.cursorMode)\r
+            {\r
+              seqPanel.insertGapAtCursor(evt.isControlDown());\r
+            }\r
             break;\r
 \r
-          case KeyEvent.VK_BACK_SPACE:\r
           case KeyEvent.VK_DELETE:\r
-            alignFrame.cut_actionPerformed(null);\r
+            if(av.cursorMode)\r
+            {\r
+              seqPanel.deleteGapAtCursor(evt.isControlDown());\r
+              break;\r
+            }\r
+\r
+          case KeyEvent.VK_BACK_SPACE:\r
+            if(!av.cursorMode)\r
+            {\r
+              alignFrame.cut_actionPerformed(null);\r
+              seqPanel.seqCanvas.repaint();\r
+            }\r
             break;\r
 \r
-          case KeyEvent.VK_P:\r
-            seqPanel.seqCanvas.increaseAARatio();\r
+          case KeyEvent.VK_Q:\r
+            if(av.cursorMode)\r
+            {\r
+              seqPanel.setSelectionAreaAtCursor(true);\r
+            }\r
             break;\r
-          case KeyEvent.VK_L:\r
-            seqPanel.seqCanvas.decreaseAARation();\r
+          case KeyEvent.VK_M:\r
+            if(av.cursorMode)\r
+            {\r
+              seqPanel.setSelectionAreaAtCursor(false);\r
+            }\r
+            break;\r
+\r
+         case KeyEvent.VK_F2:\r
+           av.cursorMode = ! av.cursorMode;\r
+           alignFrame.statusBar.setText("Keyboard editing mode is "+\r
+               (av.cursorMode ? "on" : "off"));\r
+           if(av.cursorMode)\r
+           {\r
+             seqPanel.seqCanvas.cursorX = av.startRes;\r
+             seqPanel.seqCanvas.cursorY = av.startSeq;\r
+           }\r
+           seqPanel.seqCanvas.repaint();\r
+           break;\r
+\r
+          case KeyEvent.VK_F1:\r
+            try\r
+            {\r
+              ClassLoader cl = jalview.gui.Desktop.class.getClassLoader();\r
+              java.net.URL url = javax.help.HelpSet.findHelpSet(cl, "help/help");\r
+              javax.help.HelpSet hs = new javax.help.HelpSet(cl, url);\r
+\r
+              javax.help.HelpBroker hb = hs.createHelpBroker();\r
+              hb.setCurrentID("home");\r
+              hb.setDisplayed(true);\r
+            }\r
+            catch (Exception ex)\r
+            {\r
+              ex.printStackTrace();\r
+            }\r
             break;\r
+\r
         }\r
       }\r
     });\r
@@ -373,7 +455,7 @@ public class AlignmentPanel extends GAlignmentPanel
    */\r
   public boolean scrollRight(boolean right)\r
   {\r
-    if (right)\r
+    if (!right)\r
     {\r
       if (hscroll.getValue() < 1)\r
       {\r
index 2b5995c..99447a4 100755 (executable)
@@ -34,8 +34,8 @@ import javax.swing.*;
  */\r
 public class SeqCanvas extends JComponent\r
 {\r
-    FeatureRenderer fr;\r
-    SequenceRenderer sr;\r
+    final FeatureRenderer fr;\r
+    final SequenceRenderer sr;\r
     BufferedImage img;\r
     Graphics2D gg;\r
     int imgWidth;\r
@@ -46,6 +46,11 @@ public class SeqCanvas extends JComponent
     int LABEL_WEST;\r
     int LABEL_EAST;\r
 \r
+\r
+    int cursorX = 0;\r
+    int cursorY = 0;\r
+\r
+\r
     /**\r
      * Creates a new SeqCanvas object.\r
      *\r
@@ -342,7 +347,7 @@ public class SeqCanvas extends JComponent
 \r
         if (pdbCanvas != null)\r
         {\r
-         pdbCanvas.updateSeqColours();\r
+           pdbCanvas.updateSeqColours();\r
         }\r
 \r
     }\r
@@ -431,11 +436,18 @@ public class SeqCanvas extends JComponent
         av.endRes = av.startRes + cWidth;\r
 \r
 \r
-        int endx = (startRes + cWidth) - 1;\r
+        int endx;\r
         int ypos = hgap;\r
 \r
         while ((ypos <= canvasHeight) && (startRes < av.alignment.getWidth()))\r
         {\r
+          endx = startRes + cWidth;\r
+\r
+          if (endx > al.getWidth())\r
+          {\r
+            endx = al.getWidth();\r
+          }\r
+\r
             g.setFont(av.getFont());\r
             g.setColor(Color.black);\r
 \r
@@ -472,12 +484,6 @@ public class SeqCanvas extends JComponent
                     cWidth * av.charWidth, (int) clip.getBounds().getHeight());\r
             }\r
 \r
-            if (av.vconsensus!=null && av.alignment.getWidth() >= av.vconsensus.size())\r
-            {\r
-              endx = av.vconsensus.size() - 2;\r
-            }\r
-\r
-\r
             drawPanel(g, startRes, endx, 0, al.getHeight(), ypos);\r
 \r
             if(av.showAnnotation)\r
@@ -486,7 +492,7 @@ public class SeqCanvas extends JComponent
               if(annotations==null)\r
                 annotations = new AnnotationPanel(av);\r
 \r
-              annotations.drawComponent( (Graphics2D) g, startRes, endx + 1);\r
+              annotations.drawComponent( (Graphics2D) g, startRes, endx);\r
               g.translate(0, -cHeight - ypos);\r
             }\r
             g.setClip(clip);\r
@@ -497,12 +503,6 @@ public class SeqCanvas extends JComponent
               ypos -= 3;\r
 \r
             startRes += cWidth;\r
-            endx = (startRes + cWidth) - 1;\r
-\r
-            if (endx > al.getWidth())\r
-            {\r
-                endx = al.getWidth();\r
-            }\r
         }\r
     }\r
 \r
@@ -522,35 +522,12 @@ public class SeqCanvas extends JComponent
      * DOCUMENT ME!\r
      *\r
      * @param g1 DOCUMENT ME!\r
-     * @param x1 DOCUMENT ME!\r
-     * @param x2 DOCUMENT ME!\r
-     * @param y1 DOCUMENT ME!\r
-     * @param y2 DOCUMENT ME!\r
-     * @param startx DOCUMENT ME!\r
-     * @param starty DOCUMENT ME!\r
+     * @param startRes DOCUMENT ME!\r
+     * @param endRes DOCUMENT ME!\r
+     * @param startSeq DOCUMENT ME!\r
+     * @param endSeq DOCUMENT ME!\r
      * @param offset DOCUMENT ME!\r
      */\r
-\r
-    float aaRatio = 2f/3f;\r
-    public void increaseAARatio()\r
-    {\r
-      aaRatio += .025;\r
-      if(aaRatio>1)\r
-        aaRatio = 1;\r
-\r
-      repaint();\r
-    }\r
-\r
-    public void decreaseAARation()\r
-    {\r
-      aaRatio -= .025;\r
-      if(aaRatio<0)\r
-        aaRatio = 0;\r
-\r
-      repaint();\r
-    }\r
-\r
-\r
     void drawPanel(Graphics g1, int startRes, int endRes,\r
                     int startSeq, int endSeq, int offset)\r
     {\r
@@ -621,9 +598,10 @@ public class SeqCanvas extends JComponent
                    int offset)\r
    {\r
 \r
-      sr.renderGaps(av.renderGaps);\r
+\r
       Graphics2D g = (Graphics2D) g1;\r
       g.setFont(av.getFont());\r
+      sr.prepare(g, av.renderGaps);\r
 \r
       SequenceI nextSeq;\r
 \r
@@ -633,15 +611,14 @@ public class SeqCanvas extends JComponent
         {\r
             nextSeq = av.alignment.getSequenceAt(i);\r
 \r
-            sr.drawSequence(g, nextSeq, av.alignment.findAllGroups(nextSeq),\r
+            sr.drawSequence(nextSeq, av.alignment.findAllGroups(nextSeq),\r
                             startRes, endRes,\r
                             offset + ( (i - startSeq) * av.charHeight));\r
 \r
             if (av.showSequenceFeatures)\r
             {\r
                 fr.drawSequence(g1, nextSeq, startRes, endRes,\r
-                    offset + ((i - startSeq) * av.charHeight), av.charWidth,\r
-                    av.charHeight);\r
+                    offset + ((i - startSeq) * av.charHeight));\r
             }\r
 \r
             /// Highlight search Results once all sequences have been drawn\r
@@ -655,10 +632,16 @@ public class SeqCanvas extends JComponent
                   sr.drawHighlightedText(nextSeq, visibleResults[r],\r
                                          visibleResults[r + 1],\r
                                          (visibleResults[r] - startRes) * av.charWidth,\r
-                                         offset + ( (i - startSeq) * av.charHeight),\r
-                                         av.charWidth, av.charHeight);\r
+                                         offset + ( (i - startSeq) * av.charHeight));\r
                 }\r
             }\r
+\r
+            if(av.cursorMode && cursorY==i\r
+               && cursorX>=startRes && cursorX<=endRes)\r
+            {\r
+              sr.drawCursor(nextSeq, cursorX, (cursorX - startRes) * av.charWidth,\r
+                            offset + ( (i - startSeq) * av.charHeight));\r
+            }\r
           }\r
 \r
         //\r
index 2fe27b3..3f49cc4 100755 (executable)
@@ -45,8 +45,6 @@ public class SeqPanel extends JPanel implements MouseListener,
     public AlignmentPanel ap;\r
     protected int lastres;\r
     protected int startseq;\r
-    int startEdit = -1;\r
-    int endEdit = -1;\r
     protected AlignViewport av;\r
 \r
     // if character is inserted or deleted, we will need to recalculate the conservation\r
@@ -173,8 +171,145 @@ public class SeqPanel extends JPanel implements MouseListener,
      seqEditOccurred = false;\r
      editingSeqs = false;\r
      groupEditing = false;\r
+     keyboardGaps = null;\r
     }\r
 \r
+\r
+    void moveCursor(int dx, int dy)\r
+    {\r
+      seqCanvas.cursorX += dx;\r
+      seqCanvas.cursorY += dy;\r
+\r
+      if(seqCanvas.cursorX<0)\r
+        seqCanvas.cursorX = 0;\r
+      else if(seqCanvas.cursorX>av.alignment.getWidth()-1)\r
+        seqCanvas.cursorX = av.alignment.getWidth()-1;\r
+      if(seqCanvas.cursorX<av.startRes)\r
+        ap.scrollRight(false);\r
+      else if(seqCanvas.cursorX>av.endRes)\r
+        ap.scrollRight(true);\r
+\r
+      if(seqCanvas.cursorY<0)\r
+        seqCanvas.cursorY=0;\r
+      else if(seqCanvas.cursorY>av.alignment.getHeight()-1)\r
+        seqCanvas.cursorY = av.alignment.getHeight()-1;\r
+      if(seqCanvas.cursorY<av.startSeq)\r
+        ap.scrollUp(true);\r
+      else if(seqCanvas.cursorY+1>av.endSeq)\r
+        ap.scrollUp(false);\r
+\r
+      setStatusMessage(av.alignment.getSequenceAt(seqCanvas.cursorY),\r
+                       seqCanvas.cursorX, seqCanvas.cursorY);\r
+      seqCanvas.repaint();\r
+    }\r
+\r
+    void setSelectionAreaAtCursor(boolean topLeft)\r
+    {\r
+      SequenceI sequence =\r
+          (Sequence) av.getAlignment().getSequenceAt(seqCanvas.cursorY);\r
+\r
+      if(av.getSelectionGroup()!=null)\r
+      {\r
+        SequenceGroup sg = av.selectionGroup;\r
+        //Find the top and bottom of this group\r
+        int min = av.alignment.getHeight(), max = 0;\r
+        for(int i=0; i<sg.getSize(); i++)\r
+        {\r
+          int index = av.alignment.findIndex( sg.getSequenceAt(i) );\r
+          if(index > max)\r
+            max = index;\r
+          if(index < min)\r
+            min = index;\r
+        }\r
+\r
+        max ++;\r
+\r
+        if(topLeft)\r
+        {\r
+          sg.setStartRes(seqCanvas.cursorX);\r
+          if(sg.getEndRes()<seqCanvas.cursorX)\r
+            sg.setEndRes(seqCanvas.cursorX);\r
+\r
+          min = seqCanvas.cursorY;\r
+        }\r
+        else\r
+        {\r
+          sg.setEndRes(seqCanvas.cursorX);\r
+          if(sg.getStartRes()>seqCanvas.cursorX)\r
+            sg.setStartRes(seqCanvas.cursorX);\r
+\r
+          max = seqCanvas.cursorY+1;\r
+        }\r
+\r
+        if(min>max)\r
+        {\r
+          // Only the user can do this\r
+          av.setSelectionGroup(null);\r
+        }\r
+        else\r
+        {\r
+          // Now add any sequences between min and max\r
+          sg.sequences.clear();\r
+          for (int i = min; i < max; i++)\r
+          {\r
+            sg.addSequence(av.alignment.getSequenceAt(i), false);\r
+          }\r
+        }\r
+      }\r
+\r
+      if (av.getSelectionGroup() == null)\r
+      {\r
+        SequenceGroup sg = new SequenceGroup();\r
+        sg.setStartRes(seqCanvas.cursorX);\r
+        sg.setEndRes(seqCanvas.cursorX);\r
+        sg.addSequence(sequence, false);\r
+        av.setSelectionGroup(sg);\r
+      }\r
+\r
+\r
+      ap.repaint();\r
+    }\r
+\r
+    void insertGapAtCursor(boolean group)\r
+    {\r
+      ap.alignFrame.addHistoryItem(new HistoryItem("Edit Sequence",\r
+                                                   av.alignment, HistoryItem.EDIT));\r
+      groupEditing = group;\r
+      startseq = seqCanvas.cursorY;\r
+      lastres = seqCanvas.cursorX;\r
+      editSequence(true, seqCanvas.cursorX+getKeyboardGaps());\r
+      editOccurred();\r
+    }\r
+\r
+    void deleteGapAtCursor(boolean group)\r
+    {\r
+      ap.alignFrame.addHistoryItem(new HistoryItem("Edit Sequence",\r
+                                                   av.alignment, HistoryItem.EDIT));\r
+      groupEditing = group;\r
+      startseq = seqCanvas.cursorY;\r
+      lastres = seqCanvas.cursorX+getKeyboardGaps();\r
+      editSequence(false, seqCanvas.cursorX);\r
+      editOccurred();\r
+    }\r
+\r
+    void numberPressed(char value)\r
+    {\r
+      if(keyboardGaps==null)\r
+        keyboardGaps = new StringBuffer();\r
+\r
+      keyboardGaps.append(value);\r
+    }\r
+\r
+    StringBuffer keyboardGaps;\r
+    int getKeyboardGaps()\r
+    {\r
+      if(keyboardGaps==null)\r
+        return 1;\r
+      else\r
+        return Integer.parseInt(keyboardGaps.toString());\r
+    }\r
+\r
+\r
     /**\r
      * DOCUMENT ME!\r
      *\r
@@ -183,6 +318,7 @@ public class SeqPanel extends JPanel implements MouseListener,
     public void mouseReleased(MouseEvent evt)\r
     {\r
       mouseDragging = false;\r
+      mouseWheelPressed = false;\r
 \r
       if (!editingSeqs)\r
       {\r
@@ -190,13 +326,10 @@ public class SeqPanel extends JPanel implements MouseListener,
          return;\r
       }\r
 \r
-        if (seqEditOccurred)\r
-        {\r
-            editOccurred();\r
-        }\r
+       editOccurred();\r
 \r
-        endEditing();\r
-        ap.repaint();\r
+       endEditing();\r
+       ap.repaint();\r
     }\r
 \r
 \r
@@ -230,8 +363,6 @@ public class SeqPanel extends JPanel implements MouseListener,
       }\r
 \r
 \r
-      ap.alignFrame.addHistoryItem(new HistoryItem("Edit Sequence",\r
-                                                   av.alignment, HistoryItem.EDIT));\r
 \r
       int seq = findSeq(evt);\r
       int res = findRes(evt);\r
@@ -239,6 +370,9 @@ public class SeqPanel extends JPanel implements MouseListener,
       if(seq<0 || res<0)\r
         return;\r
 \r
+      ap.alignFrame.addHistoryItem(new HistoryItem("Edit Sequence",\r
+                                                         av.alignment, HistoryItem.EDIT));\r
+\r
         if ((seq < av.getAlignment().getHeight()) &&\r
                 (res < av.getAlignment().getSequenceAt(seq).getLength()))\r
         {\r
@@ -251,9 +385,6 @@ public class SeqPanel extends JPanel implements MouseListener,
             lastres = -1;\r
         }\r
 \r
-        startEdit = lastres;\r
-        endEdit = lastres;\r
-\r
         return;\r
     }\r
 \r
@@ -274,6 +405,7 @@ public class SeqPanel extends JPanel implements MouseListener,
       int res = findRes(evt);\r
       int seq = findSeq(evt);\r
 \r
+\r
       if(res<0 || seq<0 || seq >= av.getAlignment().getHeight())\r
             return;\r
 \r
@@ -289,36 +421,7 @@ public class SeqPanel extends JPanel implements MouseListener,
         seqCanvas.pdbCanvas.highlightRes(sequence.findPosition(res));\r
       }\r
 \r
-\r
-        StringBuffer text = new StringBuffer("Sequence " + (seq + 1) + " ID: " +\r
-                sequence.getName());\r
-\r
-        Object obj = null;\r
-        if (av.alignment.isNucleotide())\r
-        {\r
-          obj = ResidueProperties.nucleotideName.get(sequence.getCharAt(res) +\r
-              "");\r
-          if(obj!=null)\r
-            text.append(" Nucleotide: ");\r
-        }\r
-        else\r
-        {\r
-          obj = ResidueProperties.aa2Triplet.get(sequence.getCharAt(res) + "");\r
-          if(obj!=null)\r
-            text.append("  Residue: ");\r
-        }\r
-\r
-        if (obj != null)\r
-        {\r
-\r
-          if (obj != "")\r
-          {\r
-            text.append( obj + " (" +\r
-                        av.getAlignment().getSequenceAt(seq).findPosition(res) + ")");\r
-          }\r
-        }\r
-\r
-        ap.alignFrame.statusBar.setText(text.toString());\r
+      setStatusMessage(sequence, res, seq);\r
 \r
         // use aa to see if the mouse pointer is on a\r
         if (av.showSequenceFeatures)\r
@@ -334,7 +437,8 @@ public class SeqPanel extends JPanel implements MouseListener,
                 if ( (features[i].getBegin() <= sequence.findPosition(res)) &&\r
                     (features[i].getEnd() >= sequence.findPosition(res)))\r
                 {\r
-                  if(!av.featuresDisplayed.containsKey(features[i].getType()))\r
+                  if(av.featuresDisplayed==null\r
+                    || !av.featuresDisplayed.containsKey(features[i].getType()))\r
                   continue;\r
 \r
 \r
@@ -382,6 +486,39 @@ public class SeqPanel extends JPanel implements MouseListener,
         }\r
     }\r
 \r
+    void setStatusMessage(SequenceI sequence, int res, int seq)\r
+    {\r
+      StringBuffer text = new StringBuffer("Sequence " + (seq + 1) + " ID: " +\r
+                                           sequence.getName());\r
+\r
+      Object obj = null;\r
+      if (av.alignment.isNucleotide())\r
+      {\r
+        obj = ResidueProperties.nucleotideName.get(sequence.getCharAt(res) +\r
+                                                   "");\r
+        if (obj != null)\r
+          text.append(" Nucleotide: ");\r
+      }\r
+      else\r
+      {\r
+        obj = ResidueProperties.aa2Triplet.get(sequence.getCharAt(res) + "");\r
+        if (obj != null)\r
+          text.append("  Residue: ");\r
+      }\r
+\r
+      if (obj != null)\r
+      {\r
+\r
+        if (obj != "")\r
+        {\r
+          text.append(obj + " (" + sequence.findPosition(res) +\r
+                      ")");\r
+        }\r
+      }\r
+      ap.alignFrame.statusBar.setText(text.toString());\r
+\r
+    }\r
+\r
     /**\r
      * DOCUMENT ME!\r
      *\r
@@ -407,19 +544,33 @@ public class SeqPanel extends JPanel implements MouseListener,
             return;\r
         }\r
 \r
-        boolean dragRight = true;\r
-\r
-        if ((res < av.getAlignment().getWidth()) && (res < lastres))\r
+        if ( (res < av.getAlignment().getWidth()) && (res < lastres))\r
         {\r
-            dragRight = false;\r
+          // dragLeft, delete gap\r
+          editSequence(false, res);\r
         }\r
-        else if(av.hasHiddenColumns)\r
+        else\r
+          editSequence(true, res);\r
+\r
+        mouseDragging = true;\r
+        if(scrollThread!=null)\r
+          scrollThread.setEvent(evt);\r
+\r
+    }\r
+\r
+    void editSequence(boolean insertGap, int startres)\r
+    {\r
+      int fixedLeft = -1;\r
+      int fixedRight = -1;\r
+      boolean fixedColumns = false;\r
+\r
+       if(insertGap && av.hasHiddenColumns)\r
         {\r
           //Stop editing if the user has dragged beyond hiddenBoundary\r
-          int lastCol = av.getColumnSelection().getHiddenRegionBoundary(lastres);\r
-          if( lastCol < res)\r
+          fixedRight = av.getColumnSelection().getHiddenRegionBoundary(lastres);\r
+          if( fixedRight < lastres)\r
           {\r
-            if(lastres!=lastCol)\r
+            if(lastres!=fixedRight)\r
             {\r
               endEditing();\r
               return;\r
@@ -427,220 +578,332 @@ public class SeqPanel extends JPanel implements MouseListener,
           }\r
         }\r
 \r
-        if(!groupEditing && av.hasHiddenRows)\r
+        if (!groupEditing && av.hasHiddenRows)\r
         {\r
-          if(av.alignment.getSequenceAt(startseq).getHiddenSequences()!=null)\r
+          if (av.alignment.getSequenceAt(startseq).getHiddenSequences() != null)\r
           {\r
             groupEditing = true;\r
           }\r
         }\r
 \r
 \r
-        if (res != lastres)\r
-        {\r
-            SequenceI seq;\r
-            // Group editing\r
-            if (groupEditing)\r
-            {\r
-                SequenceGroup sg = av.getSelectionGroup();\r
+        SequenceI seq = av.alignment.getSequenceAt(startseq);\r
+        StringBuffer message = new StringBuffer();\r
+        if (groupEditing)\r
+          message.append("Edit group:");\r
+       else\r
+            message.append("Edit sequence: "+seq.getName());\r
 \r
-                if (av.hasHiddenRows)\r
-                {\r
-                  //sg might be null as the user may only see 1 sequence\r
-                  if(sg==null)\r
-                  {\r
-                    sg = new SequenceGroup();\r
-                    sg.addSequence(av.alignment.getSequenceAt(startseq), false);\r
-                  }\r
+       if(insertGap)\r
+         message.append(" insert ");\r
+       else\r
+         message.append(" delete ");\r
 \r
-                  SequenceGroup tmp = new SequenceGroup();\r
+       message.append(Math.abs(startres-lastres)+" gaps.");\r
+       ap.alignFrame.statusBar.setText(message.toString());\r
 \r
-                  //Do any of the sequences have hidden associates?\r
-                  for (int s = 0; s < sg.getSize(); s++)\r
-                  {\r
-                    seq = sg.getSequenceAt(s);\r
-                    tmp.addSequence(seq, false);\r
-                    if (seq.getHiddenSequences()!=null)\r
-                    {\r
-                      for(int h=0; h<seq.getHiddenSequences().getSize(); h++)\r
-                        tmp.addSequence(seq.getHiddenSequences().getSequenceAt(h),\r
-                                        false);\r
-                    }\r
-                  }\r
 \r
-                  sg = tmp;\r
-                }\r
+        //Are we editing within a selection group?\r
+        if (groupEditing\r
+            || (av.getSelectionGroup() != null &&\r
+                av.getSelectionGroup().sequences.contains(seq)))\r
+        {\r
+          fixedColumns = true;\r
 \r
+          fixedLeft = av.getSelectionGroup().getStartRes();\r
+          fixedRight = av.getSelectionGroup().getEndRes();\r
 \r
-                if (sg == null)\r
-                {\r
-                    endEditing();\r
-                    return;\r
-                }\r
+          if (   (startres < fixedLeft && lastres >= fixedLeft)\r
+              || (startres >= fixedLeft && lastres < fixedLeft)\r
+              || (startres > fixedRight && lastres <=fixedRight)\r
+              || (startres <= fixedRight && lastres > fixedRight))\r
+          {\r
+            endEditing();\r
+            return;\r
+          }\r
+\r
+          if (fixedLeft > startres)\r
+          {\r
+            fixedRight = fixedLeft - 1;\r
+            fixedLeft = 0;\r
+          }\r
+          else if (fixedRight < startres)\r
+          {\r
+            fixedLeft = fixedRight;\r
+            fixedRight = -1;\r
+          }\r
+        }\r
 \r
-                int blankColumn = -1;\r
+        if (groupEditing)\r
+        {\r
+          SequenceGroup sg = av.getSelectionGroup();\r
+          if(fixedLeft>sg.getEndRes()\r
+          ||fixedRight<sg.getStartRes())\r
+       {\r
+         endEditing();\r
+         return;\r
+       }\r
 \r
-                // drag to right\r
-                if (dragRight)\r
-                {\r
+          if (av.hasHiddenRows)\r
+          {\r
+            //sg might be null as the user may only see 1 sequence\r
+            if (sg == null)\r
+            {\r
+              sg = new SequenceGroup();\r
+              sg.addSequence(av.alignment.getSequenceAt(startseq), false);\r
+            }\r
 \r
-                  // Is it valid??\r
-                  // Find the next gap before the end\r
-                  // of the visible region boundary\r
-                  if (av.hasHiddenColumns)\r
-                  {\r
-                    if(res-lastres > 1)\r
-                    {\r
-                      res = lastres+1;\r
-                    }\r
+            SequenceGroup tmp = new SequenceGroup();\r
 \r
+            //Do any of the sequences have hidden associates?\r
+            for (int s = 0; s < sg.getSize(); s++)\r
+            {\r
+              seq = sg.getSequenceAt(s);\r
+              tmp.addSequence(seq, false);\r
+              if (seq.getHiddenSequences() != null)\r
+              {\r
+                for (int h = 0; h < seq.getHiddenSequences().getSize(); h++)\r
+                  tmp.addSequence(seq.getHiddenSequences().getSequenceAt(h),\r
+                                  false);\r
+              }\r
+            }\r
 \r
-                    int lastCol = av.getColumnSelection().\r
-                          getHiddenRegionBoundary(res);\r
+            sg = tmp;\r
+          }\r
 \r
-                    if(lastCol!=res)\r
-                    {\r
-                      for (blankColumn = lastCol;\r
-                           blankColumn > lastres;\r
-                           blankColumn--)\r
-                      {\r
-                        boolean blank = true;\r
-                        for (int s = 0; s < sg.getSize(); s++)\r
-                        {\r
-                          seq = sg.getSequenceAt(s);\r
-\r
-                          if (seq.getSequence().length() <= blankColumn)\r
-                          {\r
-                            continue;\r
-                          }\r
-\r
-                          if (!jalview.util.Comparison.isGap(\r
-                              seq.getSequence().charAt(blankColumn)))\r
-                          {\r
-                            blank = false;\r
-                            continue;\r
-                          }\r
-                        }\r
-                        if (blank)\r
-                          break;\r
-                      }\r
-\r
-\r
-                      if (blankColumn <= lastres)\r
-                      {\r
-                        endEditing();\r
-                        return;\r
-                      }\r
-                    }\r
-                    else\r
-                      blankColumn = -1;\r
+          if (sg == null)\r
+          {\r
+            endEditing();\r
+            return;\r
+          }\r
 \r
-                  }\r
+         // int blankColumn = -1;\r
 \r
-                  sg.setEndRes(sg.getEndRes() + (res - lastres));\r
-                }\r
+          // drag to right\r
+          if (insertGap)\r
+          {\r
+            // Is it valid??\r
+            // Find the next gap before the end\r
+            // of the visible region boundary\r
+            if (av.hasHiddenColumns)\r
+            {\r
+             // int lastCol = av.getColumnSelection().\r
+             //     getHiddenRegionBoundary(res);\r
 \r
-                // drag to left\r
-                else\r
+            }\r
+\r
+              if (fixedRight != startres && fixedRight<av.alignment.getWidth()-1)\r
+              {\r
+                for (fixedRight = fixedRight;\r
+                     fixedRight > lastres;\r
+                     fixedRight --)\r
                 {\r
-                    /// Are we able to delete?\r
-                    // ie are all columns blank?\r
+                  boolean blank = true;\r
+                  for (int s = 0; s < sg.getSize(); s++)\r
+                  {\r
+                    seq = sg.getSequenceAt(s);\r
 \r
-                    for (int s = 0; s < sg.getSize(); s++)\r
+                    if (seq.getSequence().length() <= fixedRight)\r
                     {\r
-                        seq = sg.getSequenceAt(s);\r
-\r
-                        for (int j = res; j < lastres; j++)\r
-                        {\r
-                            if (seq.getSequence().length() <= j)\r
-                            {\r
-                                continue;\r
-                            }\r
-\r
-                            if (!jalview.util.Comparison.isGap(\r
-                                        seq.getSequence().charAt(j)))\r
-                            {\r
-                                // Not a gap, block edit not valid\r
-                                endEditing();\r
-                                return;\r
-                            }\r
-                        }\r
+                      continue;\r
                     }\r
 \r
-                    if(res<sg.getStartRes())\r
+                    if (!jalview.util.Comparison.isGap(\r
+                        seq.getCharAt(fixedRight)))\r
                     {\r
-                      sg.setStartRes(sg.getStartRes() - 1);\r
+                      blank = false;\r
+                      continue;\r
                     }\r
-                    sg.setEndRes(sg.getEndRes() - (lastres - res));\r
+                  }\r
+                  if (blank)\r
+                    break;\r
                 }\r
+              }\r
+\r
+              if (fixedRight <= startres)\r
+              {\r
+                endEditing();\r
+                return;\r
+              }\r
+            }\r
 \r
-                for (int i = 0; i < sg.getSize(); i++)\r
+\r
+          // drag to left\r
+          else\r
+          {\r
+            /// Are we able to delete?\r
+            // ie are all columns blank?\r
+\r
+            for (int s = 0; s < sg.getSize(); s++)\r
+            {\r
+              seq = sg.getSequenceAt(s);\r
+\r
+              for (int j = startres; j < lastres; j++)\r
+              {\r
+                if (seq.getSequence().length() <= j)\r
                 {\r
-                    seq = sg.getSequenceAt(i);\r
+                  continue;\r
+                }\r
 \r
-                    // drag to right\r
-                    if (dragRight)\r
-                    {\r
-                        for (int j = lastres; j < res; j++)\r
-                        {\r
-                            insertChar(j, seq, blankColumn);\r
-                        }\r
-                    }\r
+                if (!jalview.util.Comparison.isGap(\r
+                    seq.getSequence().charAt(j)))\r
+                {\r
+                  // Not a gap, block edit not valid\r
+                  endEditing();\r
+                  return;\r
+                }\r
+              }\r
+            }\r
+          }\r
 \r
-                    // drag to left\r
-                    else\r
-                    {\r
-                        for (int j = res; j < lastres; j++)\r
-                        {\r
-                            if (seq.getLength()-1 > res)\r
-                            {\r
-                                deleteChar(res, seq);\r
-                            }\r
-                        }\r
-                    }\r
+\r
+          for (int i = 0; i < sg.getSize(); i++)\r
+          {\r
+            seq = sg.getSequenceAt(i);\r
+\r
+            if (insertGap)\r
+            {\r
+              // dragging to the right\r
+              for (int j = lastres; j < startres; j++)\r
+              {\r
+                if (fixedColumns && fixedRight != -1)\r
+                {\r
+                  insertChar(j, seq, fixedRight);\r
                 }\r
+                else\r
+                  insertChar(j, seq);\r
+              }\r
             }\r
-            else /////Editing a single sequence///////////\r
+            else\r
             {\r
-                seq = av.alignment.getSequenceAt(startseq);\r
-                if ((res < av.getAlignment().getWidth()) && (res > lastres))\r
+              // dragging to the left\r
+              for (int j = lastres; j > startres; j--)\r
+              {\r
+                if (fixedColumns && fixedRight != -1)\r
                 {\r
-                    // dragging to the right\r
-                    for (int j = lastres; j < res; j++)\r
-                    {\r
-                        insertChar(j, seq, j);\r
-                    }\r
+                  deleteChar(startres, seq, fixedRight);\r
                 }\r
-                else if ((res < av.getAlignment().getWidth()) &&\r
-                        (res < lastres))\r
+                else\r
                 {\r
-                    // dragging to the left\r
-                    for (int j = lastres; j > res; j--)\r
-                    {\r
-                        if (jalview.util.Comparison.isGap(\r
-                                    av.alignment.getSequenceAt(startseq)\r
-                                                    .getSequence().charAt(res)))\r
-                        {\r
-                            deleteChar(res, seq);\r
-                        }\r
-                        else\r
-                        {\r
-                            break;\r
-                        }\r
-                    }\r
+                  deleteChar(startres, seq);\r
                 }\r
+              }\r
             }\r
+          }\r
         }\r
+        else /////Editing a single sequence///////////\r
+        {\r
 \r
-        mouseDragging = true;\r
-        if(scrollThread!=null)\r
-          scrollThread.setEvent(evt);\r
+          if (insertGap)\r
+          {\r
+            // dragging to the right\r
+            for (int j = lastres; j < startres; j++)\r
+            {\r
+              if (fixedColumns && fixedRight != -1)\r
+                insertChar(j, seq, fixedRight);\r
+              else\r
+                insertChar(j, seq);\r
+            }\r
+          }\r
+          else\r
+          {\r
+            // dragging to the left\r
+            for (int j = lastres; j > startres; j--)\r
+            {\r
+              if (fixedColumns && fixedRight != -1)\r
+              {\r
+                deleteChar(startres, seq, fixedRight);\r
+              }\r
+              else\r
+              {\r
+                deleteChar(startres, seq);\r
+              }\r
+            }\r
+          }\r
+        }\r
 \r
-        endEdit = res;\r
-        lastres = res;\r
+        lastres = startres;\r
         seqCanvas.repaint();\r
     }\r
 \r
+\r
+    /**\r
+     * DOCUMENT ME!\r
+     *\r
+     * @param j DOCUMENT ME!\r
+     * @param seq DOCUMENT ME!\r
+     */\r
+    void insertChar(int j, SequenceI seq)\r
+    {\r
+        seq.insertCharAt(j, av.getGapCharacter());\r
+        seqEditOccurred = true;\r
+    }\r
+\r
+    void insertChar(int j, SequenceI seq, int fixedColumn)\r
+    {\r
+      //Find the next gap before the end of the visible region boundary\r
+      //If lastCol > j, theres a boundary after the gap insertion\r
+      int blankColumn = fixedColumn;\r
+      for (blankColumn = fixedColumn; blankColumn > j; blankColumn--)\r
+      {\r
+        if (jalview.util.Comparison.isGap(seq.getCharAt(blankColumn)))\r
+    {\r
+          //Theres a space, so break and insert the gap\r
+          break;\r
+        }\r
+      }\r
+\r
+      if (blankColumn <= j)\r
+      {\r
+        endEditing();\r
+        return;\r
+      }\r
+\r
+      if (!jalview.util.Comparison.isGap(seq.getCharAt(blankColumn)))\r
+      {\r
+        //Just Checking\r
+        System.out.println("Tried removing residue (INSERT)"+seq.getCharAt(fixedColumn));\r
+        return;\r
+      }\r
+\r
+      seq.deleteCharAt(blankColumn);\r
+      seq.insertCharAt(j, av.getGapCharacter());\r
+      seqEditOccurred = true;\r
+    }\r
+\r
+    void deleteChar(int j, SequenceI seq, int fixedColumn)\r
+    {\r
+      if (!jalview.util.Comparison.isGap(seq.getCharAt(j)))\r
+      {\r
+        ap.alignFrame.statusBar.setText(\r
+            "End editing: Tried removing residue " + seq.getCharAt(j));\r
+        return;\r
+      }\r
+\r
+      seq.deleteCharAt(j);\r
+      seq.insertCharAt(fixedColumn, av.getGapCharacter());\r
+      seqEditOccurred = true;\r
+    }\r
+\r
+    /**\r
+     * DOCUMENT ME!\r
+     *\r
+     * @param j DOCUMENT ME!\r
+     * @param seq DOCUMENT ME!\r
+     */\r
+    void deleteChar(int j, SequenceI seq)\r
+    {\r
+      if (!jalview.util.Comparison.isGap(seq.getCharAt(j)))\r
+      {\r
+        ap.alignFrame.statusBar.setText(\r
+            "End editing: Tried removing residue " + seq.getCharAt(j));\r
+        return;\r
+      }\r
+\r
+        seq.deleteCharAt(j);\r
+        seqEditOccurred = true;\r
+        seqCanvas.repaint();\r
+    }\r
     /**\r
      * DOCUMENT ME!\r
      *\r
@@ -681,6 +944,7 @@ public class SeqPanel extends JPanel implements MouseListener,
 \r
     public void mouseWheelMoved(MouseWheelEvent e)\r
     {\r
+      e.consume();\r
       if (mouseWheelPressed)\r
       {\r
         Font font = av.getFont();\r
@@ -704,78 +968,6 @@ public class SeqPanel extends JPanel implements MouseListener,
     }\r
 \r
 \r
-    /**\r
-     * DOCUMENT ME!\r
-     *\r
-     * @param j DOCUMENT ME!\r
-     * @param seq DOCUMENT ME!\r
-     */\r
-    void insertChar(int j, SequenceI seq, int blankColumn)\r
-    {\r
-        if(av.hasHiddenColumns)\r
-        {\r
-          //Find the next gap before the end of the visible region boundary\r
-          int lastCol = av.getColumnSelection().getHiddenRegionBoundary(j);\r
-          if(lastCol != j)\r
-          {\r
-            if (!groupEditing || lastCol <= j)\r
-            {\r
-              blankColumn = lastCol;\r
-              //If lastCol > j, theres a boundary after the gap insertion\r
-              if (lastCol > j)\r
-              {\r
-                for (blankColumn = lastCol; blankColumn > j; blankColumn--)\r
-                {\r
-                  if (jalview.util.Comparison.isGap(seq.getCharAt(blankColumn)))\r
-                  {\r
-                    //Theres a space, so break and insert the gap\r
-                    break;\r
-                  }\r
-                }\r
-\r
-                if (blankColumn <= j)\r
-                {\r
-                  endEditing();\r
-                  return;\r
-                }\r
-              }\r
-\r
-            }\r
-\r
-            // Editing with hidden regions only!!\r
-            seq.deleteCharAt(blankColumn);\r
-          }\r
-      }\r
-\r
-        seq.insertCharAt(j, av.getGapCharacter());\r
-        seqEditOccurred = true;\r
-    }\r
-\r
-    /**\r
-     * DOCUMENT ME!\r
-     *\r
-     * @param j DOCUMENT ME!\r
-     * @param seq DOCUMENT ME!\r
-     */\r
-    public void deleteChar(int j, SequenceI seq)\r
-    {\r
-      if (av.hasHiddenColumns)\r
-      {\r
-        //Find the next gap before the end of the visible region boundary\r
-        int lastCol = av.getColumnSelection().getHiddenRegionBoundary(j);\r
-\r
-        //If lastCol > j, theres a boundary after the gap insertion\r
-        if (lastCol > j)\r
-        {\r
-          seq.insertCharAt(lastCol, av.getGapCharacter());\r
-        }\r
-      }\r
-\r
-        seq.deleteCharAt(j);\r
-        seqEditOccurred = true;\r
-\r
-        seqCanvas.repaint();\r
-    }\r
 \r
     /**\r
      * DOCUMENT ME!\r
@@ -784,12 +976,14 @@ public class SeqPanel extends JPanel implements MouseListener,
      */\r
     void editOccurred()\r
     {\r
-      if (endEdit == startEdit)\r
+      if (!seqEditOccurred)\r
       {\r
         ap.alignFrame.historyList.pop();\r
         ap.alignFrame.updateEditMenuBar();\r
       }\r
 \r
+      endEditing();\r
+\r
       av.firePropertyChange("alignment", null,av.getAlignment().getSequences());\r
 \r
     }\r
@@ -819,7 +1013,6 @@ public class SeqPanel extends JPanel implements MouseListener,
       if(seq<0 || res<0)\r
             return;\r
 \r
-\r
         SequenceI sequence = (Sequence) av.getAlignment().getSequenceAt(seq);\r
 \r
         if ((sequence == null) || (res > sequence.getLength()))\r
@@ -867,6 +1060,15 @@ public class SeqPanel extends JPanel implements MouseListener,
             }\r
         }\r
 \r
+        if (av.cursorMode)\r
+        {\r
+          seqCanvas.cursorX = findRes(evt);\r
+          seqCanvas.cursorY = findSeq(evt);\r
+          seqCanvas.repaint();\r
+          return;\r
+        }\r
+\r
+\r
         if (stretchGroup == null)\r
         {\r
             // define a new group here\r
@@ -1106,11 +1308,11 @@ public class SeqPanel extends JPanel implements MouseListener,
 \r
                     if (mouseDragging && (evt.getX() < 0))\r
                     {\r
-                        running = ap.scrollRight(true);\r
+                        running = ap.scrollRight(false);\r
                     }\r
                     else if (mouseDragging && (evt.getX() >= getWidth()))\r
                     {\r
-                        running = ap.scrollRight(false);\r
+                        running = ap.scrollRight(true);\r
                     }\r
                 }\r
 \r