X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FSeqPanel.java;h=44cf4d49c360cffff4b011dbe3fa5a0bcae273cd;hb=99c58ee0ae2a848f982552e53feaf6d5cb9925e5;hp=3595fe626c6bcf948b2ba0355f499edc15f65c41;hpb=b7172420ab674c14e744ff085a4c4e689d7de095;p=jalview.git diff --git a/src/jalview/gui/SeqPanel.java b/src/jalview/gui/SeqPanel.java index 3595fe6..44cf4d4 100755 --- a/src/jalview/gui/SeqPanel.java +++ b/src/jalview/gui/SeqPanel.java @@ -1,3 +1,22 @@ +/* +* 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.*; @@ -6,8 +25,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,12 +33,10 @@ 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; @@ -30,6 +46,9 @@ public class SeqPanel extends JPanel ScrollThread scrollThread = null; boolean mouseDragging = false; + boolean editingSeqs = false; + boolean groupEditing = false; + public SeqPanel(AlignViewport avp, AlignmentPanel p) { this.av = avp; @@ -52,7 +71,7 @@ public class SeqPanel extends JPanel { if(av.getWrapAlignment()) return; - if(evt.isShiftDown() || evt.isAltDown() || evt.isControlDown()) + if( editingSeqs ) doMouseDragged(evt); else doMouseDraggedDefineMode(evt); @@ -65,32 +84,37 @@ 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() || evt.isShiftDown() || evt.isAltDown() || - evt.isControlDown()) + if (av.getWrapAlignment() || editingSeqs) return; doMouseExitedDefineMode(evt); } public void mouseEntered(MouseEvent evt) { - if (av.getWrapAlignment() || evt.isShiftDown() || evt.isAltDown() || - evt.isControlDown()) + if (av.getWrapAlignment() || editingSeqs) return; doMouseEnteredDefineMode(evt); } @@ -102,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; - 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; @@ -134,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; } @@ -175,8 +186,6 @@ public class SeqPanel extends JPanel y %= chunkHeight; seq = y / av.getCharHeight() + av.getStartSeq(); - // chunkHeight = (da.getHeight() + 2)*charHeight; - // startx += chunkWidth; } else { @@ -234,59 +243,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.getSelectionGroup(); + SequenceGroup sg = av.getSelectionGroup(); if(sg==null) - av.getAlignment().findGroup(startseq); - 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++) @@ -295,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/////////// { @@ -322,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(); } @@ -350,20 +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) { + 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); + } + } + + if(cs instanceof ClustalxColourScheme) + { + ((ClustalxColourScheme)cs).resetClustalX(av.alignment.getSequences(), + av.alignment.getWidth()); + av.setGlobalColourScheme(cs); + } + } ////////////////////////////////////////// @@ -422,14 +480,9 @@ public class SeqPanel extends JPanel 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)) @@ -448,6 +501,7 @@ public class SeqPanel extends JPanel // Edit end res position of selected group changeStartRes = true; + stretchGroup.getWidth(); repaint(); @@ -474,27 +528,14 @@ public class SeqPanel extends JPanel else if(stretchGroup.cs instanceof ConservationColourScheme) { - ConservationColourScheme ccs = (ConservationColourScheme)stretchGroup.cs; - - + ConservationColourScheme ccs = (ConservationColourScheme)stretchGroup.cs; stretchGroup.cs = ccs; - - - Desktop.setConservationSliderSource(ap, stretchGroup.cs, stretchGroup.getName()) ; + SliderPanel.setConservationSlider(ap, stretchGroup.cs, stretchGroup.getName()) ; 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; @@ -513,6 +554,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; @@ -560,6 +605,7 @@ public class SeqPanel extends JPanel } else { + if(seq!=null) stretchGroup.addSequence(seq); stretchGroup.addSequence(nextSeq); }