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(MessageManager.formatMessage("label.conservation_colour_increment", new String[]{source}));
63 if (ap.av.getAlignment().getGroups() != null)
65 sp.setAllGroupsCheckEnabled(true);
69 sp.setAllGroupsCheckEnabled(false);
75 public static void showConservationSlider()
79 PIDSlider.setVisible(false);
81 } catch (Exception ex)
85 if (!conservationSlider.isVisible())
87 jalview.bin.JalviewLite.addFrame(conservationSlider,
88 conservationSlider.getTitle(), 420, 100);
89 conservationSlider.addWindowListener(new WindowAdapter()
91 public void windowClosing(WindowEvent e)
93 conservationSlider = null;
101 public static int setPIDSliderSource(AlignmentPanel ap, ColourSchemeI cs,
104 SliderPanel pid = null;
105 if (PIDSlider == null)
107 pid = new SliderPanel(ap, 50, false, cs);
108 PIDSlider = new Frame();
113 pid = (SliderPanel) PIDSlider.getComponent(0);
116 PIDSlider.setTitle(MessageManager.formatMessage("label.percentage_identity_thereshold", new String[]{source}));
118 if (ap.av.getAlignment().getGroups() != null)
120 pid.setAllGroupsCheckEnabled(true);
124 pid.setAllGroupsCheckEnabled(false);
127 return pid.getValue();
131 public static void showPIDSlider()
135 conservationSlider.setVisible(false);
136 conservationSlider = null;
137 } catch (Exception ex)
141 if (!PIDSlider.isVisible())
143 jalview.bin.JalviewLite.addFrame(PIDSlider, PIDSlider.getTitle(),
145 PIDSlider.addWindowListener(new WindowAdapter()
147 public void windowClosing(WindowEvent e)
156 public SliderPanel(AlignmentPanel ap, int value, boolean forConserve,
162 } catch (Exception e)
168 forConservation = forConserve;
169 undoButton.setVisible(false);
170 applyButton.setVisible(false);
173 label.setText(MessageManager
174 .getString("label.modify_conservation_visibility"));
175 slider.setMinimum(0);
176 slider.setMaximum(50 + slider.getVisibleAmount());
177 slider.setUnitIncrement(1);
181 label.setText(MessageManager
182 .getString("label.colour_residues_above_occurence"));
183 slider.setMinimum(0);
184 slider.setMaximum(100 + slider.getVisibleAmount());
185 slider.setBlockIncrement(1);
188 slider.addAdjustmentListener(this);
189 slider.addMouseListener(this);
191 slider.setValue(value);
192 valueField.setText(value + "");
195 public void valueChanged(int i)
202 ColourSchemeI toChange = cs;
203 Iterator<SequenceGroup> allGroups = null;
205 if (allGroupsCheck.getState())
207 allGroups = ap.av.getAlignment().getGroups().listIterator();
210 while (toChange != null)
214 toChange.setConservationInc(i);
218 toChange.setThreshold(i, ap.av.getIgnoreGapsConsensus());
220 if (allGroups != null && allGroups.hasNext())
222 while ((toChange = allGroups.next().cs) == null
223 && allGroups.hasNext())
232 ap.seqPanel.seqCanvas.repaint();
236 public void setAllGroupsCheckEnabled(boolean b)
238 allGroupsCheck.setEnabled(b);
241 public void actionPerformed(ActionEvent evt)
243 if (evt.getSource() == applyButton)
245 applyButton_actionPerformed();
247 else if (evt.getSource() == undoButton)
249 undoButton_actionPerformed();
251 else if (evt.getSource() == valueField)
253 valueField_actionPerformed();
257 public void adjustmentValueChanged(AdjustmentEvent evt)
259 valueField.setText(slider.getValue() + "");
260 valueChanged(slider.getValue());
263 public void valueField_actionPerformed()
267 int i = Integer.parseInt(valueField.getText());
269 } catch (Exception ex)
271 valueField.setText(slider.getValue() + "");
275 public void setValue(int value)
277 slider.setValue(value);
280 public int getValue()
282 return Integer.parseInt(valueField.getText());
285 // this is used for conservation colours, PID colours and redundancy threshold
286 protected Scrollbar slider = new Scrollbar();
288 protected TextField valueField = new TextField();
290 protected Label label = new Label();
292 Panel jPanel1 = new Panel();
294 Panel jPanel2 = new Panel();
296 protected Button applyButton = new Button();
298 protected Button undoButton = new Button();
300 FlowLayout flowLayout1 = new FlowLayout();
302 protected Checkbox allGroupsCheck = new Checkbox();
304 BorderLayout borderLayout1 = new BorderLayout();
306 BorderLayout borderLayout2 = new BorderLayout();
308 FlowLayout flowLayout2 = new FlowLayout();
310 private void jbInit() throws Exception
312 this.setLayout(borderLayout2);
314 // slider.setMajorTickSpacing(10);
315 // slider.setMinorTickSpacing(1);
316 // slider.setPaintTicks(true);
317 slider.setBackground(Color.white);
318 slider.setFont(new java.awt.Font("Verdana", 0, 11));
319 slider.setOrientation(0);
320 valueField.setFont(new java.awt.Font("Verdana", 0, 11));
321 valueField.setText(" ");
322 valueField.addActionListener(this);
323 valueField.setColumns(3);
324 label.setFont(new java.awt.Font("Verdana", 0, 11));
325 label.setText(MessageManager.getString("label.set_this_label_text"));
326 jPanel1.setLayout(borderLayout1);
327 jPanel2.setLayout(flowLayout1);
328 applyButton.setFont(new java.awt.Font("Verdana", 0, 11));
329 applyButton.setLabel(MessageManager.getString("action.apply"));
330 applyButton.addActionListener(this);
331 undoButton.setEnabled(false);
332 undoButton.setFont(new java.awt.Font("Verdana", 0, 11));
333 undoButton.setLabel(MessageManager.getString("action.undo"));
334 undoButton.addActionListener(this);
335 allGroupsCheck.setEnabled(false);
336 allGroupsCheck.setFont(new java.awt.Font("Verdana", 0, 11));
337 allGroupsCheck.setLabel(MessageManager
338 .getString("action.apply_threshold_all_groups"));
339 allGroupsCheck.setName(MessageManager
340 .getString("action.apply_all_groups"));
341 this.setBackground(Color.white);
342 this.setForeground(Color.black);
343 jPanel2.add(label, null);
344 jPanel2.add(applyButton, null);
345 jPanel2.add(undoButton, null);
346 jPanel2.add(allGroupsCheck);
347 jPanel1.add(valueField, java.awt.BorderLayout.EAST);
348 jPanel1.add(slider, java.awt.BorderLayout.CENTER);
349 this.add(jPanel1, java.awt.BorderLayout.SOUTH);
350 this.add(jPanel2, java.awt.BorderLayout.CENTER);
353 protected void applyButton_actionPerformed()
357 protected void undoButton_actionPerformed()
361 public void mousePressed(MouseEvent evt)
365 public void mouseReleased(MouseEvent evt)
367 ap.paintAlignment(true);
370 public void mouseClicked(MouseEvent evt)
374 public void mouseEntered(MouseEvent evt)
378 public void mouseExited(MouseEvent evt)