2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
21 package jalview.appletgui;
23 import jalview.schemes.AnnotationColourGradient;
24 import jalview.util.MessageManager;
26 import java.awt.Button;
27 import java.awt.Checkbox;
28 import java.awt.Choice;
29 import java.awt.Frame;
30 import java.awt.Panel;
31 import java.awt.Scrollbar;
32 import java.awt.TextField;
33 import java.awt.event.ActionEvent;
35 @SuppressWarnings("serial")
36 public abstract class AnnotationRowFilter extends Panel
38 protected AlignViewport av;
40 protected AlignmentPanel ap;
42 protected int[] annmap;
44 protected boolean enableSeqAss = false;
46 private jalview.datamodel.AlignmentAnnotation currentAnnotation;
48 protected boolean adjusting = false;
50 protected Checkbox currentColours = new Checkbox();
52 protected Panel minColour = new Panel();
54 protected Panel maxColour = new Panel();
56 protected Checkbox seqAssociated = new Checkbox();
58 protected Checkbox thresholdIsMin = new Checkbox();
60 protected Scrollbar slider = new Scrollbar(Scrollbar.HORIZONTAL);
62 protected Checkbox percentThreshold = new Checkbox();
64 protected TextField thresholdValue = new TextField(20);
66 protected Frame frame;
68 protected Button ok = new Button();
70 protected Button cancel = new Button();
73 * enabled if the user is dragging the slider - try to keep updates to a
76 protected boolean sliderDragging = false;
78 public AnnotationRowFilter(AlignViewport av, final AlignmentPanel ap)
84 public AnnotationRowFilter()
89 protected int getSelectedThresholdItem(int indexValue)
91 int selectedThresholdItem = -1;
94 selectedThresholdItem = AnnotationColourGradient.ABOVE_THRESHOLD;
96 else if (indexValue == 2)
98 selectedThresholdItem = AnnotationColourGradient.BELOW_THRESHOLD;
100 return selectedThresholdItem;
103 public void modelChanged()
105 seqAssociated.setEnabled(enableSeqAss);
108 public void ok_actionPerformed(ActionEvent e)
111 frame.setVisible(false);
114 public void cancel_actionPerformed(ActionEvent e)
117 ap.paintAlignment(true);
118 frame.setVisible(false);
121 public void thresholdCheck_actionPerformed(ActionEvent e)
126 public void annotations_actionPerformed(ActionEvent e)
131 public void threshold_actionPerformed(ActionEvent e)
137 * update the text field from the threshold slider. preserves state of
138 * 'adjusting' so safe to call in init.
140 protected void setThresholdValueText()
142 boolean oldadj = adjusting;
144 if (percentThreshold.getState())
146 double scl = slider.getMaximum() - slider.getMinimum();
147 scl = (slider.getValue() - slider.getMinimum()) / scl;
148 thresholdValue.setText(100f * scl + "");
152 thresholdValue.setText((slider.getValue() / 1000f) + "");
154 thresholdValue.setCaretPosition(0);
158 public void thresholdValue_actionPerformed(ActionEvent e)
162 float f = Float.parseFloat(thresholdValue.getText());
163 if (percentThreshold.getState())
165 int pos = slider.getMinimum()
166 + (int) ((slider.getMaximum() - slider.getMinimum()) * f / 100f);
167 slider.setValue(pos);
171 slider.setValue((int) (f * 1000));
174 } catch (NumberFormatException ex)
179 protected void percentageValue_actionPerformed()
181 setThresholdValueText();
184 protected void populateThresholdComboBox(Choice threshold)
186 threshold.addItem(MessageManager
187 .getString("label.threshold_feature_no_threshold"));
188 threshold.addItem(MessageManager
189 .getString("label.threshold_feature_above_threshold"));
190 threshold.addItem(MessageManager
191 .getString("label.threshold_feature_below_threshold"));
194 public jalview.datamodel.AlignmentAnnotation getCurrentAnnotation()
196 return currentAnnotation;
199 public void setCurrentAnnotation(
200 jalview.datamodel.AlignmentAnnotation currentAnnotation)
202 this.currentAnnotation = currentAnnotation;
205 public abstract void valueChanged(boolean updateAllAnnotation);
207 public abstract void updateView();
209 public abstract void reset();