From 0e54db5074938de828bc20412dfd59898fafc7db Mon Sep 17 00:00:00 2001 From: amwaterhouse Date: Fri, 17 Dec 2004 14:19:17 +0000 Subject: [PATCH] Fixed bug in editing by group --- src/jalview/gui/SeqPanel.java | 173 ++++++++++++++++++----------------------- 1 file changed, 75 insertions(+), 98 deletions(-) diff --git a/src/jalview/gui/SeqPanel.java b/src/jalview/gui/SeqPanel.java index e2caa41..5d2a741 100755 --- a/src/jalview/gui/SeqPanel.java +++ b/src/jalview/gui/SeqPanel.java @@ -21,7 +21,6 @@ public class SeqPanel extends JPanel protected int startseq; protected int padseq; - public boolean editFlag; protected AlignViewport av; // if character is inserted or deleted, we will need to recalculate the conservation @@ -79,8 +78,6 @@ public class SeqPanel extends JPanel endres = res; - // This is to detect edits - we're at the end of an edit if mouse is up - editFlag = false; startseq = -1; startres = -1; lastres = -1; @@ -105,7 +102,8 @@ public class SeqPanel extends JPanel res = x/av.getCharWidth() + av.getStartRes(); seq = y/av.getCharHeight() + av.getStartSeq(); - if (seq < av.getAlignment().getHeight() && res < av.getAlignment().getSequenceAt(seq).getLength()) + if (seq < av.getAlignment().getHeight() && + res < av.getAlignment().getSequenceAt(seq).getLength()) { //char resstr = align.getSequenceAt(seq).getSequence().charAt(res); // Find the residue's position in the sequence (res is the position @@ -113,16 +111,17 @@ public class SeqPanel extends JPanel startseq = seq; - if (startseq == (av.getAlignment().getHeight()-1)) { + if (startseq == (av.getAlignment().getHeight() - 1)) padseq = 1; - } else { + else padseq = 1; - } startres = res; lastres = res; - } else { + } + else + { startseq = -1; startres = -1; lastres = -1; @@ -176,110 +175,90 @@ public class SeqPanel extends JPanel public void doMouseDragged(MouseEvent evt) { // If we're dragging we're editing - editFlag = true; int x = evt.getX(); int res = x/av.getCharWidth() + av.getStartRes(); - if (res < 0) {res = 0;} - - if (res != lastres) { - if (startseq != -1) { + if (res < 0) + res = 0; + if (res != lastres) + { // Group editing - if (evt.isControlDown()) { + if (evt.isControlDown()) + { SequenceGroup sg = av.getAlignment().findGroup(startseq); - - if(sg!=null) - if (res < av.getAlignment().getWidth() && res < lastres) + if (sg != null) { - boolean flag = false; - for (int i= 0 ; i < sg.getSize(); i++) + boolean deleteAllowed = false; + if (res < av.getAlignment().getWidth() && res < lastres) { - SequenceI s = (SequenceI)sg.getSequenceAt(i); - for (int j=lastres-1; j >= res; j--) + /// Are we able to delete? + boolean allGaps = true; + for (int i = 0; i < sg.getSize(); i++) { - if (!flag) + SequenceI s = sg.getSequenceAt(i); + for (int j = lastres-1; j >= res && allGaps; j--) { - if (s.getSequence().charAt(j)!=av.getAlignment().getGapCharacter() && - s.getSequence().charAt(j)==' ') - { - res = j+1; - flag = true; - } - } - } - } - } + if (!jalview.util.Comparison.isGap(s.getSequence().charAt(j))) + { + res = j + 1; + allGaps = false; + } + } - if(sg!=null) - for (int i= 0 ; i < sg.getSize(); i++) - { - SequenceI s = (SequenceI)sg.getSequenceAt(i); - boolean found = false; - int sno = -1; - for (int k = 0; k < av.getAlignment().getHeight(); k++) - { - if (av.getAlignment().getSequenceAt(k) == s) - { - found = true; - sno = k; - break; - } - } - if (found && sno != -1) { - if (res < av.getAlignment().getWidth() && res > lastres) - { - for (int j = lastres; j < res; j++) - insertChar(j,sno); + if(!deleteAllowed && allGaps) + deleteAllowed = true; - int index = av.getAlignment().findIndex(s); - if (index != -1) - drawChars(index,index+1,lastres); - - - } else if (res < av.getAlignment().getWidth() && res < lastres) - { - for (int j = res; j < lastres; j++) - { - deleteChar(j,res,sno); - startres = res; - } - int index = av.getAlignment().findIndex(s); - if (index != -1) - drawChars(index,index+1,res); + } + } - } - } - } - lastres = res; - } else { + for (int i = 0; i < sg.getSize(); i++) + { + SequenceI s = sg.getSequenceAt(i); + int k = av.alignment.findIndex(s); + // drag to right + if (res < av.getAlignment().getWidth() && res > lastres) + for (int j = lastres; j < res; j++) + insertChar(j, k); - if (res < av.getAlignment().getWidth() && res > lastres) { + // drag to left + else if (deleteAllowed && res < av.getAlignment().getWidth() && res < lastres) + { + for (int j = res; j < lastres; j++) + { + deleteChar(j, k); + startres = res; + } + } + } + } + } + else /////Editing a single sequence/////////// + { + if (res < av.getAlignment().getWidth() && res > lastres) + { // dragging to the right - for (int j = lastres; j < res; j++) - insertChar(j,startseq); - - drawChars(startseq,startseq+1,lastres); - - } else if (res < av.getAlignment().getWidth() && res < lastres) + for (int j = lastres; j < res; j++) + insertChar(j, startseq); + } + else if (res < av.getAlignment().getWidth() && res < lastres) { - // dragging to the left - for (int j = res; j < lastres; j++) { - deleteChar(j,res,startseq); - startres = res; - } - drawChars(startseq,startseq+1,res); + for (int j = res; j < lastres; j++) + { + deleteChar(j, startseq); + startres = res; + } } + } - } - lastres = res; + } + lastres = res; repaint(); - return; } public void drawChars(int seqstart, int seqend, int start) { @@ -289,21 +268,17 @@ public class SeqPanel extends JPanel public void insertChar(int j, int seq) { - av.getAlignment().getSequenceAt(seq).insertCharAt(j, av.getGapCharacter()); + av.alignment.getSequenceAt(seq).insertCharAt(j, av.getGapCharacter()); seqEditOccurred=seq; } - public void deleteChar(int j, int res, int seq) + public void deleteChar(int j, int seq) { - if (av.getAlignment().getSequenceAt(seq).getSequence().charAt(j)=='.' || - av.getAlignment().getSequenceAt(seq).getSequence().charAt(j)=='-' || - av.getAlignment().getSequenceAt(seq).getSequence().charAt(j)==' ' ) - { - av.getAlignment().getSequenceAt(seq).deleteCharAt(j); - } + if ( jalview.util.Comparison.isGap( av.alignment.getSequenceAt(seq).getSequence().charAt(j))) + av.alignment.getSequenceAt(seq).deleteCharAt(j); - av.getAlignment().getWidth(); + av.alignment.getWidth(); repaint(); seqEditOccurred=seq; } @@ -328,8 +303,10 @@ public class SeqPanel extends JPanel ccs.conserve = c;*/ } +////////////////////////////////////////// +/////Everything below this is for defining the boundary of the rubberband +////////////////////////////////////////// int oldSeq = -1; - public void doMousePressedDefineMode(MouseEvent evt) { int res = evt.getX()/av.getCharWidth() + av.getStartRes(); -- 1.7.10.2