2 * Jalview - A Sequence Alignment Editor and Viewer
\r
3 * Copyright (C) 2007 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
\r
5 * This program is free software; you can redistribute it and/or
\r
6 * modify it under the terms of the GNU General Public License
\r
7 * as published by the Free Software Foundation; either version 2
\r
8 * of the License, or (at your option) any later version.
\r
10 * This program is distributed in the hope that it will be useful,
\r
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
13 * GNU General Public License for more details.
\r
15 * You should have received a copy of the GNU General Public License
\r
16 * along with this program; if not, write to the Free Software
\r
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
\r
20 package jalview.appletgui;
\r
25 import java.awt.event.*;
\r
27 import jalview.datamodel.*;
\r
28 import jalview.schemes.*;
\r
30 public class SliderPanel
\r
31 extends Panel implements ActionListener,
\r
36 boolean forConservation = true;
\r
39 static Frame conservationSlider;
\r
40 static Frame PIDSlider;
\r
42 public static int setConservationSlider(AlignmentPanel ap, ColourSchemeI cs,
\r
45 SliderPanel sp = null;
\r
47 if (conservationSlider == null)
\r
49 sp = new SliderPanel(ap, cs.getConservationInc(), true, cs);
\r
50 conservationSlider = new Frame();
\r
51 conservationSlider.add(sp);
\r
55 sp = (SliderPanel) conservationSlider.getComponent(0);
\r
59 conservationSlider.setTitle("Conservation Colour Increment (" + source +
\r
61 if (ap.av.alignment.getGroups() != null)
\r
63 sp.setAllGroupsCheckEnabled(true);
\r
67 sp.setAllGroupsCheckEnabled(false);
\r
70 return sp.getValue();
\r
73 public static void showConservationSlider()
\r
77 PIDSlider.setVisible(false);
\r
80 catch (Exception ex)
\r
83 if (!conservationSlider.isVisible())
\r
85 jalview.bin.JalviewLite.addFrame(conservationSlider,
\r
86 conservationSlider.getTitle(), 420, 100);
\r
87 conservationSlider.addWindowListener(new WindowAdapter()
\r
89 public void windowClosing(WindowEvent e)
\r
91 conservationSlider = null;
\r
99 public static int setPIDSliderSource(AlignmentPanel ap, ColourSchemeI cs,
\r
102 SliderPanel pid = null;
\r
103 if (PIDSlider == null)
\r
105 pid = new SliderPanel(ap, 50, false, cs);
\r
106 PIDSlider = new Frame();
\r
107 PIDSlider.add(pid);
\r
111 pid = (SliderPanel) PIDSlider.getComponent(0);
\r
114 PIDSlider.setTitle("Percentage Identity Threshold (" + source + ")");
\r
116 if (ap.av.alignment.getGroups() != null)
\r
118 pid.setAllGroupsCheckEnabled(true);
\r
122 pid.setAllGroupsCheckEnabled(false);
\r
125 return pid.getValue();
\r
129 public static void showPIDSlider()
\r
133 conservationSlider.setVisible(false);
\r
134 conservationSlider = null;
\r
136 catch (Exception ex)
\r
139 if (!PIDSlider.isVisible())
\r
141 jalview.bin.JalviewLite.addFrame(PIDSlider, PIDSlider.getTitle(), 420,
\r
143 PIDSlider.addWindowListener(new WindowAdapter()
\r
145 public void windowClosing(WindowEvent e)
\r
154 public SliderPanel(AlignmentPanel ap, int value, boolean forConserve,
\r
161 catch (Exception e)
\r
163 e.printStackTrace();
\r
167 forConservation = forConserve;
\r
168 undoButton.setVisible(false);
\r
169 applyButton.setVisible(false);
\r
170 if (forConservation)
\r
172 label.setText("Modify conservation visibility");
\r
173 slider.setMinimum(0);
\r
174 slider.setMaximum(50 + slider.getVisibleAmount());
\r
175 slider.setUnitIncrement(1);
\r
179 label.setText("Colour residues above % occurence");
\r
180 slider.setMinimum(0);
\r
181 slider.setMaximum(100 + slider.getVisibleAmount());
\r
182 slider.setBlockIncrement(1);
\r
185 slider.addAdjustmentListener(this);
\r
186 slider.addMouseListener(this);
\r
188 slider.setValue(value);
\r
189 valueField.setText(value + "");
\r
192 public void valueChanged(int i)
\r
199 ColourSchemeI toChange = null;
\r
200 Vector allGroups = null;
\r
201 int groupIndex = 0;
\r
203 if (allGroupsCheck.getState())
\r
205 allGroups = ap.av.alignment.getGroups();
\r
206 groupIndex = allGroups.size() - 1;
\r
213 while (groupIndex > -1)
\r
215 if (allGroups != null)
\r
217 toChange = ( (SequenceGroup) allGroups.elementAt(groupIndex)).cs;
\r
220 if (forConservation)
\r
222 toChange.setConservationInc(i);
\r
226 toChange.setThreshold(i, ap.av.getIgnoreGapsConsensus());
\r
232 ap.seqPanel.seqCanvas.repaint();
\r
236 public void setAllGroupsCheckEnabled(boolean b)
\r
238 allGroupsCheck.setEnabled(b);
\r
241 public void actionPerformed(ActionEvent evt)
\r
243 if (evt.getSource() == applyButton)
\r
245 applyButton_actionPerformed();
\r
247 else if (evt.getSource() == undoButton)
\r
249 undoButton_actionPerformed();
\r
251 else if (evt.getSource() == valueField)
\r
253 valueField_actionPerformed();
\r
257 public void adjustmentValueChanged(AdjustmentEvent evt)
\r
259 valueField.setText(slider.getValue() + "");
\r
260 valueChanged(slider.getValue());
\r
263 public void valueField_actionPerformed()
\r
267 int i = Integer.parseInt(valueField.getText());
\r
268 slider.setValue(i);
\r
270 catch (Exception ex)
\r
272 valueField.setText(slider.getValue() + "");
\r
276 public void setValue(int value)
\r
278 slider.setValue(value);
\r
281 public int getValue()
\r
283 return Integer.parseInt(valueField.getText());
\r
286 // this is used for conservation colours, PID colours and redundancy threshold
\r
287 protected Scrollbar slider = new Scrollbar();
\r
288 protected TextField valueField = new TextField();
\r
289 protected Label label = new Label();
\r
290 Panel jPanel1 = new Panel();
\r
291 Panel jPanel2 = new Panel();
\r
292 protected Button applyButton = new Button();
\r
293 protected Button undoButton = new Button();
\r
294 FlowLayout flowLayout1 = new FlowLayout();
\r
295 protected Checkbox allGroupsCheck = new Checkbox();
\r
296 BorderLayout borderLayout1 = new BorderLayout();
\r
297 BorderLayout borderLayout2 = new BorderLayout();
\r
298 FlowLayout flowLayout2 = new FlowLayout();
\r
300 private void jbInit()
\r
303 this.setLayout(borderLayout2);
\r
305 // slider.setMajorTickSpacing(10);
\r
306 // slider.setMinorTickSpacing(1);
\r
307 // slider.setPaintTicks(true);
\r
308 slider.setBackground(Color.white);
\r
309 slider.setFont(new java.awt.Font("Verdana", 0, 11));
\r
310 slider.setOrientation(0);
\r
311 valueField.setFont(new java.awt.Font("Verdana", 0, 11));
\r
312 valueField.setText(" ");
\r
313 valueField.addActionListener(this);
\r
314 label.setFont(new java.awt.Font("Verdana", 0, 11));
\r
315 label.setText("set this label text");
\r
316 jPanel1.setLayout(borderLayout1);
\r
317 jPanel2.setLayout(flowLayout1);
\r
318 applyButton.setFont(new java.awt.Font("Verdana", 0, 11));
\r
319 applyButton.setLabel("Apply");
\r
320 applyButton.addActionListener(this);
\r
321 undoButton.setEnabled(false);
\r
322 undoButton.setFont(new java.awt.Font("Verdana", 0, 11));
\r
323 undoButton.setLabel("Undo");
\r
324 undoButton.addActionListener(this);
\r
325 allGroupsCheck.setEnabled(false);
\r
326 allGroupsCheck.setFont(new java.awt.Font("Verdana", 0, 11));
\r
327 allGroupsCheck.setLabel("Apply threshold to all groups");
\r
328 allGroupsCheck.setName("Apply to all Groups");
\r
329 this.setBackground(Color.white);
\r
330 this.setForeground(Color.black);
\r
331 jPanel2.add(label, null);
\r
332 jPanel2.add(applyButton, null);
\r
333 jPanel2.add(undoButton, null);
\r
334 jPanel2.add(allGroupsCheck);
\r
335 jPanel1.add(valueField, java.awt.BorderLayout.EAST);
\r
336 jPanel1.add(slider, java.awt.BorderLayout.CENTER);
\r
337 this.add(jPanel1, java.awt.BorderLayout.SOUTH);
\r
338 this.add(jPanel2, java.awt.BorderLayout.CENTER);
\r
341 protected void applyButton_actionPerformed()
\r
344 protected void undoButton_actionPerformed()
\r
347 public void mousePressed(MouseEvent evt)
\r
350 public void mouseReleased(MouseEvent evt)
\r
352 ap.paintAlignment(true);
\r
355 public void mouseClicked(MouseEvent evt)
\r
358 public void mouseEntered(MouseEvent evt)
\r
361 public void mouseExited(MouseEvent evt)
\r