2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.9)
3 * Copyright (C) 2015 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.datamodel.SequenceGroup;
24 import jalview.schemes.ColourSchemeI;
25 import jalview.util.MessageManager;
27 import java.awt.BorderLayout;
28 import java.awt.Button;
29 import java.awt.Checkbox;
30 import java.awt.Color;
31 import java.awt.FlowLayout;
32 import java.awt.Frame;
33 import java.awt.Label;
34 import java.awt.Panel;
35 import java.awt.Scrollbar;
36 import java.awt.TextField;
37 import java.awt.event.ActionEvent;
38 import java.awt.event.ActionListener;
39 import java.awt.event.AdjustmentEvent;
40 import java.awt.event.AdjustmentListener;
41 import java.awt.event.MouseEvent;
42 import java.awt.event.MouseListener;
43 import java.awt.event.WindowAdapter;
44 import java.awt.event.WindowEvent;
45 import java.util.Iterator;
47 public class SliderPanel extends Panel implements ActionListener,
48 AdjustmentListener, MouseListener
52 boolean forConservation = true;
56 static Frame conservationSlider;
58 static Frame PIDSlider;
60 public static int setConservationSlider(AlignmentPanel ap,
61 ColourSchemeI cs, String source)
63 SliderPanel sp = null;
65 if (conservationSlider == null)
67 sp = new SliderPanel(ap, cs.getConservationInc(), true, cs);
68 conservationSlider = new Frame();
69 conservationSlider.add(sp);
73 sp = (SliderPanel) conservationSlider.getComponent(0);
78 .setTitle(MessageManager.formatMessage(
79 "label.conservation_colour_increment",
80 new String[] { source }));
81 if (ap.av.getAlignment().getGroups() != null)
83 sp.setAllGroupsCheckEnabled(true);
87 sp.setAllGroupsCheckEnabled(false);
93 public static void showConservationSlider()
97 PIDSlider.setVisible(false);
99 } catch (Exception ex)
103 if (!conservationSlider.isVisible())
105 jalview.bin.JalviewLite.addFrame(conservationSlider,
106 conservationSlider.getTitle(), 420, 100);
107 conservationSlider.addWindowListener(new WindowAdapter()
109 public void windowClosing(WindowEvent e)
111 conservationSlider = null;
119 public static int setPIDSliderSource(AlignmentPanel ap, ColourSchemeI cs,
122 SliderPanel pid = null;
123 if (PIDSlider == null)
125 pid = new SliderPanel(ap, 50, false, cs);
126 PIDSlider = new Frame();
131 pid = (SliderPanel) PIDSlider.getComponent(0);
134 PIDSlider.setTitle(MessageManager
135 .formatMessage("label.percentage_identity_thereshold",
136 new String[] { source }));
138 if (ap.av.getAlignment().getGroups() != null)
140 pid.setAllGroupsCheckEnabled(true);
144 pid.setAllGroupsCheckEnabled(false);
147 return pid.getValue();
151 public static void showPIDSlider()
155 conservationSlider.setVisible(false);
156 conservationSlider = null;
157 } catch (Exception ex)
161 if (!PIDSlider.isVisible())
163 jalview.bin.JalviewLite.addFrame(PIDSlider, PIDSlider.getTitle(),
165 PIDSlider.addWindowListener(new WindowAdapter()
167 public void windowClosing(WindowEvent e)
176 public SliderPanel(AlignmentPanel ap, int value, boolean forConserve,
182 } catch (Exception e)
188 forConservation = forConserve;
189 undoButton.setVisible(false);
190 applyButton.setVisible(false);
193 label.setText(MessageManager
194 .getString("label.modify_conservation_visibility"));
195 slider.setMinimum(0);
196 slider.setMaximum(50 + slider.getVisibleAmount());
197 slider.setUnitIncrement(1);
201 label.setText(MessageManager
202 .getString("label.colour_residues_above_occurence"));
203 slider.setMinimum(0);
204 slider.setMaximum(100 + slider.getVisibleAmount());
205 slider.setBlockIncrement(1);
208 slider.addAdjustmentListener(this);
209 slider.addMouseListener(this);
211 slider.setValue(value);
212 valueField.setText(value + "");
215 public void valueChanged(int i)
222 ColourSchemeI toChange = cs;
223 Iterator<SequenceGroup> allGroups = null;
225 if (allGroupsCheck.getState())
227 allGroups = ap.av.getAlignment().getGroups().listIterator();
230 while (toChange != null)
234 toChange.setConservationInc(i);
238 toChange.setThreshold(i, ap.av.isIgnoreGapsConsensus());
240 if (allGroups != null && allGroups.hasNext())
242 while ((toChange = allGroups.next().cs) == null
243 && allGroups.hasNext())
254 ap.seqPanel.seqCanvas.repaint();
258 public void setAllGroupsCheckEnabled(boolean b)
260 allGroupsCheck.setEnabled(b);
263 public void actionPerformed(ActionEvent evt)
265 if (evt.getSource() == applyButton)
267 applyButton_actionPerformed();
269 else if (evt.getSource() == undoButton)
271 undoButton_actionPerformed();
273 else if (evt.getSource() == valueField)
275 valueField_actionPerformed();
279 public void adjustmentValueChanged(AdjustmentEvent evt)
281 valueField.setText(slider.getValue() + "");
282 valueChanged(slider.getValue());
285 public void valueField_actionPerformed()
289 int i = Integer.parseInt(valueField.getText());
291 } catch (Exception ex)
293 valueField.setText(slider.getValue() + "");
297 public void setValue(int value)
299 slider.setValue(value);
302 public int getValue()
304 return Integer.parseInt(valueField.getText());
307 // this is used for conservation colours, PID colours and redundancy threshold
308 protected Scrollbar slider = new Scrollbar();
310 protected TextField valueField = new TextField();
312 protected Label label = new Label();
314 Panel jPanel1 = new Panel();
316 Panel jPanel2 = new Panel();
318 protected Button applyButton = new Button();
320 protected Button undoButton = new Button();
322 FlowLayout flowLayout1 = new FlowLayout();
324 protected Checkbox allGroupsCheck = new Checkbox();
326 BorderLayout borderLayout1 = new BorderLayout();
328 BorderLayout borderLayout2 = new BorderLayout();
330 FlowLayout flowLayout2 = new FlowLayout();
332 private void jbInit() throws Exception
334 this.setLayout(borderLayout2);
336 // slider.setMajorTickSpacing(10);
337 // slider.setMinorTickSpacing(1);
338 // slider.setPaintTicks(true);
339 slider.setBackground(Color.white);
340 slider.setFont(new java.awt.Font("Verdana", 0, 11));
341 slider.setOrientation(0);
342 valueField.setFont(new java.awt.Font("Verdana", 0, 11));
343 valueField.setText(" ");
344 valueField.addActionListener(this);
345 valueField.setColumns(3);
346 label.setFont(new java.awt.Font("Verdana", 0, 11));
347 label.setText(MessageManager.getString("label.set_this_label_text"));
348 jPanel1.setLayout(borderLayout1);
349 jPanel2.setLayout(flowLayout1);
350 applyButton.setFont(new java.awt.Font("Verdana", 0, 11));
351 applyButton.setLabel(MessageManager.getString("action.apply"));
352 applyButton.addActionListener(this);
353 undoButton.setEnabled(false);
354 undoButton.setFont(new java.awt.Font("Verdana", 0, 11));
355 undoButton.setLabel(MessageManager.getString("action.undo"));
356 undoButton.addActionListener(this);
357 allGroupsCheck.setEnabled(false);
358 allGroupsCheck.setFont(new java.awt.Font("Verdana", 0, 11));
359 allGroupsCheck.setLabel(MessageManager
360 .getString("action.apply_threshold_all_groups"));
361 allGroupsCheck.setName(MessageManager
362 .getString("action.apply_all_groups"));
363 this.setBackground(Color.white);
364 this.setForeground(Color.black);
365 jPanel2.add(label, null);
366 jPanel2.add(applyButton, null);
367 jPanel2.add(undoButton, null);
368 jPanel2.add(allGroupsCheck);
369 jPanel1.add(valueField, java.awt.BorderLayout.EAST);
370 jPanel1.add(slider, java.awt.BorderLayout.CENTER);
371 this.add(jPanel1, java.awt.BorderLayout.SOUTH);
372 this.add(jPanel2, java.awt.BorderLayout.CENTER);
375 protected void applyButton_actionPerformed()
379 protected void undoButton_actionPerformed()
383 public void mousePressed(MouseEvent evt)
387 public void mouseReleased(MouseEvent evt)
389 ap.paintAlignment(true);
392 public void mouseClicked(MouseEvent evt)
396 public void mouseEntered(MouseEvent evt)
400 public void mouseExited(MouseEvent evt)