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.JButton;
15 import javax.swing.JCheckBox;
16 import javax.swing.JComboBox;
17 import javax.swing.JInternalFrame;
18 import javax.swing.JPanel;
19 import javax.swing.JSlider;
20 import javax.swing.JTextField;
21 import javax.swing.event.ChangeEvent;
22 import javax.swing.event.ChangeListener;
24 @SuppressWarnings("serial")
25 public abstract class AnnotationRowFilter extends JPanel
27 protected AlignViewport av;
29 protected AlignmentPanel ap;
31 protected int[] annmap;
33 protected boolean enableSeqAss = false;
35 private jalview.datamodel.AlignmentAnnotation currentAnnotation;
37 protected boolean adjusting = false;
39 protected JCheckBox currentColours = new JCheckBox();
41 protected JPanel minColour = new JPanel();
43 protected JPanel maxColour = new JPanel();
45 protected JCheckBox seqAssociated = new JCheckBox();
47 protected JCheckBox thresholdIsMin = new JCheckBox();
49 protected JSlider slider = new JSlider();
51 protected JTextField thresholdValue = new JTextField(20);
53 protected JInternalFrame frame;
55 protected JButton ok = new JButton();
57 protected JButton cancel = new JButton();
60 * enabled if the user is dragging the slider - try to keep updates to a
63 protected boolean sliderDragging = false;
65 protected void addSliderChangeListener()
68 slider.addChangeListener(new ChangeListener()
71 public void stateChanged(ChangeEvent evt)
75 thresholdValue.setText((slider.getValue() / 1000f) + "");
76 valueChanged(!sliderDragging);
82 protected void addSliderMouseListeners()
85 slider.addMouseListener(new MouseAdapter()
88 public void mousePressed(MouseEvent e)
90 sliderDragging = true;
91 super.mousePressed(e);
95 public void mouseDragged(MouseEvent e)
97 sliderDragging = true;
98 super.mouseDragged(e);
102 public void mouseReleased(MouseEvent evt)
106 sliderDragging = false;
109 ap.paintAlignment(true);
115 public AnnotationRowFilter(AlignViewport av, final AlignmentPanel ap)
121 public AnnotationRowFilter()
126 public Vector<String> getAnnotationItems(boolean isSeqAssociated)
128 Vector<String> list = new Vector<String>();
130 int[] anmap = new int[av.getAlignment().getAlignmentAnnotation().length];
131 for (int i = 0; i < av.getAlignment().getAlignmentAnnotation().length; i++)
133 if (av.getAlignment().getAlignmentAnnotation()[i].sequenceRef == null)
144 String label = av.getAlignment().getAlignmentAnnotation()[i].label;
145 if (!list.contains(label))
147 anmap[list.size()] = i;
153 if (!isSeqAssociated)
155 anmap[list.size()] = i;
156 list.add(label + "_" + (index++));
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)
188 frame.setClosed(true);
189 } catch (Exception ex)
194 public void cancel_actionPerformed(ActionEvent e)
197 ap.paintAlignment(true);
200 frame.setClosed(true);
201 } catch (Exception ex)
206 public void thresholdCheck_actionPerformed(ActionEvent e)
211 public void annotations_actionPerformed(ActionEvent e)
216 public void threshold_actionPerformed(ActionEvent e)
221 public void thresholdValue_actionPerformed(ActionEvent e)
225 float f = Float.parseFloat(thresholdValue.getText());
226 slider.setValue((int) (f * 1000));
228 } catch (NumberFormatException ex)
233 public void thresholdIsMin_actionPerformed(ActionEvent actionEvent)
238 protected void populateThresholdComboBox(JComboBox<String> threshold)
240 threshold.addItem(MessageManager
241 .getString("label.threshold_feature_no_thereshold"));
242 threshold.addItem(MessageManager
243 .getString("label.threshold_feature_above_thereshold"));
244 threshold.addItem(MessageManager
245 .getString("label.threshold_feature_below_thereshold"));
248 protected void seqAssociated_actionPerformed(ActionEvent arg0,
249 JComboBox<String> annotations, JCheckBox seqAssociated)
252 String cursel = (String) annotations.getSelectedItem();
253 boolean isvalid = false, isseqs = seqAssociated.isSelected();
254 annotations.removeAllItems();
255 for (String anitem : getAnnotationItems(seqAssociated.isSelected()))
257 if (anitem.equals(cursel) || (isseqs && cursel.startsWith(anitem)))
262 annotations.addItem(anitem);
267 annotations.setSelectedItem(cursel);
271 if (annotations.getItemCount() > 0)
273 annotations.setSelectedIndex(0);
278 protected void propagateSeqAssociatedThreshold(boolean allAnnotation,
279 AlignmentAnnotation annotation)
281 if (annotation.sequenceRef == null || annotation.threshold == null)
286 float thr = annotation.threshold.value;
287 for (int i = 0; i < av.getAlignment().getAlignmentAnnotation().length; i++)
289 AlignmentAnnotation aa = av.getAlignment().getAlignmentAnnotation()[i];
290 if (aa.label.equals(annotation.label)
291 && (annotation.getCalcId() == null ? aa.getCalcId() == null
292 : annotation.getCalcId().equals(aa.getCalcId())))
294 if (aa.threshold == null)
296 aa.threshold = new GraphLine(annotation.threshold);
300 aa.threshold.value = thr;
306 protected boolean colorAlignmContaining(
307 AlignmentAnnotation currentAnnotation, int selectedThresholdItem)
310 AnnotationColourGradient acg = null;
311 if (currentColours.isSelected())
313 acg = new AnnotationColourGradient(currentAnnotation,
314 av.getGlobalColourScheme(), selectedThresholdItem);
318 acg = new AnnotationColourGradient(currentAnnotation,
319 minColour.getBackground(), maxColour.getBackground(),
320 selectedThresholdItem);
322 acg.setSeqAssociated(seqAssociated.isSelected());
324 if (currentAnnotation.graphMin == 0f
325 && currentAnnotation.graphMax == 0f)
327 acg.setPredefinedColours(true);
330 acg.thresholdIsMinMax = thresholdIsMin.isSelected();
332 av.setGlobalColourScheme(acg);
334 if (av.getAlignment().getGroups() != null)
337 for (SequenceGroup sg : ap.av.getAlignment().getGroups())
344 if (currentColours.isSelected())
346 sg.cs = new AnnotationColourGradient(currentAnnotation, sg.cs,
347 selectedThresholdItem);
348 ((AnnotationColourGradient) sg.cs).setSeqAssociated(seqAssociated
354 sg.cs = new AnnotationColourGradient(currentAnnotation,
355 minColour.getBackground(), maxColour.getBackground(),
356 selectedThresholdItem);
357 ((AnnotationColourGradient) sg.cs).setSeqAssociated(seqAssociated
367 public jalview.datamodel.AlignmentAnnotation getCurrentAnnotation()
369 return currentAnnotation;
372 public void setCurrentAnnotation(
373 jalview.datamodel.AlignmentAnnotation currentAnnotation)
375 this.currentAnnotation = currentAnnotation;
378 public abstract void valueChanged(boolean updateAllAnnotation);
380 public abstract void updateView();
382 public abstract void reset();