basic house keeping
[jalview.git] / src / jalview / gui / AnnotationColumnChooser.java
index 3db148d..31b5b64 100644 (file)
@@ -1,11 +1,8 @@
 package jalview.gui;
 
+import jalview.api.analysis.AnnotationFilterParameter;
 import jalview.datamodel.AlignmentAnnotation;
-import jalview.datamodel.AnnotationFilterParameter;
 import jalview.datamodel.ColumnSelection;
-import jalview.jbgui.FurtherActionPanel;
-import jalview.jbgui.SearchPanel;
-import jalview.jbgui.StructureFilterPanel;
 import jalview.schemes.AnnotationColourGradient;
 import jalview.util.MessageManager;
 
@@ -19,14 +16,19 @@ import java.awt.event.ItemEvent;
 import java.awt.event.ItemListener;
 import java.util.Iterator;
 
+import javax.swing.ButtonGroup;
 import javax.swing.JButton;
+import javax.swing.JCheckBox;
 import javax.swing.JComboBox;
 import javax.swing.JInternalFrame;
 import javax.swing.JLabel;
 import javax.swing.JLayeredPane;
 import javax.swing.JPanel;
 import javax.swing.JRadioButton;
+import javax.swing.JTextField;
 import javax.swing.border.TitledBorder;
+import javax.swing.event.DocumentEvent;
+import javax.swing.event.DocumentListener;
 
 import net.miginfocom.swing.MigLayout;
 
@@ -35,40 +37,38 @@ public class AnnotationColumnChooser extends AnnotationRowFilter implements
         ItemListener
 {
 
-  private ColumnSelection oldColumnSelection;
-
   private JComboBox<String> annotations;
 
-  JButton ok = new JButton();
+  private JButton ok = new JButton();
 
-  JButton cancel = new JButton();
+  private JButton cancel = new JButton();
 
-  JPanel actionPanel = new JPanel();
+  private JPanel actionPanel = new JPanel();
 
-  JPanel thresholdPanel = new JPanel();
+  private JPanel thresholdPanel = new JPanel();
 
-  JPanel switchableViewsPanel = new JPanel(new CardLayout());
+  private JPanel switchableViewsPanel = new JPanel(new CardLayout());
 
-  CardLayout switchableViewsLayout = (CardLayout) (switchableViewsPanel
+  private CardLayout switchableViewsLayout = (CardLayout) (switchableViewsPanel
           .getLayout());
 
-  JPanel noGraphFilterView = new JPanel();
+  private JPanel noGraphFilterView = new JPanel();
 
-  JPanel graphFilterView = new JPanel();
+  private JPanel graphFilterView = new JPanel();
 
-  JPanel annotationComboBoxPanel = new JPanel();
+  private JPanel annotationComboBoxPanel = new JPanel();
 
-  StructureFilterPanel gStructureFilterPanel;
+  private JLabel annotationLabel = new JLabel();
 
-  StructureFilterPanel ngStructureFilterPanel;
+  private BorderLayout borderLayout1 = new BorderLayout();
 
-  private StructureFilterPanel currentStructureFilterPanel;
+  private JComboBox<String> threshold = new JComboBox<String>();
 
-  JLabel annotationLabel = new JLabel();
+  private StructureFilterPanel gStructureFilterPanel;
 
-  BorderLayout borderLayout1 = new BorderLayout();
+  private StructureFilterPanel ngStructureFilterPanel;
 
-  private JComboBox<String> threshold = new JComboBox<String>();
+  private StructureFilterPanel currentStructureFilterPanel;
 
   private SearchPanel currentSearchPanel;
 
@@ -92,6 +92,19 @@ public class AnnotationColumnChooser extends AnnotationRowFilter implements
 
   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);
@@ -115,7 +128,7 @@ public class AnnotationColumnChooser extends AnnotationRowFilter implements
     setAnnotations(new JComboBox<String>(getAnnotationItems(false)));
     populateThresholdComboBox(threshold);
 
-    // restore the Object state from the previous session if one exists
+    // restore Object state from the previous session if one exists
     if (av.getAnnotationColumnSelectionState() != null)
     {
       currentSearchPanel = av.getAnnotationColumnSelectionState()
@@ -128,7 +141,6 @@ public class AnnotationColumnChooser extends AnnotationRowFilter implements
               .getThreshold().getSelectedIndex());
       actionOption = av.getAnnotationColumnSelectionState()
               .getActionOption();
-
     }
 
     try
@@ -144,17 +156,6 @@ public class AnnotationColumnChooser extends AnnotationRowFilter implements
     frame.pack();
   }
 
-  public AnnotationColumnChooser()
-  {
-    try
-    {
-      jbInit();
-    } catch (Exception ex)
-    {
-      ex.printStackTrace();
-    }
-  }
-
   private void jbInit() throws Exception
   {
     ok.setOpaque(false);
@@ -167,6 +168,7 @@ public class AnnotationColumnChooser extends AnnotationRowFilter implements
         ok_actionPerformed(e);
       }
     });
+
     cancel.setOpaque(false);
     cancel.setText(MessageManager.getString("action.cancel"));
     cancel.addActionListener(new ActionListener()
@@ -178,8 +180,8 @@ public class AnnotationColumnChooser extends AnnotationRowFilter implements
       }
     });
 
-    getAnnotations().addItemListener(this);
-    getThreshold().addActionListener(new ActionListener()
+    annotations.addItemListener(this);
+    threshold.addActionListener(new ActionListener()
     {
       @Override
       public void actionPerformed(ActionEvent e)
@@ -188,6 +190,8 @@ public class AnnotationColumnChooser extends AnnotationRowFilter implements
       }
     });
 
+    thresholdValue.setEnabled(false);
+    thresholdValue.setColumns(7);
     thresholdValue.addActionListener(new ActionListener()
     {
       @Override
@@ -196,14 +200,13 @@ public class AnnotationColumnChooser extends AnnotationRowFilter implements
         thresholdValue_actionPerformed(e);
       }
     });
+
     slider.setPaintLabels(false);
     slider.setPaintTicks(true);
     slider.setBackground(Color.white);
     slider.setEnabled(false);
     slider.setOpaque(false);
     slider.setPreferredSize(new Dimension(100, 32));
-    thresholdValue.setEnabled(false);
-    thresholdValue.setColumns(7);
 
     annotationLabel.setBackground(Color.white);
     annotationLabel.setFont(JvSwingUtils.getLabelFont());
@@ -217,7 +220,6 @@ public class AnnotationColumnChooser extends AnnotationRowFilter implements
     actionPanel.setBackground(Color.white);
     actionPanel.setFont(JvSwingUtils.getLabelFont());
 
-    this.setLayout(borderLayout1);
     graphFilterView.setLayout(new MigLayout("", "[left][right]", "[][]"));
     graphFilterView.setBackground(Color.white);
 
@@ -233,7 +235,6 @@ public class AnnotationColumnChooser extends AnnotationRowFilter implements
     gStructureFilterPanel = new StructureFilterPanel(this);
     ngStructureFilterPanel = new StructureFilterPanel(this);
 
-
     thresholdPanel.add(getThreshold());
     thresholdPanel.add(thresholdValue, "wrap");
     thresholdPanel.add(slider, "grow, span, wrap");
@@ -256,6 +257,7 @@ public class AnnotationColumnChooser extends AnnotationRowFilter implements
     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);
@@ -288,7 +290,6 @@ public class AnnotationColumnChooser extends AnnotationRowFilter implements
         }
         av.setColumnSelection(oldSelection);
       }
-      // ap.alignmentChanged();
       ap.paintAlignment(true);
     }
 
@@ -464,7 +465,6 @@ public class AnnotationColumnChooser extends AnnotationRowFilter implements
     }
   }
 
-
   public void select_action(ActionEvent actionEvent)
   {
     JRadioButton radioButton = (JRadioButton) actionEvent.getSource();
@@ -485,7 +485,6 @@ public class AnnotationColumnChooser extends AnnotationRowFilter implements
     }
   }
 
-
   @Override
   public void itemStateChanged(ItemEvent e)
   {
@@ -500,25 +499,19 @@ public class AnnotationColumnChooser extends AnnotationRowFilter implements
     {
       currentView = AnnotationColumnChooser.GRAPH_VIEW;
     }
-    // else{
-    // threshold.setSelectedIndex(AlignmentAnnotation.NO_GRAPH);
-    // }
-    
+
     gSearchPanel.syncState();
     gFurtherActionPanel.syncState();
-    gFurtherActionPanel.syncState();
-    gFurtherActionPanel.syncState();
+    gStructureFilterPanel.syncState();
 
     ngSearchPanel.syncState();
     ngFurtherActionPanel.syncState();
     ngStructureFilterPanel.syncState();
-    ngFurtherActionPanel.syncState();
 
     switchableViewsLayout.show(switchableViewsPanel, currentView);
     updateView();
   }
 
-  
   public FurtherActionPanel getCurrentFutherActionPanel()
   {
     return currentFurtherActionPanel;
@@ -561,4 +554,463 @@ public class AnnotationColumnChooser extends AnnotationRowFilter implements
     this.currentStructureFilterPanel = currentStructureFilterPanel;
   }
 
+  public class FurtherActionPanel extends JPanel
+  {
+    private AnnotationColumnChooser aColChooser;
+
+    private JRadioButton hideOption = new JRadioButton();
+
+    private JRadioButton selectOption = new JRadioButton();
+
+    private ButtonGroup optionsGroup = new ButtonGroup();
+
+    public FurtherActionPanel(AnnotationColumnChooser aColChooser)
+    {
+      this.aColChooser = aColChooser;
+      getSelectOption().setBackground(Color.white);
+      getSelectOption().setFont(JvSwingUtils.getLabelFont());
+      getSelectOption().setText("Select");
+      getSelectOption().addActionListener(new ActionListener()
+      {
+        @Override
+        public void actionPerformed(ActionEvent actionEvent)
+        {
+          selectRadioAction(actionEvent);
+        }
+      });
+
+      getHideOption().setBackground(Color.white);
+      getHideOption().setFont(JvSwingUtils.getLabelFont());
+      getHideOption().setText("Hide");
+      getHideOption().addActionListener(new ActionListener()
+      {
+        @Override
+        public void actionPerformed(ActionEvent actionEvent)
+        {
+          hideRadioAction(actionEvent);
+        }
+      });
+
+      getOptionsGroup().add(getSelectOption());
+      getOptionsGroup().add(getHideOption());
+      getOptionsGroup().setSelected(getSelectOption().getModel(), true);
+
+      this.setBackground(Color.white);
+      this.setFont(JvSwingUtils.getLabelFont());
+      syncState();
+
+      this.add(getSelectOption());
+      this.add(getHideOption());
+    }
+
+    public void selectRadioAction(ActionEvent actionEvent)
+    {
+      aColChooser.setCurrentFutherActionPanel(this);
+      aColChooser.select_action(actionEvent);
+    }
+
+    public void hideRadioAction(ActionEvent actionEvent)
+    {
+      aColChooser.setCurrentFutherActionPanel(this);
+      aColChooser.hide_action(actionEvent);
+    }
+
+    public JRadioButton getHideOption()
+    {
+      return hideOption;
+    }
+
+    public void setHideOption(JRadioButton hideOption)
+    {
+      this.hideOption = hideOption;
+    }
+
+    public JRadioButton getSelectOption()
+    {
+      return selectOption;
+    }
+
+    public void setSelectOption(JRadioButton selectOption)
+    {
+      this.selectOption = selectOption;
+    }
+
+    public ButtonGroup getOptionsGroup()
+    {
+      return optionsGroup;
+    }
+
+    public void setOptionsGroup(ButtonGroup optionsGroup)
+    {
+      this.optionsGroup = optionsGroup;
+    }
+
+    public void syncState()
+    {
+      if (aColChooser.getActionOption() == AnnotationColumnChooser.ACTION_OPTION_HIDE)
+      {
+        this.getOptionsGroup().setSelected(this.getHideOption().getModel(),
+                true);
+      }
+      else
+      {
+        this.getOptionsGroup().setSelected(
+                this.getSelectOption().getModel(), true);
+      }
+    }
+  }
+
+  public class StructureFilterPanel extends JPanel
+  {
+    private AnnotationColumnChooser aColChooser;
+
+    private JCheckBox alphaHelix = new JCheckBox();
+
+    private JCheckBox betaStrand = new JCheckBox();
+
+    private JCheckBox turn = new JCheckBox();
+
+    private JCheckBox all = new JCheckBox();
+
+    public StructureFilterPanel(AnnotationColumnChooser aColChooser)
+    {
+      this.aColChooser = aColChooser;
+
+      alphaHelix.setBackground(Color.white);
+      alphaHelix.setFont(JvSwingUtils.getLabelFont());
+      alphaHelix.setText("Alpha Helix");
+      alphaHelix.addActionListener(new ActionListener()
+      {
+        @Override
+        public void actionPerformed(ActionEvent actionEvent)
+        {
+          alphaHelix_actionPerformed();
+        }
+      });
+
+      betaStrand.setBackground(Color.white);
+      betaStrand.setFont(JvSwingUtils.getLabelFont());
+      betaStrand.setText("Beta Strand");
+      betaStrand.addActionListener(new ActionListener()
+      {
+        @Override
+        public void actionPerformed(ActionEvent actionEvent)
+        {
+          betaStrand_actionPerformed();
+        }
+      });
+
+      turn.setBackground(Color.white);
+      turn.setFont(JvSwingUtils.getLabelFont());
+      turn.setText("Turn");
+      turn.addActionListener(new ActionListener()
+      {
+        @Override
+        public void actionPerformed(ActionEvent actionEvent)
+        {
+          turn_actionPerformed();
+        }
+      });
+
+      all.setBackground(Color.white);
+      all.setFont(JvSwingUtils.getLabelFont());
+      all.setText("Select all");
+      all.addActionListener(new ActionListener()
+      {
+        @Override
+        public void actionPerformed(ActionEvent actionEvent)
+        {
+          all_actionPerformed();
+        }
+      });
+
+      this.setBorder(new TitledBorder("Structures Filter"));
+      this.setBackground(Color.white);
+      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.isSelected())
+      {
+        alphaHelix.setSelected(true);
+        betaStrand.setSelected(true);
+        turn.setSelected(true);
+      }
+      else
+      {
+        alphaHelix.setSelected(false);
+        betaStrand.setSelected(false);
+        turn.setSelected(false);
+      }
+      aColChooser.setCurrentStructureFilterPanel(this);
+      aColChooser.updateView();
+    }
+
+    public void updateSelectAllState()
+    {
+      if (alphaHelix.isSelected() && betaStrand.isSelected()
+              && turn.isSelected())
+      {
+        all.setSelected(true);
+      }
+      else
+      {
+        all.setSelected(false);
+      }
+    }
+
+    public void syncState()
+    {
+      StructureFilterPanel sfp = aColChooser
+              .getCurrentStructureFilterPanel();
+      if (sfp != null)
+      {
+        alphaHelix.setSelected(sfp.getAlphaHelix().isSelected());
+        betaStrand.setSelected(sfp.getBetaStrand().isSelected());
+        turn.setSelected(sfp.getTurn().isSelected());
+        if (sfp.getAll().isSelected())
+        {
+          all.setSelected(true);
+          alphaHelix.setSelected(true);
+          betaStrand.setSelected(true);
+          turn.setSelected(true);
+        }
+      }
+
+    }
+
+    public JCheckBox getAlphaHelix()
+    {
+      return alphaHelix;
+    }
+
+    public void setAlphaHelix(JCheckBox alphaHelix)
+    {
+      this.alphaHelix = alphaHelix;
+    }
+
+    public JCheckBox getBetaStrand()
+    {
+      return betaStrand;
+    }
+
+    public void setBetaStrand(JCheckBox betaStrand)
+    {
+      this.betaStrand = betaStrand;
+    }
+
+    public JCheckBox getTurn()
+    {
+      return turn;
+    }
+
+    public void setTurn(JCheckBox turn)
+    {
+      this.turn = turn;
+    }
+
+    public JCheckBox getAll()
+    {
+      return all;
+    }
+
+    public void setAll(JCheckBox all)
+    {
+      this.all = all;
+
+    }
+  }
+
+  public class SearchPanel extends JPanel
+  {
+    private AnnotationColumnChooser aColChooser;
+
+    private JCheckBox displayName = new JCheckBox();
+
+    private JCheckBox description = new JCheckBox();
+
+    private JTextField searchBox = new JTextField(10);
+
+    private JCheckBox structuresFilter = new JCheckBox();
+
+    public SearchPanel(AnnotationColumnChooser aColChooser)
+    {
+
+      this.aColChooser = aColChooser;
+      this.setBorder(new TitledBorder("Search Filter"));
+      this.setBackground(Color.white);
+      this.setFont(JvSwingUtils.getLabelFont());
+
+      getSearchBox().setBackground(Color.white);
+      getSearchBox().setFont(JvSwingUtils.getLabelFont());
+      getSearchBox().getDocument().addDocumentListener(
+              new DocumentListener()
+              {
+                @Override
+                public void insertUpdate(DocumentEvent e)
+                {
+                  searchStringAction();
+                }
+
+                @Override
+                public void removeUpdate(DocumentEvent e)
+                {
+                  searchStringAction();
+                }
+
+                @Override
+                public void changedUpdate(DocumentEvent e)
+                {
+                  searchStringAction();
+                }
+              });
+
+      getDisplayName().setBackground(Color.white);
+      getDisplayName().setFont(JvSwingUtils.getLabelFont());
+      getDisplayName().setText("Display Name");
+      getDisplayName().setEnabled(false);
+      getDisplayName().addActionListener(new ActionListener()
+      {
+        @Override
+        public void actionPerformed(ActionEvent actionEvent)
+        {
+          displayNameCheckboxAction();
+        }
+      });
+
+      getDescription().setBackground(Color.white);
+      getDescription().setFont(JvSwingUtils.getLabelFont());
+      getDescription().setText("Description");
+      getDescription().setEnabled(false);
+      getDescription().addActionListener(new ActionListener()
+      {
+        @Override
+        public void actionPerformed(ActionEvent actionEvent)
+        {
+          discriptionCheckboxAction();
+        }
+      });
+
+      syncState();
+      this.add(getSearchBox());
+      this.add(getDisplayName());
+      this.add(getDescription());
+    }
+
+    public boolean isDescriptionChecked()
+    {
+      return getDescription().isSelected();
+    }
+
+    public boolean isDisplayNameChecked()
+    {
+      return getDisplayName().isSelected();
+    }
+
+    public String getSearchString()
+    {
+      return getSearchBox().getText();
+    }
+
+    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 JCheckBox getDisplayName()
+    {
+      return displayName;
+    }
+
+    public void setDisplayName(JCheckBox displayName)
+    {
+      this.displayName = displayName;
+    }
+
+    public JCheckBox getDescription()
+    {
+      return description;
+    }
+
+    public void setDescription(JCheckBox description)
+    {
+      this.description = description;
+    }
+
+    public JTextField getSearchBox()
+    {
+      return searchBox;
+    }
+
+    public void setSearchBox(JTextField searchBox)
+    {
+      this.searchBox = searchBox;
+    }
+
+    public JCheckBox getStructuresFilter()
+    {
+      return structuresFilter;
+    }
+
+    public void setStructuresFilter(JCheckBox structuresFilter)
+    {
+      this.structuresFilter = structuresFilter;
+    }
+
+    public void syncState()
+    {
+      SearchPanel sp = aColChooser.getCurrentSearchPanel();
+      if (sp != null)
+      {
+        description.setEnabled(sp.getDescription().isEnabled());
+        description.setSelected(sp.getDescription().isSelected());
+
+        displayName.setEnabled(sp.getDisplayName().isEnabled());
+        displayName.setSelected(sp.getDisplayName().isSelected());
+
+        searchBox.setText(sp.getSearchBox().getText());
+      }
+    }
+  }
+
 }