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.renderer.ResidueShaderI;
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
52 private static final String BACKGROUND = "Background";
56 boolean forConservation = true;
60 static Frame conservationSlider;
62 static Frame PIDSlider;
64 public static int setConservationSlider(AlignmentPanel ap,
65 ResidueShaderI ccs, String source)
67 SliderPanel sp = null;
69 if (conservationSlider == null)
71 sp = new SliderPanel(ap, ccs.getConservationInc(), true, ccs);
72 conservationSlider = new Frame();
73 conservationSlider.add(sp);
77 sp = (SliderPanel) conservationSlider.getComponent(0);
79 sp.valueField.setText(String.valueOf(ccs.getConservationInc()));
82 conservationSlider.setTitle(MessageManager.formatMessage(
83 "label.conservation_colour_increment",
84 new String[] { source == null ? BACKGROUND : source }));
85 if (ap.av.getAlignment().getGroups() != null)
87 sp.setAllGroupsCheckEnabled(true);
91 sp.setAllGroupsCheckEnabled(false);
97 public static void showConservationSlider()
101 PIDSlider.setVisible(false);
103 } catch (Exception ex)
107 if (!conservationSlider.isVisible())
109 jalview.bin.JalviewLite.addFrame(conservationSlider,
110 conservationSlider.getTitle(), 420, 100);
111 conservationSlider.addWindowListener(new WindowAdapter()
114 public void windowClosing(WindowEvent e)
116 conservationSlider = null;
124 public static int setPIDSliderSource(AlignmentPanel ap,
125 ResidueShaderI ccs, String source)
127 SliderPanel pid = null;
128 if (PIDSlider == null)
130 pid = new SliderPanel(ap, ccs.getThreshold(), false, ccs);
131 PIDSlider = new Frame();
136 pid = (SliderPanel) PIDSlider.getComponent(0);
138 pid.valueField.setText(String.valueOf(ccs.getThreshold()));
140 PIDSlider.setTitle(MessageManager.formatMessage(
141 "label.percentage_identity_threshold",
142 new String[] { source == null ? BACKGROUND : source }));
144 if (ap.av.getAlignment().getGroups() != null)
146 pid.setAllGroupsCheckEnabled(true);
150 pid.setAllGroupsCheckEnabled(false);
153 return pid.getValue();
157 public static void showPIDSlider()
161 conservationSlider.setVisible(false);
162 conservationSlider = null;
163 } catch (Exception ex)
167 if (!PIDSlider.isVisible())
169 jalview.bin.JalviewLite.addFrame(PIDSlider, PIDSlider.getTitle(),
171 PIDSlider.addWindowListener(new WindowAdapter()
174 public void windowClosing(WindowEvent e)
184 * Hides the PID slider panel if it is shown
186 public static void hidePIDSlider()
188 if (PIDSlider != null)
190 PIDSlider.setVisible(false);
196 * Hides the Conservation slider panel if it is shown
198 public static void hideConservationSlider()
200 if (conservationSlider != null)
202 conservationSlider.setVisible(false);
203 conservationSlider = null;
206 public SliderPanel(AlignmentPanel ap, int value, boolean forConserve,
207 ResidueShaderI shader)
212 } catch (Exception e)
218 forConservation = forConserve;
219 undoButton.setVisible(false);
220 applyButton.setVisible(false);
223 label.setText(MessageManager
224 .getString("label.modify_conservation_visibility"));
225 slider.setMinimum(0);
226 slider.setMaximum(50 + slider.getVisibleAmount());
227 slider.setUnitIncrement(1);
231 label.setText(MessageManager
232 .getString("label.colour_residues_above_occurrence"));
233 slider.setMinimum(0);
234 slider.setMaximum(100 + slider.getVisibleAmount());
235 slider.setBlockIncrement(1);
238 slider.addAdjustmentListener(this);
239 slider.addMouseListener(this);
241 slider.setValue(value);
242 valueField.setText(value + "");
245 public void valueChanged(int i)
252 ResidueShaderI toChange = cs;
253 Iterator<SequenceGroup> allGroups = null;
255 if (allGroupsCheck.getState())
257 allGroups = ap.av.getAlignment().getGroups().listIterator();
260 while (toChange != null)
264 toChange.setConservationInc(i);
268 toChange.setThreshold(i, ap.av.isIgnoreGapsConsensus());
270 if (allGroups != null && allGroups.hasNext())
272 while ((toChange = allGroups.next().cs) == null
273 && allGroups.hasNext())
284 ap.seqPanel.seqCanvas.repaint();
288 public void setAllGroupsCheckEnabled(boolean b)
290 allGroupsCheck.setEnabled(b);
294 public void actionPerformed(ActionEvent evt)
296 if (evt.getSource() == applyButton)
298 applyButton_actionPerformed();
300 else if (evt.getSource() == undoButton)
302 undoButton_actionPerformed();
304 else if (evt.getSource() == valueField)
306 valueField_actionPerformed();
311 public void adjustmentValueChanged(AdjustmentEvent evt)
313 valueField.setText(slider.getValue() + "");
314 valueChanged(slider.getValue());
317 public void valueField_actionPerformed()
321 int i = Integer.valueOf(valueField.getText());
323 } catch (NumberFormatException ex)
325 valueField.setText(String.valueOf(slider.getValue()));
329 public void setValue(int value)
331 slider.setValue(value);
334 public int getValue()
336 return Integer.parseInt(valueField.getText());
339 // this is used for conservation colours, PID colours and redundancy threshold
340 protected Scrollbar slider = new Scrollbar();
342 protected TextField valueField = new TextField();
344 protected Label label = new Label();
346 Panel jPanel1 = new Panel();
348 Panel jPanel2 = new Panel();
350 protected Button applyButton = new Button();
352 protected Button undoButton = new Button();
354 FlowLayout flowLayout1 = new FlowLayout();
356 protected Checkbox allGroupsCheck = new Checkbox();
358 BorderLayout borderLayout1 = new BorderLayout();
360 BorderLayout borderLayout2 = new BorderLayout();
362 FlowLayout flowLayout2 = new FlowLayout();
364 private void jbInit() throws Exception
366 this.setLayout(borderLayout2);
368 // slider.setMajorTickSpacing(10);
369 // slider.setMinorTickSpacing(1);
370 // slider.setPaintTicks(true);
371 slider.setBackground(Color.white);
372 slider.setFont(new java.awt.Font("Verdana", 0, 11));
373 slider.setOrientation(0);
374 valueField.setFont(new java.awt.Font("Verdana", 0, 11));
375 valueField.setText(" ");
376 valueField.addActionListener(this);
377 valueField.setColumns(3);
378 valueField.addFocusListener(new FocusAdapter()
381 public void focusLost(FocusEvent e)
383 valueField_actionPerformed();
384 valueChanged(slider.getValue());
388 label.setFont(new java.awt.Font("Verdana", 0, 11));
389 label.setText(MessageManager.getString("label.set_this_label_text"));
390 jPanel1.setLayout(borderLayout1);
391 jPanel2.setLayout(flowLayout1);
392 applyButton.setFont(new java.awt.Font("Verdana", 0, 11));
393 applyButton.setLabel(MessageManager.getString("action.apply"));
394 applyButton.addActionListener(this);
395 undoButton.setEnabled(false);
396 undoButton.setFont(new java.awt.Font("Verdana", 0, 11));
397 undoButton.setLabel(MessageManager.getString("action.undo"));
398 undoButton.addActionListener(this);
399 allGroupsCheck.setEnabled(false);
400 allGroupsCheck.setFont(new java.awt.Font("Verdana", 0, 11));
401 allGroupsCheck.setLabel(MessageManager
402 .getString("action.apply_threshold_all_groups"));
403 allGroupsCheck.setName(MessageManager
404 .getString("action.apply_all_groups"));
405 this.setBackground(Color.white);
406 this.setForeground(Color.black);
407 jPanel2.add(label, null);
408 jPanel2.add(applyButton, null);
409 jPanel2.add(undoButton, null);
410 jPanel2.add(allGroupsCheck);
411 jPanel1.add(valueField, java.awt.BorderLayout.EAST);
412 jPanel1.add(slider, java.awt.BorderLayout.CENTER);
413 this.add(jPanel1, java.awt.BorderLayout.SOUTH);
414 this.add(jPanel2, java.awt.BorderLayout.CENTER);
417 protected void applyButton_actionPerformed()
421 protected void undoButton_actionPerformed()
426 public void mousePressed(MouseEvent evt)
431 public void mouseReleased(MouseEvent evt)
433 ap.paintAlignment(true);
437 public void mouseClicked(MouseEvent evt)
442 public void mouseEntered(MouseEvent evt)
447 public void mouseExited(MouseEvent evt)