2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8)
3 * Copyright (C) 2012 J Procter, AM Waterhouse, LM Lui, J Engelhardt, 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 Iterator<SequenceGroup> allGroups = null;
200 if (allGroupsCheck.getState())
202 allGroups = ap.av.getAlignment().getGroups().listIterator();
211 if (allGroups != null)
213 toChange = allGroups.next().cs;
218 toChange.setConservationInc(i);
222 toChange.setThreshold(i, ap.av.getIgnoreGapsConsensus());
225 } while (allGroups != null && allGroups.hasNext());
227 ap.seqPanel.seqCanvas.repaint();
231 public void setAllGroupsCheckEnabled(boolean b)
233 allGroupsCheck.setEnabled(b);
236 public void actionPerformed(ActionEvent evt)
238 if (evt.getSource() == applyButton)
240 applyButton_actionPerformed();
242 else if (evt.getSource() == undoButton)
244 undoButton_actionPerformed();
246 else if (evt.getSource() == valueField)
248 valueField_actionPerformed();
252 public void adjustmentValueChanged(AdjustmentEvent evt)
254 valueField.setText(slider.getValue() + "");
255 valueChanged(slider.getValue());
258 public void valueField_actionPerformed()
262 int i = Integer.parseInt(valueField.getText());
264 } catch (Exception ex)
266 valueField.setText(slider.getValue() + "");
270 public void setValue(int value)
272 slider.setValue(value);
275 public int getValue()
277 return Integer.parseInt(valueField.getText());
280 // this is used for conservation colours, PID colours and redundancy threshold
281 protected Scrollbar slider = new Scrollbar();
283 protected TextField valueField = new TextField();
285 protected Label label = new Label();
287 Panel jPanel1 = new Panel();
289 Panel jPanel2 = new Panel();
291 protected Button applyButton = new Button();
293 protected Button undoButton = new Button();
295 FlowLayout flowLayout1 = new FlowLayout();
297 protected Checkbox allGroupsCheck = new Checkbox();
299 BorderLayout borderLayout1 = new BorderLayout();
301 BorderLayout borderLayout2 = new BorderLayout();
303 FlowLayout flowLayout2 = new FlowLayout();
305 private void jbInit() throws Exception
307 this.setLayout(borderLayout2);
309 // slider.setMajorTickSpacing(10);
310 // slider.setMinorTickSpacing(1);
311 // slider.setPaintTicks(true);
312 slider.setBackground(Color.white);
313 slider.setFont(new java.awt.Font("Verdana", 0, 11));
314 slider.setOrientation(0);
315 valueField.setFont(new java.awt.Font("Verdana", 0, 11));
316 valueField.setText(" ");
317 valueField.addActionListener(this);
318 label.setFont(new java.awt.Font("Verdana", 0, 11));
319 label.setText("set this label text");
320 jPanel1.setLayout(borderLayout1);
321 jPanel2.setLayout(flowLayout1);
322 applyButton.setFont(new java.awt.Font("Verdana", 0, 11));
323 applyButton.setLabel("Apply");
324 applyButton.addActionListener(this);
325 undoButton.setEnabled(false);
326 undoButton.setFont(new java.awt.Font("Verdana", 0, 11));
327 undoButton.setLabel("Undo");
328 undoButton.addActionListener(this);
329 allGroupsCheck.setEnabled(false);
330 allGroupsCheck.setFont(new java.awt.Font("Verdana", 0, 11));
331 allGroupsCheck.setLabel("Apply threshold to all groups");
332 allGroupsCheck.setName("Apply to all Groups");
333 this.setBackground(Color.white);
334 this.setForeground(Color.black);
335 jPanel2.add(label, null);
336 jPanel2.add(applyButton, null);
337 jPanel2.add(undoButton, null);
338 jPanel2.add(allGroupsCheck);
339 jPanel1.add(valueField, java.awt.BorderLayout.EAST);
340 jPanel1.add(slider, java.awt.BorderLayout.CENTER);
341 this.add(jPanel1, java.awt.BorderLayout.SOUTH);
342 this.add(jPanel2, java.awt.BorderLayout.CENTER);
345 protected void applyButton_actionPerformed()
349 protected void undoButton_actionPerformed()
353 public void mousePressed(MouseEvent evt)
357 public void mouseReleased(MouseEvent evt)
359 ap.paintAlignment(true);
362 public void mouseClicked(MouseEvent evt)
366 public void mouseEntered(MouseEvent evt)
370 public void mouseExited(MouseEvent evt)