3 import jalview.datamodel.AlignmentAnnotation;
4 import jalview.datamodel.AnnotationFilterParameter;
5 import jalview.datamodel.ColumnSelection;
6 import jalview.jbgui.FurtherActionPanel;
7 import jalview.jbgui.SearchPanel;
8 import jalview.jbgui.StructureFilterPanel;
9 import jalview.schemes.AnnotationColourGradient;
10 import jalview.util.MessageManager;
12 import java.awt.BorderLayout;
13 import java.awt.CardLayout;
14 import java.awt.Color;
15 import java.awt.Dimension;
16 import java.awt.event.ActionEvent;
17 import java.awt.event.ActionListener;
18 import java.awt.event.ItemEvent;
19 import java.awt.event.ItemListener;
20 import java.util.Iterator;
22 import javax.swing.JButton;
23 import javax.swing.JComboBox;
24 import javax.swing.JInternalFrame;
25 import javax.swing.JLabel;
26 import javax.swing.JLayeredPane;
27 import javax.swing.JPanel;
28 import javax.swing.JRadioButton;
29 import javax.swing.border.TitledBorder;
31 import net.miginfocom.swing.MigLayout;
33 @SuppressWarnings("serial")
34 public class AnnotationColumnChooser extends AnnotationRowFilter implements
38 private ColumnSelection oldColumnSelection;
40 private JComboBox<String> annotations;
42 JButton ok = new JButton();
44 JButton cancel = new JButton();
46 JPanel actionPanel = new JPanel();
48 JPanel thresholdPanel = new JPanel();
50 JPanel switchableViewsPanel = new JPanel(new CardLayout());
52 CardLayout switchableViewsLayout = (CardLayout) (switchableViewsPanel
55 JPanel noGraphFilterView = new JPanel();
57 JPanel graphFilterView = new JPanel();
59 JPanel annotationComboBoxPanel = new JPanel();
61 StructureFilterPanel gStructureFilterPanel;
63 StructureFilterPanel ngStructureFilterPanel;
65 private StructureFilterPanel currentStructureFilterPanel;
67 JLabel annotationLabel = new JLabel();
69 BorderLayout borderLayout1 = new BorderLayout();
71 private JComboBox<String> threshold = new JComboBox<String>();
73 private SearchPanel currentSearchPanel;
75 private SearchPanel gSearchPanel;
77 private SearchPanel ngSearchPanel;
79 private FurtherActionPanel currentFurtherActionPanel;
81 private FurtherActionPanel gFurtherActionPanel;
83 private FurtherActionPanel ngFurtherActionPanel;
85 public static final int ACTION_OPTION_SELECT = 1;
87 public static int ACTION_OPTION_HIDE = 2;
89 public static String NO_GRAPH_VIEW = "0";
91 public static String GRAPH_VIEW = "1";
93 private int actionOption = ACTION_OPTION_SELECT;
95 public AnnotationColumnChooser(AlignViewport av, final AlignmentPanel ap)
98 frame = new JInternalFrame();
99 frame.setContentPane(this);
100 frame.setLayer(JLayeredPane.PALETTE_LAYER);
101 Desktop.addInternalFrame(frame,
102 MessageManager.getString("label.select_by_annotation"), 520,
105 addSliderChangeListener();
106 addSliderMouseListeners();
108 if (av.getAlignment().getAlignmentAnnotation() == null)
112 setOldColumnSelection(av.getColumnSelection());
115 setAnnotations(new JComboBox<String>(getAnnotationItems(false)));
116 populateThresholdComboBox(threshold);
118 // restore the Object state from the previous session if one exists
119 if (av.getAnnotationColumnSelectionState() != null)
121 currentSearchPanel = av.getAnnotationColumnSelectionState()
122 .getCurrentSearchPanel();
123 currentStructureFilterPanel = av.getAnnotationColumnSelectionState()
124 .getCurrentStructureFilterPanel();
125 annotations.setSelectedIndex(av.getAnnotationColumnSelectionState()
126 .getAnnotations().getSelectedIndex());
127 threshold.setSelectedIndex(av.getAnnotationColumnSelectionState()
128 .getThreshold().getSelectedIndex());
129 actionOption = av.getAnnotationColumnSelectionState()
137 } catch (Exception ex)
147 public AnnotationColumnChooser()
152 } catch (Exception ex)
154 ex.printStackTrace();
158 private void jbInit() throws Exception
161 ok.setText(MessageManager.getString("action.ok"));
162 ok.addActionListener(new ActionListener()
165 public void actionPerformed(ActionEvent e)
167 ok_actionPerformed(e);
170 cancel.setOpaque(false);
171 cancel.setText(MessageManager.getString("action.cancel"));
172 cancel.addActionListener(new ActionListener()
175 public void actionPerformed(ActionEvent e)
177 cancel_actionPerformed(e);
181 getAnnotations().addItemListener(this);
182 getThreshold().addActionListener(new ActionListener()
185 public void actionPerformed(ActionEvent e)
187 threshold_actionPerformed(e);
191 thresholdValue.addActionListener(new ActionListener()
194 public void actionPerformed(ActionEvent e)
196 thresholdValue_actionPerformed(e);
199 slider.setPaintLabels(false);
200 slider.setPaintTicks(true);
201 slider.setBackground(Color.white);
202 slider.setEnabled(false);
203 slider.setOpaque(false);
204 slider.setPreferredSize(new Dimension(100, 32));
205 thresholdValue.setEnabled(false);
206 thresholdValue.setColumns(7);
208 annotationLabel.setBackground(Color.white);
209 annotationLabel.setFont(JvSwingUtils.getLabelFont());
210 annotationLabel.setText("Select Annotation : ");
212 thresholdPanel.setBorder(new TitledBorder("Threshold Filter"));
213 thresholdPanel.setBackground(Color.white);
214 thresholdPanel.setFont(JvSwingUtils.getLabelFont());
215 thresholdPanel.setLayout(new MigLayout("", "[left][right]", "[][]"));
217 actionPanel.setBackground(Color.white);
218 actionPanel.setFont(JvSwingUtils.getLabelFont());
220 this.setLayout(borderLayout1);
221 graphFilterView.setLayout(new MigLayout("", "[left][right]", "[][]"));
222 graphFilterView.setBackground(Color.white);
224 noGraphFilterView.setLayout(new MigLayout("", "[left][right]", "[][]"));
225 noGraphFilterView.setBackground(Color.white);
226 annotationComboBoxPanel.setBackground(Color.white);
227 annotationComboBoxPanel.setFont(JvSwingUtils.getLabelFont());
229 gSearchPanel = new SearchPanel(this);
230 ngSearchPanel = new SearchPanel(this);
231 gFurtherActionPanel = new FurtherActionPanel(this);
232 ngFurtherActionPanel = new FurtherActionPanel(this);
233 gStructureFilterPanel = new StructureFilterPanel(this);
234 ngStructureFilterPanel = new StructureFilterPanel(this);
237 thresholdPanel.add(getThreshold());
238 thresholdPanel.add(thresholdValue, "wrap");
239 thresholdPanel.add(slider, "grow, span, wrap");
242 actionPanel.add(cancel);
244 graphFilterView.add(gSearchPanel, "grow, span, wrap");
245 graphFilterView.add(gStructureFilterPanel, "grow, span, wrap");
246 graphFilterView.add(thresholdPanel, "grow, span, wrap");
247 graphFilterView.add(gFurtherActionPanel);
249 noGraphFilterView.add(ngSearchPanel, "grow, span, wrap");
250 noGraphFilterView.add(ngStructureFilterPanel, "grow, span, wrap");
251 noGraphFilterView.add(ngFurtherActionPanel);
253 annotationComboBoxPanel.add(getAnnotations());
254 switchableViewsPanel.add(noGraphFilterView,
255 AnnotationColumnChooser.NO_GRAPH_VIEW);
256 switchableViewsPanel.add(graphFilterView,
257 AnnotationColumnChooser.GRAPH_VIEW);
259 this.add(annotationComboBoxPanel, java.awt.BorderLayout.PAGE_START);
260 this.add(switchableViewsPanel, java.awt.BorderLayout.CENTER);
261 this.add(actionPanel, java.awt.BorderLayout.SOUTH);
263 selectedAnnotationChanged();
267 @SuppressWarnings("unchecked")
270 if (this.getOldColumnSelection() != null)
272 av.getColumnSelection().clear();
274 if (av.getAnnotationColumnSelectionState() != null)
276 ColumnSelection oldSelection = av
277 .getAnnotationColumnSelectionState()
278 .getOldColumnSelection();
279 if (oldSelection != null && oldSelection.getHiddenColumns() != null
280 && !oldSelection.getHiddenColumns().isEmpty())
282 for (Iterator<int[]> itr = oldSelection.getHiddenColumns()
283 .iterator(); itr.hasNext();)
285 int positions[] = itr.next();
286 av.hideColumns(positions[0], positions[1]);
289 av.setColumnSelection(oldSelection);
291 // ap.alignmentChanged();
292 ap.paintAlignment(true);
297 public void valueChanged(boolean updateAllAnnotation)
299 if (slider.isEnabled())
301 getCurrentAnnotation().threshold.value = slider.getValue() / 1000f;
303 propagateSeqAssociatedThreshold(updateAllAnnotation,
304 getCurrentAnnotation());
305 ap.paintAlignment(false);
309 public JComboBox<String> getThreshold()
314 public void setThreshold(JComboBox<String> threshold)
316 this.threshold = threshold;
319 public JComboBox<String> getAnnotations()
324 public void setAnnotations(JComboBox<String> annotations)
326 this.annotations = annotations;
330 public void updateView()
332 // Check if combobox is still adjusting
338 AnnotationFilterParameter filterParams = new AnnotationFilterParameter();
340 setCurrentAnnotation(av.getAlignment().getAlignmentAnnotation()[annmap[getAnnotations()
341 .getSelectedIndex()]]);
343 int selectedThresholdItem = getSelectedThresholdItem(getThreshold()
344 .getSelectedIndex());
346 slider.setEnabled(true);
347 thresholdValue.setEnabled(true);
349 if (selectedThresholdItem == AnnotationColourGradient.NO_THRESHOLD)
351 slider.setEnabled(false);
352 thresholdValue.setEnabled(false);
353 thresholdValue.setText("");
354 // build filter params
356 else if (selectedThresholdItem != AnnotationColourGradient.NO_THRESHOLD)
358 if (getCurrentAnnotation().threshold == null)
360 getCurrentAnnotation()
362 new jalview.datamodel.GraphLine(
363 (getCurrentAnnotation().graphMax - getCurrentAnnotation().graphMin) / 2f,
364 "Threshold", Color.black));
368 float range = getCurrentAnnotation().graphMax * 1000
369 - getCurrentAnnotation().graphMin * 1000;
371 slider.setMinimum((int) (getCurrentAnnotation().graphMin * 1000));
372 slider.setMaximum((int) (getCurrentAnnotation().graphMax * 1000));
373 slider.setValue((int) (getCurrentAnnotation().threshold.value * 1000));
374 thresholdValue.setText(getCurrentAnnotation().threshold.value + "");
375 slider.setMajorTickSpacing((int) (range / 10f));
376 slider.setEnabled(true);
377 thresholdValue.setEnabled(true);
380 // build filter params
382 .setThresholdType(AnnotationFilterParameter.ThresholdType.NO_THRESHOLD);
383 if (getCurrentAnnotation().graph != AlignmentAnnotation.NO_GRAPH)
386 if (selectedThresholdItem == AnnotationColourGradient.ABOVE_THRESHOLD)
389 .setThresholdType(AnnotationFilterParameter.ThresholdType.ABOVE_THRESHOLD);
391 else if (selectedThresholdItem == AnnotationColourGradient.BELOW_THRESHOLD)
394 .setThresholdType(AnnotationFilterParameter.ThresholdType.BELOW_THRESHOLD);
399 if (currentStructureFilterPanel != null)
401 if (currentStructureFilterPanel.getAlphaHelix().isSelected())
403 filterParams.setFilterAlphaHelix(true);
405 if (currentStructureFilterPanel.getBetaStrand().isSelected())
407 filterParams.setFilterBetaSheet(true);
409 if (currentStructureFilterPanel.getTurn().isSelected())
411 filterParams.setFilterTurn(true);
415 if (currentSearchPanel != null)
417 if (!currentSearchPanel.getSearchString().isEmpty())
419 currentSearchPanel.getDescription().setEnabled(true);
420 currentSearchPanel.getDisplayName().setEnabled(true);
421 filterParams.setRegexString(currentSearchPanel.getSearchString());
422 if (currentSearchPanel.isDisplayNameChecked())
425 .addRegexSearchField(AnnotationFilterParameter.SearchableAnnotationField.DISPLAY_STRING);
427 if (currentSearchPanel.isDescriptionChecked())
430 .addRegexSearchField(AnnotationFilterParameter.SearchableAnnotationField.DESCRIPTION);
435 currentSearchPanel.getDescription().setEnabled(false);
436 currentSearchPanel.getDisplayName().setEnabled(false);
440 filterAnnotations(getCurrentAnnotation().annotations, filterParams,
441 av.getColumnSelection());
443 av.showAllHiddenColumns();
444 if (getActionOption() == ACTION_OPTION_HIDE)
446 av.hideSelectedColumns();
450 av.setAnnotationColumnSelectionState(this);
451 ap.paintAlignment(true);
454 public ColumnSelection getOldColumnSelection()
456 return oldColumnSelection;
459 public void setOldColumnSelection(ColumnSelection currentColumnSelection)
461 if (currentColumnSelection != null)
463 this.oldColumnSelection = new ColumnSelection(currentColumnSelection);
468 public void select_action(ActionEvent actionEvent)
470 JRadioButton radioButton = (JRadioButton) actionEvent.getSource();
471 if (radioButton.isSelected())
473 setActionOption(ACTION_OPTION_SELECT);
478 public void hide_action(ActionEvent actionEvent)
480 JRadioButton radioButton = (JRadioButton) actionEvent.getSource();
481 if (radioButton.isSelected())
483 setActionOption(ACTION_OPTION_HIDE);
490 public void itemStateChanged(ItemEvent e)
492 selectedAnnotationChanged();
495 public void selectedAnnotationChanged()
497 String currentView = AnnotationColumnChooser.NO_GRAPH_VIEW;
498 if (av.getAlignment().getAlignmentAnnotation()[annmap[getAnnotations()
499 .getSelectedIndex()]].graph != AlignmentAnnotation.NO_GRAPH)
501 currentView = AnnotationColumnChooser.GRAPH_VIEW;
504 // threshold.setSelectedIndex(AlignmentAnnotation.NO_GRAPH);
507 gSearchPanel.syncState();
508 gFurtherActionPanel.syncState();
509 gFurtherActionPanel.syncState();
510 gFurtherActionPanel.syncState();
512 ngSearchPanel.syncState();
513 ngFurtherActionPanel.syncState();
514 ngStructureFilterPanel.syncState();
515 ngFurtherActionPanel.syncState();
517 switchableViewsLayout.show(switchableViewsPanel, currentView);
522 public FurtherActionPanel getCurrentFutherActionPanel()
524 return currentFurtherActionPanel;
527 public void setCurrentFutherActionPanel(
528 FurtherActionPanel currentFutherActionPanel)
530 this.currentFurtherActionPanel = currentFutherActionPanel;
533 public SearchPanel getCurrentSearchPanel()
535 return currentSearchPanel;
538 public void setCurrentSearchPanel(SearchPanel currentSearchPanel)
540 this.currentSearchPanel = currentSearchPanel;
543 public int getActionOption()
548 public void setActionOption(int actionOption)
550 this.actionOption = actionOption;
553 public StructureFilterPanel getCurrentStructureFilterPanel()
555 return currentStructureFilterPanel;
558 public void setCurrentStructureFilterPanel(
559 StructureFilterPanel currentStructureFilterPanel)
561 this.currentStructureFilterPanel = currentStructureFilterPanel;