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 java.awt.Color;
30 import java.awt.FlowLayout;
31 import java.awt.event.ActionEvent;
32 import java.awt.event.ActionListener;
33 import java.awt.event.AdjustmentEvent;
34 import java.awt.event.AdjustmentListener;
35 import java.awt.event.MouseEvent;
36 import java.awt.event.MouseListener;
37 import java.awt.event.WindowAdapter;
38 import java.awt.event.WindowEvent;
39 import java.util.Iterator;
41 import javax.swing.JButton;
42 import javax.swing.JCheckBox;
43 import javax.swing.JFrame;
44 import javax.swing.JLabel;
45 import javax.swing.JPanel;
46 import javax.swing.JScrollBar;
47 import javax.swing.JTextField;
49 public class SliderPanel extends JPanel implements ActionListener,
50 AdjustmentListener, MouseListener
54 boolean forConservation = true;
58 static JFrame conservationSlider;
60 static JFrame 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 JFrame();
71 conservationSlider.add(sp);
75 sp = (SliderPanel) conservationSlider.getComponent(0);
79 conservationSlider.setTitle(MessageManager.formatMessage("label.conservation_colour_increment", new String[]{source}));
80 if (ap.av.getAlignment().getGroups() != null)
82 sp.setAllGroupsCheckEnabled(true);
86 sp.setAllGroupsCheckEnabled(false);
92 public static void showConservationSlider()
96 PIDSlider.setVisible(false);
98 } catch (Exception ex)
102 if (!conservationSlider.isVisible())
104 JalviewLite.addFrame(conservationSlider,
105 conservationSlider.getTitle(), 420, 100);
106 conservationSlider.addWindowListener(new WindowAdapter()
108 public void windowClosing(WindowEvent e)
110 conservationSlider = null;
118 public static int setPIDSliderSource(AlignmentPanel ap, ColourSchemeI cs,
121 SliderPanel pid = null;
122 if (PIDSlider == null)
124 pid = new SliderPanel(ap, 50, false, cs);
125 PIDSlider = new JFrame();
130 pid = (SliderPanel) PIDSlider.getComponent(0);
133 PIDSlider.setTitle(MessageManager.formatMessage("label.percentage_identity_thereshold", new String[]{source}));
135 if (ap.av.getAlignment().getGroups() != null)
137 pid.setAllGroupsCheckEnabled(true);
141 pid.setAllGroupsCheckEnabled(false);
144 return pid.getValue();
148 public static void showPIDSlider()
152 conservationSlider.setVisible(false);
153 conservationSlider = null;
154 } catch (Exception ex)
158 if (!PIDSlider.isVisible())
160 JalviewLite.addFrame(PIDSlider, PIDSlider.getTitle(),
162 PIDSlider.addWindowListener(new WindowAdapter()
164 public void windowClosing(WindowEvent e)
173 public SliderPanel(AlignmentPanel ap, int value, boolean forConserve,
179 } catch (Exception e)
185 forConservation = forConserve;
186 undoButton.setVisible(false);
187 applyButton.setVisible(false);
190 label.setText(MessageManager
191 .getString("label.modify_conservation_visibility"));
192 slider.setMinimum(0);
193 slider.setMaximum(50 + slider.getVisibleAmount());
194 slider.setUnitIncrement(1);
198 label.setText(MessageManager
199 .getString("label.colour_residues_above_occurence"));
200 slider.setMinimum(0);
201 slider.setMaximum(100 + slider.getVisibleAmount());
202 slider.setBlockIncrement(1);
205 slider.addAdjustmentListener(this);
206 slider.addMouseListener(this);
208 slider.setValue(value);
209 valueField.setText(value + "");
212 public void valueChanged(int i)
219 ColourSchemeI toChange = cs;
220 Iterator<SequenceGroup> allGroups = null;
222 if (allGroupsCheck.isSelected())
224 allGroups = ap.av.getAlignment().getGroups().listIterator();
227 while (toChange != null)
231 toChange.setConservationInc(i);
235 toChange.setThreshold(i, ap.av.isIgnoreGapsConsensus());
237 if (allGroups != null && allGroups.hasNext())
239 while ((toChange = allGroups.next().cs) == null
240 && allGroups.hasNext())
251 ap.seqPanel.seqCanvas.repaint();
255 public void setAllGroupsCheckEnabled(boolean b)
257 allGroupsCheck.setEnabled(b);
260 public void actionPerformed(ActionEvent evt)
262 if (evt.getSource() == applyButton)
264 applyButton_actionPerformed();
266 else if (evt.getSource() == undoButton)
268 undoButton_actionPerformed();
270 else if (evt.getSource() == valueField)
272 valueField_actionPerformed();
276 public void adjustmentValueChanged(AdjustmentEvent evt)
278 valueField.setText(slider.getValue() + "");
279 valueChanged(slider.getValue());
282 public void valueField_actionPerformed()
286 int i = Integer.parseInt(valueField.getText());
288 } catch (Exception ex)
290 valueField.setText(slider.getValue() + "");
294 public void setValue(int value)
296 slider.setValue(value);
299 public int getValue()
301 return Integer.parseInt(valueField.getText());
304 // this is used for conservation colours, PID colours and redundancy threshold
305 protected JScrollBar slider = new JScrollBar();
307 protected JTextField valueField = new JTextField();
309 protected JLabel label = new JLabel();
311 JPanel jPanel1 = new JPanel();
313 JPanel jPanel2 = new JPanel();
315 protected JButton applyButton = new JButton();
317 protected JButton undoButton = new JButton();
319 FlowLayout flowLayout1 = new FlowLayout();
321 protected JCheckBox allGroupsCheck = new JCheckBox();
323 BorderLayout borderLayout1 = new BorderLayout();
325 BorderLayout borderLayout2 = new BorderLayout();
327 FlowLayout flowLayout2 = new FlowLayout();
329 private void jbInit() throws Exception
331 this.setLayout(borderLayout2);
333 // slider.setMajorTickSpacing(10);
334 // slider.setMinorTickSpacing(1);
335 // slider.setPaintTicks(true);
336 slider.setBackground(Color.white);
337 slider.setFont(new java.awt.Font("Verdana", 0, 11));
338 slider.setOrientation(0);
339 valueField.setFont(new java.awt.Font("Verdana", 0, 11));
340 valueField.setText(" ");
341 valueField.addActionListener(this);
342 valueField.setColumns(3);
343 label.setFont(new java.awt.Font("Verdana", 0, 11));
344 label.setText(MessageManager.getString("label.set_this_label_text"));
345 jPanel1.setLayout(borderLayout1);
346 jPanel2.setLayout(flowLayout1);
347 applyButton.setFont(new java.awt.Font("Verdana", 0, 11));
348 applyButton.setLabel(MessageManager.getString("action.apply"));
349 applyButton.addActionListener(this);
350 undoButton.setEnabled(false);
351 undoButton.setFont(new java.awt.Font("Verdana", 0, 11));
352 undoButton.setLabel(MessageManager.getString("action.undo"));
353 undoButton.addActionListener(this);
354 allGroupsCheck.setEnabled(false);
355 allGroupsCheck.setFont(new java.awt.Font("Verdana", 0, 11));
356 allGroupsCheck.setLabel(MessageManager
357 .getString("action.apply_threshold_all_groups"));
358 allGroupsCheck.setName(MessageManager
359 .getString("action.apply_all_groups"));
360 this.setBackground(Color.white);
361 this.setForeground(Color.black);
362 jPanel2.add(label, null);
363 jPanel2.add(applyButton, null);
364 jPanel2.add(undoButton, null);
365 jPanel2.add(allGroupsCheck);
366 jPanel1.add(valueField, java.awt.BorderLayout.EAST);
367 jPanel1.add(slider, java.awt.BorderLayout.CENTER);
368 this.add(jPanel1, java.awt.BorderLayout.SOUTH);
369 this.add(jPanel2, java.awt.BorderLayout.CENTER);
372 protected void applyButton_actionPerformed()
376 protected void undoButton_actionPerformed()
380 public void mousePressed(MouseEvent evt)
384 public void mouseReleased(MouseEvent evt)
386 ap.paintAlignment(true);
389 public void mouseClicked(MouseEvent evt)
393 public void mouseEntered(MouseEvent evt)
397 public void mouseExited(MouseEvent evt)