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.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);
135 .setTitle(MessageManager.formatMessage(
136 "label.percentage_identity_threshold",
137 new String[] { source }));
139 if (ap.av.getAlignment().getGroups() != null)
141 pid.setAllGroupsCheckEnabled(true);
145 pid.setAllGroupsCheckEnabled(false);
148 return pid.getValue();
152 public static void showPIDSlider()
156 conservationSlider.setVisible(false);
157 conservationSlider = null;
158 } catch (Exception ex)
162 if (!PIDSlider.isVisible())
164 jalview.bin.JalviewLite.addFrame(PIDSlider, PIDSlider.getTitle(),
166 PIDSlider.addWindowListener(new WindowAdapter()
168 public void windowClosing(WindowEvent e)
177 public SliderPanel(AlignmentPanel ap, int value, boolean forConserve,
183 } catch (Exception e)
189 forConservation = forConserve;
190 undoButton.setVisible(false);
191 applyButton.setVisible(false);
194 label.setText(MessageManager
195 .getString("label.modify_conservation_visibility"));
196 slider.setMinimum(0);
197 slider.setMaximum(50 + slider.getVisibleAmount());
198 slider.setUnitIncrement(1);
202 label.setText(MessageManager
203 .getString("label.colour_residues_above_occurence"));
204 slider.setMinimum(0);
205 slider.setMaximum(100 + slider.getVisibleAmount());
206 slider.setBlockIncrement(1);
209 slider.addAdjustmentListener(this);
210 slider.addMouseListener(this);
212 slider.setValue(value);
213 valueField.setText(value + "");
216 public void valueChanged(int i)
223 ColourSchemeI toChange = cs;
224 Iterator<SequenceGroup> allGroups = null;
226 if (allGroupsCheck.getState())
228 allGroups = ap.av.getAlignment().getGroups().listIterator();
231 while (toChange != null)
235 toChange.setConservationInc(i);
239 toChange.setThreshold(i, ap.av.isIgnoreGapsConsensus());
241 if (allGroups != null && allGroups.hasNext())
243 while ((toChange = allGroups.next().cs) == null
244 && allGroups.hasNext())
255 ap.seqPanel.seqCanvas.repaint();
259 public void setAllGroupsCheckEnabled(boolean b)
261 allGroupsCheck.setEnabled(b);
264 public void actionPerformed(ActionEvent evt)
266 if (evt.getSource() == applyButton)
268 applyButton_actionPerformed();
270 else if (evt.getSource() == undoButton)
272 undoButton_actionPerformed();
274 else if (evt.getSource() == valueField)
276 valueField_actionPerformed();
280 public void adjustmentValueChanged(AdjustmentEvent evt)
282 valueField.setText(slider.getValue() + "");
283 valueChanged(slider.getValue());
286 public void valueField_actionPerformed()
290 int i = Integer.parseInt(valueField.getText());
292 } catch (Exception ex)
294 valueField.setText(slider.getValue() + "");
298 public void setValue(int value)
300 slider.setValue(value);
303 public int getValue()
305 return Integer.parseInt(valueField.getText());
308 // this is used for conservation colours, PID colours and redundancy threshold
309 protected Scrollbar slider = new Scrollbar();
311 protected TextField valueField = new TextField();
313 protected Label label = new Label();
315 Panel jPanel1 = new Panel();
317 Panel jPanel2 = new Panel();
319 protected Button applyButton = new Button();
321 protected Button undoButton = new Button();
323 FlowLayout flowLayout1 = new FlowLayout();
325 protected Checkbox allGroupsCheck = new Checkbox();
327 BorderLayout borderLayout1 = new BorderLayout();
329 BorderLayout borderLayout2 = new BorderLayout();
331 FlowLayout flowLayout2 = new FlowLayout();
333 private void jbInit() throws Exception
335 this.setLayout(borderLayout2);
337 // slider.setMajorTickSpacing(10);
338 // slider.setMinorTickSpacing(1);
339 // slider.setPaintTicks(true);
340 slider.setBackground(Color.white);
341 slider.setFont(new java.awt.Font("Verdana", 0, 11));
342 slider.setOrientation(0);
343 valueField.setFont(new java.awt.Font("Verdana", 0, 11));
344 valueField.setText(" ");
345 valueField.addActionListener(this);
346 valueField.setColumns(3);
347 label.setFont(new java.awt.Font("Verdana", 0, 11));
348 label.setText(MessageManager.getString("label.set_this_label_text"));
349 jPanel1.setLayout(borderLayout1);
350 jPanel2.setLayout(flowLayout1);
351 applyButton.setFont(new java.awt.Font("Verdana", 0, 11));
352 applyButton.setLabel(MessageManager.getString("action.apply"));
353 applyButton.addActionListener(this);
354 undoButton.setEnabled(false);
355 undoButton.setFont(new java.awt.Font("Verdana", 0, 11));
356 undoButton.setLabel(MessageManager.getString("action.undo"));
357 undoButton.addActionListener(this);
358 allGroupsCheck.setEnabled(false);
359 allGroupsCheck.setFont(new java.awt.Font("Verdana", 0, 11));
360 allGroupsCheck.setLabel(MessageManager
361 .getString("action.apply_threshold_all_groups"));
362 allGroupsCheck.setName(MessageManager
363 .getString("action.apply_all_groups"));
364 this.setBackground(Color.white);
365 this.setForeground(Color.black);
366 jPanel2.add(label, null);
367 jPanel2.add(applyButton, null);
368 jPanel2.add(undoButton, null);
369 jPanel2.add(allGroupsCheck);
370 jPanel1.add(valueField, java.awt.BorderLayout.EAST);
371 jPanel1.add(slider, java.awt.BorderLayout.CENTER);
372 this.add(jPanel1, java.awt.BorderLayout.SOUTH);
373 this.add(jPanel2, java.awt.BorderLayout.CENTER);
376 protected void applyButton_actionPerformed()
380 protected void undoButton_actionPerformed()
384 public void mousePressed(MouseEvent evt)
388 public void mouseReleased(MouseEvent evt)
390 ap.paintAlignment(true);
393 public void mouseClicked(MouseEvent evt)
397 public void mouseEntered(MouseEvent evt)
401 public void mouseExited(MouseEvent evt)