X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FSeqPanel.java;h=44cf4d49c360cffff4b011dbe3fa5a0bcae273cd;hb=99c58ee0ae2a848f982552e53feaf6d5cb9925e5;hp=468fadb91d40b98ccb3e31060c3647818135d229;hpb=4b65534cd7d7dad17375e16d38848a69f23882b4;p=jalview.git diff --git a/src/jalview/gui/SeqPanel.java b/src/jalview/gui/SeqPanel.java index 468fadb..44cf4d4 100755 --- a/src/jalview/gui/SeqPanel.java +++ b/src/jalview/gui/SeqPanel.java @@ -1,31 +1,55 @@ +/* +* Jalview - A Sequence Alignment Editor and Viewer +* Copyright (C) 2005 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* as published by the Free Software Foundation; either version 2 +* of the License, or (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA +*/ + package jalview.gui; import java.awt.*; import java.awt.event.*; import jalview.datamodel.*; import javax.swing.*; +import java.util.*; import jalview.schemes.*; -import jalview.analysis.*; - +import jalview.analysis.Conservation; public class SeqPanel extends JPanel { public SeqCanvas seqCanvas; - public AlignmentPanel parent; + 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; @@ -33,16 +57,21 @@ 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(evt.isShiftDown() || evt.isAltDown() || evt.isControlDown()) + if(av.getWrapAlignment()) + return; + if( editingSeqs ) doMouseDragged(evt); else doMouseDraggedDefineMode(evt); @@ -53,18 +82,42 @@ public class SeqPanel extends JPanel { public void mouseReleased(MouseEvent evt) { - if(evt.isShiftDown() || evt.isAltDown() || evt.isControlDown()) + if(av.getWrapAlignment()) + return; + 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(); @@ -73,26 +126,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; - parent.RefreshPanels(); - repaint(); - + ap.repaint(); } public void doMousePressed(MouseEvent evt) { - parent.alignFrame.addHistoryItem("sequence edit"); + + ap.alignFrame.addHistoryItem( new HistoryItem( + "Edit Sequence",av.alignment, HistoryItem.EDIT)); + int seq; int res; @@ -105,28 +155,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; } @@ -146,8 +186,6 @@ public class SeqPanel extends JPanel y %= chunkHeight; seq = y / av.getCharHeight() + av.getStartSeq(); - // chunkHeight = (da.getHeight() + 2)*charHeight; - // startx += chunkWidth; } else { @@ -159,68 +197,115 @@ 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 - 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++) @@ -229,21 +314,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/////////// { @@ -256,17 +340,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(); } @@ -284,33 +375,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;*/ } ////////////////////////////////////////// @@ -323,20 +434,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)); + { + 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; } } @@ -355,13 +475,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 @@ -375,11 +501,10 @@ public class SeqPanel extends JPanel // Edit end res position of selected group changeStartRes = true; + stretchGroup.getWidth(); - seqCanvas.paintFlag = true; repaint(); - } boolean changeEndSeq = false; @@ -390,9 +515,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()); + repaint(); + } + + else if(stretchGroup.cs instanceof ConservationColourScheme) + { + ConservationColourScheme ccs = (ConservationColourScheme)stretchGroup.cs; + stretchGroup.cs = ccs; + SliderPanel.setConservationSlider(ap, stretchGroup.cs, stretchGroup.getName()) ; + + repaint(); + } + else + SliderPanel.setPIDSliderSource(ap, stretchGroup.cs, stretchGroup.getName()); + + changeEndRes = false; changeStartRes = false; stretchGroup = null; + ap.idPanel.repaint(); } @@ -402,13 +551,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; @@ -428,14 +583,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) + {} + } + } +} + + }