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.analysis.Conservation;
24 import jalview.datamodel.SequenceGroup;
25 import jalview.renderer.ResidueShaderI;
26 import jalview.util.MessageManager;
28 import java.awt.BorderLayout;
29 import java.awt.Button;
30 import java.awt.Checkbox;
31 import java.awt.Color;
32 import java.awt.FlowLayout;
33 import java.awt.Frame;
34 import java.awt.Label;
35 import java.awt.Panel;
36 import java.awt.Scrollbar;
37 import java.awt.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.FocusAdapter;
43 import java.awt.event.FocusEvent;
44 import java.awt.event.MouseEvent;
45 import java.awt.event.MouseListener;
46 import java.awt.event.WindowAdapter;
47 import java.awt.event.WindowEvent;
48 import java.util.List;
50 public class SliderPanel extends Panel
51 implements ActionListener, AdjustmentListener, MouseListener
53 private static final String BACKGROUND = "Background";
57 boolean forConservation = true;
61 static Frame conservationSlider;
63 static Frame PIDSlider;
65 public static int setConservationSlider(AlignmentPanel ap,
66 ResidueShaderI ccs, String source)
68 SliderPanel sp = null;
70 if (conservationSlider == null)
72 sp = new SliderPanel(ap, ccs.getConservationInc(), true, ccs);
73 conservationSlider = new Frame();
74 conservationSlider.add(sp);
78 sp = (SliderPanel) conservationSlider.getComponent(0);
80 sp.valueField.setText(String.valueOf(ccs.getConservationInc()));
83 conservationSlider.setTitle(MessageManager.formatMessage(
84 "label.conservation_colour_increment", new String[]
85 { source == null ? BACKGROUND : source }));
86 List<SequenceGroup> groups = ap.av.getAlignment().getGroups();
87 if (groups != null && !groups.isEmpty())
89 sp.setAllGroupsCheckEnabled(true);
93 sp.setAllGroupsCheckEnabled(false);
99 public static void showConservationSlider()
103 PIDSlider.setVisible(false);
105 } catch (Exception ex)
109 if (!conservationSlider.isVisible())
111 jalview.bin.JalviewLite.addFrame(conservationSlider,
112 conservationSlider.getTitle(), 420, 100);
113 conservationSlider.addWindowListener(new WindowAdapter()
116 public void windowClosing(WindowEvent e)
118 conservationSlider = null;
126 public static int setPIDSliderSource(AlignmentPanel ap,
127 ResidueShaderI ccs, String source)
129 SliderPanel pid = null;
130 if (PIDSlider == null)
132 pid = new SliderPanel(ap, ccs.getThreshold(), false, ccs);
133 PIDSlider = new Frame();
138 pid = (SliderPanel) PIDSlider.getComponent(0);
140 pid.valueField.setText(String.valueOf(ccs.getThreshold()));
142 PIDSlider.setTitle(MessageManager.formatMessage(
143 "label.percentage_identity_threshold", new String[]
144 { source == null ? BACKGROUND : source }));
146 if (ap.av.getAlignment().getGroups() != null)
148 pid.setAllGroupsCheckEnabled(true);
152 pid.setAllGroupsCheckEnabled(false);
155 return pid.getValue();
159 public static void showPIDSlider()
163 conservationSlider.setVisible(false);
164 conservationSlider = null;
165 } catch (Exception ex)
169 if (!PIDSlider.isVisible())
171 jalview.bin.JalviewLite.addFrame(PIDSlider, PIDSlider.getTitle(), 420,
173 PIDSlider.addWindowListener(new WindowAdapter()
176 public void windowClosing(WindowEvent e)
186 * Hides the PID slider panel if it is shown
188 public static void hidePIDSlider()
190 if (PIDSlider != null)
192 PIDSlider.setVisible(false);
198 * Hides the Conservation slider panel if it is shown
200 public static void hideConservationSlider()
202 if (conservationSlider != null)
204 conservationSlider.setVisible(false);
205 conservationSlider = null;
209 public SliderPanel(AlignmentPanel ap, int value, boolean forConserve,
210 ResidueShaderI shader)
215 } catch (Exception e)
221 forConservation = forConserve;
222 undoButton.setVisible(false);
223 applyButton.setVisible(false);
226 label.setText(MessageManager
227 .getString("label.modify_conservation_visibility"));
228 slider.setMinimum(0);
229 slider.setMaximum(50 + slider.getVisibleAmount());
230 slider.setUnitIncrement(1);
234 label.setText(MessageManager
235 .getString("label.colour_residues_above_occurrence"));
236 slider.setMinimum(0);
237 slider.setMaximum(100 + slider.getVisibleAmount());
238 slider.setBlockIncrement(1);
241 slider.addAdjustmentListener(this);
242 slider.addMouseListener(this);
244 slider.setValue(value);
245 valueField.setText(value + "");
248 public void valueChanged(int i)
256 cs.setConservationApplied(true);
257 cs.setConservationInc(i);
261 cs.setThreshold(i, ap.av.isIgnoreGapsConsensus());
264 if (allGroupsCheck.getState())
266 for (SequenceGroup group : ap.av.getAlignment().getGroups())
268 ResidueShaderI groupColourScheme = group.getGroupColourScheme();
271 if (!groupColourScheme.conservationApplied())
274 * first time the colour scheme has had Conservation shading applied
275 * - compute conservation
277 Conservation c = new Conservation("Group",
278 group.getSequences(null), group.getStartRes(),
281 c.verdict(false, ap.av.getConsPercGaps());
282 group.cs.setConservation(c);
285 groupColourScheme.setConservationApplied(true);
286 groupColourScheme.setConservationInc(i);
290 groupColourScheme.setThreshold(i, ap.av.isIgnoreGapsConsensus());
295 ap.seqPanel.seqCanvas.repaint();
298 public void setAllGroupsCheckEnabled(boolean b)
300 allGroupsCheck.setState(ap.av.getColourAppliesToAllGroups());
301 allGroupsCheck.setEnabled(b);
305 public void actionPerformed(ActionEvent evt)
307 if (evt.getSource() == applyButton)
309 applyButton_actionPerformed();
311 else if (evt.getSource() == undoButton)
313 undoButton_actionPerformed();
315 else if (evt.getSource() == valueField)
317 valueField_actionPerformed();
322 public void adjustmentValueChanged(AdjustmentEvent evt)
324 valueField.setText(slider.getValue() + "");
325 valueChanged(slider.getValue());
328 public void valueField_actionPerformed()
332 int i = Integer.valueOf(valueField.getText());
334 } catch (NumberFormatException ex)
336 valueField.setText(String.valueOf(slider.getValue()));
340 public void setValue(int value)
342 slider.setValue(value);
345 public int getValue()
347 return Integer.parseInt(valueField.getText());
350 // this is used for conservation colours, PID colours and redundancy threshold
351 protected Scrollbar slider = new Scrollbar();
353 protected TextField valueField = new TextField();
355 protected Label label = new Label();
357 Panel jPanel1 = new Panel();
359 Panel jPanel2 = new Panel();
361 protected Button applyButton = new Button();
363 protected Button undoButton = new Button();
365 FlowLayout flowLayout1 = new FlowLayout();
367 protected Checkbox allGroupsCheck = new Checkbox();
369 BorderLayout borderLayout1 = new BorderLayout();
371 BorderLayout borderLayout2 = new BorderLayout();
373 FlowLayout flowLayout2 = new FlowLayout();
375 private void jbInit() throws Exception
377 this.setLayout(borderLayout2);
379 // slider.setMajorTickSpacing(10);
380 // slider.setMinorTickSpacing(1);
381 // slider.setPaintTicks(true);
382 slider.setBackground(Color.white);
383 slider.setFont(new java.awt.Font("Verdana", 0, 11));
384 slider.setOrientation(0);
385 valueField.setFont(new java.awt.Font("Verdana", 0, 11));
386 valueField.setText(" ");
387 valueField.addActionListener(this);
388 valueField.setColumns(3);
389 valueField.addFocusListener(new FocusAdapter()
392 public void focusLost(FocusEvent e)
394 valueField_actionPerformed();
395 valueChanged(slider.getValue());
399 label.setFont(new java.awt.Font("Verdana", 0, 11));
400 label.setText(MessageManager.getString("label.set_this_label_text"));
401 jPanel1.setLayout(borderLayout1);
402 jPanel2.setLayout(flowLayout1);
403 applyButton.setFont(new java.awt.Font("Verdana", 0, 11));
404 applyButton.setLabel(MessageManager.getString("action.apply"));
405 applyButton.addActionListener(this);
406 undoButton.setEnabled(false);
407 undoButton.setFont(new java.awt.Font("Verdana", 0, 11));
408 undoButton.setLabel(MessageManager.getString("action.undo"));
409 undoButton.addActionListener(this);
410 allGroupsCheck.setEnabled(false);
411 allGroupsCheck.setFont(new java.awt.Font("Verdana", 0, 11));
412 allGroupsCheck.setLabel(
413 MessageManager.getString("action.apply_threshold_all_groups"));
415 .setName(MessageManager.getString("action.apply_all_groups"));
416 this.setBackground(Color.white);
417 this.setForeground(Color.black);
418 jPanel2.add(label, null);
419 jPanel2.add(applyButton, null);
420 jPanel2.add(undoButton, null);
421 jPanel2.add(allGroupsCheck);
422 jPanel1.add(valueField, java.awt.BorderLayout.EAST);
423 jPanel1.add(slider, java.awt.BorderLayout.CENTER);
424 this.add(jPanel1, java.awt.BorderLayout.SOUTH);
425 this.add(jPanel2, java.awt.BorderLayout.CENTER);
428 protected void applyButton_actionPerformed()
432 protected void undoButton_actionPerformed()
437 public void mousePressed(MouseEvent evt)
442 public void mouseReleased(MouseEvent evt)
444 ap.paintAlignment(true, true);
448 public void mouseClicked(MouseEvent evt)
453 public void mouseEntered(MouseEvent evt)
458 public void mouseExited(MouseEvent evt)