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.getString("label.modify_conservation_visibility"));
175 slider.setMinimum(0);
176 slider.setMaximum(50 + slider.getVisibleAmount());
177 slider.setUnitIncrement(1);
181 label.setText(MessageManager.getString("label.colour_residues_above_occurence"));
182 slider.setMinimum(0);
183 slider.setMaximum(100 + slider.getVisibleAmount());
184 slider.setBlockIncrement(1);
187 slider.addAdjustmentListener(this);
188 slider.addMouseListener(this);
190 slider.setValue(value);
191 valueField.setText(value + "");
194 public void valueChanged(int i)
201 ColourSchemeI toChange = cs;
202 Iterator<SequenceGroup> allGroups = null;
204 if (allGroupsCheck.getState())
206 allGroups = ap.av.getAlignment().getGroups().listIterator();
209 while (toChange != null)
213 toChange.setConservationInc(i);
217 toChange.setThreshold(i, ap.av.getIgnoreGapsConsensus());
219 if (allGroups != null && allGroups.hasNext())
221 while ((toChange = allGroups.next().cs) == null
222 && allGroups.hasNext())
231 ap.seqPanel.seqCanvas.repaint();
235 public void setAllGroupsCheckEnabled(boolean b)
237 allGroupsCheck.setEnabled(b);
240 public void actionPerformed(ActionEvent evt)
242 if (evt.getSource() == applyButton)
244 applyButton_actionPerformed();
246 else if (evt.getSource() == undoButton)
248 undoButton_actionPerformed();
250 else if (evt.getSource() == valueField)
252 valueField_actionPerformed();
256 public void adjustmentValueChanged(AdjustmentEvent evt)
258 valueField.setText(slider.getValue() + "");
259 valueChanged(slider.getValue());
262 public void valueField_actionPerformed()
266 int i = Integer.parseInt(valueField.getText());
268 } catch (Exception ex)
270 valueField.setText(slider.getValue() + "");
274 public void setValue(int value)
276 slider.setValue(value);
279 public int getValue()
281 return Integer.parseInt(valueField.getText());
284 // this is used for conservation colours, PID colours and redundancy threshold
285 protected Scrollbar slider = new Scrollbar();
287 protected TextField valueField = new TextField();
289 protected Label label = new Label();
291 Panel jPanel1 = new Panel();
293 Panel jPanel2 = new Panel();
295 protected Button applyButton = new Button();
297 protected Button undoButton = new Button();
299 FlowLayout flowLayout1 = new FlowLayout();
301 protected Checkbox allGroupsCheck = new Checkbox();
303 BorderLayout borderLayout1 = new BorderLayout();
305 BorderLayout borderLayout2 = new BorderLayout();
307 FlowLayout flowLayout2 = new FlowLayout();
309 private void jbInit() throws Exception
311 this.setLayout(borderLayout2);
313 // slider.setMajorTickSpacing(10);
314 // slider.setMinorTickSpacing(1);
315 // slider.setPaintTicks(true);
316 slider.setBackground(Color.white);
317 slider.setFont(new java.awt.Font("Verdana", 0, 11));
318 slider.setOrientation(0);
319 valueField.setFont(new java.awt.Font("Verdana", 0, 11));
320 valueField.setText(" ");
321 valueField.addActionListener(this);
322 valueField.setColumns(3);
323 label.setFont(new java.awt.Font("Verdana", 0, 11));
324 label.setText(MessageManager.getString("label.set_this_label_text"));
325 jPanel1.setLayout(borderLayout1);
326 jPanel2.setLayout(flowLayout1);
327 applyButton.setFont(new java.awt.Font("Verdana", 0, 11));
328 applyButton.setLabel(MessageManager.getString("action.apply"));
329 applyButton.addActionListener(this);
330 undoButton.setEnabled(false);
331 undoButton.setFont(new java.awt.Font("Verdana", 0, 11));
332 undoButton.setLabel(MessageManager.getString("action.undo"));
333 undoButton.addActionListener(this);
334 allGroupsCheck.setEnabled(false);
335 allGroupsCheck.setFont(new java.awt.Font("Verdana", 0, 11));
336 allGroupsCheck.setLabel(MessageManager.getString("action.apply_threshold_all_groups"));
337 allGroupsCheck.setName(MessageManager.getString("action.apply_all_groups"));
338 this.setBackground(Color.white);
339 this.setForeground(Color.black);
340 jPanel2.add(label, null);
341 jPanel2.add(applyButton, null);
342 jPanel2.add(undoButton, null);
343 jPanel2.add(allGroupsCheck);
344 jPanel1.add(valueField, java.awt.BorderLayout.EAST);
345 jPanel1.add(slider, java.awt.BorderLayout.CENTER);
346 this.add(jPanel1, java.awt.BorderLayout.SOUTH);
347 this.add(jPanel2, java.awt.BorderLayout.CENTER);
350 protected void applyButton_actionPerformed()
354 protected void undoButton_actionPerformed()
358 public void mousePressed(MouseEvent evt)
362 public void mouseReleased(MouseEvent evt)
364 ap.paintAlignment(true);
367 public void mouseClicked(MouseEvent evt)
371 public void mouseEntered(MouseEvent evt)
375 public void mouseExited(MouseEvent evt)