2 * Jalview - A Sequence Alignment Editor and Viewer
\r
3 * Copyright (C) 2005 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
\r
5 * This program is free software; you can redistribute it and/or
\r
6 * modify it under the terms of the GNU General Public License
\r
7 * as published by the Free Software Foundation; either version 2
\r
8 * of the License, or (at your option) any later version.
\r
10 * This program is distributed in the hope that it will be useful,
\r
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
13 * GNU General Public License for more details.
\r
15 * You should have received a copy of the GNU General Public License
\r
16 * along with this program; if not, write to the Free Software
\r
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
\r
19 package jalview.gui;
\r
21 import jalview.datamodel.*;
\r
23 import jalview.jbgui.*;
\r
25 import java.awt.event.*;
\r
29 import javax.swing.event.*;
\r
36 * @version $Revision$
\r
38 public class RedundancyPanel extends GSliderPanel
\r
42 Stack historyList = new Stack(); // simpler than synching with alignFrame.
\r
45 * Creates a new RedundancyPanel object.
\r
47 * @param ap DOCUMENT ME!
\r
48 * @param af DOCUMENT ME!
\r
50 public RedundancyPanel(AlignmentPanel ap, AlignFrame af)
\r
54 label.setText("Enter the redundancy threshold");
\r
56 slider.addChangeListener(new ChangeListener()
\r
58 public void stateChanged(ChangeEvent evt)
\r
60 valueField.setText(slider.getValue() + "");
\r
64 slider.setMinimum(0);
\r
65 slider.setMaximum(100);
\r
66 slider.setValue(100);
\r
72 * @param e DOCUMENT ME!
\r
74 public void applyButton_actionPerformed(ActionEvent e)
\r
76 float threshold = slider.getValue();
\r
79 historyList.push(it = new HistoryItem("Remove redundancy",
\r
80 ap.av.alignment, HistoryItem.HIDE));
\r
82 if ((historyList.size() == 1) ||
\r
83 !af.historyList.contains(historyList.firstElement()))
\r
85 af.addHistoryItem((HistoryItem) historyList.firstElement());
\r
86 af.updateEditMenuBar();
\r
89 undoButton.setEnabled(true);
\r
91 SequenceGroup sg = ap.av.getSelectionGroup();
\r
93 if ((sg != null) && (sg.getSize() >= 1))
\r
95 del = ap.av.alignment.removeRedundancy(threshold, sg.sequences);
\r
97 for (int i = 0; i < del.size(); i++)
\r
99 if (sg.sequences.contains((SequenceI) del.elementAt(i)))
\r
101 sg.deleteSequence((SequenceI) del.elementAt(i), true);
\r
107 Vector s = new Vector();
\r
110 while (i < ap.av.alignment.getHeight())
\r
112 s.addElement(ap.av.alignment.getSequenceAt(i));
\r
116 del = ap.av.alignment.removeRedundancy(threshold, s);
\r
119 // This has to be done before the restoreHistoryItem method of alignFrame will
\r
120 // actually restore these sequences.
\r
121 if (del.size() > 0)
\r
123 for (int i = 0, j = del.size(); i < j; i++)
\r
125 SequenceI sq = (SequenceI) del.elementAt(i);
\r
126 sq.deleteChars(0, sq.getLength());
\r
130 ap.av.firePropertyChange("alignment", null,
\r
131 ap.av.getAlignment().getSequences());
\r
132 ap.av.resetSeqLimits(ap.seqPanel.seqCanvas.getHeight());
\r
134 if (ap.av.getAlignment().getHeight() < 1)
\r
138 af.setClosed(true);
\r
140 catch (Exception ex)
\r
145 ap.av.updateConservation();
\r
146 ap.av.updateConsensus();
\r
147 af.updateEditMenuBar();
\r
154 * @param e DOCUMENT ME!
\r
156 public void undoButton_actionPerformed(ActionEvent e)
\r
158 HistoryItem hi = (HistoryItem) historyList.pop();
\r
159 af.restoreHistoryItem(hi);
\r
161 if (historyList.size() == 0)
\r
163 undoButton.setEnabled(false);
\r
165 if (af.historyList.contains(hi))
\r
167 af.historyList.remove(hi);
\r
168 af.updateEditMenuBar();
\r
176 * @param e DOCUMENT ME!
\r
178 public void valueField_actionPerformed(ActionEvent e)
\r
182 int i = Integer.parseInt(valueField.getText());
\r
183 slider.setValue(i);
\r
185 catch (Exception ex)
\r
187 valueField.setText(slider.getValue() + "");
\r