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.border.TitledBorder; @SuppressWarnings("serial") 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; } }