X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;ds=inline;f=src%2Fjalview%2Fgui%2FSeqPanel.java;h=b48861a0d34130ece6a660e774363376a6d994bf;hb=2ba9716bbffe4b35f640f8a85be4b60fe5fb2fdd;hp=35c5aefb54cdc2cd7c630b501a081b4ad164c188;hpb=8030eb1b0676c7ffe57f90d8131525ab7ff4b243;p=jalview.git diff --git a/src/jalview/gui/SeqPanel.java b/src/jalview/gui/SeqPanel.java index 35c5aef..b48861a 100755 --- a/src/jalview/gui/SeqPanel.java +++ b/src/jalview/gui/SeqPanel.java @@ -6,8 +6,7 @@ import jalview.datamodel.*; import javax.swing.*; import java.util.*; import jalview.schemes.*; -import jalview.analysis.*; - +import jalview.analysis.Conservation; public class SeqPanel extends JPanel { @@ -15,18 +14,23 @@ public class SeqPanel extends JPanel public SeqCanvas seqCanvas; public AlignmentPanel ap; - protected int startres; protected int lastres; - protected int endres; - protected int startseq; - protected int padseq; + int startEdit=-1; + int endEdit=-1; protected AlignViewport av; // if character is inserted or deleted, we will need to recalculate the conservation int seqEditOccurred = -1; + ScrollThread scrollThread = null; + boolean mouseDragging = false; + + boolean editingSeqs = false; + boolean groupEditing = false; + + public SeqPanel(AlignViewport avp, AlignmentPanel p) { this.av = avp; @@ -48,7 +52,7 @@ public class SeqPanel extends JPanel { if(av.getWrapAlignment()) return; - if(evt.isShiftDown() || evt.isAltDown() || evt.isControlDown()) + if( editingSeqs ) doMouseDragged(evt); else doMouseDraggedDefineMode(evt); @@ -61,20 +65,40 @@ public class SeqPanel extends JPanel { if(av.getWrapAlignment()) return; - if(evt.isShiftDown() || evt.isAltDown() || evt.isControlDown()) + if(editingSeqs) doMouseReleased(evt); else doMouseReleasedDefineMode(evt); + } public void mousePressed(MouseEvent evt) { if(av.getWrapAlignment()) return; if(evt.isShiftDown() || evt.isAltDown() || evt.isControlDown()) + { + if(evt.isAltDown() || evt.isControlDown()) + groupEditing = true; + + editingSeqs = true; doMousePressed(evt); + } else doMousePressedDefineMode(evt); } + public void mouseExited(MouseEvent evt) + { + if (av.getWrapAlignment() || editingSeqs) + return; + doMouseExitedDefineMode(evt); + + } + public void mouseEntered(MouseEvent evt) + { + if (av.getWrapAlignment() || editingSeqs) + return; + doMouseEnteredDefineMode(evt); + } }); repaint(); @@ -83,26 +107,23 @@ public class SeqPanel extends JPanel public void doMouseReleased(MouseEvent evt) { - int x = evt.getX(); - int res = x/av.getCharWidth() + av.getStartRes(); - - endres = res; + if(seqEditOccurred>-1) + editOccurred(seqEditOccurred); startseq = -1; - startres = -1; lastres = -1; - if(seqEditOccurred>-1) - updateConservation(seqEditOccurred); - seqEditOccurred = -1; + editingSeqs = false; + groupEditing = false; - ap.RefreshPanels(); - repaint(); - + ap.repaint(); } public void doMousePressed(MouseEvent evt) { - ap.alignFrame.addHistoryItem("sequence edit"); + + ap.alignFrame.addHistoryItem( new HistoryItem( + "Edit Sequence",av.alignment, HistoryItem.EDIT)); + int seq; int res; @@ -115,28 +136,18 @@ public class SeqPanel extends JPanel 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 - // in the alignment - startseq = seq; - - if (startseq == (av.getAlignment().getHeight() - 1)) - padseq = 1; - else - padseq = 1; - - startres = res; lastres = res; - } else { startseq = -1; - startres = -1; lastres = -1; } + startEdit = lastres; + endEdit = lastres; + return; } @@ -156,8 +167,6 @@ public class SeqPanel extends JPanel y %= chunkHeight; seq = y / av.getCharHeight() + av.getStartSeq(); - // chunkHeight = (da.getHeight() + 2)*charHeight; - // startx += chunkWidth; } else { @@ -215,57 +224,69 @@ public class SeqPanel extends JPanel } public void doMouseDragged(MouseEvent evt) { + // If we're dragging we're editing + int res = evt.getX() / av.getCharWidth() + av.getStartRes(); + if (res < 0) + res = 0; - if(lastres==-1) + if (lastres == -1 || lastres == res) return; - int x = evt.getX(); + boolean dragRight = true; + if (res < av.getAlignment().getWidth() && res < lastres) + dragRight = false; - int res = x/av.getCharWidth() + av.getStartRes(); - if (res < 0) - res = 0; if (res != lastres) { - // Group editing - if (evt.isAltDown() || evt.isControlDown()) + // Group editing + if (groupEditing) { - SequenceGroup sg = av.getAlignment().findGroup(startseq); - if (sg != null) + SequenceGroup sg = av.getSelectionGroup(); + if(sg==null) { - boolean deleteAllowed = false; - if (res < av.getAlignment().getWidth() && res < lastres) + lastres=-1; + return; + } + + // drag to right + if(dragRight) + sg.setEndRes(sg.getEndRes() + (res-lastres)); + + // drag to left + else { - /// Are we able to delete? - boolean allGaps = true; - for (int i = 0; i < sg.getSize(); i++) + /// Are we able to delete? + // ie are all columns blank? + boolean deleteAllowed = false; + for (int s = 0; s < sg.getSize(); s++) { - SequenceI s = sg.getSequenceAt(i); - for (int j = lastres-1; j >= res && allGaps; j--) + SequenceI seq = sg.getSequenceAt(s); + for (int j=res; j lastres) - sg.setEndRes(sg.getEndRes() + 1); - - // drag to left - else if (deleteAllowed && res < av.getAlignment().getWidth() && - res < lastres) - sg.setEndRes(sg.getEndRes() - 1); + if(!deleteAllowed) + { + lastres = -1; + return; + } + sg.setEndRes(sg.getEndRes() - (lastres-res)); + } for (int i = 0; i < sg.getSize(); i++) @@ -274,21 +295,20 @@ public class SeqPanel extends JPanel int k = av.alignment.findIndex(s); // drag to right - if (res < av.getAlignment().getWidth() && res > lastres) + if (dragRight) for (int j = lastres; j < res; j++) insertChar(j, k); // drag to left - else if (deleteAllowed && res < av.getAlignment().getWidth() && res < lastres) + else { for (int j = res; j < lastres; j++) { - deleteChar(j, k); - startres = res; + if(s.getLength()>j) + deleteChar(res, k); } } } - } } else /////Editing a single sequence/////////// { @@ -301,17 +321,24 @@ public class SeqPanel extends JPanel else if (res < av.getAlignment().getWidth() && res < lastres) { // dragging to the left - for (int j = res; j < lastres; j++) + for (int j = lastres; j > res; j--) { - deleteChar(j, startseq); - startres = res; - } - } + if( jalview.util.Comparison.isGap( + av.alignment.getSequenceAt(startseq).getSequence().charAt(res))) + + deleteChar(res, startseq); + else + { - } + break; + } + } + } + } } + endEdit = res; lastres = res; repaint(); } @@ -329,33 +356,53 @@ public class SeqPanel extends JPanel public void deleteChar(int j, int seq) { - - if ( jalview.util.Comparison.isGap( av.alignment.getSequenceAt(seq).getSequence().charAt(j))) - av.alignment.getSequenceAt(seq).deleteCharAt(j); + av.alignment.getSequenceAt(seq).deleteCharAt(j); + seqEditOccurred=seq; av.alignment.getWidth(); repaint(); - seqEditOccurred=seq; } - void updateConservation(int i) + void editOccurred(int i) { - /* Alignment al = (Alignment) av.getAlignment(); - SequenceGroup sg = av.alignment.findGroup( al.getSequenceAt(i)); - if(sg==null || !(sg.cs instanceof ConservationColourScheme)) - return; + if(endEdit==startEdit) + { + ap.alignFrame.historyList.pop(); + ap.alignFrame.updateEditMenuBar(); + } + + av.updateConservation(); + av.updateConsensus(); + + // Y O Y CLUSTALX + ColourSchemeI cs = av.getGlobalColourScheme(); + if(cs instanceof ConservationColourScheme) + { + ConservationColourScheme ccs = (ConservationColourScheme) cs; + if(ccs.cs instanceof ClustalxColourScheme) + { + Conservation c = new Conservation("All", + ResidueProperties.propHash, 3, + av.alignment.getSequences(), 0, + av.alignment.getWidth() - 1); + c.calculate(); + c.verdict(false, av.ConsPercGaps); + + ClustalxColourScheme cxs = (ClustalxColourScheme)ccs.cs; + cxs.resetClustalX(av.alignment.getSequences(), av.alignment.getWidth()); + ccs = new ConservationColourScheme(c, cxs); + av.setGlobalColourScheme(ccs); + } + } - Conservation c = sg.getConservation(); + if(cs instanceof ClustalxColourScheme) + { + ((ClustalxColourScheme)cs).resetClustalX(av.alignment.getSequences(), + av.alignment.getWidth()); + av.setGlobalColourScheme(cs); + } - c = new Conservation("All", al.cons, - ResidueProperties.propHash, 3, sg.sequences, 0, - al.getWidth()); - c.calculate(); - c.verdict(false, 100); - sg.setConservation(c); - ConservationColourScheme ccs = (ConservationColourScheme)sg.cs; - ccs.conserve = c;*/ } ////////////////////////////////////////// @@ -369,15 +416,19 @@ public class SeqPanel extends JPanel oldSeq = seq; SequenceI sequence = (Sequence) av.getAlignment().getSequenceAt(seq); - if(res>sequence.getLength()) + + if(sequence==null || res>sequence.getLength()) return; - stretchGroup = av.getRubberbandGroup(); + stretchGroup = av.getSelectionGroup(); if(stretchGroup == null) { stretchGroup = av.alignment.findGroup( sequence ); - av.setRubberbandGroup( stretchGroup ); + if(stretchGroup!=null && res>stretchGroup.getStartRes() && res= res) { stretchGroup = allGroups[i]; - av.setRubberbandGroup(stretchGroup); + av.setSelectionGroup(stretchGroup); break; } } @@ -406,18 +457,13 @@ public class SeqPanel extends JPanel sg.setStartRes(res); sg.setEndRes(res); sg.addSequence( sequence ); - av.setRubberbandGroup( sg ); + av.setSelectionGroup( sg ); stretchGroup = sg; if(av.getConservationSelected()) - Desktop.setConservationSliderSource(ap, av.getGlobalColourScheme(), "Background"); - else if(av.getGlobalColourScheme()!=null && av.getGlobalColourScheme().canThreshold()) - { - ResidueColourScheme rcs = (ResidueColourScheme) av.getGlobalColourScheme(); - int threshold = rcs.getThreshold(); - if (threshold > 0) - Desktop.setPIDSliderSource(ap, av.getGlobalColourScheme(), "Background"); - } + SliderPanel.setConservationSlider(ap, av.getGlobalColourScheme(), "Background"); + if(av.getAbovePIDThreshold()) + SliderPanel.setPIDSliderSource(ap, av.getGlobalColourScheme(), "Background"); } else if( javax.swing.SwingUtilities.isRightMouseButton(evt)) @@ -436,8 +482,8 @@ public class SeqPanel extends JPanel // Edit end res position of selected group changeStartRes = true; + stretchGroup.getWidth(); - seqCanvas.paintFlag = true; repaint(); } @@ -450,52 +496,33 @@ public class SeqPanel extends JPanel public void doMouseReleasedDefineMode(MouseEvent evt) { + mouseDragging = false; + if(stretchGroup==null) return; if(stretchGroup.cs instanceof ClustalxColourScheme) { stretchGroup.cs = new ClustalxColourScheme(stretchGroup.sequences, av.alignment.getWidth()); - seqCanvas.paintFlag = true; repaint(); } else if(stretchGroup.cs instanceof ConservationColourScheme) { - ConservationColourScheme ccs = (ConservationColourScheme)stretchGroup.cs; - - Conservation c = new Conservation("Group", - ResidueProperties.propHash, 3, stretchGroup.sequences, 0, - av.alignment.getWidth() ); - - c.calculate(); - c.verdict(false, 100); - ccs = new ConservationColourScheme(c, ccs.cs); - + ConservationColourScheme ccs = (ConservationColourScheme)stretchGroup.cs; stretchGroup.cs = ccs; + SliderPanel.setConservationSlider(ap, stretchGroup.cs, stretchGroup.getName()) ; - - Desktop.setConservationSliderSource(ap, stretchGroup.cs, stretchGroup.getName()) ; - - seqCanvas.paintFlag = true; repaint(); } else - { - if(stretchGroup.cs !=null && stretchGroup.cs.canThreshold()) - { - ResidueColourScheme rcs = (ResidueColourScheme) stretchGroup.cs; - int threshold = rcs.getThreshold(); - if(threshold>0) - Desktop.setPIDSliderSource(ap, stretchGroup.cs, stretchGroup.getName()); - } - - } + SliderPanel.setPIDSliderSource(ap, stretchGroup.cs, stretchGroup.getName()); changeEndRes = false; changeStartRes = false; stretchGroup = null; + ap.idPanel.repaint(); } @@ -508,6 +535,10 @@ public class SeqPanel extends JPanel if(stretchGroup==null) return; + if(res>av.alignment.getWidth()) + res = av.alignment.getWidth()-1; + + if(stretchGroup.getEndRes()==res) // Edit end res position of selected group changeEndRes = true; @@ -533,14 +564,13 @@ public class SeqPanel extends JPanel stretchGroup.setStartRes( res ); } - int dragDirection = 0; if (y > oldSeq) dragDirection = 1; else if (y < oldSeq) dragDirection = -1; - while (y != oldSeq) + while (y != oldSeq && oldSeq>0 && y 0) + running = ap.scrollUp(true); + + if (mouseDragging && evt.getY() >= getHeight() && + av.alignment.getHeight() > av.getEndSeq()) + running = ap.scrollUp(false); + + if (mouseDragging && evt.getX() < 0) + running = ap.scrollRight(true); + + else if (mouseDragging && evt.getX() >= getWidth()) + running = ap.scrollRight(false); + } + + try + { + Thread.sleep(75); + } + catch (Exception ex) + {} + } + } +} + + }