From: janengelhardt Date: Wed, 20 Jul 2011 14:09:34 +0000 (+0200) Subject: JAL-842; toy example to insert nucleotides in sequences in the X-Git-Tag: Jalview_2_9~576^2~23 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=4e665c174de86f7fb68b257ccb2b0aa2d62cb429;p=jalview.git JAL-842; toy example to insert nucleotides in sequences in the AlignmentPanel; Change-Id: I9901d08b1f06861c4d9b7795a4a935ac040d7b2b --- diff --git a/src/jalview/commands/EditCommand.java b/src/jalview/commands/EditCommand.java index 5310838..03b94d3 100644 --- a/src/jalview/commands/EditCommand.java +++ b/src/jalview/commands/EditCommand.java @@ -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); diff --git a/src/jalview/gui/AlignFrame.java b/src/jalview/gui/AlignFrame.java index 7b6c6af..f05d873 100755 --- a/src/jalview/gui/AlignFrame.java +++ b/src/jalview/gui/AlignFrame.java @@ -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) diff --git a/src/jalview/gui/SeqPanel.java b/src/jalview/gui/SeqPanel.java index 50ece22..6a03b53 100644 --- a/src/jalview/gui/SeqPanel.java +++ b/src/jalview/gui/SeqPanel.java @@ -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"); + } + } } }