2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ 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;
23 import jalview.bin.JalviewLite;
24 import jalview.datamodel.SequenceGroup;
25 import jalview.schemes.ColourSchemeI;
26 import jalview.util.MessageManager;
28 import java.awt.BorderLayout;
29 import awt2swing.Button;
30 import awt2swing.Checkbox;
31 import java.awt.Color;
32 import java.awt.FlowLayout;
33 import awt2swing.Frame;
34 import awt2swing.Label;
35 import awt2swing.Panel;
36 import awt2swing.Scrollbar;
37 import awt2swing.TextField;
38 import java.awt.event.ActionEvent;
39 import java.awt.event.ActionListener;
40 import java.awt.event.AdjustmentEvent;
41 import java.awt.event.AdjustmentListener;
42 import java.awt.event.MouseEvent;
43 import java.awt.event.MouseListener;
44 import java.awt.event.WindowAdapter;
45 import java.awt.event.WindowEvent;
46 import java.util.Iterator;
48 public class SliderPanel extends Panel implements ActionListener,
49 AdjustmentListener, MouseListener
53 boolean forConservation = true;
57 static Frame conservationSlider;
59 static Frame PIDSlider;
61 public static int setConservationSlider(AlignmentPanel ap,
62 ColourSchemeI cs, String source)
64 SliderPanel sp = null;
66 if (conservationSlider == null)
68 sp = new SliderPanel(ap, cs.getConservationInc(), true, cs);
69 conservationSlider = new Frame();
70 conservationSlider.add(sp);
74 sp = (SliderPanel) conservationSlider.getComponent(0);
78 conservationSlider.setTitle(MessageManager.formatMessage("label.conservation_colour_increment", new String[]{source}));
79 if (ap.av.getAlignment().getGroups() != null)
81 sp.setAllGroupsCheckEnabled(true);
85 sp.setAllGroupsCheckEnabled(false);
91 public static void showConservationSlider()
95 PIDSlider.setVisible(false);
97 } catch (Exception ex)
101 if (!conservationSlider.isVisible())
103 JalviewLite.addFrame(conservationSlider,
104 conservationSlider.getTitle(), 420, 100);
105 conservationSlider.addWindowListener(new WindowAdapter()
107 public void windowClosing(WindowEvent e)
109 conservationSlider = null;
117 public static int setPIDSliderSource(AlignmentPanel ap, ColourSchemeI cs,
120 SliderPanel pid = null;
121 if (PIDSlider == null)
123 pid = new SliderPanel(ap, 50, false, cs);
124 PIDSlider = new Frame();
129 pid = (SliderPanel) PIDSlider.getComponent(0);
132 PIDSlider.setTitle(MessageManager.formatMessage("label.percentage_identity_thereshold", new String[]{source}));
134 if (ap.av.getAlignment().getGroups() != null)
136 pid.setAllGroupsCheckEnabled(true);
140 pid.setAllGroupsCheckEnabled(false);
143 return pid.getValue();
147 public static void showPIDSlider()
151 conservationSlider.setVisible(false);
152 conservationSlider = null;
153 } catch (Exception ex)
157 if (!PIDSlider.isVisible())
159 JalviewLite.addFrame(PIDSlider, PIDSlider.getTitle(),
161 PIDSlider.addWindowListener(new WindowAdapter()
163 public void windowClosing(WindowEvent e)
172 public SliderPanel(AlignmentPanel ap, int value, boolean forConserve,
178 } catch (Exception e)
184 forConservation = forConserve;
185 undoButton.setVisible(false);
186 applyButton.setVisible(false);
189 label.setText(MessageManager
190 .getString("label.modify_conservation_visibility"));
191 slider.setMinimum(0);
192 slider.setMaximum(50 + slider.getVisibleAmount());
193 slider.setUnitIncrement(1);
197 label.setText(MessageManager
198 .getString("label.colour_residues_above_occurence"));
199 slider.setMinimum(0);
200 slider.setMaximum(100 + slider.getVisibleAmount());
201 slider.setBlockIncrement(1);
204 slider.addAdjustmentListener(this);
205 slider.addMouseListener(this);
207 slider.setValue(value);
208 valueField.setText(value + "");
211 public void valueChanged(int i)
218 ColourSchemeI toChange = cs;
219 Iterator<SequenceGroup> allGroups = null;
221 if (allGroupsCheck.getState())
223 allGroups = ap.av.getAlignment().getGroups().listIterator();
226 while (toChange != null)
230 toChange.setConservationInc(i);
234 toChange.setThreshold(i, ap.av.isIgnoreGapsConsensus());
236 if (allGroups != null && allGroups.hasNext())
238 while ((toChange = allGroups.next().cs) == null
239 && allGroups.hasNext())
250 ap.seqPanel.seqCanvas.repaint();
254 public void setAllGroupsCheckEnabled(boolean b)
256 allGroupsCheck.setEnabled(b);
259 public void actionPerformed(ActionEvent evt)
261 if (evt.getSource() == applyButton)
263 applyButton_actionPerformed();
265 else if (evt.getSource() == undoButton)
267 undoButton_actionPerformed();
269 else if (evt.getSource() == valueField)
271 valueField_actionPerformed();
275 public void adjustmentValueChanged(AdjustmentEvent evt)
277 valueField.setText(slider.getValue() + "");
278 valueChanged(slider.getValue());
281 public void valueField_actionPerformed()
285 int i = Integer.parseInt(valueField.getText());
287 } catch (Exception ex)
289 valueField.setText(slider.getValue() + "");
293 public void setValue(int value)
295 slider.setValue(value);
298 public int getValue()
300 return Integer.parseInt(valueField.getText());
303 // this is used for conservation colours, PID colours and redundancy threshold
304 protected Scrollbar slider = new Scrollbar();
306 protected TextField valueField = new TextField();
308 protected Label label = new Label();
310 Panel jPanel1 = new Panel();
312 Panel jPanel2 = new Panel();
314 protected Button applyButton = new Button();
316 protected Button undoButton = new Button();
318 FlowLayout flowLayout1 = new FlowLayout();
320 protected Checkbox allGroupsCheck = new Checkbox();
322 BorderLayout borderLayout1 = new BorderLayout();
324 BorderLayout borderLayout2 = new BorderLayout();
326 FlowLayout flowLayout2 = new FlowLayout();
328 private void jbInit() throws Exception
330 this.setLayout(borderLayout2);
332 // slider.setMajorTickSpacing(10);
333 // slider.setMinorTickSpacing(1);
334 // slider.setPaintTicks(true);
335 slider.setBackground(Color.white);
336 slider.setFont(new java.awt.Font("Verdana", 0, 11));
337 slider.setOrientation(0);
338 valueField.setFont(new java.awt.Font("Verdana", 0, 11));
339 valueField.setText(" ");
340 valueField.addActionListener(this);
341 valueField.setColumns(3);
342 label.setFont(new java.awt.Font("Verdana", 0, 11));
343 label.setText(MessageManager.getString("label.set_this_label_text"));
344 jPanel1.setLayout(borderLayout1);
345 jPanel2.setLayout(flowLayout1);
346 applyButton.setFont(new java.awt.Font("Verdana", 0, 11));
347 applyButton.setLabel(MessageManager.getString("action.apply"));
348 applyButton.addActionListener(this);
349 undoButton.setEnabled(false);
350 undoButton.setFont(new java.awt.Font("Verdana", 0, 11));
351 undoButton.setLabel(MessageManager.getString("action.undo"));
352 undoButton.addActionListener(this);
353 allGroupsCheck.setEnabled(false);
354 allGroupsCheck.setFont(new java.awt.Font("Verdana", 0, 11));
355 allGroupsCheck.setLabel(MessageManager
356 .getString("action.apply_threshold_all_groups"));
357 allGroupsCheck.setName(MessageManager
358 .getString("action.apply_all_groups"));
359 this.setBackground(Color.white);
360 this.setForeground(Color.black);
361 jPanel2.add(label, null);
362 jPanel2.add(applyButton, null);
363 jPanel2.add(undoButton, null);
364 jPanel2.add(allGroupsCheck);
365 jPanel1.add(valueField, java.awt.BorderLayout.EAST);
366 jPanel1.add(slider, java.awt.BorderLayout.CENTER);
367 this.add(jPanel1, java.awt.BorderLayout.SOUTH);
368 this.add(jPanel2, java.awt.BorderLayout.CENTER);
371 protected void applyButton_actionPerformed()
375 protected void undoButton_actionPerformed()
379 public void mousePressed(MouseEvent evt)
383 public void mouseReleased(MouseEvent evt)
385 ap.paintAlignment(true);
388 public void mouseClicked(MouseEvent evt)
392 public void mouseEntered(MouseEvent evt)
396 public void mouseExited(MouseEvent evt)