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.
23 import jalview.datamodel.AlignmentAnnotation;
24 import jalview.datamodel.GraphLine;
25 import jalview.datamodel.SequenceGroup;
26 import jalview.schemes.AnnotationColourGradient;
27 import jalview.util.MessageManager;
29 import java.awt.event.MouseAdapter;
30 import java.awt.event.MouseEvent;
31 import java.util.Vector;
33 import javax.swing.JButton;
34 import javax.swing.JCheckBox;
35 import javax.swing.JComboBox;
36 import javax.swing.JInternalFrame;
37 import javax.swing.JPanel;
38 import javax.swing.JSlider;
39 import javax.swing.JTextField;
40 import javax.swing.event.ChangeEvent;
41 import javax.swing.event.ChangeListener;
43 @SuppressWarnings("serial")
44 public abstract class AnnotationRowFilter extends JPanel
46 protected AlignViewport av;
48 protected AlignmentPanel ap;
50 protected int[] annmap;
52 protected boolean enableSeqAss = false;
54 private AlignmentAnnotation currentAnnotation;
56 protected boolean adjusting = false;
58 protected JCheckBox currentColours = new JCheckBox();
60 protected JPanel minColour = new JPanel();
62 protected JPanel maxColour = new JPanel();
64 protected JCheckBox seqAssociated = new JCheckBox();
66 protected JCheckBox thresholdIsMin = new JCheckBox();
68 protected JSlider slider = new JSlider();
70 protected JTextField thresholdValue = new JTextField(20);
72 protected JInternalFrame frame;
74 protected JButton ok = new JButton();
76 protected JButton cancel = new JButton();
79 * enabled if the user is dragging the slider - try to keep updates to a
82 protected boolean sliderDragging = false;
84 protected void addSliderChangeListener()
87 slider.addChangeListener(new ChangeListener()
90 public void stateChanged(ChangeEvent evt)
94 thresholdValue.setText((slider.getValue() / 1000f) + "");
95 valueChanged(!sliderDragging);
101 protected void addSliderMouseListeners()
104 slider.addMouseListener(new MouseAdapter()
107 public void mousePressed(MouseEvent e)
109 sliderDragging = true;
110 super.mousePressed(e);
114 public void mouseDragged(MouseEvent e)
116 sliderDragging = true;
117 super.mouseDragged(e);
121 public void mouseReleased(MouseEvent evt)
125 sliderDragging = false;
128 ap.paintAlignment(true);
133 public AnnotationRowFilter(AlignViewport av, final AlignmentPanel ap)
139 public AnnotationRowFilter()
144 public Vector<String> getAnnotationItems(boolean isSeqAssociated)
146 Vector<String> list = new Vector<String>();
148 int[] anmap = new int[av.getAlignment().getAlignmentAnnotation().length];
149 for (int i = 0; i < av.getAlignment().getAlignmentAnnotation().length; i++)
151 if (av.getAlignment().getAlignmentAnnotation()[i].sequenceRef == null)
162 String label = av.getAlignment().getAlignmentAnnotation()[i].label;
163 // add associated sequence ID if available
165 && av.getAlignment().getAlignmentAnnotation()[i].sequenceRef != null)
169 + av.getAlignment().getAlignmentAnnotation()[i].sequenceRef
173 if (!list.contains(label))
175 anmap[list.size()] = i;
180 if (!isSeqAssociated)
182 anmap[list.size()] = i;
183 list.add(label + "_" + (index++));
187 this.annmap = new int[list.size()];
188 System.arraycopy(anmap, 0, this.annmap, 0, this.annmap.length);
192 protected int getSelectedThresholdItem(int indexValue)
194 int selectedThresholdItem = -1;
197 selectedThresholdItem = AnnotationColourGradient.ABOVE_THRESHOLD;
199 else if (indexValue == 2)
201 selectedThresholdItem = AnnotationColourGradient.BELOW_THRESHOLD;
203 return selectedThresholdItem;
206 public void modelChanged()
208 seqAssociated.setEnabled(enableSeqAss);
211 public void ok_actionPerformed()
215 frame.setClosed(true);
216 } catch (Exception ex)
221 public void cancel_actionPerformed()
224 ap.paintAlignment(true);
227 frame.setClosed(true);
228 } catch (Exception ex)
233 public void thresholdCheck_actionPerformed()
238 public void annotations_actionPerformed()
243 public void threshold_actionPerformed()
248 public void thresholdValue_actionPerformed()
252 float f = Float.parseFloat(thresholdValue.getText());
253 slider.setValue((int) (f * 1000));
255 } catch (NumberFormatException ex)
260 public void thresholdIsMin_actionPerformed()
265 protected void populateThresholdComboBox(JComboBox<String> threshold)
267 threshold.addItem(MessageManager
268 .getString("label.threshold_feature_no_threshold"));
269 threshold.addItem(MessageManager
270 .getString("label.threshold_feature_above_threshold"));
271 threshold.addItem(MessageManager
272 .getString("label.threshold_feature_below_threshold"));
275 protected void seqAssociated_actionPerformed(JComboBox<String> annotations)
278 String cursel = (String) annotations.getSelectedItem();
279 boolean isvalid = false, isseqs = seqAssociated.isSelected();
280 annotations.removeAllItems();
281 for (String anitem : getAnnotationItems(seqAssociated.isSelected()))
283 if (anitem.equals(cursel) || (isseqs && cursel.startsWith(anitem)))
288 annotations.addItem(anitem);
293 annotations.setSelectedItem(cursel);
297 if (annotations.getItemCount() > 0)
299 annotations.setSelectedIndex(0);
304 protected void propagateSeqAssociatedThreshold(boolean allAnnotation,
305 AlignmentAnnotation annotation)
307 if (annotation.sequenceRef == null || annotation.threshold == null)
312 float thr = annotation.threshold.value;
313 for (int i = 0; i < av.getAlignment().getAlignmentAnnotation().length; i++)
315 AlignmentAnnotation aa = av.getAlignment().getAlignmentAnnotation()[i];
316 if (aa.label.equals(annotation.label)
317 && (annotation.getCalcId() == null ? aa.getCalcId() == null
318 : annotation.getCalcId().equals(aa.getCalcId())))
320 if (aa.threshold == null)
322 aa.threshold = new GraphLine(annotation.threshold);
326 aa.threshold.value = thr;
332 protected boolean colorAlignmContaining(AlignmentAnnotation currentAnn,
333 int selectedThresholdOption)
336 AnnotationColourGradient acg = null;
337 if (currentColours.isSelected())
339 acg = new AnnotationColourGradient(currentAnn,
340 av.getGlobalColourScheme(), selectedThresholdOption);
344 acg = new AnnotationColourGradient(currentAnn,
345 minColour.getBackground(), maxColour.getBackground(),
346 selectedThresholdOption);
348 acg.setSeqAssociated(seqAssociated.isSelected());
350 if (currentAnn.graphMin == 0f && currentAnn.graphMax == 0f)
352 acg.setPredefinedColours(true);
355 acg.thresholdIsMinMax = thresholdIsMin.isSelected();
357 av.setGlobalColourScheme(acg);
359 if (av.getAlignment().getGroups() != null)
362 for (SequenceGroup sg : ap.av.getAlignment().getGroups())
369 AnnotationColourGradient scheme = null;
370 if (currentColours.isSelected())
372 scheme = new AnnotationColourGradient(currentAnn,
373 sg.getColourScheme(), selectedThresholdOption);
377 scheme = new AnnotationColourGradient(currentAnn,
378 minColour.getBackground(), maxColour.getBackground(),
379 selectedThresholdOption);
381 scheme.setSeqAssociated(seqAssociated.isSelected());
382 sg.setColourScheme(scheme);
388 public jalview.datamodel.AlignmentAnnotation getCurrentAnnotation()
390 return currentAnnotation;
393 public void setCurrentAnnotation(
394 jalview.datamodel.AlignmentAnnotation currentAnnotation)
396 this.currentAnnotation = currentAnnotation;
399 public abstract void valueChanged(boolean updateAllAnnotation);
401 public abstract void updateView();
403 public abstract void reset();