2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.1)
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 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/>.
17 * The Jalview Authors are detailed in the 'AUTHORS' file.
19 package jalview.appletgui;
24 import java.awt.event.*;
26 import jalview.datamodel.*;
27 import jalview.schemes.*;
28 import jalview.util.MessageManager;
30 public class SliderPanel extends Panel implements ActionListener,
31 AdjustmentListener, MouseListener
35 boolean forConservation = true;
39 static Frame conservationSlider;
41 static Frame PIDSlider;
43 public static int setConservationSlider(AlignmentPanel ap,
44 ColourSchemeI cs, String source)
46 SliderPanel sp = null;
48 if (conservationSlider == null)
50 sp = new SliderPanel(ap, cs.getConservationInc(), true, cs);
51 conservationSlider = new Frame();
52 conservationSlider.add(sp);
56 sp = (SliderPanel) conservationSlider.getComponent(0);
60 conservationSlider.setTitle("Conservation Colour Increment (" + source
62 if (ap.av.getAlignment().getGroups() != null)
64 sp.setAllGroupsCheckEnabled(true);
68 sp.setAllGroupsCheckEnabled(false);
74 public static void showConservationSlider()
78 PIDSlider.setVisible(false);
80 } catch (Exception ex)
84 if (!conservationSlider.isVisible())
86 jalview.bin.JalviewLite.addFrame(conservationSlider,
87 conservationSlider.getTitle(), 420, 100);
88 conservationSlider.addWindowListener(new WindowAdapter()
90 public void windowClosing(WindowEvent e)
92 conservationSlider = null;
100 public static int setPIDSliderSource(AlignmentPanel ap, ColourSchemeI cs,
103 SliderPanel pid = null;
104 if (PIDSlider == null)
106 pid = new SliderPanel(ap, 50, false, cs);
107 PIDSlider = new Frame();
112 pid = (SliderPanel) PIDSlider.getComponent(0);
115 PIDSlider.setTitle("Percentage Identity Threshold (" + source + ")");
117 if (ap.av.getAlignment().getGroups() != null)
119 pid.setAllGroupsCheckEnabled(true);
123 pid.setAllGroupsCheckEnabled(false);
126 return pid.getValue();
130 public static void showPIDSlider()
134 conservationSlider.setVisible(false);
135 conservationSlider = null;
136 } catch (Exception ex)
140 if (!PIDSlider.isVisible())
142 jalview.bin.JalviewLite.addFrame(PIDSlider, PIDSlider.getTitle(),
144 PIDSlider.addWindowListener(new WindowAdapter()
146 public void windowClosing(WindowEvent e)
155 public SliderPanel(AlignmentPanel ap, int value, boolean forConserve,
161 } catch (Exception e)
167 forConservation = forConserve;
168 undoButton.setVisible(false);
169 applyButton.setVisible(false);
172 label.setText(MessageManager.getString("label.modify_conservation_visibility"));
173 slider.setMinimum(0);
174 slider.setMaximum(50 + slider.getVisibleAmount());
175 slider.setUnitIncrement(1);
179 label.setText(MessageManager.getString("label.colour_residues_above_occurence"));
180 slider.setMinimum(0);
181 slider.setMaximum(100 + slider.getVisibleAmount());
182 slider.setBlockIncrement(1);
185 slider.addAdjustmentListener(this);
186 slider.addMouseListener(this);
188 slider.setValue(value);
189 valueField.setText(value + "");
192 public void valueChanged(int i)
199 ColourSchemeI toChange = cs;
200 Iterator<SequenceGroup> allGroups = null;
202 if (allGroupsCheck.getState())
204 allGroups = ap.av.getAlignment().getGroups().listIterator();
207 while (toChange != null)
211 toChange.setConservationInc(i);
215 toChange.setThreshold(i, ap.av.getIgnoreGapsConsensus());
217 if (allGroups != null && allGroups.hasNext())
219 while ((toChange = allGroups.next().cs) == null
220 && allGroups.hasNext())
229 ap.seqPanel.seqCanvas.repaint();
233 public void setAllGroupsCheckEnabled(boolean b)
235 allGroupsCheck.setEnabled(b);
238 public void actionPerformed(ActionEvent evt)
240 if (evt.getSource() == applyButton)
242 applyButton_actionPerformed();
244 else if (evt.getSource() == undoButton)
246 undoButton_actionPerformed();
248 else if (evt.getSource() == valueField)
250 valueField_actionPerformed();
254 public void adjustmentValueChanged(AdjustmentEvent evt)
256 valueField.setText(slider.getValue() + "");
257 valueChanged(slider.getValue());
260 public void valueField_actionPerformed()
264 int i = Integer.parseInt(valueField.getText());
266 } catch (Exception ex)
268 valueField.setText(slider.getValue() + "");
272 public void setValue(int value)
274 slider.setValue(value);
277 public int getValue()
279 return Integer.parseInt(valueField.getText());
282 // this is used for conservation colours, PID colours and redundancy threshold
283 protected Scrollbar slider = new Scrollbar();
285 protected TextField valueField = new TextField();
287 protected Label label = new Label();
289 Panel jPanel1 = new Panel();
291 Panel jPanel2 = new Panel();
293 protected Button applyButton = new Button();
295 protected Button undoButton = new Button();
297 FlowLayout flowLayout1 = new FlowLayout();
299 protected Checkbox allGroupsCheck = new Checkbox();
301 BorderLayout borderLayout1 = new BorderLayout();
303 BorderLayout borderLayout2 = new BorderLayout();
305 FlowLayout flowLayout2 = new FlowLayout();
307 private void jbInit() throws Exception
309 this.setLayout(borderLayout2);
311 // slider.setMajorTickSpacing(10);
312 // slider.setMinorTickSpacing(1);
313 // slider.setPaintTicks(true);
314 slider.setBackground(Color.white);
315 slider.setFont(new java.awt.Font("Verdana", 0, 11));
316 slider.setOrientation(0);
317 valueField.setFont(new java.awt.Font("Verdana", 0, 11));
318 valueField.setText(" ");
319 valueField.addActionListener(this);
320 valueField.setColumns(3);
321 label.setFont(new java.awt.Font("Verdana", 0, 11));
322 label.setText(MessageManager.getString("label.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(MessageManager.getString("action.apply"));
327 applyButton.addActionListener(this);
328 undoButton.setEnabled(false);
329 undoButton.setFont(new java.awt.Font("Verdana", 0, 11));
330 undoButton.setLabel(MessageManager.getString("action.undo"));
331 undoButton.addActionListener(this);
332 allGroupsCheck.setEnabled(false);
333 allGroupsCheck.setFont(new java.awt.Font("Verdana", 0, 11));
334 allGroupsCheck.setLabel(MessageManager.getString("action.apply_threshold_all_groups"));
335 allGroupsCheck.setName(MessageManager.getString("action.apply_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)