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;
21 import java.util.List;
24 import java.awt.event.*;
26 import jalview.datamodel.*;
27 import jalview.schemes.*;
29 public class SliderPanel extends Panel implements ActionListener,
30 AdjustmentListener, MouseListener
34 boolean forConservation = true;
38 static Frame conservationSlider;
40 static Frame PIDSlider;
42 public static int setConservationSlider(AlignmentPanel ap,
43 ColourSchemeI cs, String source)
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.getAlignment().getGroups() != null)
63 sp.setAllGroupsCheckEnabled(true);
67 sp.setAllGroupsCheckEnabled(false);
73 public static void showConservationSlider()
77 PIDSlider.setVisible(false);
79 } catch (Exception ex)
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.getAlignment().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;
135 } catch (Exception ex)
139 if (!PIDSlider.isVisible())
141 jalview.bin.JalviewLite.addFrame(PIDSlider, PIDSlider.getTitle(),
143 PIDSlider.addWindowListener(new WindowAdapter()
145 public void windowClosing(WindowEvent e)
154 public SliderPanel(AlignmentPanel ap, int value, boolean forConserve,
160 } catch (Exception e)
166 forConservation = forConserve;
167 undoButton.setVisible(false);
168 applyButton.setVisible(false);
171 label.setText("Modify conservation visibility");
172 slider.setMinimum(0);
173 slider.setMaximum(50 + slider.getVisibleAmount());
174 slider.setUnitIncrement(1);
178 label.setText("Colour residues above % occurence");
179 slider.setMinimum(0);
180 slider.setMaximum(100 + slider.getVisibleAmount());
181 slider.setBlockIncrement(1);
184 slider.addAdjustmentListener(this);
185 slider.addMouseListener(this);
187 slider.setValue(value);
188 valueField.setText(value + "");
191 public void valueChanged(int i)
198 ColourSchemeI toChange = null;
199 Iterator<SequenceGroup> allGroups = null;
201 if (allGroupsCheck.getState())
203 allGroups = ap.av.getAlignment().getGroups().listIterator();
212 if (allGroups != null)
214 toChange = allGroups.next().cs;
219 toChange.setConservationInc(i);
223 toChange.setThreshold(i, ap.av.getIgnoreGapsConsensus());
226 } while (allGroups!=null && allGroups.hasNext());
228 ap.seqPanel.seqCanvas.repaint();
232 public void setAllGroupsCheckEnabled(boolean b)
234 allGroupsCheck.setEnabled(b);
237 public void actionPerformed(ActionEvent evt)
239 if (evt.getSource() == applyButton)
241 applyButton_actionPerformed();
243 else if (evt.getSource() == undoButton)
245 undoButton_actionPerformed();
247 else if (evt.getSource() == valueField)
249 valueField_actionPerformed();
253 public void adjustmentValueChanged(AdjustmentEvent evt)
255 valueField.setText(slider.getValue() + "");
256 valueChanged(slider.getValue());
259 public void valueField_actionPerformed()
263 int i = Integer.parseInt(valueField.getText());
265 } catch (Exception ex)
267 valueField.setText(slider.getValue() + "");
271 public void setValue(int value)
273 slider.setValue(value);
276 public int getValue()
278 return Integer.parseInt(valueField.getText());
281 // this is used for conservation colours, PID colours and redundancy threshold
282 protected Scrollbar slider = new Scrollbar();
284 protected TextField valueField = new TextField();
286 protected Label label = new Label();
288 Panel jPanel1 = new Panel();
290 Panel jPanel2 = new Panel();
292 protected Button applyButton = new Button();
294 protected Button undoButton = new Button();
296 FlowLayout flowLayout1 = new FlowLayout();
298 protected Checkbox allGroupsCheck = new Checkbox();
300 BorderLayout borderLayout1 = new BorderLayout();
302 BorderLayout borderLayout2 = new BorderLayout();
304 FlowLayout flowLayout2 = new FlowLayout();
306 private void jbInit() throws Exception
308 this.setLayout(borderLayout2);
310 // slider.setMajorTickSpacing(10);
311 // slider.setMinorTickSpacing(1);
312 // slider.setPaintTicks(true);
313 slider.setBackground(Color.white);
314 slider.setFont(new java.awt.Font("Verdana", 0, 11));
315 slider.setOrientation(0);
316 valueField.setFont(new java.awt.Font("Verdana", 0, 11));
317 valueField.setText(" ");
318 valueField.addActionListener(this);
319 label.setFont(new java.awt.Font("Verdana", 0, 11));
320 label.setText("set this label text");
321 jPanel1.setLayout(borderLayout1);
322 jPanel2.setLayout(flowLayout1);
323 applyButton.setFont(new java.awt.Font("Verdana", 0, 11));
324 applyButton.setLabel("Apply");
325 applyButton.addActionListener(this);
326 undoButton.setEnabled(false);
327 undoButton.setFont(new java.awt.Font("Verdana", 0, 11));
328 undoButton.setLabel("Undo");
329 undoButton.addActionListener(this);
330 allGroupsCheck.setEnabled(false);
331 allGroupsCheck.setFont(new java.awt.Font("Verdana", 0, 11));
332 allGroupsCheck.setLabel("Apply threshold to all groups");
333 allGroupsCheck.setName("Apply to all Groups");
334 this.setBackground(Color.white);
335 this.setForeground(Color.black);
336 jPanel2.add(label, null);
337 jPanel2.add(applyButton, null);
338 jPanel2.add(undoButton, null);
339 jPanel2.add(allGroupsCheck);
340 jPanel1.add(valueField, java.awt.BorderLayout.EAST);
341 jPanel1.add(slider, java.awt.BorderLayout.CENTER);
342 this.add(jPanel1, java.awt.BorderLayout.SOUTH);
343 this.add(jPanel2, java.awt.BorderLayout.CENTER);
346 protected void applyButton_actionPerformed()
350 protected void undoButton_actionPerformed()
354 public void mousePressed(MouseEvent evt)
358 public void mouseReleased(MouseEvent evt)
360 ap.paintAlignment(true);
363 public void mouseClicked(MouseEvent evt)
367 public void mouseEntered(MouseEvent evt)
371 public void mouseExited(MouseEvent evt)