X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fjbgui%2FSearchPanel.java;fp=src%2Fjalview%2Fjbgui%2FSearchPanel.java;h=6a583352630bae06512f9fd51bdda8840e311a64;hb=c03d2649512cdc491a46dda1d1370273241b5253;hp=0000000000000000000000000000000000000000;hpb=57b121a5f97c475b3078281ea2e3f3035e2c8703;p=jalview.git diff --git a/src/jalview/jbgui/SearchPanel.java b/src/jalview/jbgui/SearchPanel.java new file mode 100644 index 0000000..6a58335 --- /dev/null +++ b/src/jalview/jbgui/SearchPanel.java @@ -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()); + } + } +}