3 import jalview.api.AnnotationRowFilterI;
4 import jalview.datamodel.AlignmentAnnotation;
5 import jalview.datamodel.Annotation;
6 import jalview.datamodel.AnnotationFilterParameter;
7 import jalview.datamodel.AnnotationFilterParameter.SearchableAnnotationField;
8 import jalview.datamodel.ColumnSelection;
9 import jalview.datamodel.GraphLine;
10 import jalview.datamodel.SequenceGroup;
11 import jalview.schemes.AnnotationColourGradient;
12 import jalview.util.MessageManager;
14 import java.awt.event.ActionEvent;
15 import java.awt.event.MouseAdapter;
16 import java.awt.event.MouseEvent;
17 import java.util.List;
18 import java.util.Vector;
20 import javax.swing.JCheckBox;
21 import javax.swing.JComboBox;
22 import javax.swing.JInternalFrame;
23 import javax.swing.JPanel;
24 import javax.swing.JSlider;
25 import javax.swing.JTextField;
26 import javax.swing.event.ChangeEvent;
27 import javax.swing.event.ChangeListener;
29 @SuppressWarnings("serial")
30 public abstract class AnnotationRowFilter extends JPanel implements
33 protected AlignViewport av;
35 protected AlignmentPanel ap;
37 protected int[] annmap;
39 protected boolean enableSeqAss = false;
41 private jalview.datamodel.AlignmentAnnotation currentAnnotation;
43 protected boolean adjusting = false;
45 protected JCheckBox currentColours = new JCheckBox();
47 protected JPanel minColour = new JPanel();
49 protected JPanel maxColour = new JPanel();
51 protected JCheckBox seqAssociated = new JCheckBox();
53 protected JCheckBox thresholdIsMin = new JCheckBox();
55 protected JSlider slider = new JSlider();
57 protected JTextField thresholdValue = new JTextField(20);
59 protected JInternalFrame frame;
61 * enabled if the user is dragging the slider - try to keep updates to a
64 protected boolean sliderDragging = false;
66 protected void addSliderChangeListener()
69 slider.addChangeListener(new ChangeListener()
72 public void stateChanged(ChangeEvent evt)
76 thresholdValue.setText((slider.getValue() / 1000f) + "");
77 valueChanged(!sliderDragging);
83 protected void addSliderMouseListeners()
86 slider.addMouseListener(new MouseAdapter()
89 public void mousePressed(MouseEvent e)
91 sliderDragging = true;
92 super.mousePressed(e);
96 public void mouseDragged(MouseEvent e)
98 sliderDragging = true;
99 super.mouseDragged(e);
103 public void mouseReleased(MouseEvent evt)
107 sliderDragging = false;
110 ap.paintAlignment(true);
116 public AnnotationRowFilter(AlignViewport av, final AlignmentPanel ap)
122 public AnnotationRowFilter()
128 public Vector<String> getAnnotationItems(boolean isSeqAssociated)
130 Vector<String> list = new Vector<String>();
132 int[] anmap = new int[av.getAlignment().getAlignmentAnnotation().length];
133 for (int i = 0; i < av.getAlignment().getAlignmentAnnotation().length; i++)
135 if (av.getAlignment().getAlignmentAnnotation()[i].sequenceRef == null)
146 String label = av.getAlignment().getAlignmentAnnotation()[i].label;
147 if (!list.contains(label))
149 anmap[list.size()] = i;
155 if (!isSeqAssociated)
157 anmap[list.size()] = i;
158 list.add(label + "_" + (index++));
162 this.annmap = new int[list.size()];
163 System.arraycopy(anmap, 0, this.annmap, 0, this.annmap.length);
167 protected int getSelectedThresholdItem(int indexValue)
169 int selectedThresholdItem = -1;
172 selectedThresholdItem = AnnotationColourGradient.ABOVE_THRESHOLD;
174 else if (indexValue == 2)
176 selectedThresholdItem = AnnotationColourGradient.BELOW_THRESHOLD;
178 return selectedThresholdItem;
181 public void modelChanged()
183 seqAssociated.setEnabled(enableSeqAss);
186 public void ok_actionPerformed(ActionEvent e)
191 frame.setClosed(true);
192 } catch (Exception ex)
197 public void cancel_actionPerformed(ActionEvent e)
200 ap.paintAlignment(true);
203 frame.setClosed(true);
204 } catch (Exception ex)
209 public void thresholdCheck_actionPerformed(ActionEvent e)
214 public void annotations_actionPerformed(ActionEvent e)
219 public void threshold_actionPerformed(ActionEvent e)
224 public void thresholdValue_actionPerformed(ActionEvent e)
228 float f = Float.parseFloat(thresholdValue.getText());
229 slider.setValue((int) (f * 1000));
231 } catch (NumberFormatException ex)
236 public void thresholdIsMin_actionPerformed(ActionEvent actionEvent)
241 protected void populateThresholdComboBox(JComboBox<String> threshold)
243 threshold.addItem(MessageManager
244 .getString("label.threshold_feature_no_thereshold"));
245 threshold.addItem(MessageManager
246 .getString("label.threshold_feature_above_thereshold"));
247 threshold.addItem(MessageManager
248 .getString("label.threshold_feature_below_thereshold"));
251 protected void seqAssociated_actionPerformed(ActionEvent arg0,
252 JComboBox<String> annotations, JCheckBox seqAssociated)
255 String cursel = (String) annotations.getSelectedItem();
256 boolean isvalid = false, isseqs = seqAssociated.isSelected();
257 annotations.removeAllItems();
258 for (String anitem : getAnnotationItems(seqAssociated.isSelected()))
260 if (anitem.equals(cursel) || (isseqs && cursel.startsWith(anitem)))
265 annotations.addItem(anitem);
270 annotations.setSelectedItem(cursel);
274 if (annotations.getItemCount() > 0)
276 annotations.setSelectedIndex(0);
281 protected void propagateSeqAssociatedThreshold(boolean allAnnotation,
282 AlignmentAnnotation annotation)
284 if (annotation.sequenceRef == null || annotation.threshold == null)
289 float thr = annotation.threshold.value;
290 for (int i = 0; i < av.getAlignment().getAlignmentAnnotation().length; i++)
292 AlignmentAnnotation aa = av.getAlignment().getAlignmentAnnotation()[i];
293 if (aa.label.equals(annotation.label)
294 && (annotation.getCalcId() == null ? aa.getCalcId() == null
295 : annotation.getCalcId().equals(aa.getCalcId())))
297 if (aa.threshold == null)
299 aa.threshold = new GraphLine(annotation.threshold);
303 aa.threshold.value = thr;
309 protected boolean colorAlignmContaining(
310 AlignmentAnnotation currentAnnotation, int selectedThresholdItem)
313 AnnotationColourGradient acg = null;
314 if (currentColours.isSelected())
316 acg = new AnnotationColourGradient(currentAnnotation,
317 av.getGlobalColourScheme(), selectedThresholdItem);
321 acg = new AnnotationColourGradient(currentAnnotation,
322 minColour.getBackground(), maxColour.getBackground(),
323 selectedThresholdItem);
325 acg.setSeqAssociated(seqAssociated.isSelected());
327 if (currentAnnotation.graphMin == 0f
328 && currentAnnotation.graphMax == 0f)
330 acg.setPredefinedColours(true);
333 acg.thresholdIsMinMax = thresholdIsMin.isSelected();
335 av.setGlobalColourScheme(acg);
337 if (av.getAlignment().getGroups() != null)
340 for (SequenceGroup sg : ap.av.getAlignment().getGroups())
347 if (currentColours.isSelected())
349 sg.cs = new AnnotationColourGradient(currentAnnotation, sg.cs,
350 selectedThresholdItem);
351 ((AnnotationColourGradient) sg.cs).setSeqAssociated(seqAssociated
357 sg.cs = new AnnotationColourGradient(currentAnnotation,
358 minColour.getBackground(), maxColour.getBackground(),
359 selectedThresholdItem);
360 ((AnnotationColourGradient) sg.cs).setSeqAssociated(seqAssociated
369 protected boolean filterAnnotations(Annotation[] annotations,
370 AnnotationFilterParameter filterParams, ColumnSelection cs)
372 av.showAllHiddenColumns();
377 if (annotations[count] != null)
380 boolean itemMatched = false;
382 if (filterParams.getThresholdType() == AnnotationFilterParameter.ThresholdType.ABOVE_THRESHOLD
383 && annotations[count].value > currentAnnotation.threshold.value)
387 if (filterParams.getThresholdType() == AnnotationFilterParameter.ThresholdType.BELOW_THRESHOLD
388 && annotations[count].value < currentAnnotation.threshold.value)
393 if (filterParams.isFilterAlphaHelix()
394 && annotations[count].secondaryStructure == 'H')
399 if (filterParams.isFilterBetaSheet()
400 && annotations[count].secondaryStructure == 'E')
405 if (filterParams.isFilterTurn()
406 && annotations[count].secondaryStructure == 'S')
411 String regexSearchString = filterParams.getRegexString();
412 if (regexSearchString != null
413 && !filterParams.getRegexSearchFields().isEmpty())
415 List<SearchableAnnotationField> fields = filterParams
416 .getRegexSearchFields();
419 if (fields.contains(SearchableAnnotationField.DISPLAY_STRING)
420 && annotations[count].displayCharacter
421 .matches(regexSearchString))
425 } catch (java.util.regex.PatternSyntaxException pse)
427 if (annotations[count].displayCharacter
428 .equals(regexSearchString))
433 if (fields.contains(SearchableAnnotationField.DESCRIPTION)
434 && annotations[count].description != null
435 && annotations[count].description
436 .matches(regexSearchString))
444 cs.addElement(count);
448 } while (count < annotations.length);
452 public jalview.datamodel.AlignmentAnnotation getCurrentAnnotation()
454 return currentAnnotation;
457 public void setCurrentAnnotation(
458 jalview.datamodel.AlignmentAnnotation currentAnnotation)
460 this.currentAnnotation = currentAnnotation;