X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FRedundancyPanel.java;h=daee8623f3469e5939ec69d276fa06433e9d7643;hb=2fa86d263d7bd66fb270a5d26878df37b96a61f4;hp=93ffd9cad1df038c975ba53c65e62a71a75773f9;hpb=79f4b175e12f4c16d598b4cb56ffe62532b592a1;p=jalview.git diff --git a/src/jalview/gui/RedundancyPanel.java b/src/jalview/gui/RedundancyPanel.java index 93ffd9c..daee862 100755 --- a/src/jalview/gui/RedundancyPanel.java +++ b/src/jalview/gui/RedundancyPanel.java @@ -1,103 +1,161 @@ +/* + * 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 jalview.jbgui.*; -import jalview.datamodel.*; -import java.awt.event.*; import java.util.*; + +import java.awt.event.*; import javax.swing.event.*; -public class RedundancyPanel extends GSliderPanel +import jalview.datamodel.*; +import jalview.jbgui.*; + +public class RedundancyPanel + extends GSliderPanel { + AlignFrame af; AlignmentPanel ap; + Stack historyList = new Stack(); // simpler than synching with alignFrame. - SequenceI[] oldAlignment; - - - public RedundancyPanel(AlignmentPanel ap) + public RedundancyPanel(AlignmentPanel ap, AlignFrame af) { this.ap = ap; - + this.af = af; label.setText("Enter the redundancy threshold"); slider.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent evt) { - valueField.setText( slider.getValue()+"" ); + valueField.setText(slider.getValue() + ""); } }); slider.setMinimum(0); slider.setMaximum(100); - slider.setValue(100 ); - + slider.setValue(100); } public void applyButton_actionPerformed(ActionEvent e) { - float threshold = slider.getValue(); - Vector del; + float threshold = slider.getValue(); + Vector del; + HistoryItem it; + historyList.push(it = new HistoryItem("Remove redundancy", + ap.av.alignment, HistoryItem.HIDE)); + + if ( (historyList.size() == 1) || + !af.historyList.contains(historyList.firstElement())) + { + af.addHistoryItem( (HistoryItem) historyList.firstElement()); + af.updateEditMenuBar(); + } + + undoButton.setEnabled(true); + + SequenceGroup sg = ap.av.getSelectionGroup(); + + if ( (sg != null) && (sg.getSize() >= 1)) + { + del = ap.av.alignment.removeRedundancy(threshold, sg.sequences); - oldAlignment = new SequenceI[ap.av.alignment.getHeight()]; - for (int i = 0; i < ap.av.alignment.getHeight(); i++) + for (int i = 0; i < del.size(); i++) + { + if (sg.sequences.contains( (SequenceI) del.elementAt(i))) { - oldAlignment[i] = new Sequence(ap.av.alignment.getSequenceAt(i).getName(), - ap.av.alignment.getSequenceAt(i). - getSequence()); + sg.deleteSequence( (SequenceI) del.elementAt(i), true); } + } + } + else + { + Vector s = new Vector(); + int i = 0; - undoButton.setEnabled(true); - - SequenceGroup sg = ap.av.getSelectionGroup(); - if (sg != null && sg.getSize() > 1) - { - - del = ap.av.alignment.removeRedundancy(threshold, sg.sequences); - for (int i = 0; i < del.size(); i++) - if (sg.sequences.contains( (SequenceI) del.elementAt(i))) - sg.deleteSequence( (SequenceI) del.elementAt(i)); - - } - else - { - Vector s = new Vector(); - int i=0; - while(i < ap.av.alignment.getHeight()) - { - s.addElement( ap.av.alignment.getSequenceAt(i) ); - i++; - } - del = ap.av.alignment.removeRedundancy(threshold,s); - for (int j=0; j < del.size(); j++) - { - if (sg.sequences.contains((SequenceI)del.elementAt(j))) - sg.deleteSequence((SequenceI)del.elementAt(j)); - - } - } - - ap.repaint(); + while (i < ap.av.alignment.getHeight()) + { + s.addElement(ap.av.alignment.getSequenceAt(i)); + i++; + } + del = ap.av.alignment.removeRedundancy(threshold, s); + } + + // This has to be done before the restoreHistoryItem method of alignFrame will + // actually restore these sequences. + if (del.size() > 0) + { + for (int i = 0, j = del.size(); i < j; i++) + { + SequenceI sq = (SequenceI) del.elementAt(i); + sq.deleteChars(0, sq.getLength()); + } + } + + ap.av.firePropertyChange("alignment", null, + ap.av.getAlignment().getSequences()); + ap.av.resetSeqLimits(ap.seqPanel.seqCanvas.getHeight()); + + if (ap.av.getAlignment().getHeight() < 1) + { + try + { + af.setClosed(true); + } + catch (Exception ex) + { + } + } + + ap.av.updateConservation(); + ap.av.updateConsensus(); + af.updateEditMenuBar(); + ap.repaint(); } public void undoButton_actionPerformed(ActionEvent e) { + HistoryItem hi = (HistoryItem) historyList.pop(); + af.restoreHistoryItem(hi); + + if (historyList.size() == 0) + { undoButton.setEnabled(false); - ap.av.setAlignment( new Alignment(oldAlignment) ); - oldAlignment = null; - ap.repaint(); - } + if (af.historyList.contains(hi)) + { + af.historyList.remove(hi); + af.updateEditMenuBar(); + } + } + } public void valueField_actionPerformed(ActionEvent e) { - try{ + try + { int i = Integer.parseInt(valueField.getText()); slider.setValue(i); } - catch(Exception ex) + catch (Exception ex) { - valueField.setText( slider.getValue()+"" ); + valueField.setText(slider.getValue() + ""); } } }