JAL-842; toy example to insert nucleotides in sequences in the
authorjanengelhardt <engelhardt87@googlemail.com>
Wed, 20 Jul 2011 14:09:34 +0000 (16:09 +0200)
committerjanengelhardt <engelhardt87@googlemail.com>
Mon, 25 Jul 2011 12:58:35 +0000 (14:58 +0200)
AlignmentPanel;

Change-Id: I9901d08b1f06861c4d9b7795a4a935ac040d7b2b

src/jalview/commands/EditCommand.java
src/jalview/gui/AlignFrame.java
src/jalview/gui/SeqPanel.java

index 5310838..03b94d3 100644 (file)
@@ -54,6 +54,8 @@ public class EditCommand implements CommandI
   public static final int PASTE = 3;
 
   public static final int REPLACE = 4;
+  
+  public static final int INSERT_NUC=5;
 
   Edit[] edits;
 
@@ -192,6 +194,10 @@ public class EditCommand implements CommandI
       case REPLACE:
         replace(edits[e]);
         break;
+        //TODO:add deleteNuc for UNDO
+      case INSERT_NUC:
+       insertNuc(edits[e]);
+       break;
       }
     }
   }
@@ -223,7 +229,7 @@ public class EditCommand implements CommandI
       case REPLACE:
         replace(edits[e]);
         break;
-      }
+       }
     }
   }
 
@@ -234,6 +240,19 @@ public class EditCommand implements CommandI
     {
       command.seqs[s].insertCharAt(command.position, command.number,
               command.gapChar);
+      System.out.println("pos: "+command.position+" number: "+command.number);
+    }
+
+    adjustAnnotations(command, true, false, null);
+  }
+  
+  final void insertNuc(Edit command)
+  {
+
+    for (int s = 0; s < command.seqs.length; s++)
+    {
+        System.out.println("pos: "+command.position+" number: "+command.number);
+       command.seqs[s].insertCharAt(command.position, command.number,'A');
     }
 
     adjustAnnotations(command, true, false, null);
index 7b6c6af..f05d873 100755 (executable)
@@ -401,7 +401,22 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
                     || evt.isShiftDown() || evt.isAltDown());
           }
           break;
-
+          
+        case KeyEvent.VK_A:
+               if (viewport.cursorMode)
+            {
+                       alignPanel.seqPanel.insertNucAtCursor(false,"A");
+                       //System.out.println("A");
+            }
+               break;
+        /*     
+        case KeyEvent.VK_CLOSE_BRACKET:
+               if (viewport.cursorMode)
+            {
+                       System.out.println("closing bracket");
+            }
+               break;
+         */
         case KeyEvent.VK_DELETE:
         case KeyEvent.VK_BACK_SPACE:
           if (!viewport.cursorMode)
index 50ece22..6a03b53 100644 (file)
@@ -470,7 +470,7 @@ public class SeqPanel extends JPanel implements MouseListener,
     groupEditing = group;
     startseq = seqCanvas.cursorY;
     lastres = seqCanvas.cursorX;
-    editSequence(true, seqCanvas.cursorX + getKeyboardNo1());
+    editSequence(true, false, seqCanvas.cursorX + getKeyboardNo1());
     endEditing();
   }
 
@@ -479,9 +479,17 @@ public class SeqPanel extends JPanel implements MouseListener,
     groupEditing = group;
     startseq = seqCanvas.cursorY;
     lastres = seqCanvas.cursorX + getKeyboardNo1();
-    editSequence(false, seqCanvas.cursorX);
+    editSequence(false, false, seqCanvas.cursorX);
     endEditing();
   }
+  
+  void insertNucAtCursor(boolean group,String nuc){
+         groupEditing = group;
+           startseq = seqCanvas.cursorY;
+           lastres = seqCanvas.cursorX;
+           editSequence(false, true, seqCanvas.cursorX + getKeyboardNo1());
+           endEditing();
+  }
 
   void numberPressed(char value)
   {
@@ -1010,11 +1018,11 @@ public class SeqPanel extends JPanel implements MouseListener,
     if ((res < av.getAlignment().getWidth()) && (res < lastres))
     {
       // dragLeft, delete gap
-      editSequence(false, res);
+      editSequence(false, false,res);
     }
     else
     {
-      editSequence(true, res);
+      editSequence(true, false,res);
     }
 
     mouseDragging = true;
@@ -1024,7 +1032,8 @@ public class SeqPanel extends JPanel implements MouseListener,
     }
   }
 
-  synchronized void editSequence(boolean insertGap, int startres)
+  //TODO: Make it more clever than many booleans
+  synchronized void editSequence(boolean insertGap, boolean editSeq, int startres)
   {
     int fixedLeft = -1;
     int fixedRight = -1;
@@ -1294,7 +1303,7 @@ public class SeqPanel extends JPanel implements MouseListener,
     else
     // ///Editing a single sequence///////////
     {
-      if (insertGap)
+      if (insertGap && !editSeq)
       {
         // dragging to the right
         if (fixedColumns && fixedRight != -1)
@@ -1303,16 +1312,21 @@ public class SeqPanel extends JPanel implements MouseListener,
           {
             insertChar(j, new SequenceI[]
             { seq }, fixedRight);
+               System.out.println("InsertGap1");
+
           }
         }
         else
         {
           editCommand.appendEdit(EditCommand.INSERT_GAP, new SequenceI[]
           { seq }, lastres, startres - lastres, av.alignment, true);
+          System.out.println("InsertGap2 - lastres: "+lastres+" startres: "+startres);
+
         }
       }
       else
       {
+       if(!editSeq){
         // dragging to the left
         if (fixedColumns && fixedRight != -1)
         {
@@ -1346,6 +1360,24 @@ public class SeqPanel extends JPanel implements MouseListener,
             { seq }, startres, max, av.alignment, true);
           }
         }
+       }else{//insertGap==false AND editSeq==TRUE;
+               if (fixedColumns && fixedRight != -1)
+            {
+              for (int j = lastres; j < startres; j++)
+              {
+                insertChar(j, new SequenceI[]
+                { seq }, fixedRight);
+              }
+               System.out.println("EditSeq1");
+
+            }
+            else
+            {
+              editCommand.appendEdit(EditCommand.INSERT_NUC, new SequenceI[]
+              { seq }, lastres, startres - lastres, av.alignment, true);
+               System.out.println("EditSeq2");
+             }
+       }
       }
     }