2 * Jalview - A Sequence Alignment Editor and Viewer
3 * Copyright (C) 2006 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
20 package jalview.appletgui;
25 import java.awt.event.*;
27 import jalview.datamodel.*;
28 import jalview.schemes.*;
30 public class SliderPanel extends Panel
31 implements ActionListener,
36 boolean forConservation = true;
39 static Frame conservationSlider;
40 static Frame PIDSlider;
42 public static int setConservationSlider(AlignmentPanel ap, ColourSchemeI cs,
45 SliderPanel sp = null;
47 if (conservationSlider == null)
49 sp = new SliderPanel(ap, cs.getConservationInc(), true, cs);
50 conservationSlider = new Frame();
51 conservationSlider.add(sp);
55 sp = (SliderPanel) conservationSlider.getComponent(0);
59 conservationSlider.setTitle("Conservation Colour Increment (" + source +
61 if (ap.av.alignment.getGroups() != null)
63 sp.setAllGroupsCheckEnabled(true);
67 sp.setAllGroupsCheckEnabled(false);
73 public static void showConservationSlider()
77 PIDSlider.setVisible(false);
83 if (!conservationSlider.isVisible())
85 jalview.bin.JalviewLite.addFrame(conservationSlider,
86 conservationSlider.getTitle(), 420, 100);
87 conservationSlider.addWindowListener(new WindowAdapter()
89 public void windowClosing(WindowEvent e)
91 conservationSlider = null;
99 public static int setPIDSliderSource(AlignmentPanel ap, ColourSchemeI cs,
102 SliderPanel pid = null;
103 if (PIDSlider == null)
105 pid = new SliderPanel(ap, 50, false, cs);
106 PIDSlider = new Frame();
111 pid = (SliderPanel) PIDSlider.getComponent(0);
114 PIDSlider.setTitle("Percentage Identity Threshold (" + source + ")");
116 if (ap.av.alignment.getGroups() != null)
118 pid.setAllGroupsCheckEnabled(true);
122 pid.setAllGroupsCheckEnabled(false);
125 return pid.getValue();
129 public static void showPIDSlider()
133 conservationSlider.setVisible(false);
134 conservationSlider = null;
139 if (!PIDSlider.isVisible())
141 jalview.bin.JalviewLite.addFrame(PIDSlider, PIDSlider.getTitle(), 420,
143 PIDSlider.addWindowListener(new WindowAdapter()
145 public void windowClosing(WindowEvent e)
154 public SliderPanel(AlignmentPanel ap, int value, boolean forConserve,
159 } catch (Exception e) {
164 forConservation = forConserve;
165 undoButton.setVisible(false);
166 applyButton.setVisible(false);
169 label.setText("Modify conservation visibility");
170 slider.setMinimum(0);
171 slider.setMaximum(50 + slider.getVisibleAmount());
172 slider.setUnitIncrement(1);
176 label.setText("Colour residues above % occurence");
177 slider.setMinimum(0);
178 slider.setMaximum(100 + slider.getVisibleAmount());
179 slider.setBlockIncrement(1);
182 slider.addAdjustmentListener(this);
183 slider.addMouseListener(this);
185 slider.setValue(value);
186 valueField.setText(value + "");
189 public void valueChanged(int i)
196 ColourSchemeI toChange = null;
197 Vector allGroups = null;
200 if (allGroupsCheck.getState())
202 allGroups = ap.av.alignment.getGroups();
203 groupIndex = allGroups.size() - 1;
210 while (groupIndex > -1)
212 if (allGroups != null)
214 toChange = ( (SequenceGroup) allGroups.elementAt(groupIndex)).cs;
219 toChange.setConservationInc(i);
223 toChange.setThreshold(i, ap.av.getIgnoreGapsConsensus());
229 ap.seqPanel.seqCanvas.repaint();
233 public void setAllGroupsCheckEnabled(boolean b)
235 allGroupsCheck.setEnabled(b);
238 public void actionPerformed(ActionEvent evt)
240 if(evt.getSource()==applyButton)
241 applyButton_actionPerformed();
242 else if(evt.getSource()==undoButton)
243 undoButton_actionPerformed();
244 else if(evt.getSource()==valueField)
245 valueField_actionPerformed();
248 public void adjustmentValueChanged(AdjustmentEvent evt)
250 valueField.setText(slider.getValue() + "");
251 valueChanged(slider.getValue());
255 public void valueField_actionPerformed()
259 int i = Integer.parseInt(valueField.getText());
264 valueField.setText(slider.getValue() + "");
268 public void setValue(int value)
270 slider.setValue(value);
273 public int getValue()
275 return Integer.parseInt(valueField.getText());
278 // this is used for conservation colours, PID colours and redundancy threshold
279 protected Scrollbar slider = new Scrollbar();
280 protected TextField valueField = new TextField();
281 protected Label label = new Label();
282 Panel jPanel1 = new Panel();
283 Panel jPanel2 = new Panel();
284 protected Button applyButton = new Button();
285 protected Button undoButton = new Button();
286 FlowLayout flowLayout1 = new FlowLayout();
287 protected Checkbox allGroupsCheck = new Checkbox();
288 BorderLayout borderLayout1 = new BorderLayout();
289 BorderLayout borderLayout2 = new BorderLayout();
290 FlowLayout flowLayout2 = new FlowLayout();
292 private void jbInit() throws Exception {
293 this.setLayout(borderLayout2);
295 // slider.setMajorTickSpacing(10);
296 // slider.setMinorTickSpacing(1);
297 // slider.setPaintTicks(true);
298 slider.setBackground(Color.white);
299 slider.setFont(new java.awt.Font("Verdana", 0, 11));
300 slider.setOrientation(0);
301 valueField.setFont(new java.awt.Font("Verdana", 0, 11));
302 valueField.setText(" ");
303 valueField.addActionListener(this);
304 label.setFont(new java.awt.Font("Verdana", 0, 11));
305 label.setText("set this label text");
306 jPanel1.setLayout(borderLayout1);
307 jPanel2.setLayout(flowLayout1);
308 applyButton.setFont(new java.awt.Font("Verdana", 0, 11));
309 applyButton.setLabel("Apply");
310 applyButton.addActionListener(this);
311 undoButton.setEnabled(false);
312 undoButton.setFont(new java.awt.Font("Verdana", 0, 11));
313 undoButton.setLabel("Undo");
314 undoButton.addActionListener(this);
315 allGroupsCheck.setEnabled(false);
316 allGroupsCheck.setFont(new java.awt.Font("Verdana", 0, 11));
317 allGroupsCheck.setLabel("Apply threshold to all groups");
318 allGroupsCheck.setName("Apply to all Groups");
319 this.setBackground(Color.white);
320 this.setForeground(Color.black);
321 jPanel2.add(label, null);
322 jPanel2.add(applyButton, null);
323 jPanel2.add(undoButton, null);
324 jPanel2.add(allGroupsCheck);
325 jPanel1.add(valueField, java.awt.BorderLayout.EAST);
326 jPanel1.add(slider, java.awt.BorderLayout.CENTER);
327 this.add(jPanel1, java.awt.BorderLayout.SOUTH);
328 this.add(jPanel2, java.awt.BorderLayout.CENTER);
331 protected void applyButton_actionPerformed()
334 protected void undoButton_actionPerformed()
337 public void mousePressed(MouseEvent evt)
340 public void mouseReleased(MouseEvent evt)
342 if (ap.overviewPanel != null)
343 ap.overviewPanel.updateOverviewImage();
345 public void mouseClicked(MouseEvent evt)
347 public void mouseEntered(MouseEvent evt)
349 public void mouseExited(MouseEvent evt)