-package jalview.appletgui;
-
-import jalview.bin.JalviewLite;
-import jalview.datamodel.AlignmentAnnotation;
-import jalview.datamodel.ColumnSelection;
-import jalview.datamodel.GraphLine;
-import jalview.schemes.AnnotationColourGradient;
-import jalview.util.MessageManager;
-import jalview.viewmodel.annotationfilter.AnnotationFilterParameter;
-
-import java.awt.BorderLayout;
-import java.awt.CardLayout;
-import java.awt.Checkbox;
-import java.awt.Choice;
-import java.awt.Color;
-import java.awt.Dimension;
-import java.awt.Frame;
-import java.awt.Panel;
-import java.awt.TextField;
-import java.awt.event.ActionEvent;
-import java.awt.event.ActionListener;
-import java.awt.event.AdjustmentEvent;
-import java.awt.event.AdjustmentListener;
-import java.awt.event.ItemEvent;
-import java.awt.event.ItemListener;
-import java.awt.event.MouseAdapter;
-import java.awt.event.MouseEvent;
-import java.awt.event.MouseListener;
-import java.awt.event.TextEvent;
-import java.awt.event.TextListener;
-import java.util.Iterator;
-import java.util.Vector;
-
-import javax.swing.JPanel;
-
-//import net.miginfocom.swing.MigLayout;
-
-public class AnnotationColumnChooser extends AnnotationRowFilter implements
- ActionListener, AdjustmentListener, ItemListener, MouseListener
-{
-
- private Choice annotations = new Choice();
-
- private Panel actionPanel = new Panel();
-
- private TitledPanel thresholdPanel = new TitledPanel();
-
- private Panel switchableViewsPanel = new Panel(new CardLayout());
-
- private CardLayout switchableViewsLayout = (CardLayout) (switchableViewsPanel
- .getLayout());
-
- private Panel noGraphFilterView = new Panel();
-
- private Panel graphFilterView = new Panel();
-
- private Panel annotationComboBoxPanel = new Panel();
-
- private BorderLayout borderLayout1 = new BorderLayout();
-
- private BorderLayout gBorderLayout = new BorderLayout();
-
- private BorderLayout ngBorderLayout = new BorderLayout();
-
- private Choice threshold = new Choice();
-
- private StructureFilterPanel gStructureFilterPanel;
-
- private StructureFilterPanel ngStructureFilterPanel;
-
- private StructureFilterPanel currentStructureFilterPanel;
-
- private SearchPanel currentSearchPanel;
-
- private SearchPanel gSearchPanel;
-
- private SearchPanel ngSearchPanel;
-
- private FurtherActionPanel currentFurtherActionPanel;
-
- private FurtherActionPanel gFurtherActionPanel;
-
- private FurtherActionPanel ngFurtherActionPanel;
-
- public static final int ACTION_OPTION_SELECT = 1;
-
- public static int ACTION_OPTION_HIDE = 2;
-
- public static String NO_GRAPH_VIEW = "0";
-
- public static String GRAPH_VIEW = "1";
-
- private int actionOption = ACTION_OPTION_SELECT;
-
- private ColumnSelection oldColumnSelection;
-
- public AnnotationColumnChooser()
- {
- try
- {
- jbInit();
- } catch (Exception ex)
- {
- ex.printStackTrace();
- }
- }
-
- public AnnotationColumnChooser(AlignViewport av, final AlignmentPanel ap)
- {
- super(av, ap);
- frame = new JFrame();
- frame.add(this);
- JalviewLite.addFrame(frame,
- MessageManager.getString("label.select_by_annotation"), 520,
- 215);
-
- slider.addAdjustmentListener(this);
- slider.addMouseListener(this);
-
- if (av.getAlignment().getAlignmentAnnotation() == null)
- {
- return;
- }
- setOldColumnSelection(av.getColumnSelection());
- adjusting = true;
- Vector list = new Vector();
- int index = 1;
- for (int i = 0; i < av.getAlignment().getAlignmentAnnotation().length; i++)
- {
- String label = av.getAlignment().getAlignmentAnnotation()[i].label;
- if (!list.contains(label))
- {
- list.addElement(label);
- }
- else
- {
- list.addElement(label + "_" + (index++));
- }
- }
-
- for (int i = 0; i < list.size(); i++)
- {
- annotations.addItem(list.elementAt(i).toString());
- }
-
- populateThresholdComboBox(threshold);
-
- // restore Object state from the previous session if one exists
- if (av.getAnnotationColumnSelectionState() != null)
- {
- currentSearchPanel = av.getAnnotationColumnSelectionState()
- .getCurrentSearchPanel();
- currentStructureFilterPanel = av.getAnnotationColumnSelectionState()
- .getCurrentStructureFilterPanel();
- annotations.select(av.getAnnotationColumnSelectionState()
- .getAnnotations().getSelectedIndex());
- threshold.select(av.getAnnotationColumnSelectionState()
- .getThreshold().getSelectedIndex());
- actionOption = av.getAnnotationColumnSelectionState()
- .getActionOption();
- }
-
- try
- {
- jbInit();
- } catch (Exception ex)
- {
- }
- adjusting = false;
-
- updateView();
- frame.invalidate();
- frame.pack();
- }
-
- private void jbInit() throws Exception
- {
- ok.setLabel(MessageManager.getString("action.ok"));
-
- cancel.setLabel(MessageManager.getString("action.cancel"));
-
- thresholdValue.setEnabled(false);
- thresholdValue.setColumns(7);
-
- ok.addActionListener(this);
- cancel.addActionListener(this);
- annotations.addItemListener(this);
- thresholdValue.addActionListener(this);
- threshold.addItemListener(this);
-
- slider.setBackground(Color.white);
- slider.setEnabled(false);
- slider.setPreferredSize(new Dimension(100, 32));
-
- thresholdPanel.setBackground(Color.white);
- // thresholdPanel.setFont(JvSwingUtils.getLabelFont());
- // thresholdPanel.setLayout(new MigLayout("", "[left][right]", "[][]"));
-
- actionPanel.setBackground(Color.white);
- // actionPanel.setFont(JvSwingUtils.getLabelFont());
-
- graphFilterView.setLayout(gBorderLayout);
- graphFilterView.setBackground(Color.white);
-
- noGraphFilterView.setLayout(ngBorderLayout);
- noGraphFilterView.setBackground(Color.white);
-
- annotationComboBoxPanel.setBackground(Color.white);
- // annotationComboBoxPanel.setFont(JvSwingUtils.getLabelFont());
-
- gSearchPanel = new SearchPanel(this);
- ngSearchPanel = new SearchPanel(this);
- gFurtherActionPanel = new FurtherActionPanel(this);
- ngFurtherActionPanel = new FurtherActionPanel(this);
- gStructureFilterPanel = new StructureFilterPanel(this);
- ngStructureFilterPanel = new StructureFilterPanel(this);
-
- thresholdPanel.setTitle("Threshold Filter");
- thresholdPanel.add(getThreshold());
- thresholdPanel.add(slider);
- thresholdPanel.add(thresholdValue);
-
- actionPanel.add(ok);
- actionPanel.add(cancel);
-
- JPanel staticPanel = new JPanel();
- staticPanel.setLayout(new BorderLayout());
- staticPanel.setBackground(Color.white);
-
- staticPanel.add(gSearchPanel, java.awt.BorderLayout.NORTH);
- staticPanel.add(gStructureFilterPanel, java.awt.BorderLayout.SOUTH);
-
- graphFilterView.add(staticPanel, java.awt.BorderLayout.NORTH);
- graphFilterView.add(thresholdPanel, java.awt.BorderLayout.CENTER);
- graphFilterView.add(gFurtherActionPanel, java.awt.BorderLayout.SOUTH);
-
- noGraphFilterView.add(ngSearchPanel, java.awt.BorderLayout.PAGE_START);
- noGraphFilterView.add(ngStructureFilterPanel,
- java.awt.BorderLayout.CENTER);
- noGraphFilterView.add(ngFurtherActionPanel,
- java.awt.BorderLayout.CENTER);
-
- annotationComboBoxPanel.add(getAnnotations());
- switchableViewsPanel.add(noGraphFilterView,
- AnnotationColumnChooser.NO_GRAPH_VIEW);
- switchableViewsPanel.add(graphFilterView,
- AnnotationColumnChooser.GRAPH_VIEW);
-
- this.setLayout(borderLayout1);
- this.add(annotationComboBoxPanel, java.awt.BorderLayout.PAGE_START);
- this.add(switchableViewsPanel, java.awt.BorderLayout.CENTER);
- this.add(actionPanel, java.awt.BorderLayout.SOUTH);
-
- selectedAnnotationChanged();
- this.validate();
- }
-
- @SuppressWarnings("unchecked")
- public void reset()
- {
- if (this.getOldColumnSelection() != null)
- {
- av.getColumnSelection().clear();
-
- if (av.getAnnotationColumnSelectionState() != null)
- {
- ColumnSelection oldSelection = av
- .getAnnotationColumnSelectionState()
- .getOldColumnSelection();
- if (oldSelection != null && oldSelection.getHiddenColumns() != null
- && !oldSelection.getHiddenColumns().isEmpty())
- {
- for (Iterator<int[]> itr = oldSelection.getHiddenColumns()
- .iterator(); itr.hasNext();)
- {
- int positions[] = itr.next();
- av.hideColumns(positions[0], positions[1]);
- }
- }
- av.setColumnSelection(oldSelection);
- }
- ap.paintAlignment(true);
- }
-
- }
-
- public void adjustmentValueChanged(AdjustmentEvent evt)
- {
- if (!adjusting)
- {
- thresholdValue.setText((slider.getValue() / 1000f) + "");
- valueChanged(!sliderDragging);
- }
- }
-
- protected void addSliderMouseListeners()
- {
-
- slider.addMouseListener(new MouseAdapter()
- {
- @Override
- public void mousePressed(MouseEvent e)
- {
- sliderDragging = true;
- super.mousePressed(e);
- }
-
- @Override
- public void mouseDragged(MouseEvent e)
- {
- sliderDragging = true;
- super.mouseDragged(e);
- }
-
- @Override
- public void mouseReleased(MouseEvent evt)
- {
- if (sliderDragging)
- {
- sliderDragging = false;
- valueChanged(true);
- }
- ap.paintAlignment(true);
- }
- });
- }
-
- public void valueChanged(boolean updateAllAnnotation)
- {
- if (slider.isEnabled())
- {
- getCurrentAnnotation().threshold.value = slider.getValue() / 1000f;
- updateView();
- ap.paintAlignment(false);
- }
- }
-
- public Choice getThreshold()
- {
- return threshold;
- }
-
- public void setThreshold(Choice threshold)
- {
- this.threshold = threshold;
- }
-
- public Choice getAnnotations()
- {
- return annotations;
- }
-
- public void setAnnotations(Choice annotations)
- {
- this.annotations = annotations;
- }
-
- @Override
- public void updateView()
- {
- // Check if combobox is still adjusting
- if (adjusting)
- {
- return;
- }
-
- AnnotationFilterParameter filterParams = new AnnotationFilterParameter();
- setCurrentAnnotation(av.getAlignment().getAlignmentAnnotation()[getAnnotations()
- .getSelectedIndex()]);
-
- int selectedThresholdItem = getSelectedThresholdItem(getThreshold()
- .getSelectedIndex());
-
- slider.setEnabled(true);
- thresholdValue.setEnabled(true);
-
- if (selectedThresholdItem == AnnotationColourGradient.NO_THRESHOLD)
- {
- slider.setEnabled(false);
- thresholdValue.setEnabled(false);
- thresholdValue.setText("");
- // build filter params
- }
- else if (selectedThresholdItem != AnnotationColourGradient.NO_THRESHOLD)
- {
- if (getCurrentAnnotation().threshold == null)
- {
- getCurrentAnnotation()
- .setThreshold(
- new GraphLine(
- (getCurrentAnnotation().graphMax - getCurrentAnnotation().graphMin) / 2f,
- "Threshold", Color.black));
- }
-
- adjusting = true;
- float range = getCurrentAnnotation().graphMax * 1000
- - getCurrentAnnotation().graphMin * 1000;
-
- slider.setMinimum((int) (getCurrentAnnotation().graphMin * 1000));
- slider.setMaximum((int) (getCurrentAnnotation().graphMax * 1000));
- slider.setValue((int) (getCurrentAnnotation().threshold.value * 1000));
- thresholdValue.setText(getCurrentAnnotation().threshold.value + "");
- // slider.setMajorTickSpacing((int) (range / 10f));
- slider.setEnabled(true);
- thresholdValue.setEnabled(true);
- adjusting = false;
-
- // build filter params
- filterParams
- .setThresholdType(AnnotationFilterParameter.ThresholdType.NO_THRESHOLD);
- if (getCurrentAnnotation().graph != AlignmentAnnotation.NO_GRAPH)
- {
- filterParams
- .setThresholdValue(getCurrentAnnotation().threshold.value);
-
- if (selectedThresholdItem == AnnotationColourGradient.ABOVE_THRESHOLD)
- {
- filterParams
- .setThresholdType(AnnotationFilterParameter.ThresholdType.ABOVE_THRESHOLD);
- }
- else if (selectedThresholdItem == AnnotationColourGradient.BELOW_THRESHOLD)
- {
- filterParams
- .setThresholdType(AnnotationFilterParameter.ThresholdType.BELOW_THRESHOLD);
- }
- }
- }
-
- if (currentStructureFilterPanel != null)
- {
- if (currentStructureFilterPanel.alphaHelix.getState())
- {
- filterParams.setFilterAlphaHelix(true);
- }
- if (currentStructureFilterPanel.betaStrand.getState())
- {
- filterParams.setFilterBetaSheet(true);
- }
- if (currentStructureFilterPanel.turn.getState())
- {
- filterParams.setFilterTurn(true);
- }
- }
-
- if (currentSearchPanel != null)
- {
-
- if (!currentSearchPanel.searchBox.getText().isEmpty())
- {
- currentSearchPanel.description.setEnabled(true);
- currentSearchPanel.displayName.setEnabled(true);
- filterParams.setRegexString(currentSearchPanel.searchBox.getText());
- if (currentSearchPanel.displayName.getState())
- {
- filterParams
- .addRegexSearchField(AnnotationFilterParameter.SearchableAnnotationField.DISPLAY_STRING);
- }
- if (currentSearchPanel.description.getState())
- {
- filterParams
- .addRegexSearchField(AnnotationFilterParameter.SearchableAnnotationField.DESCRIPTION);
- }
- }
- else
- {
- currentSearchPanel.description.setEnabled(false);
- currentSearchPanel.displayName.setEnabled(false);
- }
- }
-
- av.getColumnSelection().filterAnnotations(
- getCurrentAnnotation().annotations, filterParams);
-
- av.showAllHiddenColumns();
- if (getActionOption() == ACTION_OPTION_HIDE)
- {
- av.hideSelectedColumns();
- }
-
- filterParams = null;
- av.setAnnotationColumnSelectionState(this);
- ap.paintAlignment(true);
- }
-
- public ColumnSelection getOldColumnSelection()
- {
- return oldColumnSelection;
- }
-
- public void setOldColumnSelection(ColumnSelection currentColumnSelection)
- {
- if (currentColumnSelection != null)
- {
- this.oldColumnSelection = new ColumnSelection(currentColumnSelection);
- }
- }
-
- public FurtherActionPanel getCurrentFutherActionPanel()
- {
- return currentFurtherActionPanel;
- }
-
- public void setCurrentFutherActionPanel(
- FurtherActionPanel currentFutherActionPanel)
- {
- this.currentFurtherActionPanel = currentFutherActionPanel;
- }
-
- public SearchPanel getCurrentSearchPanel()
- {
- return currentSearchPanel;
- }
-
- public void setCurrentSearchPanel(SearchPanel currentSearchPanel)
- {
- this.currentSearchPanel = currentSearchPanel;
- }
-
- public int getActionOption()
- {
- return actionOption;
- }
-
- public void setActionOption(int actionOption)
- {
- this.actionOption = actionOption;
- }
-
- public StructureFilterPanel getCurrentStructureFilterPanel()
- {
- return currentStructureFilterPanel;
- }
-
- public void setCurrentStructureFilterPanel(
- StructureFilterPanel currentStructureFilterPanel)
- {
- this.currentStructureFilterPanel = currentStructureFilterPanel;
- }
-
- @Override
- public void itemStateChanged(ItemEvent e)
- {
- if (e.getSource() == annotations)
- {
- selectedAnnotationChanged();
- }
- else if (e.getSource() == threshold)
- {
- threshold_actionPerformed(null);
- }
- }
-
- public void selectedAnnotationChanged()
- {
- String currentView = AnnotationColumnChooser.NO_GRAPH_VIEW;
- if (av.getAlignment().getAlignmentAnnotation()[getAnnotations()
- .getSelectedIndex()].graph != AlignmentAnnotation.NO_GRAPH)
- {
- currentView = AnnotationColumnChooser.GRAPH_VIEW;
- }
-
- gSearchPanel.syncState();
- gFurtherActionPanel.syncState();
- gStructureFilterPanel.syncState();
-
- ngSearchPanel.syncState();
- ngFurtherActionPanel.syncState();
- ngStructureFilterPanel.syncState();
-
- switchableViewsLayout.show(switchableViewsPanel, currentView);
- updateView();
- }
-
- public class FurtherActionPanel extends Panel implements
- ItemListener
- {
- private AnnotationColumnChooser aColChooser;
-
- private Choice furtherAction = new Choice();
-
- public FurtherActionPanel(AnnotationColumnChooser aColChooser)
- {
- this.aColChooser = aColChooser;
- furtherAction.addItem("Select");
- furtherAction.addItem("Hide");
- furtherAction.addItemListener(this);
- syncState();
-
- // this.setTitle("Filter Actions");
- // this.setFont(JvSwingUtils.getLabelFont());
-
- this.add(furtherAction);
- }
-
- public void syncState()
- {
- if (aColChooser.getActionOption() == AnnotationColumnChooser.ACTION_OPTION_HIDE)
- {
- furtherAction.select("Hide");
- }
- else
- {
- furtherAction.select("Select");
- }
- }
-
- @Override
- public void itemStateChanged(ItemEvent e)
- {
- aColChooser.setCurrentFutherActionPanel(this);
- if (furtherAction.getSelectedItem().equalsIgnoreCase("Select"))
- {
- setActionOption(ACTION_OPTION_SELECT);
- updateView();
- }
- else
- {
- setActionOption(ACTION_OPTION_HIDE);
- updateView();
- }
-
- }
- }
-
- public class StructureFilterPanel extends TitledPanel implements
- ItemListener
- {
- private AnnotationColumnChooser aColChooser;
-
- private Checkbox alphaHelix = new Checkbox();
-
- private Checkbox betaStrand = new Checkbox();
-
- private Checkbox turn = new Checkbox();
-
- private Checkbox all = new Checkbox();
-
- public StructureFilterPanel(AnnotationColumnChooser aColChooser)
- {
- this.aColChooser = aColChooser;
-
- alphaHelix.setLabel(MessageManager.getString("label.alpha_helix"));
- alphaHelix.setBackground(Color.white);
-
- alphaHelix.addItemListener(this);
-
- betaStrand.setLabel(MessageManager.getString("label.beta_strand"));
- betaStrand.setBackground(Color.white);
- betaStrand.addItemListener(this);
-
- turn.setLabel(MessageManager.getString("label.turn"));
- turn.setBackground(Color.white);
- turn.addItemListener(this);
-
- all.setLabel(MessageManager.getString("label.select_all"));
- all.setBackground(Color.white);
- all.addItemListener(this);
-
- this.setBackground(Color.white);
- this.setTitle("Structure Filter");
- // this.setFont(JvSwingUtils.getLabelFont());
-
- this.add(all);
- this.add(alphaHelix);
- this.add(betaStrand);
- this.add(turn);
- }
-
- public void alphaHelix_actionPerformed()
- {
- updateSelectAllState();
- aColChooser.setCurrentStructureFilterPanel(this);
- aColChooser.updateView();
- }
-
- public void betaStrand_actionPerformed()
- {
- updateSelectAllState();
- aColChooser.setCurrentStructureFilterPanel(this);
- aColChooser.updateView();
- }
-
- public void turn_actionPerformed()
- {
- updateSelectAllState();
- aColChooser.setCurrentStructureFilterPanel(this);
- aColChooser.updateView();
- }
-
- public void all_actionPerformed()
- {
- if (all.getState())
- {
- alphaHelix.setState(true);
- betaStrand.setState(true);
- turn.setState(true);
- }
- else
- {
- alphaHelix.setState(false);
- betaStrand.setState(false);
- turn.setState(false);
- }
- aColChooser.setCurrentStructureFilterPanel(this);
- aColChooser.updateView();
- }
-
- public void updateSelectAllState()
- {
- if (alphaHelix.getState() && betaStrand.getState() && turn.getState())
- {
- all.setState(true);
- }
- else
- {
- all.setState(false);
- }
- }
-
- public void syncState()
- {
- StructureFilterPanel sfp = aColChooser
- .getCurrentStructureFilterPanel();
- if (sfp != null)
- {
- alphaHelix.setState(sfp.alphaHelix.getState());
- betaStrand.setState(sfp.betaStrand.getState());
- turn.setState(sfp.turn.getState());
- if (sfp.all.getState())
- {
- all.setState(true);
- alphaHelix.setState(true);
- betaStrand.setState(true);
- turn.setState(true);
- }
- }
-
- }
-
- @Override
- public void itemStateChanged(ItemEvent e)
- {
- if (e.getSource() == alphaHelix)
- {
- alphaHelix_actionPerformed();
- }
- else if (e.getSource() == betaStrand)
- {
- betaStrand_actionPerformed();
- }
- else if (e.getSource() == turn)
- {
- turn_actionPerformed();
- }
- else if (e.getSource() == all)
- {
- all_actionPerformed();
- }
- }
- }
-
- public class SearchPanel extends TitledPanel implements ItemListener
- {
- private AnnotationColumnChooser aColChooser;
-
- private Checkbox displayName = new Checkbox();
-
- private Checkbox description = new Checkbox();
-
- private TextField searchBox = new TextField(10);
-
- public SearchPanel(AnnotationColumnChooser aColChooser)
- {
-
- this.aColChooser = aColChooser;
- searchBox.addTextListener(new TextListener()
- {
-
- @Override
- public void textValueChanged(TextEvent e)
- {
- searchStringAction();
-
- }
-
- });
-
- displayName.setLabel(MessageManager.getString("label.display_name"));
- displayName.setEnabled(false);
- displayName.addItemListener(this);
-
- description.setLabel(MessageManager.getString("label.description"));
- description.setEnabled(false);
- description.addItemListener(this);
- this.setTitle("Search Filter");
- // this.setFont(JvSwingUtils.getLabelFont());
-
- syncState();
- this.add(searchBox);
- this.add(displayName);
- this.add(description);
- }
-
- public void displayNameCheckboxAction()
- {
- aColChooser.setCurrentSearchPanel(this);
- aColChooser.updateView();
- }
-
- public void discriptionCheckboxAction()
- {
- aColChooser.setCurrentSearchPanel(this);
- aColChooser.updateView();
- }
-
- public void searchStringAction()
- {
- aColChooser.setCurrentSearchPanel(this);
- aColChooser.updateView();
- }
-
- public void syncState()
- {
- SearchPanel sp = aColChooser.getCurrentSearchPanel();
- if (sp != null)
- {
- description.setEnabled(sp.description.isEnabled());
- description.setState(sp.description.getState());
-
- displayName.setEnabled(sp.displayName.isEnabled());
- displayName.setState(sp.displayName.getState());
-
- searchBox.setText(sp.searchBox.getText());
- }
- }
-
- @Override
- public void itemStateChanged(ItemEvent e)
- {
- if (e.getSource() == displayName)
- {
- displayNameCheckboxAction();
- }
- else if (e.getSource() == description)
- {
- discriptionCheckboxAction();
- }
-
- }
- }
-
- public void actionPerformed(ActionEvent evt)
- {
- if (evt.getSource() == thresholdValue)
- {
- try
- {
- float f = new Float(thresholdValue.getText()).floatValue();
- slider.setValue((int) (f * 1000));
- adjustmentValueChanged(null);
- } catch (NumberFormatException ex)
- {
- }
- }
-
- else if (evt.getSource() == ok)
- {
- ok_actionPerformed(null);
- }
- else if (evt.getSource() == cancel)
- {
- cancel_actionPerformed(null);
- }
- else if (evt.getSource() == thresholdValue)
- {
- thresholdValue_actionPerformed(null);
- }
- else
- {
- updateView();
- }
- }
-
- @Override
- public void mouseClicked(MouseEvent e)
- {
- // TODO Auto-generated method stub
-
- }
-
- @Override
- public void mousePressed(MouseEvent e)
- {
- if (e.getSource() == slider)
- {
- updateView();
- }
-
- }
-
- @Override
- public void mouseReleased(MouseEvent e)
- {
- if (e.getSource() == slider)
- {
- updateView();
- }
- }
-
- @Override
- public void mouseEntered(MouseEvent e)
- {
- if (e.getSource() == slider)
- {
- updateView();
- }
- }
-
- @Override
- public void mouseExited(MouseEvent e)
- {
- if (e.getSource() == slider)
- {
- updateView();
- }
- }
-
-}
+package jalview.appletgui;\r
+\r
+import jalview.bin.JalviewLite;\r
+import jalview.datamodel.AlignmentAnnotation;\r
+import jalview.datamodel.ColumnSelection;\r
+import jalview.datamodel.GraphLine;\r
+import jalview.schemes.AnnotationColourGradient;\r
+import jalview.util.MessageManager;\r
+import jalview.viewmodel.annotationfilter.AnnotationFilterParameter;\r
+\r
+import java.awt.BorderLayout;\r
+import java.awt.CardLayout;\r
+import java.awt.Checkbox;\r
+import java.awt.Choice;\r
+import java.awt.Color;\r
+import java.awt.Dimension;\r
+import java.awt.Frame;\r
+import java.awt.Panel;\r
+import java.awt.TextField;\r
+import java.awt.event.ActionEvent;\r
+import java.awt.event.ActionListener;\r
+import java.awt.event.AdjustmentEvent;\r
+import java.awt.event.AdjustmentListener;\r
+import java.awt.event.ItemEvent;\r
+import java.awt.event.ItemListener;\r
+import java.awt.event.MouseAdapter;\r
+import java.awt.event.MouseEvent;\r
+import java.awt.event.MouseListener;\r
+import java.awt.event.TextEvent;\r
+import java.awt.event.TextListener;\r
+import java.util.Iterator;\r
+import java.util.Vector;\r
+\r
+import javax.swing.JPanel;\r
+\r
+//import net.miginfocom.swing.MigLayout;\r
+\r
+public class AnnotationColumnChooser extends AnnotationRowFilter implements\r
+ ActionListener, AdjustmentListener, ItemListener, MouseListener\r
+{\r
+\r
+ private Choice annotations = new Choice();\r
+\r
+ private Panel actionPanel = new Panel();\r
+\r
+ private TitledPanel thresholdPanel = new TitledPanel();\r
+\r
+ private Panel switchableViewsPanel = new Panel(new CardLayout());\r
+\r
+ private CardLayout switchableViewsLayout = (CardLayout) (switchableViewsPanel\r
+ .getLayout());\r
+\r
+ private Panel noGraphFilterView = new Panel();\r
+\r
+ private Panel graphFilterView = new Panel();\r
+\r
+ private Panel annotationComboBoxPanel = new Panel();\r
+\r
+ private BorderLayout borderLayout1 = new BorderLayout();\r
+\r
+ private BorderLayout gBorderLayout = new BorderLayout();\r
+\r
+ private BorderLayout ngBorderLayout = new BorderLayout();\r
+\r
+ private Choice threshold = new Choice();\r
+\r
+ private StructureFilterPanel gStructureFilterPanel;\r
+\r
+ private StructureFilterPanel ngStructureFilterPanel;\r
+\r
+ private StructureFilterPanel currentStructureFilterPanel;\r
+\r
+ private SearchPanel currentSearchPanel;\r
+\r
+ private SearchPanel gSearchPanel;\r
+\r
+ private SearchPanel ngSearchPanel;\r
+\r
+ private FurtherActionPanel currentFurtherActionPanel;\r
+\r
+ private FurtherActionPanel gFurtherActionPanel;\r
+\r
+ private FurtherActionPanel ngFurtherActionPanel;\r
+\r
+ public static final int ACTION_OPTION_SELECT = 1;\r
+\r
+ public static int ACTION_OPTION_HIDE = 2;\r
+\r
+ public static String NO_GRAPH_VIEW = "0";\r
+\r
+ public static String GRAPH_VIEW = "1";\r
+\r
+ private int actionOption = ACTION_OPTION_SELECT;\r
+\r
+ private ColumnSelection oldColumnSelection;\r
+\r
+ public AnnotationColumnChooser()\r
+ {\r
+ try\r
+ {\r
+ jbInit();\r
+ } catch (Exception ex)\r
+ {\r
+ ex.printStackTrace();\r
+ }\r
+ }\r
+\r
+ public AnnotationColumnChooser(AlignViewport av, final AlignmentPanel ap)\r
+ {\r
+ super(av, ap);\r
+ frame = new JFrame();\r
+ frame.add(this);\r
+ JalviewLite.addFrame(frame,\r
+ MessageManager.getString("label.select_by_annotation"), 520,\r
+ 215);\r
+\r
+ slider.addAdjustmentListener(this);\r
+ slider.addMouseListener(this);\r
+\r
+ if (av.getAlignment().getAlignmentAnnotation() == null)\r
+ {\r
+ return;\r
+ }\r
+ setOldColumnSelection(av.getColumnSelection());\r
+ adjusting = true;\r
+ Vector list = new Vector();\r
+ int index = 1;\r
+ for (int i = 0; i < av.getAlignment().getAlignmentAnnotation().length; i++)\r
+ {\r
+ String label = av.getAlignment().getAlignmentAnnotation()[i].label;\r
+ if (!list.contains(label))\r
+ {\r
+ list.addElement(label);\r
+ }\r
+ else\r
+ {\r
+ list.addElement(label + "_" + (index++));\r
+ }\r
+ }\r
+\r
+ for (int i = 0; i < list.size(); i++)\r
+ {\r
+ annotations.addItem(list.elementAt(i).toString());\r
+ }\r
+\r
+ populateThresholdComboBox(threshold);\r
+\r
+ // restore Object state from the previous session if one exists\r
+ if (av.getAnnotationColumnSelectionState() != null)\r
+ {\r
+ currentSearchPanel = av.getAnnotationColumnSelectionState()\r
+ .getCurrentSearchPanel();\r
+ currentStructureFilterPanel = av.getAnnotationColumnSelectionState()\r
+ .getCurrentStructureFilterPanel();\r
+ annotations.select(av.getAnnotationColumnSelectionState()\r
+ .getAnnotations().getSelectedIndex());\r
+ threshold.select(av.getAnnotationColumnSelectionState()\r
+ .getThreshold().getSelectedIndex());\r
+ actionOption = av.getAnnotationColumnSelectionState()\r
+ .getActionOption();\r
+ }\r
+\r
+ try\r
+ {\r
+ jbInit();\r
+ } catch (Exception ex)\r
+ {\r
+ }\r
+ adjusting = false;\r
+\r
+ updateView();\r
+ frame.invalidate();\r
+ frame.pack();\r
+ }\r
+\r
+ private void jbInit() throws Exception\r
+ {\r
+ ok.setLabel(MessageManager.getString("action.ok"));\r
+\r
+ cancel.setLabel(MessageManager.getString("action.cancel"));\r
+\r
+ thresholdValue.setEnabled(false);\r
+ thresholdValue.setColumns(7);\r
+\r
+ ok.addActionListener(this);\r
+ cancel.addActionListener(this);\r
+ annotations.addItemListener(this);\r
+ thresholdValue.addActionListener(this);\r
+ threshold.addItemListener(this);\r
+\r
+ slider.setBackground(Color.white);\r
+ slider.setEnabled(false);\r
+ slider.setPreferredSize(new Dimension(100, 32));\r
+\r
+ thresholdPanel.setBackground(Color.white);\r
+ // thresholdPanel.setFont(JvSwingUtils.getLabelFont());\r
+ // thresholdPanel.setLayout(new MigLayout("", "[left][right]", "[][]"));\r
+\r
+ actionPanel.setBackground(Color.white);\r
+ // actionPanel.setFont(JvSwingUtils.getLabelFont());\r
+\r
+ graphFilterView.setLayout(gBorderLayout);\r
+ graphFilterView.setBackground(Color.white);\r
+\r
+ noGraphFilterView.setLayout(ngBorderLayout);\r
+ noGraphFilterView.setBackground(Color.white);\r
+\r
+ annotationComboBoxPanel.setBackground(Color.white);\r
+ // annotationComboBoxPanel.setFont(JvSwingUtils.getLabelFont());\r
+\r
+ gSearchPanel = new SearchPanel(this);\r
+ ngSearchPanel = new SearchPanel(this);\r
+ gFurtherActionPanel = new FurtherActionPanel(this);\r
+ ngFurtherActionPanel = new FurtherActionPanel(this);\r
+ gStructureFilterPanel = new StructureFilterPanel(this);\r
+ ngStructureFilterPanel = new StructureFilterPanel(this);\r
+\r
+ thresholdPanel.setTitle("Threshold Filter");\r
+ thresholdPanel.add(getThreshold());\r
+ thresholdPanel.add(slider);\r
+ thresholdPanel.add(thresholdValue);\r
+\r
+ actionPanel.add(ok);\r
+ actionPanel.add(cancel);\r
+\r
+ JPanel staticPanel = new JPanel();\r
+ staticPanel.setLayout(new BorderLayout());\r
+ staticPanel.setBackground(Color.white);\r
+\r
+ staticPanel.add(gSearchPanel, java.awt.BorderLayout.NORTH);\r
+ staticPanel.add(gStructureFilterPanel, java.awt.BorderLayout.SOUTH);\r
+\r
+ graphFilterView.add(staticPanel, java.awt.BorderLayout.NORTH);\r
+ graphFilterView.add(thresholdPanel, java.awt.BorderLayout.CENTER);\r
+ graphFilterView.add(gFurtherActionPanel, java.awt.BorderLayout.SOUTH);\r
+\r
+ noGraphFilterView.add(ngSearchPanel, java.awt.BorderLayout.PAGE_START);\r
+ noGraphFilterView.add(ngStructureFilterPanel,\r
+ java.awt.BorderLayout.CENTER);\r
+ noGraphFilterView.add(ngFurtherActionPanel,\r
+ java.awt.BorderLayout.CENTER);\r
+\r
+ annotationComboBoxPanel.add(getAnnotations());\r
+ switchableViewsPanel.add(noGraphFilterView,\r
+ AnnotationColumnChooser.NO_GRAPH_VIEW);\r
+ switchableViewsPanel.add(graphFilterView,\r
+ AnnotationColumnChooser.GRAPH_VIEW);\r
+\r
+ this.setLayout(borderLayout1);\r
+ this.add(annotationComboBoxPanel, java.awt.BorderLayout.PAGE_START);\r
+ this.add(switchableViewsPanel, java.awt.BorderLayout.CENTER);\r
+ this.add(actionPanel, java.awt.BorderLayout.SOUTH);\r
+\r
+ selectedAnnotationChanged();\r
+ this.validate();\r
+ }\r
+\r
+ @SuppressWarnings("unchecked")\r
+ public void reset()\r
+ {\r
+ if (this.getOldColumnSelection() != null)\r
+ {\r
+ av.getColumnSelection().clear();\r
+\r
+ if (av.getAnnotationColumnSelectionState() != null)\r
+ {\r
+ ColumnSelection oldSelection = av\r
+ .getAnnotationColumnSelectionState()\r
+ .getOldColumnSelection();\r
+ if (oldSelection != null && oldSelection.getHiddenColumns() != null\r
+ && !oldSelection.getHiddenColumns().isEmpty())\r
+ {\r
+ for (Iterator<int[]> itr = oldSelection.getHiddenColumns()\r
+ .iterator(); itr.hasNext();)\r
+ {\r
+ int positions[] = itr.next();\r
+ av.hideColumns(positions[0], positions[1]);\r
+ }\r
+ }\r
+ av.setColumnSelection(oldSelection);\r
+ }\r
+ ap.paintAlignment(true);\r
+ }\r
+\r
+ }\r
+\r
+ public void adjustmentValueChanged(AdjustmentEvent evt)\r
+ {\r
+ if (!adjusting)\r
+ {\r
+ thresholdValue.setText((slider.getValue() / 1000f) + "");\r
+ valueChanged(!sliderDragging);\r
+ }\r
+ }\r
+\r
+ protected void addSliderMouseListeners()\r
+ {\r
+\r
+ slider.addMouseListener(new MouseAdapter()\r
+ {\r
+ @Override\r
+ public void mousePressed(MouseEvent e)\r
+ {\r
+ sliderDragging = true;\r
+ super.mousePressed(e);\r
+ }\r
+\r
+ @Override\r
+ public void mouseDragged(MouseEvent e)\r
+ {\r
+ sliderDragging = true;\r
+ super.mouseDragged(e);\r
+ }\r
+\r
+ @Override\r
+ public void mouseReleased(MouseEvent evt)\r
+ {\r
+ if (sliderDragging)\r
+ {\r
+ sliderDragging = false;\r
+ valueChanged(true);\r
+ }\r
+ ap.paintAlignment(true);\r
+ }\r
+ });\r
+ }\r
+\r
+ public void valueChanged(boolean updateAllAnnotation)\r
+ {\r
+ if (slider.isEnabled())\r
+ {\r
+ getCurrentAnnotation().threshold.value = slider.getValue() / 1000f;\r
+ updateView();\r
+ ap.paintAlignment(false);\r
+ }\r
+ }\r
+\r
+ public Choice getThreshold()\r
+ {\r
+ return threshold;\r
+ }\r
+\r
+ public void setThreshold(Choice threshold)\r
+ {\r
+ this.threshold = threshold;\r
+ }\r
+\r
+ public Choice getAnnotations()\r
+ {\r
+ return annotations;\r
+ }\r
+\r
+ public void setAnnotations(Choice annotations)\r
+ {\r
+ this.annotations = annotations;\r
+ }\r
+\r
+ @Override\r
+ public void updateView()\r
+ {\r
+ // Check if combobox is still adjusting\r
+ if (adjusting)\r
+ {\r
+ return;\r
+ }\r
+\r
+ AnnotationFilterParameter filterParams = new AnnotationFilterParameter();\r
+ setCurrentAnnotation(av.getAlignment().getAlignmentAnnotation()[getAnnotations()\r
+ .getSelectedIndex()]);\r
+\r
+ int selectedThresholdItem = getSelectedThresholdItem(getThreshold()\r
+ .getSelectedIndex());\r
+\r
+ slider.setEnabled(true);\r
+ thresholdValue.setEnabled(true);\r
+\r
+ if (selectedThresholdItem == AnnotationColourGradient.NO_THRESHOLD)\r
+ {\r
+ slider.setEnabled(false);\r
+ thresholdValue.setEnabled(false);\r
+ thresholdValue.setText("");\r
+ // build filter params\r
+ }\r
+ else if (selectedThresholdItem != AnnotationColourGradient.NO_THRESHOLD)\r
+ {\r
+ if (getCurrentAnnotation().threshold == null)\r
+ {\r
+ getCurrentAnnotation()\r
+ .setThreshold(\r
+ new GraphLine(\r
+ (getCurrentAnnotation().graphMax - getCurrentAnnotation().graphMin) / 2f,\r
+ "Threshold", Color.black));\r
+ }\r
+\r
+ adjusting = true;\r
+ float range = getCurrentAnnotation().graphMax * 1000\r
+ - getCurrentAnnotation().graphMin * 1000;\r
+\r
+ slider.setMinimum((int) (getCurrentAnnotation().graphMin * 1000));\r
+ slider.setMaximum((int) (getCurrentAnnotation().graphMax * 1000));\r
+ slider.setValue((int) (getCurrentAnnotation().threshold.value * 1000));\r
+ thresholdValue.setText(getCurrentAnnotation().threshold.value + "");\r
+ // slider.setMajorTickSpacing((int) (range / 10f));\r
+ slider.setEnabled(true);\r
+ thresholdValue.setEnabled(true);\r
+ adjusting = false;\r
+\r
+ // build filter params\r
+ filterParams\r
+ .setThresholdType(AnnotationFilterParameter.ThresholdType.NO_THRESHOLD);\r
+ if (getCurrentAnnotation().graph != AlignmentAnnotation.NO_GRAPH)\r
+ {\r
+ filterParams\r
+ .setThresholdValue(getCurrentAnnotation().threshold.value);\r
+\r
+ if (selectedThresholdItem == AnnotationColourGradient.ABOVE_THRESHOLD)\r
+ {\r
+ filterParams\r
+ .setThresholdType(AnnotationFilterParameter.ThresholdType.ABOVE_THRESHOLD);\r
+ }\r
+ else if (selectedThresholdItem == AnnotationColourGradient.BELOW_THRESHOLD)\r
+ {\r
+ filterParams\r
+ .setThresholdType(AnnotationFilterParameter.ThresholdType.BELOW_THRESHOLD);\r
+ }\r
+ }\r
+ }\r
+\r
+ if (currentStructureFilterPanel != null)\r
+ {\r
+ if (currentStructureFilterPanel.alphaHelix.getState())\r
+ {\r
+ filterParams.setFilterAlphaHelix(true);\r
+ }\r
+ if (currentStructureFilterPanel.betaStrand.getState())\r
+ {\r
+ filterParams.setFilterBetaSheet(true);\r
+ }\r
+ if (currentStructureFilterPanel.turn.getState())\r
+ {\r
+ filterParams.setFilterTurn(true);\r
+ }\r
+ }\r
+\r
+ if (currentSearchPanel != null)\r
+ {\r
+\r
+ if (!currentSearchPanel.searchBox.getText().isEmpty())\r
+ {\r
+ currentSearchPanel.description.setEnabled(true);\r
+ currentSearchPanel.displayName.setEnabled(true);\r
+ filterParams.setRegexString(currentSearchPanel.searchBox.getText());\r
+ if (currentSearchPanel.displayName.getState())\r
+ {\r
+ filterParams\r
+ .addRegexSearchField(AnnotationFilterParameter.SearchableAnnotationField.DISPLAY_STRING);\r
+ }\r
+ if (currentSearchPanel.description.getState())\r
+ {\r
+ filterParams\r
+ .addRegexSearchField(AnnotationFilterParameter.SearchableAnnotationField.DESCRIPTION);\r
+ }\r
+ }\r
+ else\r
+ {\r
+ currentSearchPanel.description.setEnabled(false);\r
+ currentSearchPanel.displayName.setEnabled(false);\r
+ }\r
+ }\r
+\r
+ av.getColumnSelection().filterAnnotations(\r
+ getCurrentAnnotation().annotations, filterParams);\r
+\r
+ av.showAllHiddenColumns();\r
+ if (getActionOption() == ACTION_OPTION_HIDE)\r
+ {\r
+ av.hideSelectedColumns();\r
+ }\r
+\r
+ filterParams = null;\r
+ av.setAnnotationColumnSelectionState(this);\r
+ ap.paintAlignment(true);\r
+ }\r
+\r
+ public ColumnSelection getOldColumnSelection()\r
+ {\r
+ return oldColumnSelection;\r
+ }\r
+\r
+ public void setOldColumnSelection(ColumnSelection currentColumnSelection)\r
+ {\r
+ if (currentColumnSelection != null)\r
+ {\r
+ this.oldColumnSelection = new ColumnSelection(currentColumnSelection);\r
+ }\r
+ }\r
+\r
+ public FurtherActionPanel getCurrentFutherActionPanel()\r
+ {\r
+ return currentFurtherActionPanel;\r
+ }\r
+\r
+ public void setCurrentFutherActionPanel(\r
+ FurtherActionPanel currentFutherActionPanel)\r
+ {\r
+ this.currentFurtherActionPanel = currentFutherActionPanel;\r
+ }\r
+\r
+ public SearchPanel getCurrentSearchPanel()\r
+ {\r
+ return currentSearchPanel;\r
+ }\r
+\r
+ public void setCurrentSearchPanel(SearchPanel currentSearchPanel)\r
+ {\r
+ this.currentSearchPanel = currentSearchPanel;\r
+ }\r
+\r
+ public int getActionOption()\r
+ {\r
+ return actionOption;\r
+ }\r
+\r
+ public void setActionOption(int actionOption)\r
+ {\r
+ this.actionOption = actionOption;\r
+ }\r
+\r
+ public StructureFilterPanel getCurrentStructureFilterPanel()\r
+ {\r
+ return currentStructureFilterPanel;\r
+ }\r
+\r
+ public void setCurrentStructureFilterPanel(\r
+ StructureFilterPanel currentStructureFilterPanel)\r
+ {\r
+ this.currentStructureFilterPanel = currentStructureFilterPanel;\r
+ }\r
+\r
+ @Override\r
+ public void itemStateChanged(ItemEvent e)\r
+ {\r
+ if (e.getSource() == annotations)\r
+ {\r
+ selectedAnnotationChanged();\r
+ }\r
+ else if (e.getSource() == threshold)\r
+ {\r
+ threshold_actionPerformed(null);\r
+ }\r
+ }\r
+\r
+ public void selectedAnnotationChanged()\r
+ {\r
+ String currentView = AnnotationColumnChooser.NO_GRAPH_VIEW;\r
+ if (av.getAlignment().getAlignmentAnnotation()[getAnnotations()\r
+ .getSelectedIndex()].graph != AlignmentAnnotation.NO_GRAPH)\r
+ {\r
+ currentView = AnnotationColumnChooser.GRAPH_VIEW;\r
+ }\r
+\r
+ gSearchPanel.syncState();\r
+ gFurtherActionPanel.syncState();\r
+ gStructureFilterPanel.syncState();\r
+\r
+ ngSearchPanel.syncState();\r
+ ngFurtherActionPanel.syncState();\r
+ ngStructureFilterPanel.syncState();\r
+\r
+ switchableViewsLayout.show(switchableViewsPanel, currentView);\r
+ updateView();\r
+ }\r
+\r
+ public class FurtherActionPanel extends Panel implements\r
+ ItemListener\r
+ {\r
+ private AnnotationColumnChooser aColChooser;\r
+\r
+ private Choice furtherAction = new Choice();\r
+\r
+ public FurtherActionPanel(AnnotationColumnChooser aColChooser)\r
+ {\r
+ this.aColChooser = aColChooser;\r
+ furtherAction.addItem("Select");\r
+ furtherAction.addItem("Hide");\r
+ furtherAction.addItemListener(this);\r
+ syncState();\r
+\r
+ // this.setTitle("Filter Actions");\r
+ // this.setFont(JvSwingUtils.getLabelFont());\r
+\r
+ this.add(furtherAction);\r
+ }\r
+\r
+ public void syncState()\r
+ {\r
+ if (aColChooser.getActionOption() == AnnotationColumnChooser.ACTION_OPTION_HIDE)\r
+ {\r
+ furtherAction.select("Hide");\r
+ }\r
+ else\r
+ {\r
+ furtherAction.select("Select");\r
+ }\r
+ }\r
+\r
+ @Override\r
+ public void itemStateChanged(ItemEvent e)\r
+ {\r
+ aColChooser.setCurrentFutherActionPanel(this);\r
+ if (furtherAction.getSelectedItem().equalsIgnoreCase("Select"))\r
+ {\r
+ setActionOption(ACTION_OPTION_SELECT);\r
+ updateView();\r
+ }\r
+ else\r
+ {\r
+ setActionOption(ACTION_OPTION_HIDE);\r
+ updateView();\r
+ }\r
+\r
+ }\r
+ }\r
+\r
+ public class StructureFilterPanel extends TitledPanel implements\r
+ ItemListener\r
+ {\r
+ private AnnotationColumnChooser aColChooser;\r
+\r
+ private Checkbox alphaHelix = new Checkbox();\r
+\r
+ private Checkbox betaStrand = new Checkbox();\r
+\r
+ private Checkbox turn = new Checkbox();\r
+\r
+ private Checkbox all = new Checkbox();\r
+\r
+ public StructureFilterPanel(AnnotationColumnChooser aColChooser)\r
+ {\r
+ this.aColChooser = aColChooser;\r
+\r
+ alphaHelix.setLabel(MessageManager.getString("label.alpha_helix"));\r
+ alphaHelix.setBackground(Color.white);\r
+\r
+ alphaHelix.addItemListener(this);\r
+\r
+ betaStrand.setLabel(MessageManager.getString("label.beta_strand"));\r
+ betaStrand.setBackground(Color.white);\r
+ betaStrand.addItemListener(this);\r
+\r
+ turn.setLabel(MessageManager.getString("label.turn"));\r
+ turn.setBackground(Color.white);\r
+ turn.addItemListener(this);\r
+\r
+ all.setLabel(MessageManager.getString("label.select_all"));\r
+ all.setBackground(Color.white);\r
+ all.addItemListener(this);\r
+\r
+ this.setBackground(Color.white);\r
+ this.setTitle("Structure Filter");\r
+ // this.setFont(JvSwingUtils.getLabelFont());\r
+\r
+ this.add(all);\r
+ this.add(alphaHelix);\r
+ this.add(betaStrand);\r
+ this.add(turn);\r
+ }\r
+\r
+ public void alphaHelix_actionPerformed()\r
+ {\r
+ updateSelectAllState();\r
+ aColChooser.setCurrentStructureFilterPanel(this);\r
+ aColChooser.updateView();\r
+ }\r
+\r
+ public void betaStrand_actionPerformed()\r
+ {\r
+ updateSelectAllState();\r
+ aColChooser.setCurrentStructureFilterPanel(this);\r
+ aColChooser.updateView();\r
+ }\r
+\r
+ public void turn_actionPerformed()\r
+ {\r
+ updateSelectAllState();\r
+ aColChooser.setCurrentStructureFilterPanel(this);\r
+ aColChooser.updateView();\r
+ }\r
+\r
+ public void all_actionPerformed()\r
+ {\r
+ if (all.getState())\r
+ {\r
+ alphaHelix.setState(true);\r
+ betaStrand.setState(true);\r
+ turn.setState(true);\r
+ }\r
+ else\r
+ {\r
+ alphaHelix.setState(false);\r
+ betaStrand.setState(false);\r
+ turn.setState(false);\r
+ }\r
+ aColChooser.setCurrentStructureFilterPanel(this);\r
+ aColChooser.updateView();\r
+ }\r
+\r
+ public void updateSelectAllState()\r
+ {\r
+ if (alphaHelix.getState() && betaStrand.getState() && turn.getState())\r
+ {\r
+ all.setState(true);\r
+ }\r
+ else\r
+ {\r
+ all.setState(false);\r
+ }\r
+ }\r
+\r
+ public void syncState()\r
+ {\r
+ StructureFilterPanel sfp = aColChooser\r
+ .getCurrentStructureFilterPanel();\r
+ if (sfp != null)\r
+ {\r
+ alphaHelix.setState(sfp.alphaHelix.getState());\r
+ betaStrand.setState(sfp.betaStrand.getState());\r
+ turn.setState(sfp.turn.getState());\r
+ if (sfp.all.getState())\r
+ {\r
+ all.setState(true);\r
+ alphaHelix.setState(true);\r
+ betaStrand.setState(true);\r
+ turn.setState(true);\r
+ }\r
+ }\r
+\r
+ }\r
+\r
+ @Override\r
+ public void itemStateChanged(ItemEvent e)\r
+ {\r
+ if (e.getSource() == alphaHelix)\r
+ {\r
+ alphaHelix_actionPerformed();\r
+ }\r
+ else if (e.getSource() == betaStrand)\r
+ {\r
+ betaStrand_actionPerformed();\r
+ }\r
+ else if (e.getSource() == turn)\r
+ {\r
+ turn_actionPerformed();\r
+ }\r
+ else if (e.getSource() == all)\r
+ {\r
+ all_actionPerformed();\r
+ }\r
+ }\r
+ }\r
+\r
+ public class SearchPanel extends TitledPanel implements ItemListener\r
+ {\r
+ private AnnotationColumnChooser aColChooser;\r
+\r
+ private Checkbox displayName = new Checkbox();\r
+\r
+ private Checkbox description = new Checkbox();\r
+\r
+ private TextField searchBox = new TextField(10);\r
+\r
+ public SearchPanel(AnnotationColumnChooser aColChooser)\r
+ {\r
+\r
+ this.aColChooser = aColChooser;\r
+ searchBox.addTextListener(new TextListener()\r
+ {\r
+\r
+ @Override\r
+ public void textValueChanged(TextEvent e)\r
+ {\r
+ searchStringAction();\r
+\r
+ }\r
+\r
+ });\r
+\r
+ displayName.setLabel(MessageManager.getString("label.display_name"));\r
+ displayName.setEnabled(false);\r
+ displayName.addItemListener(this);\r
+\r
+ description.setLabel(MessageManager.getString("label.description"));\r
+ description.setEnabled(false);\r
+ description.addItemListener(this);\r
+ this.setTitle("Search Filter");\r
+ // this.setFont(JvSwingUtils.getLabelFont());\r
+\r
+ syncState();\r
+ this.add(searchBox);\r
+ this.add(displayName);\r
+ this.add(description);\r
+ }\r
+\r
+ public void displayNameCheckboxAction()\r
+ {\r
+ aColChooser.setCurrentSearchPanel(this);\r
+ aColChooser.updateView();\r
+ }\r
+\r
+ public void discriptionCheckboxAction()\r
+ {\r
+ aColChooser.setCurrentSearchPanel(this);\r
+ aColChooser.updateView();\r
+ }\r
+\r
+ public void searchStringAction()\r
+ {\r
+ aColChooser.setCurrentSearchPanel(this);\r
+ aColChooser.updateView();\r
+ }\r
+\r
+ public void syncState()\r
+ {\r
+ SearchPanel sp = aColChooser.getCurrentSearchPanel();\r
+ if (sp != null)\r
+ {\r
+ description.setEnabled(sp.description.isEnabled());\r
+ description.setState(sp.description.getState());\r
+\r
+ displayName.setEnabled(sp.displayName.isEnabled());\r
+ displayName.setState(sp.displayName.getState());\r
+\r
+ searchBox.setText(sp.searchBox.getText());\r
+ }\r
+ }\r
+\r
+ @Override\r
+ public void itemStateChanged(ItemEvent e)\r
+ {\r
+ if (e.getSource() == displayName)\r
+ {\r
+ displayNameCheckboxAction();\r
+ }\r
+ else if (e.getSource() == description)\r
+ {\r
+ discriptionCheckboxAction();\r
+ }\r
+\r
+ }\r
+ }\r
+\r
+ public void actionPerformed(ActionEvent evt)\r
+ {\r
+ if (evt.getSource() == thresholdValue)\r
+ {\r
+ try\r
+ {\r
+ float f = new Float(thresholdValue.getText()).floatValue();\r
+ slider.setValue((int) (f * 1000));\r
+ adjustmentValueChanged(null);\r
+ } catch (NumberFormatException ex)\r
+ {\r
+ }\r
+ }\r
+\r
+ else if (evt.getSource() == ok)\r
+ {\r
+ ok_actionPerformed(null);\r
+ }\r
+ else if (evt.getSource() == cancel)\r
+ {\r
+ cancel_actionPerformed(null);\r
+ }\r
+ else if (evt.getSource() == thresholdValue)\r
+ {\r
+ thresholdValue_actionPerformed(null);\r
+ }\r
+ else\r
+ {\r
+ updateView();\r
+ }\r
+ }\r
+\r
+ @Override\r
+ public void mouseClicked(MouseEvent e)\r
+ {\r
+ // TODO Auto-generated method stub\r
+\r
+ }\r
+\r
+ @Override\r
+ public void mousePressed(MouseEvent e)\r
+ {\r
+ if (e.getSource() == slider)\r
+ {\r
+ updateView();\r
+ }\r
+\r
+ }\r
+\r
+ @Override\r
+ public void mouseReleased(MouseEvent e)\r
+ {\r
+ if (e.getSource() == slider)\r
+ {\r
+ updateView();\r
+ }\r
+ }\r
+\r
+ @Override\r
+ public void mouseEntered(MouseEvent e)\r
+ {\r
+ if (e.getSource() == slider)\r
+ {\r
+ updateView();\r
+ }\r
+ }\r
+\r
+ @Override\r
+ public void mouseExited(MouseEvent e)\r
+ {\r
+ if (e.getSource() == slider)\r
+ {\r
+ updateView();\r
+ }\r
+ }\r
+\r
+}\r