3 import jalview.datamodel.AlignmentAnnotation;
4 import jalview.datamodel.GraphLine;
5 import jalview.datamodel.SequenceGroup;
6 import jalview.schemes.AnnotationColourGradient;
7 import jalview.util.MessageManager;
9 import java.awt.event.ActionEvent;
10 import java.awt.event.MouseAdapter;
11 import java.awt.event.MouseEvent;
12 import java.util.Vector;
14 import javax.swing.JCheckBox;
15 import javax.swing.JComboBox;
16 import javax.swing.JInternalFrame;
17 import javax.swing.JPanel;
18 import javax.swing.JSlider;
19 import javax.swing.JTextField;
20 import javax.swing.event.ChangeEvent;
21 import javax.swing.event.ChangeListener;
23 @SuppressWarnings("serial")
24 public abstract class AnnotationRowFilter extends JPanel
26 protected AlignViewport av;
28 protected AlignmentPanel ap;
30 protected int[] annmap;
32 protected boolean enableSeqAss = false;
34 private jalview.datamodel.AlignmentAnnotation currentAnnotation;
36 protected boolean adjusting = false;
38 protected JCheckBox currentColours = new JCheckBox();
40 protected JPanel minColour = new JPanel();
42 protected JPanel maxColour = new JPanel();
44 protected JCheckBox seqAssociated = new JCheckBox();
46 protected JCheckBox thresholdIsMin = new JCheckBox();
48 protected JSlider slider = new JSlider();
50 protected JTextField thresholdValue = new JTextField(20);
52 protected JInternalFrame frame;
54 * enabled if the user is dragging the slider - try to keep updates to a
57 protected boolean sliderDragging = false;
59 protected void addSliderChangeListener()
62 slider.addChangeListener(new ChangeListener()
65 public void stateChanged(ChangeEvent evt)
69 thresholdValue.setText((slider.getValue() / 1000f) + "");
70 valueChanged(!sliderDragging);
76 protected void addSliderMouseListeners()
79 slider.addMouseListener(new MouseAdapter()
82 public void mousePressed(MouseEvent e)
84 sliderDragging = true;
85 super.mousePressed(e);
89 public void mouseDragged(MouseEvent e)
91 sliderDragging = true;
92 super.mouseDragged(e);
96 public void mouseReleased(MouseEvent evt)
100 sliderDragging = false;
103 ap.paintAlignment(true);
109 public AnnotationRowFilter(AlignViewport av, final AlignmentPanel ap)
115 public AnnotationRowFilter()
120 public Vector<String> getAnnotationItems(boolean isSeqAssociated)
122 Vector<String> list = new Vector<String>();
124 int[] anmap = new int[av.getAlignment().getAlignmentAnnotation().length];
125 for (int i = 0; i < av.getAlignment().getAlignmentAnnotation().length; i++)
127 if (av.getAlignment().getAlignmentAnnotation()[i].sequenceRef == null)
138 String label = av.getAlignment().getAlignmentAnnotation()[i].label;
139 if (!list.contains(label))
141 anmap[list.size()] = i;
147 if (!isSeqAssociated)
149 anmap[list.size()] = i;
150 list.add(label + "_" + (index++));
154 this.annmap = new int[list.size()];
155 System.arraycopy(anmap, 0, this.annmap, 0, this.annmap.length);
159 protected int getSelectedThresholdItem(int indexValue)
161 int selectedThresholdItem = -1;
164 selectedThresholdItem = AnnotationColourGradient.ABOVE_THRESHOLD;
166 else if (indexValue == 2)
168 selectedThresholdItem = AnnotationColourGradient.BELOW_THRESHOLD;
170 return selectedThresholdItem;
173 public void modelChanged()
175 seqAssociated.setEnabled(enableSeqAss);
178 public void ok_actionPerformed(ActionEvent e)
183 frame.setClosed(true);
184 } catch (Exception ex)
189 public void cancel_actionPerformed(ActionEvent e)
192 ap.paintAlignment(true);
195 frame.setClosed(true);
196 } catch (Exception ex)
201 public void thresholdCheck_actionPerformed(ActionEvent e)
206 public void annotations_actionPerformed(ActionEvent e)
211 public void threshold_actionPerformed(ActionEvent e)
216 public void thresholdValue_actionPerformed(ActionEvent e)
220 float f = Float.parseFloat(thresholdValue.getText());
221 slider.setValue((int) (f * 1000));
223 } catch (NumberFormatException ex)
228 public void thresholdIsMin_actionPerformed(ActionEvent actionEvent)
233 protected void populateThresholdComboBox(JComboBox<String> threshold)
235 threshold.addItem(MessageManager
236 .getString("label.threshold_feature_no_thereshold"));
237 threshold.addItem(MessageManager
238 .getString("label.threshold_feature_above_thereshold"));
239 threshold.addItem(MessageManager
240 .getString("label.threshold_feature_below_thereshold"));
243 protected void seqAssociated_actionPerformed(ActionEvent arg0,
244 JComboBox<String> annotations, JCheckBox seqAssociated)
247 String cursel = (String) annotations.getSelectedItem();
248 boolean isvalid = false, isseqs = seqAssociated.isSelected();
249 annotations.removeAllItems();
250 for (String anitem : getAnnotationItems(seqAssociated.isSelected()))
252 if (anitem.equals(cursel) || (isseqs && cursel.startsWith(anitem)))
257 annotations.addItem(anitem);
262 annotations.setSelectedItem(cursel);
266 if (annotations.getItemCount() > 0)
268 annotations.setSelectedIndex(0);
273 protected void propagateSeqAssociatedThreshold(boolean allAnnotation,
274 AlignmentAnnotation annotation)
276 if (annotation.sequenceRef == null || annotation.threshold == null)
281 float thr = annotation.threshold.value;
282 for (int i = 0; i < av.getAlignment().getAlignmentAnnotation().length; i++)
284 AlignmentAnnotation aa = av.getAlignment().getAlignmentAnnotation()[i];
285 if (aa.label.equals(annotation.label)
286 && (annotation.getCalcId() == null ? aa.getCalcId() == null
287 : annotation.getCalcId().equals(aa.getCalcId())))
289 if (aa.threshold == null)
291 aa.threshold = new GraphLine(annotation.threshold);
295 aa.threshold.value = thr;
301 protected boolean colorAlignmContaining(
302 AlignmentAnnotation currentAnnotation, int selectedThresholdItem)
305 AnnotationColourGradient acg = null;
306 if (currentColours.isSelected())
308 acg = new AnnotationColourGradient(currentAnnotation,
309 av.getGlobalColourScheme(), selectedThresholdItem);
313 acg = new AnnotationColourGradient(currentAnnotation,
314 minColour.getBackground(), maxColour.getBackground(),
315 selectedThresholdItem);
317 acg.setSeqAssociated(seqAssociated.isSelected());
319 if (currentAnnotation.graphMin == 0f
320 && currentAnnotation.graphMax == 0f)
322 acg.setPredefinedColours(true);
325 acg.thresholdIsMinMax = thresholdIsMin.isSelected();
327 av.setGlobalColourScheme(acg);
329 if (av.getAlignment().getGroups() != null)
332 for (SequenceGroup sg : ap.av.getAlignment().getGroups())
339 if (currentColours.isSelected())
341 sg.cs = new AnnotationColourGradient(currentAnnotation, sg.cs,
342 selectedThresholdItem);
343 ((AnnotationColourGradient) sg.cs).setSeqAssociated(seqAssociated
349 sg.cs = new AnnotationColourGradient(currentAnnotation,
350 minColour.getBackground(), maxColour.getBackground(),
351 selectedThresholdItem);
352 ((AnnotationColourGradient) sg.cs).setSeqAssociated(seqAssociated
362 public jalview.datamodel.AlignmentAnnotation getCurrentAnnotation()
364 return currentAnnotation;
367 public void setCurrentAnnotation(
368 jalview.datamodel.AlignmentAnnotation currentAnnotation)
370 this.currentAnnotation = currentAnnotation;
373 public abstract void valueChanged(boolean updateAllAnnotation);
375 public abstract void updateView();
377 public abstract void reset();