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.ActionEvent;
30 import java.awt.event.MouseAdapter;
31 import java.awt.event.MouseEvent;
32 import java.util.Vector;
34 import javax.swing.JButton;
35 import javax.swing.JCheckBox;
36 import javax.swing.JComboBox;
37 import javax.swing.JInternalFrame;
38 import javax.swing.JPanel;
39 import javax.swing.JSlider;
40 import javax.swing.JTextField;
41 import javax.swing.event.ChangeEvent;
42 import javax.swing.event.ChangeListener;
44 @SuppressWarnings("serial")
45 public abstract class AnnotationRowFilter extends JPanel
47 protected AlignViewport av;
49 protected AlignmentPanel ap;
51 protected int[] annmap;
53 protected boolean enableSeqAss = false;
55 private jalview.datamodel.AlignmentAnnotation currentAnnotation;
57 protected boolean adjusting = false;
59 protected JCheckBox currentColours = new JCheckBox();
61 protected JPanel minColour = new JPanel();
63 protected JPanel maxColour = new JPanel();
65 protected JCheckBox seqAssociated = new JCheckBox();
67 protected JCheckBox thresholdIsMin = new JCheckBox();
69 protected JSlider slider = new JSlider();
71 protected JTextField thresholdValue = new JTextField(20);
73 protected JInternalFrame frame;
75 protected JButton ok = new JButton();
77 protected JButton cancel = new JButton();
80 * enabled if the user is dragging the slider - try to keep updates to a
83 protected boolean sliderDragging = false;
85 protected void addSliderChangeListener()
88 slider.addChangeListener(new ChangeListener()
91 public void stateChanged(ChangeEvent evt)
95 thresholdValue.setText((slider.getValue() / 1000f) + "");
96 valueChanged(!sliderDragging);
102 protected void addSliderMouseListeners()
105 slider.addMouseListener(new MouseAdapter()
108 public void mousePressed(MouseEvent e)
110 sliderDragging = true;
111 super.mousePressed(e);
115 public void mouseDragged(MouseEvent e)
117 sliderDragging = true;
118 super.mouseDragged(e);
122 public void mouseReleased(MouseEvent evt)
126 sliderDragging = false;
129 ap.paintAlignment(true);
134 public AnnotationRowFilter(AlignViewport av, final AlignmentPanel ap)
140 public AnnotationRowFilter()
145 public Vector<String> getAnnotationItems(boolean isSeqAssociated)
147 Vector<String> list = new Vector<String>();
149 int[] anmap = new int[av.getAlignment().getAlignmentAnnotation().length];
150 for (int i = 0; i < av.getAlignment().getAlignmentAnnotation().length; i++)
152 if (av.getAlignment().getAlignmentAnnotation()[i].sequenceRef == null)
163 String label = av.getAlignment().getAlignmentAnnotation()[i].label;
164 // add associated sequence ID if available
166 && av.getAlignment().getAlignmentAnnotation()[i].sequenceRef != null)
170 + av.getAlignment().getAlignmentAnnotation()[i].sequenceRef
174 if (!list.contains(label))
176 anmap[list.size()] = i;
182 if (!isSeqAssociated)
184 anmap[list.size()] = i;
185 list.add(label + "_" + (index++));
189 this.annmap = new int[list.size()];
190 System.arraycopy(anmap, 0, this.annmap, 0, this.annmap.length);
194 protected int getSelectedThresholdItem(int indexValue)
196 int selectedThresholdItem = -1;
199 selectedThresholdItem = AnnotationColourGradient.ABOVE_THRESHOLD;
201 else if (indexValue == 2)
203 selectedThresholdItem = AnnotationColourGradient.BELOW_THRESHOLD;
205 return selectedThresholdItem;
208 public void modelChanged()
210 seqAssociated.setEnabled(enableSeqAss);
213 public void ok_actionPerformed(ActionEvent e)
217 frame.setClosed(true);
218 } catch (Exception ex)
223 public void cancel_actionPerformed(ActionEvent e)
226 ap.paintAlignment(true);
229 frame.setClosed(true);
230 } catch (Exception ex)
235 public void thresholdCheck_actionPerformed(ActionEvent e)
240 public void annotations_actionPerformed(ActionEvent e)
245 public void threshold_actionPerformed(ActionEvent e)
250 public void thresholdValue_actionPerformed(ActionEvent e)
254 float f = Float.parseFloat(thresholdValue.getText());
255 slider.setValue((int) (f * 1000));
257 } catch (NumberFormatException ex)
262 public void thresholdIsMin_actionPerformed(ActionEvent actionEvent)
267 protected void populateThresholdComboBox(JComboBox<String> threshold)
269 threshold.addItem(MessageManager
270 .getString("label.threshold_feature_no_threshold"));
271 threshold.addItem(MessageManager
272 .getString("label.threshold_feature_above_threshold"));
273 threshold.addItem(MessageManager
274 .getString("label.threshold_feature_below_threshold"));
277 protected void seqAssociated_actionPerformed(ActionEvent arg0,
278 JComboBox<String> annotations, JCheckBox seqAssociated)
281 String cursel = (String) annotations.getSelectedItem();
282 boolean isvalid = false, isseqs = seqAssociated.isSelected();
283 annotations.removeAllItems();
284 for (String anitem : getAnnotationItems(seqAssociated.isSelected()))
286 if (anitem.equals(cursel) || (isseqs && cursel.startsWith(anitem)))
291 annotations.addItem(anitem);
296 annotations.setSelectedItem(cursel);
300 if (annotations.getItemCount() > 0)
302 annotations.setSelectedIndex(0);
307 protected void propagateSeqAssociatedThreshold(boolean allAnnotation,
308 AlignmentAnnotation annotation)
310 if (annotation.sequenceRef == null || annotation.threshold == null)
315 float thr = annotation.threshold.value;
316 for (int i = 0; i < av.getAlignment().getAlignmentAnnotation().length; i++)
318 AlignmentAnnotation aa = av.getAlignment().getAlignmentAnnotation()[i];
319 if (aa.label.equals(annotation.label)
320 && (annotation.getCalcId() == null ? aa.getCalcId() == null
321 : annotation.getCalcId().equals(aa.getCalcId())))
323 if (aa.threshold == null)
325 aa.threshold = new GraphLine(annotation.threshold);
329 aa.threshold.value = thr;
335 protected boolean colorAlignmContaining(
336 AlignmentAnnotation currentAnnotation, int selectedThresholdItem)
339 AnnotationColourGradient acg = null;
340 if (currentColours.isSelected())
342 acg = new AnnotationColourGradient(currentAnnotation,
343 av.getGlobalColourScheme(), selectedThresholdItem);
347 acg = new AnnotationColourGradient(currentAnnotation,
348 minColour.getBackground(), maxColour.getBackground(),
349 selectedThresholdItem);
351 acg.setSeqAssociated(seqAssociated.isSelected());
353 if (currentAnnotation.graphMin == 0f
354 && currentAnnotation.graphMax == 0f)
356 acg.setPredefinedColours(true);
359 acg.thresholdIsMinMax = thresholdIsMin.isSelected();
361 av.setGlobalColourScheme(acg);
363 if (av.getAlignment().getGroups() != null)
366 for (SequenceGroup sg : ap.av.getAlignment().getGroups())
373 if (currentColours.isSelected())
375 sg.cs = new AnnotationColourGradient(currentAnnotation, sg.cs,
376 selectedThresholdItem);
377 ((AnnotationColourGradient) sg.cs).setSeqAssociated(seqAssociated
383 sg.cs = new AnnotationColourGradient(currentAnnotation,
384 minColour.getBackground(), maxColour.getBackground(),
385 selectedThresholdItem);
386 ((AnnotationColourGradient) sg.cs).setSeqAssociated(seqAssociated
395 public jalview.datamodel.AlignmentAnnotation getCurrentAnnotation()
397 return currentAnnotation;
400 public void setCurrentAnnotation(
401 jalview.datamodel.AlignmentAnnotation currentAnnotation)
403 this.currentAnnotation = currentAnnotation;
406 public abstract void valueChanged(boolean updateAllAnnotation);
408 public abstract void updateView();
410 public abstract void reset();