2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.7)
3 * Copyright (C) 2011 J Procter, AM Waterhouse, J Engelhardt, LM Lui, G Barton, M Clamp, S Searle
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
11 * Jalview is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty
13 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 * PURPOSE. See the GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along with Jalview. If not, see <http://www.gnu.org/licenses/>.
18 package jalview.appletgui;
23 import java.awt.event.*;
25 import jalview.datamodel.*;
26 import jalview.schemes.*;
28 public class SliderPanel extends Panel implements ActionListener,
29 AdjustmentListener, MouseListener
33 boolean forConservation = true;
37 static Frame conservationSlider;
39 static Frame PIDSlider;
41 public static int setConservationSlider(AlignmentPanel ap,
42 ColourSchemeI cs, String source)
44 SliderPanel sp = null;
46 if (conservationSlider == null)
48 sp = new SliderPanel(ap, cs.getConservationInc(), true, cs);
49 conservationSlider = new Frame();
50 conservationSlider.add(sp);
54 sp = (SliderPanel) conservationSlider.getComponent(0);
58 conservationSlider.setTitle("Conservation Colour Increment (" + source
60 if (ap.av.getAlignment().getGroups() != null)
62 sp.setAllGroupsCheckEnabled(true);
66 sp.setAllGroupsCheckEnabled(false);
72 public static void showConservationSlider()
76 PIDSlider.setVisible(false);
78 } catch (Exception ex)
82 if (!conservationSlider.isVisible())
84 jalview.bin.JalviewLite.addFrame(conservationSlider,
85 conservationSlider.getTitle(), 420, 100);
86 conservationSlider.addWindowListener(new WindowAdapter()
88 public void windowClosing(WindowEvent e)
90 conservationSlider = null;
98 public static int setPIDSliderSource(AlignmentPanel ap, ColourSchemeI cs,
101 SliderPanel pid = null;
102 if (PIDSlider == null)
104 pid = new SliderPanel(ap, 50, false, cs);
105 PIDSlider = new Frame();
110 pid = (SliderPanel) PIDSlider.getComponent(0);
113 PIDSlider.setTitle("Percentage Identity Threshold (" + source + ")");
115 if (ap.av.getAlignment().getGroups() != null)
117 pid.setAllGroupsCheckEnabled(true);
121 pid.setAllGroupsCheckEnabled(false);
124 return pid.getValue();
128 public static void showPIDSlider()
132 conservationSlider.setVisible(false);
133 conservationSlider = null;
134 } catch (Exception ex)
138 if (!PIDSlider.isVisible())
140 jalview.bin.JalviewLite.addFrame(PIDSlider, PIDSlider.getTitle(),
142 PIDSlider.addWindowListener(new WindowAdapter()
144 public void windowClosing(WindowEvent e)
153 public SliderPanel(AlignmentPanel ap, int value, boolean forConserve,
159 } catch (Exception e)
165 forConservation = forConserve;
166 undoButton.setVisible(false);
167 applyButton.setVisible(false);
170 label.setText("Modify conservation visibility");
171 slider.setMinimum(0);
172 slider.setMaximum(50 + slider.getVisibleAmount());
173 slider.setUnitIncrement(1);
177 label.setText("Colour residues above % occurence");
178 slider.setMinimum(0);
179 slider.setMaximum(100 + slider.getVisibleAmount());
180 slider.setBlockIncrement(1);
183 slider.addAdjustmentListener(this);
184 slider.addMouseListener(this);
186 slider.setValue(value);
187 valueField.setText(value + "");
190 public void valueChanged(int i)
197 ColourSchemeI toChange = null;
198 Vector allGroups = null;
201 if (allGroupsCheck.getState())
203 allGroups = ap.av.getAlignment().getGroups();
204 groupIndex = allGroups.size() - 1;
211 while (groupIndex > -1)
213 if (allGroups != null)
215 toChange = ((SequenceGroup) allGroups.elementAt(groupIndex)).cs;
220 toChange.setConservationInc(i);
224 toChange.setThreshold(i, ap.av.getIgnoreGapsConsensus());
230 ap.seqPanel.seqCanvas.repaint();
234 public void setAllGroupsCheckEnabled(boolean b)
236 allGroupsCheck.setEnabled(b);
239 public void actionPerformed(ActionEvent evt)
241 if (evt.getSource() == applyButton)
243 applyButton_actionPerformed();
245 else if (evt.getSource() == undoButton)
247 undoButton_actionPerformed();
249 else if (evt.getSource() == valueField)
251 valueField_actionPerformed();
255 public void adjustmentValueChanged(AdjustmentEvent evt)
257 valueField.setText(slider.getValue() + "");
258 valueChanged(slider.getValue());
261 public void valueField_actionPerformed()
265 int i = Integer.parseInt(valueField.getText());
267 } catch (Exception ex)
269 valueField.setText(slider.getValue() + "");
273 public void setValue(int value)
275 slider.setValue(value);
278 public int getValue()
280 return Integer.parseInt(valueField.getText());
283 // this is used for conservation colours, PID colours and redundancy threshold
284 protected Scrollbar slider = new Scrollbar();
286 protected TextField valueField = new TextField();
288 protected Label label = new Label();
290 Panel jPanel1 = new Panel();
292 Panel jPanel2 = new Panel();
294 protected Button applyButton = new Button();
296 protected Button undoButton = new Button();
298 FlowLayout flowLayout1 = new FlowLayout();
300 protected Checkbox allGroupsCheck = new Checkbox();
302 BorderLayout borderLayout1 = new BorderLayout();
304 BorderLayout borderLayout2 = new BorderLayout();
306 FlowLayout flowLayout2 = new FlowLayout();
308 private void jbInit() throws Exception
310 this.setLayout(borderLayout2);
312 // slider.setMajorTickSpacing(10);
313 // slider.setMinorTickSpacing(1);
314 // slider.setPaintTicks(true);
315 slider.setBackground(Color.white);
316 slider.setFont(new java.awt.Font("Verdana", 0, 11));
317 slider.setOrientation(0);
318 valueField.setFont(new java.awt.Font("Verdana", 0, 11));
319 valueField.setText(" ");
320 valueField.addActionListener(this);
321 label.setFont(new java.awt.Font("Verdana", 0, 11));
322 label.setText("set this label text");
323 jPanel1.setLayout(borderLayout1);
324 jPanel2.setLayout(flowLayout1);
325 applyButton.setFont(new java.awt.Font("Verdana", 0, 11));
326 applyButton.setLabel("Apply");
327 applyButton.addActionListener(this);
328 undoButton.setEnabled(false);
329 undoButton.setFont(new java.awt.Font("Verdana", 0, 11));
330 undoButton.setLabel("Undo");
331 undoButton.addActionListener(this);
332 allGroupsCheck.setEnabled(false);
333 allGroupsCheck.setFont(new java.awt.Font("Verdana", 0, 11));
334 allGroupsCheck.setLabel("Apply threshold to all groups");
335 allGroupsCheck.setName("Apply to all Groups");
336 this.setBackground(Color.white);
337 this.setForeground(Color.black);
338 jPanel2.add(label, null);
339 jPanel2.add(applyButton, null);
340 jPanel2.add(undoButton, null);
341 jPanel2.add(allGroupsCheck);
342 jPanel1.add(valueField, java.awt.BorderLayout.EAST);
343 jPanel1.add(slider, java.awt.BorderLayout.CENTER);
344 this.add(jPanel1, java.awt.BorderLayout.SOUTH);
345 this.add(jPanel2, java.awt.BorderLayout.CENTER);
348 protected void applyButton_actionPerformed()
352 protected void undoButton_actionPerformed()
356 public void mousePressed(MouseEvent evt)
360 public void mouseReleased(MouseEvent evt)
362 ap.paintAlignment(true);
365 public void mouseClicked(MouseEvent evt)
369 public void mouseEntered(MouseEvent evt)
373 public void mouseExited(MouseEvent evt)