3 import jalview.api.AnnotationRowFilterI;
4 import jalview.datamodel.AlignmentAnnotation;
5 import jalview.datamodel.Annotation;
6 import jalview.datamodel.ColumnSelection;
7 import jalview.datamodel.GraphLine;
8 import jalview.datamodel.SequenceGroup;
9 import jalview.schemes.AnnotationColourGradient;
10 import jalview.util.MessageManager;
12 import java.awt.event.ActionEvent;
13 import java.awt.event.MouseAdapter;
14 import java.awt.event.MouseEvent;
15 import java.util.Vector;
17 import javax.swing.JCheckBox;
18 import javax.swing.JComboBox;
19 import javax.swing.JInternalFrame;
20 import javax.swing.JPanel;
21 import javax.swing.JSlider;
22 import javax.swing.JTextField;
23 import javax.swing.event.ChangeEvent;
24 import javax.swing.event.ChangeListener;
26 @SuppressWarnings("serial")
27 public abstract class AnnotationRowFilter extends JPanel implements
30 protected AlignViewport av;
32 protected AlignmentPanel ap;
34 protected int[] annmap;
36 protected boolean enableSeqAss = false;
38 private jalview.datamodel.AlignmentAnnotation currentAnnotation;
40 protected boolean adjusting = false;
42 protected JCheckBox currentColours = new JCheckBox();
44 protected JPanel minColour = new JPanel();
46 protected JPanel maxColour = new JPanel();
48 protected JCheckBox seqAssociated = new JCheckBox();
50 protected JCheckBox thresholdIsMin = new JCheckBox();
52 protected JSlider slider = new JSlider();
54 protected JTextField thresholdValue = new JTextField(20);
56 protected JInternalFrame frame;
58 * enabled if the user is dragging the slider - try to keep updates to a
61 protected boolean sliderDragging = false;
63 protected void addSliderChangeListener()
66 slider.addChangeListener(new ChangeListener()
69 public void stateChanged(ChangeEvent evt)
73 thresholdValue.setText((slider.getValue() / 1000f) + "");
74 valueChanged(!sliderDragging);
80 protected void addSliderMouseListeners()
83 slider.addMouseListener(new MouseAdapter()
86 public void mousePressed(MouseEvent e)
88 sliderDragging = true;
89 super.mousePressed(e);
93 public void mouseDragged(MouseEvent e)
95 sliderDragging = true;
96 super.mouseDragged(e);
100 public void mouseReleased(MouseEvent evt)
104 sliderDragging = false;
107 ap.paintAlignment(true);
113 public AnnotationRowFilter(AlignViewport av, final AlignmentPanel ap)
119 public AnnotationRowFilter()
125 public Vector<String> getAnnotationItems(boolean isSeqAssociated)
127 Vector<String> list = new Vector<String>();
129 int[] anmap = new int[av.getAlignment().getAlignmentAnnotation().length];
130 for (int i = 0; i < av.getAlignment().getAlignmentAnnotation().length; i++)
132 if (av.getAlignment().getAlignmentAnnotation()[i].sequenceRef == null)
143 String label = av.getAlignment().getAlignmentAnnotation()[i].label;
144 if (!list.contains(label))
146 anmap[list.size()] = i;
152 if (!isSeqAssociated)
154 anmap[list.size()] = i;
155 list.add(label + "_" + (index++));
159 // seqAssociated.setEnabled(enableSeqAss);
160 this.annmap = new int[list.size()];
161 System.arraycopy(anmap, 0, this.annmap, 0, this.annmap.length);
165 protected int getSelectedThresholdItem(int indexValue)
167 int selectedThresholdItem = -1;
170 selectedThresholdItem = AnnotationColourGradient.ABOVE_THRESHOLD;
172 else if (indexValue == 2)
174 selectedThresholdItem = AnnotationColourGradient.BELOW_THRESHOLD;
176 return selectedThresholdItem;
179 public void modelChanged()
181 seqAssociated.setEnabled(enableSeqAss);
184 public void ok_actionPerformed(ActionEvent e)
189 frame.setClosed(true);
190 } catch (Exception ex)
195 public void cancel_actionPerformed(ActionEvent e)
198 ap.paintAlignment(true);
201 frame.setClosed(true);
202 } catch (Exception ex)
207 public void thresholdCheck_actionPerformed(ActionEvent e)
212 public void annotations_actionPerformed(ActionEvent e)
217 public void threshold_actionPerformed(ActionEvent e)
222 public void thresholdValue_actionPerformed(ActionEvent e)
226 float f = Float.parseFloat(thresholdValue.getText());
227 slider.setValue((int) (f * 1000));
229 } catch (NumberFormatException ex)
234 public void thresholdIsMin_actionPerformed(ActionEvent actionEvent)
239 protected void populateThresholdComboBox(JComboBox<String> threshold)
241 threshold.addItem(MessageManager
242 .getString("label.threshold_feature_no_thereshold"));
243 threshold.addItem(MessageManager
244 .getString("label.threshold_feature_above_thereshold"));
245 threshold.addItem(MessageManager
246 .getString("label.threshold_feature_below_thereshold"));
249 protected void seqAssociated_actionPerformed(ActionEvent arg0,
250 JComboBox<String> annotations, JCheckBox seqAssociated)
253 String cursel = (String) annotations.getSelectedItem();
254 boolean isvalid = false, isseqs = seqAssociated.isSelected();
255 annotations.removeAllItems();
256 for (String anitem : getAnnotationItems(seqAssociated.isSelected()))
258 if (anitem.equals(cursel) || (isseqs && cursel.startsWith(anitem)))
263 annotations.addItem(anitem);
268 annotations.setSelectedItem(cursel);
272 if (annotations.getItemCount() > 0)
274 annotations.setSelectedIndex(0);
279 protected void propagateSeqAssociatedThreshold(boolean allAnnotation,
280 AlignmentAnnotation annotation)
282 if (annotation.sequenceRef == null || annotation.threshold == null)
287 float thr = annotation.threshold.value;
288 for (int i = 0; i < av.getAlignment().getAlignmentAnnotation().length; i++)
290 AlignmentAnnotation aa = av.getAlignment().getAlignmentAnnotation()[i];
291 if (aa.label.equals(annotation.label)
292 && (annotation.getCalcId() == null ? aa.getCalcId() == null
293 : annotation.getCalcId().equals(aa.getCalcId())))
295 if (aa.threshold == null)
297 aa.threshold = new GraphLine(annotation.threshold);
301 aa.threshold.value = thr;
307 protected boolean colorAlignmContaining(
308 AlignmentAnnotation currentAnnotation, int selectedThresholdItem)
311 AnnotationColourGradient acg = null;
312 if (currentColours.isSelected())
314 acg = new AnnotationColourGradient(currentAnnotation,
315 av.getGlobalColourScheme(), selectedThresholdItem);
319 acg = new AnnotationColourGradient(currentAnnotation,
320 minColour.getBackground(), maxColour.getBackground(),
321 selectedThresholdItem);
323 acg.setSeqAssociated(seqAssociated.isSelected());
325 if (currentAnnotation.graphMin == 0f
326 && currentAnnotation.graphMax == 0f)
328 acg.setPredefinedColours(true);
331 acg.thresholdIsMinMax = thresholdIsMin.isSelected();
333 av.setGlobalColourScheme(acg);
335 if (av.getAlignment().getGroups() != null)
338 for (SequenceGroup sg : ap.av.getAlignment().getGroups())
345 if (currentColours.isSelected())
347 sg.cs = new AnnotationColourGradient(currentAnnotation, sg.cs,
348 selectedThresholdItem);
349 ((AnnotationColourGradient) sg.cs).setSeqAssociated(seqAssociated
355 sg.cs = new AnnotationColourGradient(currentAnnotation,
356 minColour.getBackground(), maxColour.getBackground(),
357 selectedThresholdItem);
358 ((AnnotationColourGradient) sg.cs).setSeqAssociated(seqAssociated
367 protected boolean markColumnsContaining(
368 AlignmentAnnotation currentAnnotation, int thresholdComparisonType)
372 if (currentAnnotation != null)
374 Annotation[] annotations = currentAnnotation.annotations;
375 ColumnSelection cs = av.getColumnSelection();
377 if (thresholdComparisonType == AnnotationColourGradient.NO_THRESHOLD)
382 if (annotations[count] != null)
384 if (currentAnnotation.label.equals("Secondary Structure")
385 && annotations[count].secondaryStructure != ' ')
387 cs.addElement(count);
389 else if (currentAnnotation.label
390 .equals("Iron Sulphur Contacts"))
392 cs.addElement(count);
394 else if (annotations[count].value != 0.0)
396 cs.addElement(count);
401 } while (count < annotations.length);
408 if (annotations[count] != null)
410 if (thresholdComparisonType == AnnotationColourGradient.ABOVE_THRESHOLD)
412 if (annotations[count].value > currentAnnotation.threshold.value)
414 cs.addElement(count);
417 else if (thresholdComparisonType == AnnotationColourGradient.BELOW_THRESHOLD)
419 if (annotations[count].value < currentAnnotation.threshold.value)
421 cs.addElement(count);
427 } while (count < annotations.length);
432 } catch (Exception e)
439 public jalview.datamodel.AlignmentAnnotation getCurrentAnnotation()
441 return currentAnnotation;
444 public void setCurrentAnnotation(
445 jalview.datamodel.AlignmentAnnotation currentAnnotation)
447 this.currentAnnotation = currentAnnotation;