X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fappletgui%2FSeqPanel.java;h=e87ab95e124c12bda65ce3cf2831f5875f180a62;hb=6dd523c9bd707b197e7311fba62387777286debb;hp=6869964d91f826c82e935dea85be8bc32a5d76e1;hpb=df9b85c1cf39894039018499fe802406cc37f209;p=jalview.git diff --git a/src/jalview/appletgui/SeqPanel.java b/src/jalview/appletgui/SeqPanel.java index 6869964..e87ab95 100755 --- a/src/jalview/appletgui/SeqPanel.java +++ b/src/jalview/appletgui/SeqPanel.java @@ -424,6 +424,9 @@ public class SeqPanel res = (x / av.getCharWidth()) + av.getStartRes(); } + if(av.hasHiddenColumns) + res = av.getColumnSelection().adjustForHiddenColumns(res); + return res; } @@ -445,11 +448,17 @@ public class SeqPanel y -= hgap; - seq = ( (y % cHeight) / av.getCharHeight()); + seq = Math.min( (y % cHeight) / av.getCharHeight(), + av.alignment.getHeight() -1); + if(seq<0) + seq = 0; } else { - seq = (y / av.getCharHeight()) + av.getStartSeq(); + seq = Math.min( (y / av.getCharHeight()) + av.getStartSeq(), + av.alignment.getHeight() -1); + if(seq<0) + seq = 0; } return seq; @@ -519,11 +528,9 @@ public class SeqPanel if (obj != null) { - if (obj != "") { - text.append(obj + " (" + - av.getAlignment().getSequenceAt(seq).findPosition(res) + ")"); + text.append(obj + " (" + sequence.findPosition(res) + ")"); } } @@ -532,6 +539,8 @@ public class SeqPanel seqCanvas.pdbCanvas.highlightRes(sequence.findPosition(res)); } + ap.alignFrame.statusBar.setText(text.toString()); + // use aa to see if the mouse pointer is on a if (av.showSequenceFeatures @@ -568,14 +577,7 @@ public class SeqPanel tooltip.repaint(); - // text.append(" Sequence Feature:"); - // text.append(featureText); - } - - - ap.alignFrame.statusBar.setText(text.toString()); - } Vector getAllFeaturesAtRes(SequenceI seq, int res) @@ -693,184 +695,221 @@ public class SeqPanel } synchronized void editSequence(boolean insertGap, int startres) - { - int fixedLeft = -1; - int fixedRight = -1; - boolean fixedColumns = false; - SequenceGroup sg = av.getSelectionGroup(); + { + int fixedLeft = -1; + int fixedRight = -1; + boolean fixedColumns = false; + SequenceGroup sg = av.getSelectionGroup(); - if(groupEditing && sg==null) - return; - SequenceI seq = av.alignment.getSequenceAt(startseq); - StringBuffer message = new StringBuffer(); - if (groupEditing) - message.append("Edit group:"); - else - message.append("Edit sequence: "+seq.getName()); + if (!groupEditing && av.hasHiddenRows) + { + if (av.alignment.getSequenceAt(startseq).getHiddenSequences() != null) + { + groupEditing = true; + } + } - if(insertGap) - message.append(" insert "); - else - message.append(" delete "); + //No group, but the sequence may represent a group + if (groupEditing + && sg == null + && av.alignment.getSequenceAt(startseq).getHiddenSequences() == null) + { + groupEditing = false; + } + + SequenceI seq = av.alignment.getSequenceAt(startseq); + StringBuffer message = new StringBuffer(); + if (groupEditing) + message.append("Edit group:"); + else + message.append("Edit sequence: "+seq.getName()); + + if(insertGap) + message.append(" insert "); + else + message.append(" delete "); + + message.append(Math.abs(startres-lastres)+" gaps."); + ap.alignFrame.statusBar.setText(message.toString()); - message.append(Math.abs(startres-lastres)+" gaps."); - ap.alignFrame.statusBar.setText(message.toString()); + //Are we editing within a selection group? + if (groupEditing + || (sg != null && sg.getSequences(true).contains(seq))) + { + fixedColumns = true; - //Are we editing within a selection group? - if (groupEditing - || (sg != null && sg.getSequences(false).contains(seq))) + //sg might be null as the user may only see 1 sequence, + //but the sequence represents a group + if (sg == null) { - fixedColumns = true; + sg = new SequenceGroup(null, null, false, false, false, 0, + av.alignment.getWidth()-1); + sg.addSequence(av.alignment.getSequenceAt(startseq), false); + } - fixedLeft = sg.getStartRes(); - fixedRight = sg.getEndRes(); + fixedLeft = sg.getStartRes(); + fixedRight = sg.getEndRes(); - if ( (startres < fixedLeft && lastres >= fixedLeft) - || (startres >= fixedLeft && lastres < fixedLeft) - || (startres > fixedRight && lastres <=fixedRight) - || (startres <= fixedRight && lastres > fixedRight)) + if ( (startres < fixedLeft && lastres >= fixedLeft) + || (startres >= fixedLeft && lastres < fixedLeft) + || (startres > fixedRight && lastres <=fixedRight) + || (startres <= fixedRight && lastres > fixedRight)) + { + endEditing(); + return; + } + + if (fixedLeft > startres) + { + fixedRight = fixedLeft - 1; + fixedLeft = 0; + } + else if (fixedRight < startres) + { + fixedLeft = fixedRight; + fixedRight = -1; + } + } + + + if(av.hasHiddenColumns ) + { + fixedColumns = true; + int y1 = av.getColumnSelection().getHiddenBoundaryLeft(startres); + int y2 = av.getColumnSelection().getHiddenBoundaryRight(startres); + + if ( (insertGap && startres > y1 && lastres < y1) + || (!insertGap && startres < y2 && lastres > y2)) { endEditing(); return; } - if (fixedLeft > startres) - { - fixedRight = fixedLeft - 1; - fixedLeft = 0; - } - else if (fixedRight < startres) + //System.out.print(y1+" "+y2+" "+fixedLeft+" "+fixedRight+"~~"); + //Selection spans a hidden region + if(fixedLefty2 || fixedRight==-1)) { - fixedLeft = fixedRight; - fixedRight = -1; + if(startres>=y2) + { + fixedLeft = y2; + } + else + { + fixedRight = y2 - 1; + } } - } + } - if (groupEditing) + if (groupEditing) + { + // drag to right + if (insertGap) { - // drag to right - if (insertGap) - { - //If the user has selected the whole sequence, and is dragging to - // the right, we can still extend the alignment and selectionGroup - if(sg.getStartRes() == 0 && sg.getEndRes() + 1 == av.alignment.getWidth()) - { - sg.setEndRes(av.alignment.getWidth() + startres - lastres); - fixedRight = sg.getEndRes(); - } + //If the user has selected the whole sequence, and is dragging to + // the right, we can still extend the alignment and selectionGroup + if( sg.getStartRes() == 0 + && sg.getEndRes() == fixedRight + && sg.getEndRes() == av.alignment.getWidth()-1 + ) + { + sg.setEndRes(av.alignment.getWidth() + startres - lastres); + fixedRight = sg.getEndRes(); + } - // Is it valid with fixed columns?? - // Find the next gap before the end - // of the visible region boundary - boolean blank = false; - for (fixedRight = fixedRight; - fixedRight > lastres; - fixedRight--) + // Is it valid with fixed columns?? + // Find the next gap before the end + // of the visible region boundary + boolean blank = false; + for (fixedRight = fixedRight; + fixedRight > lastres; + fixedRight--) + { + blank = true; + for (int s = 0; s < sg.getSize(true); s++) { - blank = true; - for (int s = 0; s < sg.getSize(false); s++) + seq = (SequenceI)sg.getSequences(true).elementAt(s); + for (int j = 0; j < startres - lastres; j++) { - seq = sg.getSequenceAt(s); - for (int j = 0; j < startres - lastres; j++) + if (!jalview.util.Comparison.isGap( + seq.getCharAt(fixedRight - j))) { - if (!jalview.util.Comparison.isGap( - seq.getCharAt(fixedRight - j))) - { - blank = false; - break; - } + blank = false; + break; } } - if (blank) - break; } + if (blank) + break; + } - if (!blank) + if (!blank) + { + if(sg.getSize(false) == av.alignment.getHeight() ) { - if(sg.getSize(false) == av.alignment.getHeight()) - { - //We can still insert gaps if the selectionGroup - //contains all the sequences - sg.setEndRes(sg.getEndRes()+startres-lastres); - fixedRight = av.alignment.getWidth()+startres-lastres; - } - else + if((av.hasHiddenColumns + && startresalWidth) + alWidth = hwidth; } + //We can still insert gaps if the selectionGroup + //contains all the sequences + sg.setEndRes(sg.getEndRes()+startres-lastres); + fixedRight = alWidth+startres-lastres; + } + else + { + endEditing(); + return; } } + } + + // drag to left + else if(!insertGap) + { + /// Are we able to delete? + // ie are all columns blank? - for (int i = 0; i < sg.getSize(false); i++) + for (int s = 0; s < sg.getSize(true); s++) { - seq = sg.getSequenceAt(i); + seq = (SequenceI)sg.getSequences(true).elementAt(s); - if (insertGap) + for (int j = startres; j < lastres; j++) { - // dragging to the right - for (int j = lastres; j < startres; j++) + if (seq.getSequence().length() <= j) { - if (fixedColumns && fixedRight != -1) - { - insertChar(j, seq, fixedRight); - } - else - insertChar(j, seq); + continue; } - } - else - { - // dragging to the left - for (int j = lastres; j > startres; j--) + + if (!jalview.util.Comparison.isGap( + seq.getSequence().charAt(j))) { - if (fixedColumns && fixedRight != -1) - { - deleteChar(startres, seq, fixedRight); - } - else - { - deleteChar(startres, seq); - } + // Not a gap, block edit not valid + endEditing(); + return; } } } } - else /////Editing a single sequence/////////// + + + for (int i = 0; i < sg.getSize(true); i++) { + seq = (SequenceI) sg.getSequences(true).elementAt(i); + if (insertGap) { // dragging to the right @@ -878,18 +917,7 @@ public class SeqPanel { if (fixedColumns && fixedRight != -1) { - 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); + insertChar(j, seq, fixedRight); } else insertChar(j, seq); @@ -911,10 +939,42 @@ public class SeqPanel } } } + } + 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); + } + else + insertChar(j, seq); + } + } + else + { + // dragging to the left + for (int j = lastres; j > startres; j--) + { + if (fixedColumns && fixedRight != -1) + { + deleteChar(startres, seq, fixedRight); + } + else + { + deleteChar(startres, seq); + } + } + } + } - lastres = startres; - seqCanvas.repaint(); - } + lastres = startres; + seqCanvas.repaint(); + } /** @@ -1081,15 +1141,6 @@ public class SeqPanel av.setSelectionGroup(stretchGroup); } - if (av.cursorMode) - { - seqCanvas.cursorX = findRes(evt); - seqCanvas.cursorY = findSeq(evt); - seqCanvas.repaint(); - return; - } - - // DETECT RIGHT MOUSE BUTTON IN AWT if ( (evt.getModifiers() & InputEvent.BUTTON3_MASK) == @@ -1118,9 +1169,17 @@ public class SeqPanel this.add(popup); popup.show(this, evt.getX(), evt.getY()); ap.repaint(); + return; } - else + + if (av.cursorMode) { + seqCanvas.cursorX = findRes(evt); + seqCanvas.cursorY = findSeq(evt); + seqCanvas.repaint(); + return; + } + //Only if left mouse button do we want to change group sizes if (stretchGroup == null) @@ -1145,19 +1204,6 @@ public class SeqPanel } } - - if (stretchGroup != null && stretchGroup.getEndRes() == res) - { - // Edit end res position of selected group - changeEndRes = true; - } - - else if (stretchGroup != null && stretchGroup.getStartRes() == res) - { - // Edit end res position of selected group - changeStartRes = true; - } - } } public void doMouseReleasedDefineMode(MouseEvent evt) @@ -1333,6 +1379,28 @@ public class SeqPanel } } + 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 class ScrollThread extends Thread @@ -1376,12 +1444,12 @@ public class SeqPanel if (mouseDragging && evt.getX() < 0) { - running = ap.scrollRight(true); + running = ap.scrollRight(false); } else if (mouseDragging && evt.getX() >= getSize().width) { - running = ap.scrollRight(false); + running = ap.scrollRight(true); } }