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.FocusAdapter;
30 import java.awt.event.FocusEvent;
31 import java.awt.event.MouseAdapter;
32 import java.awt.event.MouseEvent;
33 import java.util.Vector;
35 import javax.swing.JButton;
36 import javax.swing.JCheckBox;
37 import javax.swing.JComboBox;
38 import javax.swing.JInternalFrame;
39 import javax.swing.JPanel;
40 import javax.swing.JSlider;
41 import javax.swing.JTextField;
42 import javax.swing.event.ChangeEvent;
43 import javax.swing.event.ChangeListener;
45 @SuppressWarnings("serial")
46 public abstract class AnnotationRowFilter extends JPanel
48 protected AlignViewport av;
50 protected AlignmentPanel ap;
52 protected int[] annmap;
54 protected boolean enableSeqAss = false;
56 private AlignmentAnnotation currentAnnotation;
58 protected boolean adjusting = false;
60 protected JCheckBox currentColours = new JCheckBox();
62 protected JPanel minColour = new JPanel();
64 protected JPanel maxColour = new JPanel();
66 protected JCheckBox seqAssociated = new JCheckBox();
68 protected JCheckBox thresholdIsMin = new JCheckBox();
70 protected JSlider slider = new JSlider();
72 protected JTextField thresholdValue = new JTextField(20);
74 protected JInternalFrame frame;
76 protected JButton ok = new JButton();
78 protected JButton cancel = new JButton();
81 * enabled if the user is dragging the slider - try to keep updates to a
84 protected boolean sliderDragging = false;
86 protected void addSliderChangeListener()
89 slider.addChangeListener(new ChangeListener()
92 public void stateChanged(ChangeEvent evt)
96 thresholdValue.setText((slider.getValue() / 1000f) + "");
97 valueChanged(!sliderDragging);
103 protected void addSliderMouseListeners()
106 slider.addMouseListener(new MouseAdapter()
109 public void mousePressed(MouseEvent e)
111 sliderDragging = true;
112 super.mousePressed(e);
116 public void mouseDragged(MouseEvent e)
118 sliderDragging = true;
119 super.mouseDragged(e);
123 public void mouseReleased(MouseEvent evt)
127 sliderDragging = false;
130 ap.paintAlignment(true);
135 public AnnotationRowFilter(AlignViewport av, final AlignmentPanel ap)
139 thresholdValue.addFocusListener(new FocusAdapter()
142 public void focusLost(FocusEvent e)
144 thresholdValue_actionPerformed();
149 public AnnotationRowFilter()
154 public Vector<String> getAnnotationItems(boolean isSeqAssociated)
156 Vector<String> list = new Vector<String>();
158 int[] anmap = new int[av.getAlignment().getAlignmentAnnotation().length];
159 for (int i = 0; i < av.getAlignment().getAlignmentAnnotation().length; i++)
161 if (av.getAlignment().getAlignmentAnnotation()[i].sequenceRef == null)
172 String label = av.getAlignment().getAlignmentAnnotation()[i].label;
173 // add associated sequence ID if available
175 && av.getAlignment().getAlignmentAnnotation()[i].sequenceRef != null)
179 + av.getAlignment().getAlignmentAnnotation()[i].sequenceRef
183 if (!list.contains(label))
185 anmap[list.size()] = i;
190 if (!isSeqAssociated)
192 anmap[list.size()] = i;
193 list.add(label + "_" + (index++));
197 this.annmap = new int[list.size()];
198 System.arraycopy(anmap, 0, this.annmap, 0, this.annmap.length);
202 protected int getSelectedThresholdItem(int indexValue)
204 int selectedThresholdItem = -1;
207 selectedThresholdItem = AnnotationColourGradient.ABOVE_THRESHOLD;
209 else if (indexValue == 2)
211 selectedThresholdItem = AnnotationColourGradient.BELOW_THRESHOLD;
213 return selectedThresholdItem;
216 public void modelChanged()
218 seqAssociated.setEnabled(enableSeqAss);
221 public void ok_actionPerformed()
225 frame.setClosed(true);
226 } catch (Exception ex)
231 public void cancel_actionPerformed()
234 ap.paintAlignment(true);
237 frame.setClosed(true);
238 } catch (Exception ex)
243 public void thresholdCheck_actionPerformed()
248 public void annotations_actionPerformed()
253 public void threshold_actionPerformed()
258 public void thresholdValue_actionPerformed()
262 float f = Float.parseFloat(thresholdValue.getText());
263 slider.setValue((int) (f * 1000));
265 } catch (NumberFormatException ex)
270 public void thresholdIsMin_actionPerformed()
275 protected void populateThresholdComboBox(JComboBox<String> threshold)
277 threshold.addItem(MessageManager
278 .getString("label.threshold_feature_no_threshold"));
279 threshold.addItem(MessageManager
280 .getString("label.threshold_feature_above_threshold"));
281 threshold.addItem(MessageManager
282 .getString("label.threshold_feature_below_threshold"));
285 protected void seqAssociated_actionPerformed(JComboBox<String> annotations)
288 String cursel = (String) annotations.getSelectedItem();
289 boolean isvalid = false, isseqs = seqAssociated.isSelected();
290 annotations.removeAllItems();
291 for (String anitem : getAnnotationItems(seqAssociated.isSelected()))
293 if (anitem.equals(cursel) || (isseqs && cursel.startsWith(anitem)))
298 annotations.addItem(anitem);
303 annotations.setSelectedItem(cursel);
307 if (annotations.getItemCount() > 0)
309 annotations.setSelectedIndex(0);
314 protected void propagateSeqAssociatedThreshold(boolean allAnnotation,
315 AlignmentAnnotation annotation)
317 if (annotation.sequenceRef == null || annotation.threshold == null)
322 float thr = annotation.threshold.value;
323 for (int i = 0; i < av.getAlignment().getAlignmentAnnotation().length; i++)
325 AlignmentAnnotation aa = av.getAlignment().getAlignmentAnnotation()[i];
326 if (aa.label.equals(annotation.label)
327 && (annotation.getCalcId() == null ? aa.getCalcId() == null
328 : annotation.getCalcId().equals(aa.getCalcId())))
330 if (aa.threshold == null)
332 aa.threshold = new GraphLine(annotation.threshold);
336 aa.threshold.value = thr;
342 protected boolean colorAlignmContaining(AlignmentAnnotation currentAnn,
343 int selectedThresholdOption)
346 AnnotationColourGradient acg = null;
347 if (currentColours.isSelected())
349 acg = new AnnotationColourGradient(currentAnn,
350 av.getGlobalColourScheme(), selectedThresholdOption);
354 acg = new AnnotationColourGradient(currentAnn,
355 minColour.getBackground(), maxColour.getBackground(),
356 selectedThresholdOption);
358 acg.setSeqAssociated(seqAssociated.isSelected());
360 if (currentAnn.graphMin == 0f && currentAnn.graphMax == 0f)
362 acg.setPredefinedColours(true);
365 acg.thresholdIsMinMax = thresholdIsMin.isSelected();
367 av.setGlobalColourScheme(acg);
369 if (av.getAlignment().getGroups() != null)
372 for (SequenceGroup sg : ap.av.getAlignment().getGroups())
379 AnnotationColourGradient scheme = null;
380 if (currentColours.isSelected())
382 scheme = new AnnotationColourGradient(currentAnn,
383 sg.getColourScheme(), selectedThresholdOption);
387 scheme = new AnnotationColourGradient(currentAnn,
388 minColour.getBackground(), maxColour.getBackground(),
389 selectedThresholdOption);
391 scheme.setSeqAssociated(seqAssociated.isSelected());
392 sg.setColourScheme(scheme);
398 public jalview.datamodel.AlignmentAnnotation getCurrentAnnotation()
400 return currentAnnotation;
403 public void setCurrentAnnotation(
404 jalview.datamodel.AlignmentAnnotation currentAnnotation)
406 this.currentAnnotation = currentAnnotation;
409 public abstract void valueChanged(boolean updateAllAnnotation);
411 public abstract void updateView();
413 public abstract void reset();