JAL-1553 enhancement of column selection by annotation row to include the query filte...
[jalview.git] / src / jalview / jbgui / SearchPanel.java
diff --git a/src/jalview/jbgui/SearchPanel.java b/src/jalview/jbgui/SearchPanel.java
new file mode 100644 (file)
index 0000000..6a58335
--- /dev/null
@@ -0,0 +1,182 @@
+package jalview.jbgui;
+
+import jalview.gui.AnnotationColumnChooser;
+import jalview.gui.JvSwingUtils;
+
+import java.awt.Color;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+
+import javax.swing.JCheckBox;
+import javax.swing.JPanel;
+import javax.swing.JTextField;
+import javax.swing.border.TitledBorder;
+import javax.swing.event.DocumentEvent;
+import javax.swing.event.DocumentListener;
+
+@SuppressWarnings("serial")
+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());
+    }
+  }
+}