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.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.FocusAdapter;
42 import java.awt.event.FocusEvent;
43 import java.awt.event.MouseEvent;
44 import java.awt.event.MouseListener;
45 import java.awt.event.WindowAdapter;
46 import java.awt.event.WindowEvent;
47 import java.util.Iterator;
49 public class SliderPanel extends Panel implements ActionListener,
50 AdjustmentListener, MouseListener
54 boolean forConservation = true;
58 static Frame conservationSlider;
60 static Frame PIDSlider;
62 public static int setConservationSlider(AlignmentPanel ap,
63 ColourSchemeI cs, String source)
65 SliderPanel sp = null;
67 if (conservationSlider == null)
69 sp = new SliderPanel(ap, cs.getConservationInc(), true, cs);
70 conservationSlider = new Frame();
71 conservationSlider.add(sp);
75 sp = (SliderPanel) conservationSlider.getComponent(0);
80 .setTitle(MessageManager.formatMessage(
81 "label.conservation_colour_increment",
82 new String[] { source }));
83 if (ap.av.getAlignment().getGroups() != null)
85 sp.setAllGroupsCheckEnabled(true);
89 sp.setAllGroupsCheckEnabled(false);
95 public static void showConservationSlider()
99 PIDSlider.setVisible(false);
101 } catch (Exception ex)
105 if (!conservationSlider.isVisible())
107 jalview.bin.JalviewLite.addFrame(conservationSlider,
108 conservationSlider.getTitle(), 420, 100);
109 conservationSlider.addWindowListener(new WindowAdapter()
112 public void windowClosing(WindowEvent e)
114 conservationSlider = null;
122 public static int setPIDSliderSource(AlignmentPanel ap, ColourSchemeI cs,
125 SliderPanel pid = null;
126 if (PIDSlider == null)
128 pid = new SliderPanel(ap, 50, false, cs);
129 PIDSlider = new Frame();
134 pid = (SliderPanel) PIDSlider.getComponent(0);
138 .setTitle(MessageManager.formatMessage(
139 "label.percentage_identity_threshold",
140 new String[] { source }));
142 if (ap.av.getAlignment().getGroups() != null)
144 pid.setAllGroupsCheckEnabled(true);
148 pid.setAllGroupsCheckEnabled(false);
151 return pid.getValue();
155 public static void showPIDSlider()
159 conservationSlider.setVisible(false);
160 conservationSlider = null;
161 } catch (Exception ex)
165 if (!PIDSlider.isVisible())
167 jalview.bin.JalviewLite.addFrame(PIDSlider, PIDSlider.getTitle(),
169 PIDSlider.addWindowListener(new WindowAdapter()
172 public void windowClosing(WindowEvent e)
181 public static void hidePIDSlider()
183 PIDSlider.setVisible(false);
187 public static void hideConservationSlider()
189 conservationSlider.setVisible(false);
190 conservationSlider = null;
192 public SliderPanel(AlignmentPanel ap, int value, boolean forConserve,
198 } catch (Exception e)
204 forConservation = forConserve;
205 undoButton.setVisible(false);
206 applyButton.setVisible(false);
209 label.setText(MessageManager
210 .getString("label.modify_conservation_visibility"));
211 slider.setMinimum(0);
212 slider.setMaximum(50 + slider.getVisibleAmount());
213 slider.setUnitIncrement(1);
217 label.setText(MessageManager
218 .getString("label.colour_residues_above_occurrence"));
219 slider.setMinimum(0);
220 slider.setMaximum(100 + slider.getVisibleAmount());
221 slider.setBlockIncrement(1);
224 slider.addAdjustmentListener(this);
225 slider.addMouseListener(this);
227 slider.setValue(value);
228 valueField.setText(value + "");
231 public void valueChanged(int i)
238 ColourSchemeI toChange = cs;
239 Iterator<SequenceGroup> allGroups = null;
241 if (allGroupsCheck.getState())
243 allGroups = ap.av.getAlignment().getGroups().listIterator();
246 while (toChange != null)
250 toChange.setConservationInc(i);
254 toChange.setThreshold(i, ap.av.isIgnoreGapsConsensus());
256 if (allGroups != null && allGroups.hasNext())
258 while ((toChange = allGroups.next().cs) == null
259 && allGroups.hasNext())
270 ap.seqPanel.seqCanvas.repaint();
274 public void setAllGroupsCheckEnabled(boolean b)
276 allGroupsCheck.setEnabled(b);
280 public void actionPerformed(ActionEvent evt)
282 if (evt.getSource() == applyButton)
284 applyButton_actionPerformed();
286 else if (evt.getSource() == undoButton)
288 undoButton_actionPerformed();
290 else if (evt.getSource() == valueField)
292 valueField_actionPerformed();
297 public void adjustmentValueChanged(AdjustmentEvent evt)
299 valueField.setText(slider.getValue() + "");
300 valueChanged(slider.getValue());
303 public void valueField_actionPerformed()
307 int i = Integer.valueOf(valueField.getText());
309 } catch (NumberFormatException ex)
311 valueField.setText(String.valueOf(slider.getValue()));
315 public void setValue(int value)
317 slider.setValue(value);
320 public int getValue()
322 return Integer.parseInt(valueField.getText());
325 // this is used for conservation colours, PID colours and redundancy threshold
326 protected Scrollbar slider = new Scrollbar();
328 protected TextField valueField = new TextField();
330 protected Label label = new Label();
332 Panel jPanel1 = new Panel();
334 Panel jPanel2 = new Panel();
336 protected Button applyButton = new Button();
338 protected Button undoButton = new Button();
340 FlowLayout flowLayout1 = new FlowLayout();
342 protected Checkbox allGroupsCheck = new Checkbox();
344 BorderLayout borderLayout1 = new BorderLayout();
346 BorderLayout borderLayout2 = new BorderLayout();
348 FlowLayout flowLayout2 = new FlowLayout();
350 private void jbInit() throws Exception
352 this.setLayout(borderLayout2);
354 // slider.setMajorTickSpacing(10);
355 // slider.setMinorTickSpacing(1);
356 // slider.setPaintTicks(true);
357 slider.setBackground(Color.white);
358 slider.setFont(new java.awt.Font("Verdana", 0, 11));
359 slider.setOrientation(0);
360 valueField.setFont(new java.awt.Font("Verdana", 0, 11));
361 valueField.setText(" ");
362 valueField.addActionListener(this);
363 valueField.setColumns(3);
364 valueField.addFocusListener(new FocusAdapter()
367 public void focusLost(FocusEvent e)
369 valueField_actionPerformed();
370 valueChanged(slider.getValue());
374 label.setFont(new java.awt.Font("Verdana", 0, 11));
375 label.setText(MessageManager.getString("label.set_this_label_text"));
376 jPanel1.setLayout(borderLayout1);
377 jPanel2.setLayout(flowLayout1);
378 applyButton.setFont(new java.awt.Font("Verdana", 0, 11));
379 applyButton.setLabel(MessageManager.getString("action.apply"));
380 applyButton.addActionListener(this);
381 undoButton.setEnabled(false);
382 undoButton.setFont(new java.awt.Font("Verdana", 0, 11));
383 undoButton.setLabel(MessageManager.getString("action.undo"));
384 undoButton.addActionListener(this);
385 allGroupsCheck.setEnabled(false);
386 allGroupsCheck.setFont(new java.awt.Font("Verdana", 0, 11));
387 allGroupsCheck.setLabel(MessageManager
388 .getString("action.apply_threshold_all_groups"));
389 allGroupsCheck.setName(MessageManager
390 .getString("action.apply_all_groups"));
391 this.setBackground(Color.white);
392 this.setForeground(Color.black);
393 jPanel2.add(label, null);
394 jPanel2.add(applyButton, null);
395 jPanel2.add(undoButton, null);
396 jPanel2.add(allGroupsCheck);
397 jPanel1.add(valueField, java.awt.BorderLayout.EAST);
398 jPanel1.add(slider, java.awt.BorderLayout.CENTER);
399 this.add(jPanel1, java.awt.BorderLayout.SOUTH);
400 this.add(jPanel2, java.awt.BorderLayout.CENTER);
403 protected void applyButton_actionPerformed()
407 protected void undoButton_actionPerformed()
412 public void mousePressed(MouseEvent evt)
417 public void mouseReleased(MouseEvent evt)
419 ap.paintAlignment(true);
423 public void mouseClicked(MouseEvent evt)
428 public void mouseEntered(MouseEvent evt)
433 public void mouseExited(MouseEvent evt)