2 * Jalview - A Sequence Alignment Editor and Viewer
\r
3 * Copyright (C) 2005 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
\r
5 * This program is free software; you can redistribute it and/or
\r
6 * modify it under the terms of the GNU General Public License
\r
7 * as published by the Free Software Foundation; either version 2
\r
8 * of the License, or (at your option) any later version.
\r
10 * This program is distributed in the hope that it will be useful,
\r
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
13 * GNU General Public License for more details.
\r
15 * You should have received a copy of the GNU General Public License
\r
16 * along with this program; if not, write to the Free Software
\r
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
\r
20 package jalview.appletgui;
\r
25 import java.awt.event.*;
\r
27 import jalview.datamodel.*;
\r
28 import jalview.schemes.*;
\r
30 public class SliderPanel extends Panel implements ActionListener, AdjustmentListener
\r
33 boolean forConservation = true;
\r
36 static Frame conservationSlider;
\r
37 static Frame PIDSlider;
\r
39 public static int setConservationSlider(AlignmentPanel ap, ColourSchemeI cs,
\r
42 SliderPanel sp = null;
\r
44 if (conservationSlider == null)
\r
46 sp = new SliderPanel(ap, cs.getConservationInc(), true, cs);
\r
47 conservationSlider = new Frame();
\r
48 conservationSlider.add(sp);
\r
52 sp = (SliderPanel) conservationSlider.getComponent(0);
\r
56 conservationSlider.setTitle("Conservation Colour Increment (" + source +
\r
58 if (ap.av.alignment.getGroups() != null)
\r
60 sp.setAllGroupsCheckEnabled(true);
\r
64 sp.setAllGroupsCheckEnabled(false);
\r
67 return sp.getValue();
\r
70 public static void showConservationSlider()
\r
74 PIDSlider.setVisible(false);
\r
77 catch (Exception ex)
\r
80 if (!conservationSlider.isVisible())
\r
82 jalview.bin.JalviewLite.addFrame(conservationSlider,
\r
83 conservationSlider.getTitle(), 420, 100);
\r
84 conservationSlider.addWindowListener(new WindowAdapter()
\r
86 public void windowClosing(WindowEvent e)
\r
88 conservationSlider = null;
\r
96 public static int setPIDSliderSource(AlignmentPanel ap, ColourSchemeI cs,
\r
99 SliderPanel pid = null;
\r
100 if (PIDSlider == null)
\r
102 pid = new SliderPanel(ap, 50, false, cs);
\r
103 PIDSlider = new Frame();
\r
104 PIDSlider.add(pid);
\r
108 pid = (SliderPanel) PIDSlider.getComponent(0);
\r
111 PIDSlider.setTitle("Percentage Identity Threshold (" + source + ")");
\r
113 if (ap.av.alignment.getGroups() != null)
\r
115 pid.setAllGroupsCheckEnabled(true);
\r
119 pid.setAllGroupsCheckEnabled(false);
\r
122 return pid.getValue();
\r
126 public static void showPIDSlider()
\r
130 conservationSlider.setVisible(false);
\r
131 conservationSlider = null;
\r
133 catch (Exception ex)
\r
136 if (!PIDSlider.isVisible())
\r
138 jalview.bin.JalviewLite.addFrame(PIDSlider, PIDSlider.getTitle(), 420,
\r
140 PIDSlider.addWindowListener(new WindowAdapter()
\r
142 public void windowClosing(WindowEvent e)
\r
151 public SliderPanel(AlignmentPanel ap, int value, boolean forConserve,
\r
156 } catch (Exception e) {
\r
157 e.printStackTrace();
\r
161 forConservation = forConserve;
\r
162 undoButton.setVisible(false);
\r
163 applyButton.setVisible(false);
\r
164 if (forConservation)
\r
166 label.setText("Modify conservation visibility");
\r
167 slider.setMinimum(0);
\r
168 slider.setMaximum(50 + slider.getVisibleAmount());
\r
169 slider.setUnitIncrement(1);
\r
173 label.setText("Colour residues above % occurence");
\r
174 slider.setMinimum(0);
\r
175 slider.setMaximum(100 + slider.getVisibleAmount());
\r
176 slider.setBlockIncrement(1);
\r
179 slider.addAdjustmentListener(this);
\r
181 slider.setValue(value);
\r
182 valueField.setText(value + "");
\r
185 public void valueChanged(int i)
\r
192 ColourSchemeI toChange = null;
\r
193 Vector allGroups = null;
\r
194 int groupIndex = 0;
\r
196 if (allGroupsCheck.getState())
\r
198 allGroups = ap.av.alignment.getGroups();
\r
199 groupIndex = allGroups.size() - 1;
\r
206 while (groupIndex > -1)
\r
208 if (allGroups != null)
\r
210 toChange = ( (SequenceGroup) allGroups.elementAt(groupIndex)).cs;
\r
213 if (forConservation)
\r
215 toChange.setConservationInc(i);
\r
219 toChange.setThreshold(i, ap.av.getIgnoreGapsConsensus());
\r
225 ap.seqPanel.seqCanvas.repaint();
\r
229 public void setAllGroupsCheckEnabled(boolean b)
\r
231 allGroupsCheck.setEnabled(b);
\r
234 public void actionPerformed(ActionEvent evt)
\r
236 if(evt.getSource()==applyButton)
\r
237 applyButton_actionPerformed();
\r
238 else if(evt.getSource()==undoButton)
\r
239 undoButton_actionPerformed();
\r
240 else if(evt.getSource()==valueField)
\r
241 valueField_actionPerformed();
\r
244 public void adjustmentValueChanged(AdjustmentEvent evt)
\r
246 valueField.setText(slider.getValue() + "");
\r
247 valueChanged(slider.getValue());
\r
251 public void valueField_actionPerformed()
\r
255 int i = Integer.parseInt(valueField.getText());
\r
256 slider.setValue(i);
\r
258 catch (Exception ex)
\r
260 valueField.setText(slider.getValue() + "");
\r
264 public void setValue(int value)
\r
266 slider.setValue(value);
\r
269 public int getValue()
\r
271 return Integer.parseInt(valueField.getText());
\r
274 // this is used for conservation colours, PID colours and redundancy threshold
\r
275 protected Scrollbar slider = new Scrollbar();
\r
276 protected TextField valueField = new TextField();
\r
277 protected Label label = new Label();
\r
278 Panel jPanel1 = new Panel();
\r
279 Panel jPanel2 = new Panel();
\r
280 protected Button applyButton = new Button();
\r
281 protected Button undoButton = new Button();
\r
282 FlowLayout flowLayout1 = new FlowLayout();
\r
283 protected Checkbox allGroupsCheck = new Checkbox();
\r
284 BorderLayout borderLayout1 = new BorderLayout();
\r
285 BorderLayout borderLayout2 = new BorderLayout();
\r
286 FlowLayout flowLayout2 = new FlowLayout();
\r
288 private void jbInit() throws Exception {
\r
289 this.setLayout(borderLayout2);
\r
291 // slider.setMajorTickSpacing(10);
\r
292 // slider.setMinorTickSpacing(1);
\r
293 // slider.setPaintTicks(true);
\r
294 slider.setBackground(Color.white);
\r
295 slider.setFont(new java.awt.Font("Verdana", 0, 11));
\r
296 slider.setOrientation(0);
\r
297 valueField.setFont(new java.awt.Font("Verdana", 0, 11));
\r
298 valueField.setText(" ");
\r
299 valueField.addActionListener(this);
\r
300 label.setFont(new java.awt.Font("Verdana", 0, 11));
\r
301 label.setText("set this label text");
\r
302 jPanel1.setLayout(borderLayout1);
\r
303 jPanel2.setLayout(flowLayout1);
\r
304 applyButton.setFont(new java.awt.Font("Verdana", 0, 11));
\r
305 applyButton.setLabel("Apply");
\r
306 applyButton.addActionListener(this);
\r
307 undoButton.setEnabled(false);
\r
308 undoButton.setFont(new java.awt.Font("Verdana", 0, 11));
\r
309 undoButton.setLabel("Undo");
\r
310 undoButton.addActionListener(this);
\r
311 allGroupsCheck.setEnabled(false);
\r
312 allGroupsCheck.setFont(new java.awt.Font("Verdana", 0, 11));
\r
313 allGroupsCheck.setLabel("Apply threshold to all groups");
\r
314 allGroupsCheck.setName("Apply to all Groups");
\r
315 this.setBackground(Color.white);
\r
316 this.setForeground(Color.black);
\r
317 jPanel2.add(label, null);
\r
318 jPanel2.add(applyButton, null);
\r
319 jPanel2.add(undoButton, null);
\r
320 jPanel2.add(allGroupsCheck);
\r
321 jPanel1.add(valueField, java.awt.BorderLayout.EAST);
\r
322 jPanel1.add(slider, java.awt.BorderLayout.CENTER);
\r
323 this.add(jPanel1, java.awt.BorderLayout.SOUTH);
\r
324 this.add(jPanel2, java.awt.BorderLayout.CENTER);
\r
327 protected void applyButton_actionPerformed()
\r
331 protected void undoButton_actionPerformed()
\r