X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FSeqPanel.java;h=162f978ab4adec11a87e246a6f35f6a8a2df3687;hb=e542a2b9968ee6a7def19e79e84c27684ee686e3;hp=9dcebd2159718af8b3ce2adeeb98e0fef0f13582;hpb=4b9d13acc586d87c53ce21078fb380405164e19b;p=jalview.git diff --git a/src/jalview/gui/SeqPanel.java b/src/jalview/gui/SeqPanel.java index 9dcebd2..162f978 100755 --- a/src/jalview/gui/SeqPanel.java +++ b/src/jalview/gui/SeqPanel.java @@ -4,15 +4,14 @@ import java.awt.*; import java.awt.event.*; import jalview.datamodel.*; import javax.swing.*; +import java.util.*; import jalview.schemes.*; -import jalview.analysis.*; - public class SeqPanel extends JPanel { public SeqCanvas seqCanvas; - public AlignmentPanel parent; + public AlignmentPanel ap; protected int startres; protected int lastres; @@ -26,6 +25,10 @@ public class SeqPanel extends JPanel // if character is inserted or deleted, we will need to recalculate the conservation int seqEditOccurred = -1; + ScrollThread scrollThread = null; + boolean mouseDragging = false; + + public SeqPanel(AlignViewport avp, AlignmentPanel p) { this.av = avp; @@ -33,15 +36,20 @@ public class SeqPanel extends JPanel setLayout(new BorderLayout()); add(seqCanvas, BorderLayout.CENTER); - parent = p; + ap = p; addMouseMotionListener( new MouseMotionAdapter() { public void mouseMoved(MouseEvent evt) - { doMouseMoved(evt); } + { + if(av.getWrapAlignment()) + return; + doMouseMoved(evt); } public void mouseDragged(MouseEvent evt) { + if(av.getWrapAlignment()) + return; if(evt.isShiftDown() || evt.isAltDown() || evt.isControlDown()) doMouseDragged(evt); else @@ -53,6 +61,8 @@ public class SeqPanel extends JPanel { public void mouseReleased(MouseEvent evt) { + if(av.getWrapAlignment()) + return; if(evt.isShiftDown() || evt.isAltDown() || evt.isControlDown()) doMouseReleased(evt); else @@ -60,11 +70,28 @@ public class SeqPanel extends JPanel } public void mousePressed(MouseEvent evt) { + if(av.getWrapAlignment()) + return; if(evt.isShiftDown() || evt.isAltDown() || evt.isControlDown()) doMousePressed(evt); else doMousePressedDefineMode(evt); } + public void mouseExited(MouseEvent evt) + { + if (av.getWrapAlignment() || evt.isShiftDown() || evt.isAltDown() || + evt.isControlDown()) + return; + doMouseExitedDefineMode(evt); + + } + public void mouseEntered(MouseEvent evt) + { + if (av.getWrapAlignment() || evt.isShiftDown() || evt.isAltDown() || + evt.isControlDown()) + return; + doMouseEnteredDefineMode(evt); + } }); repaint(); @@ -86,13 +113,12 @@ public class SeqPanel extends JPanel seqEditOccurred = -1; - parent.RefreshPanels(); - repaint(); + ap.repaint(); } public void doMousePressed(MouseEvent evt) { - parent.alignFrame.addHistoryItem("sequence edit"); + ap.alignFrame.addHistoryItem("sequence edit"); int seq; int res; @@ -146,8 +172,6 @@ public class SeqPanel extends JPanel y %= chunkHeight; seq = y / av.getCharHeight() + av.getStartSeq(); - // chunkHeight = (da.getHeight() + 2)*charHeight; - // startx += chunkWidth; } else { @@ -159,22 +183,57 @@ public class SeqPanel extends JPanel if(seq>=av.getAlignment().getHeight()) return; - Object obj = ResidueProperties.aa2Triplet.get( av.getAlignment().getSequenceAt(seq).getCharAt(res)+"" ) ; + SequenceI sequence = av.getAlignment().getSequenceAt(seq); + if(res>sequence.getLength()) + return; + + Object obj = ResidueProperties.aa2Triplet.get( sequence.getCharAt(res)+"" ) ; String aa = ""; if(obj!=null) aa = obj.toString(); - StringBuffer text = new StringBuffer("Sequence " +(seq+1)+" ID: "+av.getAlignment().getSequenceAt(seq).getName()); + StringBuffer text = new StringBuffer("Sequence " +(seq+1)+" ID: "+sequence.getName()); if(aa!="") text.append(" Residue: "+aa+" ("+ av.getAlignment().getSequenceAt(seq).findPosition(res)+")"); - parent.alignFrame.statusBar.setText(text.toString()); + ap.alignFrame.statusBar.setText(text.toString()); + + // use aa to see if the mouse pointer is on a + if( av.showSequenceFeatures) + { + Vector features = sequence.getSequenceFeatures(); + Enumeration e = features.elements(); + StringBuffer sbuffer = new StringBuffer(); + + + while (e.hasMoreElements()) + { + SequenceFeature sf = (SequenceFeature) e.nextElement(); + if (sf.getStart() <= sequence.findPosition(res) && + sf.getEnd() >= sequence.findPosition(res)) + { + if(sbuffer.length()>0) + sbuffer.append("; "); + sbuffer.append(sf.getType() + " " + sf.getDescription()); + if(sf.getStatus().length()>0) + sbuffer.append(" ("+sf.getStatus()+")"); + } + + } + + ToolTipManager.sharedInstance().registerComponent(this); + this.setToolTipText(sbuffer.toString()); + } + } public void doMouseDragged(MouseEvent evt) { // If we're dragging we're editing + if(lastres==-1) + return; + int x = evt.getX(); int res = x/av.getCharWidth() + av.getStartRes(); @@ -186,7 +245,9 @@ public class SeqPanel extends JPanel // Group editing if (evt.isAltDown() || evt.isControlDown()) { - SequenceGroup sg = av.getAlignment().findGroup(startseq); + SequenceGroup sg = av.getSelectionGroup(); + if(sg==null) + av.getAlignment().findGroup(startseq); if (sg != null) { boolean deleteAllowed = false; @@ -286,31 +347,29 @@ public class SeqPanel extends JPanel { if ( jalview.util.Comparison.isGap( av.alignment.getSequenceAt(seq).getSequence().charAt(j))) - av.alignment.getSequenceAt(seq).deleteCharAt(j); + av.alignment.getSequenceAt(seq).deleteCharAt(j); av.alignment.getWidth(); repaint(); seqEditOccurred=seq; + } void updateConservation(int i) { - /* Alignment al = (Alignment) av.getAlignment(); - SequenceGroup sg = av.alignment.findGroup( al.getSequenceAt(i)); - if(sg==null || !(sg.cs instanceof ConservationColourScheme)) - return; + av.updateConservation(); + av.updateConsensus(); - Conservation c = sg.getConservation(); + 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;*/ } ////////////////////////////////////////// @@ -323,16 +382,39 @@ 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)); + { + stretchGroup = av.alignment.findGroup( sequence ); + if(stretchGroup!=null && res>stretchGroup.getStartRes() && resres || stretchGroup.getEndRes()= res) + { + stretchGroup = allGroups[i]; + av.setSelectionGroup(stretchGroup); + break; + } } if(stretchGroup==null) @@ -341,13 +423,19 @@ 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()) + SliderPanel.setConservationSlider(ap, av.getGlobalColourScheme(), "Background"); + if(av.getAbovePIDThreshold()) + SliderPanel.setPIDSliderSource(ap, av.getGlobalColourScheme(), "Background"); + } else if( javax.swing.SwingUtilities.isRightMouseButton(evt)) { - jalview.gui.PopupMenu pop = new jalview.gui.PopupMenu( parent , null); + jalview.gui.PopupMenu pop = new jalview.gui.PopupMenu( ap , null); pop.show(this, evt.getX(), evt.getY()); // edit the properties of existing group @@ -362,10 +450,8 @@ public class SeqPanel extends JPanel changeStartRes = true; - seqCanvas.paintFlag = true; repaint(); - } boolean changeEndSeq = false; @@ -376,9 +462,40 @@ 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()); + repaint(); + } + + else if(stretchGroup.cs instanceof ConservationColourScheme) + { + ConservationColourScheme ccs = (ConservationColourScheme)stretchGroup.cs; + stretchGroup.cs = ccs; + SliderPanel.setConservationSlider(ap, stretchGroup.cs, stretchGroup.getName()) ; + + repaint(); + } + else + { + if(stretchGroup.cs !=null && stretchGroup.cs.canThreshold()) + { + ResidueColourScheme rcs = (ResidueColourScheme) stretchGroup.cs; + SliderPanel.setPIDSliderSource(ap, stretchGroup.cs, stretchGroup.getName()); + } + + } + + changeEndRes = false; changeStartRes = false; stretchGroup = null; + ap.idPanel.repaint(); } @@ -388,13 +505,19 @@ 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 changeEndRes = true; else if(stretchGroup.getStartRes()==res) - // Edit end res position of selected group + // Edit start res position of selected group changeStartRes = true; @@ -414,14 +537,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) + {} + } + } +} + + }