X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FSeqPanel.java;h=ca09c97fe31776b47a47ef2b6b478fd54e38a450;hb=339c2de5fce77a1e1518df6df0c2d894352d6648;hp=83dceefd72af045e699b99d6c1f454d59e05199a;hpb=cca44e3c2ffd33d3427f6bc52d4cbd8614c0c08c;p=jalview.git diff --git a/src/jalview/gui/SeqPanel.java b/src/jalview/gui/SeqPanel.java index 83dceef..ca09c97 100755 --- a/src/jalview/gui/SeqPanel.java +++ b/src/jalview/gui/SeqPanel.java @@ -6,8 +6,6 @@ import jalview.datamodel.*; import javax.swing.*; import java.util.*; import jalview.schemes.*; -import jalview.analysis.*; - public class SeqPanel extends JPanel { @@ -15,18 +13,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 +51,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 +64,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 +106,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 +135,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 +166,6 @@ public class SeqPanel extends JPanel y %= chunkHeight; seq = y / av.getCharHeight() + av.getStartSeq(); - // chunkHeight = (da.getHeight() + 2)*charHeight; - // startx += chunkWidth; } else { @@ -170,6 +178,9 @@ public class SeqPanel extends JPanel return; SequenceI sequence = av.getAlignment().getSequenceAt(seq); + if(res>sequence.getLength()) + return; + Object obj = ResidueProperties.aa2Triplet.get( sequence.getCharAt(res)+"" ) ; String aa = ""; if(obj!=null) @@ -181,7 +192,8 @@ public class SeqPanel extends JPanel ap.alignFrame.statusBar.setText(text.toString()); - if(av.showSequenceFeatures) + // use aa to see if the mouse pointer is on a + if( av.showSequenceFeatures) { Vector features = sequence.getSequenceFeatures(); Enumeration e = features.elements(); @@ -211,54 +223,69 @@ public class SeqPanel extends JPanel } public void doMouseDragged(MouseEvent evt) { - // If we're dragging we're editing - - int x = evt.getX(); - int res = x/av.getCharWidth() + av.getStartRes(); + // If we're dragging we're editing + int res = evt.getX() / av.getCharWidth() + av.getStartRes(); if (res < 0) res = 0; + if (lastres == -1 || lastres == res) + return; + + boolean dragRight = true; + if (res < av.getAlignment().getWidth() && res < lastres) + dragRight = false; + + 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++) @@ -267,21 +294,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/////////// { @@ -294,17 +320,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(); } @@ -322,33 +355,34 @@ 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(); + } - Conservation c = sg.getConservation(); + av.updateConservation(); + av.updateConsensus(); + + ColourSchemeI cs = av.getGlobalColourScheme(); + if(cs instanceof ConservationColourScheme) + cs = ( (ConservationColourScheme) cs).cs; + + if(cs instanceof ClustalxColourScheme) + cs = new ClustalxColourScheme(av.alignment.getSequences(), av.alignment.getWidth()); + + ap.alignFrame.changeColour(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;*/ } ////////////////////////////////////////// @@ -361,24 +395,29 @@ public class SeqPanel extends JPanel int seq = evt.getY()/av.getCharHeight() + av.getStartSeq(); oldSeq = seq; - stretchGroup = av.getRubberbandGroup(); + SequenceI sequence = (Sequence) av.getAlignment().getSequenceAt(seq); + + if(sequence==null || res>sequence.getLength()) + return; + + stretchGroup = av.getSelectionGroup(); if(stretchGroup == null) { - stretchGroup = av.alignment.findGroup( (Sequence) av.getAlignment(). - getSequenceAt(seq)); - av.setRubberbandGroup( stretchGroup ); + stretchGroup = av.alignment.findGroup( sequence ); + if(stretchGroup!=null && res>stretchGroup.getStartRes() && resres || stretchGroup.getEndRes()= res) { stretchGroup = allGroups[i]; - av.setRubberbandGroup(stretchGroup); + av.setSelectionGroup(stretchGroup); break; } } @@ -397,19 +436,14 @@ public class SeqPanel extends JPanel SequenceGroup sg = new SequenceGroup(); sg.setStartRes(res); sg.setEndRes(res); - sg.addSequence( (Sequence)av.getAlignment().getSequenceAt(seq) ); - av.setRubberbandGroup( sg ); + sg.addSequence( sequence ); + 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)) @@ -428,8 +462,8 @@ public class SeqPanel extends JPanel // Edit end res position of selected group changeStartRes = true; + stretchGroup.getWidth(); - seqCanvas.paintFlag = true; repaint(); } @@ -442,32 +476,23 @@ 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 @@ -475,9 +500,7 @@ public class SeqPanel extends JPanel 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()); } } @@ -486,6 +509,7 @@ public class SeqPanel extends JPanel changeEndRes = false; changeStartRes = false; stretchGroup = null; + ap.idPanel.repaint(); } @@ -495,6 +519,12 @@ public class SeqPanel extends JPanel int res = evt.getX()/av.getCharWidth() + av.getStartRes(); int y = evt.getY()/av.getCharHeight() + av.getStartSeq(); + 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 @@ -521,14 +551,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) + {} + } + } +} + + }