2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.4)
3 * Copyright (C) 2008 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
19 package jalview.appletgui;
24 import java.awt.event.*;
26 import jalview.datamodel.*;
27 import jalview.schemes.*;
29 public class SliderPanel extends Panel implements ActionListener,
30 AdjustmentListener, MouseListener
34 boolean forConservation = true;
38 static Frame conservationSlider;
40 static Frame PIDSlider;
42 public static int setConservationSlider(AlignmentPanel ap,
43 ColourSchemeI cs, String source)
45 SliderPanel sp = null;
47 if (conservationSlider == null)
49 sp = new SliderPanel(ap, cs.getConservationInc(), true, cs);
50 conservationSlider = new Frame();
51 conservationSlider.add(sp);
55 sp = (SliderPanel) conservationSlider.getComponent(0);
59 conservationSlider.setTitle("Conservation Colour Increment (" + source
61 if (ap.av.alignment.getGroups() != null)
63 sp.setAllGroupsCheckEnabled(true);
67 sp.setAllGroupsCheckEnabled(false);
73 public static void showConservationSlider()
77 PIDSlider.setVisible(false);
79 } catch (Exception ex)
83 if (!conservationSlider.isVisible())
85 jalview.bin.JalviewLite.addFrame(conservationSlider,
86 conservationSlider.getTitle(), 420, 100);
87 conservationSlider.addWindowListener(new WindowAdapter()
89 public void windowClosing(WindowEvent e)
91 conservationSlider = null;
99 public static int setPIDSliderSource(AlignmentPanel ap, ColourSchemeI cs,
102 SliderPanel pid = null;
103 if (PIDSlider == null)
105 pid = new SliderPanel(ap, 50, false, cs);
106 PIDSlider = new Frame();
111 pid = (SliderPanel) PIDSlider.getComponent(0);
114 PIDSlider.setTitle("Percentage Identity Threshold (" + source + ")");
116 if (ap.av.alignment.getGroups() != null)
118 pid.setAllGroupsCheckEnabled(true);
122 pid.setAllGroupsCheckEnabled(false);
125 return pid.getValue();
129 public static void showPIDSlider()
133 conservationSlider.setVisible(false);
134 conservationSlider = null;
135 } catch (Exception ex)
139 if (!PIDSlider.isVisible())
141 jalview.bin.JalviewLite.addFrame(PIDSlider, PIDSlider.getTitle(),
143 PIDSlider.addWindowListener(new WindowAdapter()
145 public void windowClosing(WindowEvent e)
154 public SliderPanel(AlignmentPanel ap, int value, boolean forConserve,
160 } catch (Exception e)
166 forConservation = forConserve;
167 undoButton.setVisible(false);
168 applyButton.setVisible(false);
171 label.setText("Modify conservation visibility");
172 slider.setMinimum(0);
173 slider.setMaximum(50 + slider.getVisibleAmount());
174 slider.setUnitIncrement(1);
178 label.setText("Colour residues above % occurence");
179 slider.setMinimum(0);
180 slider.setMaximum(100 + slider.getVisibleAmount());
181 slider.setBlockIncrement(1);
184 slider.addAdjustmentListener(this);
185 slider.addMouseListener(this);
187 slider.setValue(value);
188 valueField.setText(value + "");
191 public void valueChanged(int i)
198 ColourSchemeI toChange = null;
199 Vector allGroups = null;
202 if (allGroupsCheck.getState())
204 allGroups = ap.av.alignment.getGroups();
205 groupIndex = allGroups.size() - 1;
212 while (groupIndex > -1)
214 if (allGroups != null)
216 toChange = ((SequenceGroup) allGroups.elementAt(groupIndex)).cs;
221 toChange.setConservationInc(i);
225 toChange.setThreshold(i, ap.av.getIgnoreGapsConsensus());
231 ap.seqPanel.seqCanvas.repaint();
235 public void setAllGroupsCheckEnabled(boolean b)
237 allGroupsCheck.setEnabled(b);
240 public void actionPerformed(ActionEvent evt)
242 if (evt.getSource() == applyButton)
244 applyButton_actionPerformed();
246 else if (evt.getSource() == undoButton)
248 undoButton_actionPerformed();
250 else if (evt.getSource() == valueField)
252 valueField_actionPerformed();
256 public void adjustmentValueChanged(AdjustmentEvent evt)
258 valueField.setText(slider.getValue() + "");
259 valueChanged(slider.getValue());
262 public void valueField_actionPerformed()
266 int i = Integer.parseInt(valueField.getText());
268 } catch (Exception ex)
270 valueField.setText(slider.getValue() + "");
274 public void setValue(int value)
276 slider.setValue(value);
279 public int getValue()
281 return Integer.parseInt(valueField.getText());
284 // this is used for conservation colours, PID colours and redundancy threshold
285 protected Scrollbar slider = new Scrollbar();
287 protected TextField valueField = new TextField();
289 protected Label label = new Label();
291 Panel jPanel1 = new Panel();
293 Panel jPanel2 = new Panel();
295 protected Button applyButton = new Button();
297 protected Button undoButton = new Button();
299 FlowLayout flowLayout1 = new FlowLayout();
301 protected Checkbox allGroupsCheck = new Checkbox();
303 BorderLayout borderLayout1 = new BorderLayout();
305 BorderLayout borderLayout2 = new BorderLayout();
307 FlowLayout flowLayout2 = new FlowLayout();
309 private void jbInit() throws Exception
311 this.setLayout(borderLayout2);
313 // slider.setMajorTickSpacing(10);
314 // slider.setMinorTickSpacing(1);
315 // slider.setPaintTicks(true);
316 slider.setBackground(Color.white);
317 slider.setFont(new java.awt.Font("Verdana", 0, 11));
318 slider.setOrientation(0);
319 valueField.setFont(new java.awt.Font("Verdana", 0, 11));
320 valueField.setText(" ");
321 valueField.addActionListener(this);
322 label.setFont(new java.awt.Font("Verdana", 0, 11));
323 label.setText("set this label text");
324 jPanel1.setLayout(borderLayout1);
325 jPanel2.setLayout(flowLayout1);
326 applyButton.setFont(new java.awt.Font("Verdana", 0, 11));
327 applyButton.setLabel("Apply");
328 applyButton.addActionListener(this);
329 undoButton.setEnabled(false);
330 undoButton.setFont(new java.awt.Font("Verdana", 0, 11));
331 undoButton.setLabel("Undo");
332 undoButton.addActionListener(this);
333 allGroupsCheck.setEnabled(false);
334 allGroupsCheck.setFont(new java.awt.Font("Verdana", 0, 11));
335 allGroupsCheck.setLabel("Apply threshold to all groups");
336 allGroupsCheck.setName("Apply to all Groups");
337 this.setBackground(Color.white);
338 this.setForeground(Color.black);
339 jPanel2.add(label, null);
340 jPanel2.add(applyButton, null);
341 jPanel2.add(undoButton, null);
342 jPanel2.add(allGroupsCheck);
343 jPanel1.add(valueField, java.awt.BorderLayout.EAST);
344 jPanel1.add(slider, java.awt.BorderLayout.CENTER);
345 this.add(jPanel1, java.awt.BorderLayout.SOUTH);
346 this.add(jPanel2, java.awt.BorderLayout.CENTER);
349 protected void applyButton_actionPerformed()
353 protected void undoButton_actionPerformed()
357 public void mousePressed(MouseEvent evt)
361 public void mouseReleased(MouseEvent evt)
363 ap.paintAlignment(true);
366 public void mouseClicked(MouseEvent evt)
370 public void mouseEntered(MouseEvent evt)
374 public void mouseExited(MouseEvent evt)