2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.2)
3 * Copyright (C) 2014 The Jalview Authors
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
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
21 package jalview.appletgui;
26 import java.awt.event.*;
28 import jalview.datamodel.*;
29 import jalview.schemes.*;
30 import jalview.util.MessageManager;
32 public class SliderPanel extends Panel implements ActionListener,
33 AdjustmentListener, MouseListener
37 boolean forConservation = true;
41 static Frame conservationSlider;
43 static Frame PIDSlider;
45 public static int setConservationSlider(AlignmentPanel ap,
46 ColourSchemeI cs, String source)
48 SliderPanel sp = null;
50 if (conservationSlider == null)
52 sp = new SliderPanel(ap, cs.getConservationInc(), true, cs);
53 conservationSlider = new Frame();
54 conservationSlider.add(sp);
58 sp = (SliderPanel) conservationSlider.getComponent(0);
62 conservationSlider.setTitle("Conservation Colour Increment (" + source
64 if (ap.av.getAlignment().getGroups() != null)
66 sp.setAllGroupsCheckEnabled(true);
70 sp.setAllGroupsCheckEnabled(false);
76 public static void showConservationSlider()
80 PIDSlider.setVisible(false);
82 } catch (Exception ex)
86 if (!conservationSlider.isVisible())
88 jalview.bin.JalviewLite.addFrame(conservationSlider,
89 conservationSlider.getTitle(), 420, 100);
90 conservationSlider.addWindowListener(new WindowAdapter()
92 public void windowClosing(WindowEvent e)
94 conservationSlider = null;
102 public static int setPIDSliderSource(AlignmentPanel ap, ColourSchemeI cs,
105 SliderPanel pid = null;
106 if (PIDSlider == null)
108 pid = new SliderPanel(ap, 50, false, cs);
109 PIDSlider = new Frame();
114 pid = (SliderPanel) PIDSlider.getComponent(0);
117 PIDSlider.setTitle("Percentage Identity Threshold (" + source + ")");
119 if (ap.av.getAlignment().getGroups() != null)
121 pid.setAllGroupsCheckEnabled(true);
125 pid.setAllGroupsCheckEnabled(false);
128 return pid.getValue();
132 public static void showPIDSlider()
136 conservationSlider.setVisible(false);
137 conservationSlider = null;
138 } catch (Exception ex)
142 if (!PIDSlider.isVisible())
144 jalview.bin.JalviewLite.addFrame(PIDSlider, PIDSlider.getTitle(),
146 PIDSlider.addWindowListener(new WindowAdapter()
148 public void windowClosing(WindowEvent e)
157 public SliderPanel(AlignmentPanel ap, int value, boolean forConserve,
163 } catch (Exception e)
169 forConservation = forConserve;
170 undoButton.setVisible(false);
171 applyButton.setVisible(false);
174 label.setText(MessageManager
175 .getString("label.modify_conservation_visibility"));
176 slider.setMinimum(0);
177 slider.setMaximum(50 + slider.getVisibleAmount());
178 slider.setUnitIncrement(1);
182 label.setText(MessageManager
183 .getString("label.colour_residues_above_occurence"));
184 slider.setMinimum(0);
185 slider.setMaximum(100 + slider.getVisibleAmount());
186 slider.setBlockIncrement(1);
189 slider.addAdjustmentListener(this);
190 slider.addMouseListener(this);
192 slider.setValue(value);
193 valueField.setText(value + "");
196 public void valueChanged(int i)
203 ColourSchemeI toChange = cs;
204 Iterator<SequenceGroup> allGroups = null;
206 if (allGroupsCheck.getState())
208 allGroups = ap.av.getAlignment().getGroups().listIterator();
211 while (toChange != null)
215 toChange.setConservationInc(i);
219 toChange.setThreshold(i, ap.av.getIgnoreGapsConsensus());
221 if (allGroups != null && allGroups.hasNext())
223 while ((toChange = allGroups.next().cs) == null
224 && allGroups.hasNext())
233 ap.seqPanel.seqCanvas.repaint();
237 public void setAllGroupsCheckEnabled(boolean b)
239 allGroupsCheck.setEnabled(b);
242 public void actionPerformed(ActionEvent evt)
244 if (evt.getSource() == applyButton)
246 applyButton_actionPerformed();
248 else if (evt.getSource() == undoButton)
250 undoButton_actionPerformed();
252 else if (evt.getSource() == valueField)
254 valueField_actionPerformed();
258 public void adjustmentValueChanged(AdjustmentEvent evt)
260 valueField.setText(slider.getValue() + "");
261 valueChanged(slider.getValue());
264 public void valueField_actionPerformed()
268 int i = Integer.parseInt(valueField.getText());
270 } catch (Exception ex)
272 valueField.setText(slider.getValue() + "");
276 public void setValue(int value)
278 slider.setValue(value);
281 public int getValue()
283 return Integer.parseInt(valueField.getText());
286 // this is used for conservation colours, PID colours and redundancy threshold
287 protected Scrollbar slider = new Scrollbar();
289 protected TextField valueField = new TextField();
291 protected Label label = new Label();
293 Panel jPanel1 = new Panel();
295 Panel jPanel2 = new Panel();
297 protected Button applyButton = new Button();
299 protected Button undoButton = new Button();
301 FlowLayout flowLayout1 = new FlowLayout();
303 protected Checkbox allGroupsCheck = new Checkbox();
305 BorderLayout borderLayout1 = new BorderLayout();
307 BorderLayout borderLayout2 = new BorderLayout();
309 FlowLayout flowLayout2 = new FlowLayout();
311 private void jbInit() throws Exception
313 this.setLayout(borderLayout2);
315 // slider.setMajorTickSpacing(10);
316 // slider.setMinorTickSpacing(1);
317 // slider.setPaintTicks(true);
318 slider.setBackground(Color.white);
319 slider.setFont(new java.awt.Font("Verdana", 0, 11));
320 slider.setOrientation(0);
321 valueField.setFont(new java.awt.Font("Verdana", 0, 11));
322 valueField.setText(" ");
323 valueField.addActionListener(this);
324 valueField.setColumns(3);
325 label.setFont(new java.awt.Font("Verdana", 0, 11));
326 label.setText(MessageManager.getString("label.set_this_label_text"));
327 jPanel1.setLayout(borderLayout1);
328 jPanel2.setLayout(flowLayout1);
329 applyButton.setFont(new java.awt.Font("Verdana", 0, 11));
330 applyButton.setLabel(MessageManager.getString("action.apply"));
331 applyButton.addActionListener(this);
332 undoButton.setEnabled(false);
333 undoButton.setFont(new java.awt.Font("Verdana", 0, 11));
334 undoButton.setLabel(MessageManager.getString("action.undo"));
335 undoButton.addActionListener(this);
336 allGroupsCheck.setEnabled(false);
337 allGroupsCheck.setFont(new java.awt.Font("Verdana", 0, 11));
338 allGroupsCheck.setLabel(MessageManager
339 .getString("action.apply_threshold_all_groups"));
340 allGroupsCheck.setName(MessageManager
341 .getString("action.apply_all_groups"));
342 this.setBackground(Color.white);
343 this.setForeground(Color.black);
344 jPanel2.add(label, null);
345 jPanel2.add(applyButton, null);
346 jPanel2.add(undoButton, null);
347 jPanel2.add(allGroupsCheck);
348 jPanel1.add(valueField, java.awt.BorderLayout.EAST);
349 jPanel1.add(slider, java.awt.BorderLayout.CENTER);
350 this.add(jPanel1, java.awt.BorderLayout.SOUTH);
351 this.add(jPanel2, java.awt.BorderLayout.CENTER);
354 protected void applyButton_actionPerformed()
358 protected void undoButton_actionPerformed()
362 public void mousePressed(MouseEvent evt)
366 public void mouseReleased(MouseEvent evt)
368 ap.paintAlignment(true);
371 public void mouseClicked(MouseEvent evt)
375 public void mouseEntered(MouseEvent evt)
379 public void mouseExited(MouseEvent evt)