ae3c161a198209506d1720cd7ec5a932fd22d775
[jalview.git] / src / jalview / jbgui / StructureFilterPanel.java
1 package jalview.jbgui;
2
3 import jalview.gui.AnnotationColumnChooser;
4 import jalview.gui.JvSwingUtils;
5
6 import java.awt.Color;
7 import java.awt.event.ActionEvent;
8 import java.awt.event.ActionListener;
9
10 import javax.swing.JCheckBox;
11 import javax.swing.JPanel;
12 import javax.swing.border.TitledBorder;
13
14 @SuppressWarnings("serial")
15 public class StructureFilterPanel extends JPanel
16 {
17   private AnnotationColumnChooser aColChooser;
18
19   private JCheckBox alphaHelix = new JCheckBox();
20
21   private JCheckBox betaStrand = new JCheckBox();
22
23   private JCheckBox turn = new JCheckBox();
24
25   private JCheckBox all = new JCheckBox();
26
27   public StructureFilterPanel(AnnotationColumnChooser aColChooser)
28   {
29     this.aColChooser = aColChooser;
30
31     alphaHelix.setBackground(Color.white);
32     alphaHelix.setFont(JvSwingUtils.getLabelFont());
33     alphaHelix.setText("Alpha Helix");
34     alphaHelix.addActionListener(new ActionListener()
35     {
36       @Override
37       public void actionPerformed(ActionEvent actionEvent)
38       {
39         alphaHelix_actionPerformed();
40       }
41     });
42
43     betaStrand.setBackground(Color.white);
44     betaStrand.setFont(JvSwingUtils.getLabelFont());
45     betaStrand.setText("Beta Strand");
46     betaStrand.addActionListener(new ActionListener()
47     {
48       @Override
49       public void actionPerformed(ActionEvent actionEvent)
50       {
51         betaStrand_actionPerformed();
52       }
53     });
54
55     turn.setBackground(Color.white);
56     turn.setFont(JvSwingUtils.getLabelFont());
57     turn.setText("Turn");
58     turn.addActionListener(new ActionListener()
59     {
60       @Override
61       public void actionPerformed(ActionEvent actionEvent)
62       {
63         turn_actionPerformed();
64       }
65     });
66
67     all.setBackground(Color.white);
68     all.setFont(JvSwingUtils.getLabelFont());
69     all.setText("Select all");
70     all.addActionListener(new ActionListener()
71     {
72       @Override
73       public void actionPerformed(ActionEvent actionEvent)
74       {
75         all_actionPerformed();
76       }
77     });
78
79     this.setBorder(new TitledBorder("Structures Filter"));
80     this.setBackground(Color.white);
81     this.setFont(JvSwingUtils.getLabelFont());
82
83     this.add(all);
84     this.add(alphaHelix);
85     this.add(betaStrand);
86     this.add(turn);
87   }
88
89   public void alphaHelix_actionPerformed()
90   {
91     updateSelectAllState();
92     aColChooser.setCurrentStructureFilterPanel(this);
93     aColChooser.updateView();
94   }
95
96   public void betaStrand_actionPerformed()
97   {
98     updateSelectAllState();
99     aColChooser.setCurrentStructureFilterPanel(this);
100     aColChooser.updateView();
101   }
102
103   public void turn_actionPerformed()
104   {
105     updateSelectAllState();
106     aColChooser.setCurrentStructureFilterPanel(this);
107     aColChooser.updateView();
108   }
109
110   public void all_actionPerformed()
111   {
112     if (all.isSelected())
113     {
114       alphaHelix.setSelected(true);
115       betaStrand.setSelected(true);
116       turn.setSelected(true);
117     }
118     else
119     {
120       alphaHelix.setSelected(false);
121       betaStrand.setSelected(false);
122       turn.setSelected(false);
123     }
124     aColChooser.setCurrentStructureFilterPanel(this);
125     aColChooser.updateView();
126   }
127
128   public void updateSelectAllState()
129   {
130     if (alphaHelix.isSelected() && betaStrand.isSelected()
131             && turn.isSelected())
132     {
133       all.setSelected(true);
134     }
135     else
136     {
137       all.setSelected(false);
138     }
139   }
140
141   public void syncState()
142   {
143     StructureFilterPanel sfp = aColChooser.getCurrentStructureFilterPanel();
144     if (sfp != null)
145     {
146       alphaHelix.setSelected(sfp.getAlphaHelix().isSelected());
147       betaStrand.setSelected(sfp.getBetaStrand().isSelected());
148       turn.setSelected(sfp.getTurn().isSelected());
149       if (sfp.getAll().isSelected())
150       {
151         all.setSelected(true);
152         alphaHelix.setSelected(true);
153         betaStrand.setSelected(true);
154         turn.setSelected(true);
155       }
156     }
157
158   }
159
160   public JCheckBox getAlphaHelix()
161   {
162     return alphaHelix;
163   }
164
165   public void setAlphaHelix(JCheckBox alphaHelix)
166   {
167     this.alphaHelix = alphaHelix;
168   }
169
170   public JCheckBox getBetaStrand()
171   {
172     return betaStrand;
173   }
174
175   public void setBetaStrand(JCheckBox betaStrand)
176   {
177     this.betaStrand = betaStrand;
178   }
179
180   public JCheckBox getTurn()
181   {
182     return turn;
183   }
184
185   public void setTurn(JCheckBox turn)
186   {
187     this.turn = turn;
188   }
189
190   public JCheckBox getAll()
191   {
192     return all;
193   }
194
195   public void setAll(JCheckBox all)
196   {
197     this.all = all;
198
199   }
200 }