X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FRedundancyPanel.java;h=3901b1f23803004291025e46cf7ebf4a35be08aa;hb=b2319fcc38be5c500ed7cafc014cf9da96a4ce98;hp=44aa4477b4382fbe738bb0453c209051fc75c704;hpb=588042b69abf8e60bcc950b24c283933c7dd422f;p=jalview.git diff --git a/src/jalview/gui/RedundancyPanel.java b/src/jalview/gui/RedundancyPanel.java index 44aa447..3901b1f 100755 --- a/src/jalview/gui/RedundancyPanel.java +++ b/src/jalview/gui/RedundancyPanel.java @@ -18,144 +18,167 @@ */ package jalview.gui; -import java.util.*; +import jalview.datamodel.*; + +import jalview.jbgui.*; import java.awt.event.*; -import javax.swing.event.*; -import jalview.datamodel.*; -import jalview.jbgui.*; +import java.util.*; -public class RedundancyPanel - extends GSliderPanel -{ - AlignFrame af; - AlignmentPanel ap; - Stack historyList = new Stack(); // simpler than synching with alignFrame. +import javax.swing.event.*; - 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); - } - - public void applyButton_actionPerformed(ActionEvent e) - { - 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())) +/** + * DOCUMENT ME! + * + * @author $author$ + * @version $Revision$ + */ +public class RedundancyPanel extends GSliderPanel +{ + 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) { - af.addHistoryItem( (HistoryItem) historyList.firstElement()); - af.updateEditMenuBar(); + 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); } - undoButton.setEnabled(true); - - SequenceGroup sg = ap.av.getSelectionGroup(); - - if ( (sg != null) && (sg.getSize() >= 1)) + /** + * DOCUMENT ME! + * + * @param e DOCUMENT ME! + */ + public void applyButton_actionPerformed(ActionEvent e) { - del = ap.av.alignment.removeRedundancy(threshold, sg.sequences); + float threshold = slider.getValue(); + Vector del; + historyList.push(new HistoryItem("Remove redundancy", + ap.av.alignment, HistoryItem.HIDE)); - for (int i = 0; i < del.size(); i++) - { - if (sg.sequences.contains( (SequenceI) del.elementAt(i))) + if ((historyList.size() == 1) || + !af.historyList.contains(historyList.firstElement())) { - sg.deleteSequence( (SequenceI) del.elementAt(i)); + af.addHistoryItem((HistoryItem) historyList.firstElement()); + af.updateEditMenuBar(); } - } - } - else - { - Vector s = new Vector(); - int i = 0; - while (i < ap.av.alignment.getHeight()) - { - s.addElement(ap.av.alignment.getSequenceAt(i)); - i++; - } + undoButton.setEnabled(true); - del = ap.av.alignment.removeRedundancy(threshold, s); - } + SequenceGroup sg = ap.av.getSelectionGroup(); - // 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()); - } - } + 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; - ap.av.firePropertyChange("alignment", null, - ap.av.getAlignment().getSequences()); - ap.av.resetSeqLimits(ap.seqPanel.seqCanvas.getHeight()); + while (i < ap.av.alignment.getHeight()) + { + s.addElement(ap.av.alignment.getSequenceAt(i)); + i++; + } - if (ap.av.getAlignment().getHeight() < 1) - { - try - { - af.setClosed(true); - } - catch (Exception ex) - { - } - } + del = ap.av.alignment.removeRedundancy(threshold, s); + } - ap.av.updateConservation(); - ap.av.updateConsensus(); - af.updateEditMenuBar(); - ap.repaint(); - } + // 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()); + } + } - public void undoButton_actionPerformed(ActionEvent e) - { - HistoryItem hi = (HistoryItem) historyList.pop(); - af.restoreHistoryItem(hi); + ap.av.firePropertyChange("alignment", null, ap.av.getAlignment().getSequences()); + af.updateEditMenuBar(); - if (historyList.size() == 0) - { - undoButton.setEnabled(false); - if (af.historyList.contains(hi)) - { - af.historyList.remove(hi); - af.updateEditMenuBar(); - } + if (ap.av.getAlignment().getHeight() < 1) + { + try + { + af.setClosed(true); + } + catch (Exception ex) + { + } + } } - } - public void valueField_actionPerformed(ActionEvent e) - { - try + /** + * DOCUMENT ME! + * + * @param e DOCUMENT ME! + */ + public void undoButton_actionPerformed(ActionEvent e) { - int i = Integer.parseInt(valueField.getText()); - slider.setValue(i); + HistoryItem hi = (HistoryItem) historyList.pop(); + af.restoreHistoryItem(hi); + + 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() + ""); + } } - } }