From: amwaterhouse Date: Tue, 4 Apr 2006 09:31:52 +0000 (+0000) Subject: Keyboard editing X-Git-Tag: Release_2_08~84 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=1ab3860add27db695e8471783bf775ecff1fdae9;p=jalview.git Keyboard editing --- diff --git a/src/jalview/gui/SeqPanel.java b/src/jalview/gui/SeqPanel.java index 3f49cc4..536d178 100755 --- a/src/jalview/gui/SeqPanel.java +++ b/src/jalview/gui/SeqPanel.java @@ -66,6 +66,8 @@ public class SeqPanel extends JPanel implements MouseListener, boolean remove = false; boolean mouseWheelPressed = false; + StringBuffer keyboardNo1; + StringBuffer keyboardNo2; /** * Creates a new SeqPanel object. @@ -171,35 +173,90 @@ public class SeqPanel extends JPanel implements MouseListener, seqEditOccurred = false; editingSeqs = false; groupEditing = false; - keyboardGaps = null; + keyboardNo1 = null; + keyboardNo2 = null; } + void setCursorRow() + { + seqCanvas.cursorY = getKeyboardNo(keyboardNo1)-1; + scrollToVisible(); + } + + void setCursorColumn() + { + seqCanvas.cursorX = getKeyboardNo(keyboardNo1)-1; + scrollToVisible(); + } + + void setCursorRowAndColumn() + { + if(keyboardNo2==null) + { + keyboardNo2 = new StringBuffer(); + } + else + { + seqCanvas.cursorX = getKeyboardNo(keyboardNo1) - 1; + seqCanvas.cursorY = getKeyboardNo(keyboardNo2) - 1; + scrollToVisible(); + } + } + + void setCursorPosition() + { + SequenceI sequence = + (Sequence) av.getAlignment().getSequenceAt(seqCanvas.cursorY); + + seqCanvas.cursorX = sequence.findIndex( + getKeyboardNo(keyboardNo1)-1 + ); + scrollToVisible(); + } void moveCursor(int dx, int dy) { seqCanvas.cursorX += dx; seqCanvas.cursorY += dy; + scrollToVisible(); + } - if(seqCanvas.cursorX<0) + void scrollToVisible() + { + if (seqCanvas.cursorX < 0) seqCanvas.cursorX = 0; - else if(seqCanvas.cursorX>av.alignment.getWidth()-1) - seqCanvas.cursorX = av.alignment.getWidth()-1; - if(seqCanvas.cursorXav.endRes) - ap.scrollRight(true); - - if(seqCanvas.cursorY<0) - seqCanvas.cursorY=0; - else if(seqCanvas.cursorY>av.alignment.getHeight()-1) - seqCanvas.cursorY = av.alignment.getHeight()-1; - if(seqCanvas.cursorY av.alignment.getWidth() - 1) + seqCanvas.cursorX = av.alignment.getWidth() - 1; + + if (seqCanvas.cursorY < 0) + seqCanvas.cursorY = 0; + else if (seqCanvas.cursorY > av.alignment.getHeight() - 1) + seqCanvas.cursorY = av.alignment.getHeight() - 1; + + + endEditing(); + while (seqCanvas.cursorY < av.startSeq) + { ap.scrollUp(true); - else if(seqCanvas.cursorY+1>av.endSeq) + } + while (seqCanvas.cursorY + 1 > av.endSeq) + { ap.scrollUp(false); + } + while (seqCanvas.cursorX < av.startRes) + { + if(!ap.scrollRight(false)) + break; + } + while (seqCanvas.cursorX > av.endRes) + { + if(!ap.scrollRight(true)) + break; + } setStatusMessage(av.alignment.getSequenceAt(seqCanvas.cursorY), seqCanvas.cursorX, seqCanvas.cursorY); + seqCanvas.repaint(); } @@ -277,7 +334,7 @@ public class SeqPanel extends JPanel implements MouseListener, groupEditing = group; startseq = seqCanvas.cursorY; lastres = seqCanvas.cursorX; - editSequence(true, seqCanvas.cursorX+getKeyboardGaps()); + editSequence(true, seqCanvas.cursorX+getKeyboardNo(keyboardNo1)); editOccurred(); } @@ -287,26 +344,28 @@ public class SeqPanel extends JPanel implements MouseListener, av.alignment, HistoryItem.EDIT)); groupEditing = group; startseq = seqCanvas.cursorY; - lastres = seqCanvas.cursorX+getKeyboardGaps(); + lastres = seqCanvas.cursorX+getKeyboardNo(keyboardNo1); editSequence(false, seqCanvas.cursorX); editOccurred(); } void numberPressed(char value) { - if(keyboardGaps==null) - keyboardGaps = new StringBuffer(); + if(keyboardNo1==null) + keyboardNo1 = new StringBuffer(); - keyboardGaps.append(value); + if(keyboardNo2!=null) + keyboardNo2.append(value); + else + keyboardNo1.append(value); } - StringBuffer keyboardGaps; - int getKeyboardGaps() + int getKeyboardNo(StringBuffer kb) { - if(keyboardGaps==null) + if(kb==null) return 1; else - return Integer.parseInt(keyboardGaps.toString()); + return Integer.parseInt(kb.toString()); } @@ -558,40 +617,31 @@ public class SeqPanel extends JPanel implements MouseListener, } - void editSequence(boolean insertGap, int startres) + synchronized void editSequence(boolean insertGap, int startres) { int fixedLeft = -1; int fixedRight = -1; boolean fixedColumns = false; + SequenceGroup sg = av.getSelectionGroup(); - if(insertGap && av.hasHiddenColumns) - { - //Stop editing if the user has dragged beyond hiddenBoundary - fixedRight = av.getColumnSelection().getHiddenRegionBoundary(lastres); - if( fixedRight < lastres) - { - if(lastres!=fixedRight) - { - endEditing(); - return; - } - } - } + if(groupEditing && sg==null) + return; if (!groupEditing && av.hasHiddenRows) { + //This needs to check all the sequences in a group edit,m + // not just the startseq if (av.alignment.getSequenceAt(startseq).getHiddenSequences() != null) { groupEditing = true; } } - SequenceI seq = av.alignment.getSequenceAt(startseq); StringBuffer message = new StringBuffer(); if (groupEditing) - message.append("Edit group:"); - else + message.append("Edit group:"); + else message.append("Edit sequence: "+seq.getName()); if(insertGap) @@ -605,13 +655,12 @@ public class SeqPanel extends JPanel implements MouseListener, //Are we editing within a selection group? if (groupEditing - || (av.getSelectionGroup() != null && - av.getSelectionGroup().sequences.contains(seq))) + || (sg != null && sg.sequences.contains(seq))) { fixedColumns = true; - fixedLeft = av.getSelectionGroup().getStartRes(); - fixedRight = av.getSelectionGroup().getEndRes(); + fixedLeft = sg.getStartRes(); + fixedRight = sg.getEndRes(); if ( (startres < fixedLeft && lastres >= fixedLeft) || (startres >= fixedLeft && lastres < fixedLeft) @@ -634,17 +683,31 @@ public class SeqPanel extends JPanel implements MouseListener, } } + + + if(av.hasHiddenColumns) + { + fixedColumns = true; + int y1 = av.getColumnSelection().getHiddenBoundaryLeft(startres); + int y2 = av.getColumnSelection().getHiddenBoundaryRight(startres); + + if( ( insertGap && startres>y1 && lastresy2) ) + { + endEditing(); + return; + } + + if(fixedRightfixedLeft && fixedLeft==-1) + fixedLeft = y1; + } + if (groupEditing) { - SequenceGroup sg = av.getSelectionGroup(); - if(fixedLeft>sg.getEndRes() - ||fixedRight lastres; + fixedRight--) { - // int lastCol = av.getColumnSelection(). - // getHiddenRegionBoundary(res); - - } - - if (fixedRight != startres && fixedRight lastres; - fixedRight --) + seq = sg.getSequenceAt(s); + for (int j = 0; j < startres - lastres; j++) { - boolean blank = true; - for (int s = 0; s < sg.getSize(); s++) + if (!jalview.util.Comparison.isGap( + seq.getCharAt(fixedRight - j))) { - seq = sg.getSequenceAt(s); - - if (seq.getSequence().length() <= fixedRight) - { - continue; - } - - if (!jalview.util.Comparison.isGap( - seq.getCharAt(fixedRight))) - { - blank = false; - continue; - } - } - if (blank) + blank = false; break; + } } } + if (blank) + break; + } - if (fixedRight <= startres) + if (!blank) + { + if(sg.getSize() == av.alignment.getHeight()) + { + //We can still insert gaps if the selectionGroup + //contains all the sequences + sg.setEndRes(sg.getEndRes()+1+startres-lastres); + fixedRight = av.alignment.getWidth()+startres-lastres; + } + else { endEditing(); return; } } + } // drag to left - else + else if(!insertGap) { /// Are we able to delete? // ie are all columns blank? @@ -793,14 +856,26 @@ public class SeqPanel extends JPanel implements MouseListener, } else /////Editing a single sequence/////////// { - if (insertGap) { // dragging to the right for (int j = lastres; j < startres; j++) { if (fixedColumns && fixedRight != -1) - insertChar(j, seq, fixedRight); + { + if (sg.getStartRes() == 0 + && sg.getEndRes() + 1 == av.alignment.getWidth() + && !jalview.util.Comparison.isGap(seq.getCharAt(fixedRight))) + { + //Single sequence edit, whole sequence selected, + //extend the selection group + sg.setEndRes(av.alignment.getWidth() -1 + startres - lastres); + fixedColumns = false; + insertChar(j, seq); + } + else + insertChar(j, seq, fixedRight); + } else insertChar(j, seq); } @@ -847,7 +922,7 @@ public class SeqPanel extends JPanel implements MouseListener, for (blankColumn = fixedColumn; blankColumn > j; blankColumn--) { if (jalview.util.Comparison.isGap(seq.getCharAt(blankColumn))) - { + { //Theres a space, so break and insert the gap break; } @@ -1178,6 +1253,10 @@ public class SeqPanel extends JPanel implements MouseListener, { y = av.alignment.getHeight() -1; } + if(res> av.alignment.getWidth()) + { + res = av.alignment.getWidth()-1; + } if (stretchGroup.getEndRes() == res) { @@ -1263,6 +1342,27 @@ public class SeqPanel extends JPanel implements MouseListener, seqCanvas.repaint(); } + void scrollCanvas(MouseEvent evt) + { + if(evt==null) + { + if(scrollThread!=null) + { + scrollThread.running = false; + scrollThread = null; + } + mouseDragging = false; + } + else + { + if (scrollThread == null) + scrollThread = new ScrollThread(); + + mouseDragging = true; + scrollThread.setEvent(evt); + } + + } // this class allows scrolling off the bottom of the visible alignment