X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FRedundancyPanel.java;h=3901b1f23803004291025e46cf7ebf4a35be08aa;hb=eacce9627f059fc2f9e880c81d8d1bdfbe7fe5b3;hp=93ffd9cad1df038c975ba53c65e62a71a75773f9;hpb=79f4b175e12f4c16d598b4cb56ffe62532b592a1;p=jalview.git diff --git a/src/jalview/gui/RedundancyPanel.java b/src/jalview/gui/RedundancyPanel.java index 93ffd9c..3901b1f 100755 --- a/src/jalview/gui/RedundancyPanel.java +++ b/src/jalview/gui/RedundancyPanel.java @@ -1,103 +1,184 @@ +/* + * 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 jalview.jbgui.*; + import java.awt.event.*; + import java.util.*; + import javax.swing.event.*; + +/** + * DOCUMENT ME! + * + * @author $author$ + * @version $Revision$ + */ public class RedundancyPanel extends GSliderPanel { - AlignmentPanel ap; + AlignFrame af; + AlignmentPanel ap; + Stack historyList = new Stack(); // simpler than synching with alignFrame. + + /** + * Creates a new RedundancyPanel object. + * + * @param ap DOCUMENT ME! + * @param af DOCUMENT ME! + */ + 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() + ""); + } + }); + + slider.setMinimum(0); + slider.setMaximum(100); + slider.setValue(100); + } - SequenceI[] oldAlignment; + /** + * DOCUMENT ME! + * + * @param e DOCUMENT ME! + */ + public void applyButton_actionPerformed(ActionEvent e) + { + float threshold = slider.getValue(); + Vector del; + historyList.push(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(); + } - public RedundancyPanel(AlignmentPanel ap) - { - this.ap = ap; + undoButton.setEnabled(true); - label.setText("Enter the redundancy threshold"); + SequenceGroup sg = ap.av.getSelectionGroup(); - slider.addChangeListener(new ChangeListener() - { - public void stateChanged(ChangeEvent evt) - { - valueField.setText( slider.getValue()+"" ); - } - }); + 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), true); + } + } + } + else + { + Vector s = new Vector(); + int i = 0; - slider.setMinimum(0); - slider.setMaximum(100); - slider.setValue(100 ); + 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()); + af.updateEditMenuBar(); - public void applyButton_actionPerformed(ActionEvent e) - { - float threshold = slider.getValue(); - Vector del; - oldAlignment = new SequenceI[ap.av.alignment.getHeight()]; - for (int i = 0; i < ap.av.alignment.getHeight(); i++) + if (ap.av.getAlignment().getHeight() < 1) { - oldAlignment[i] = new Sequence(ap.av.alignment.getSequenceAt(i).getName(), - ap.av.alignment.getSequenceAt(i). - getSequence()); + try + { + af.setClosed(true); + } + catch (Exception ex) + { + } } + } - undoButton.setEnabled(true); + /** + * DOCUMENT ME! + * + * @param e DOCUMENT ME! + */ + public void undoButton_actionPerformed(ActionEvent e) + { + HistoryItem hi = (HistoryItem) historyList.pop(); + af.restoreHistoryItem(hi); - 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(); - - } - - public void undoButton_actionPerformed(ActionEvent e) - { - undoButton.setEnabled(false); - ap.av.setAlignment( new Alignment(oldAlignment) ); - oldAlignment = null; - ap.repaint(); - } - - - public void valueField_actionPerformed(ActionEvent e) - { - try{ - int i = Integer.parseInt(valueField.getText()); - slider.setValue(i); + if (historyList.size() == 0) + { + undoButton.setEnabled(false); + + if (af.historyList.contains(hi)) + { + af.historyList.remove(hi); + af.updateEditMenuBar(); + } + } } - catch(Exception ex) + + /** + * DOCUMENT ME! + * + * @param e DOCUMENT ME! + */ + public void valueField_actionPerformed(ActionEvent e) { - valueField.setText( slider.getValue()+"" ); + try + { + int i = Integer.parseInt(valueField.getText()); + slider.setValue(i); + } + catch (Exception ex) + { + valueField.setText(slider.getValue() + ""); + } } - } }