2 * Jalview - A Sequence Alignment Editor and Viewer
\r
3 * Copyright (C) 2005 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 extends Panel
\r
31 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
159 } catch (Exception e) {
\r
160 e.printStackTrace();
\r
164 forConservation = forConserve;
\r
165 undoButton.setVisible(false);
\r
166 applyButton.setVisible(false);
\r
167 if (forConservation)
\r
169 label.setText("Modify conservation visibility");
\r
170 slider.setMinimum(0);
\r
171 slider.setMaximum(50 + slider.getVisibleAmount());
\r
172 slider.setUnitIncrement(1);
\r
176 label.setText("Colour residues above % occurence");
\r
177 slider.setMinimum(0);
\r
178 slider.setMaximum(100 + slider.getVisibleAmount());
\r
179 slider.setBlockIncrement(1);
\r
182 slider.addAdjustmentListener(this);
\r
183 slider.addMouseListener(this);
\r
185 slider.setValue(value);
\r
186 valueField.setText(value + "");
\r
189 public void valueChanged(int i)
\r
196 ColourSchemeI toChange = null;
\r
197 Vector allGroups = null;
\r
198 int groupIndex = 0;
\r
200 if (allGroupsCheck.getState())
\r
202 allGroups = ap.av.alignment.getGroups();
\r
203 groupIndex = allGroups.size() - 1;
\r
210 while (groupIndex > -1)
\r
212 if (allGroups != null)
\r
214 toChange = ( (SequenceGroup) allGroups.elementAt(groupIndex)).cs;
\r
217 if (forConservation)
\r
219 toChange.setConservationInc(i);
\r
223 toChange.setThreshold(i, ap.av.getIgnoreGapsConsensus());
\r
229 ap.seqPanel.seqCanvas.repaint();
\r
233 public void setAllGroupsCheckEnabled(boolean b)
\r
235 allGroupsCheck.setEnabled(b);
\r
238 public void actionPerformed(ActionEvent evt)
\r
240 if(evt.getSource()==applyButton)
\r
241 applyButton_actionPerformed();
\r
242 else if(evt.getSource()==undoButton)
\r
243 undoButton_actionPerformed();
\r
244 else if(evt.getSource()==valueField)
\r
245 valueField_actionPerformed();
\r
248 public void adjustmentValueChanged(AdjustmentEvent evt)
\r
250 valueField.setText(slider.getValue() + "");
\r
251 valueChanged(slider.getValue());
\r
255 public void valueField_actionPerformed()
\r
259 int i = Integer.parseInt(valueField.getText());
\r
260 slider.setValue(i);
\r
262 catch (Exception ex)
\r
264 valueField.setText(slider.getValue() + "");
\r
268 public void setValue(int value)
\r
270 slider.setValue(value);
\r
273 public int getValue()
\r
275 return Integer.parseInt(valueField.getText());
\r
278 // this is used for conservation colours, PID colours and redundancy threshold
\r
279 protected Scrollbar slider = new Scrollbar();
\r
280 protected TextField valueField = new TextField();
\r
281 protected Label label = new Label();
\r
282 Panel jPanel1 = new Panel();
\r
283 Panel jPanel2 = new Panel();
\r
284 protected Button applyButton = new Button();
\r
285 protected Button undoButton = new Button();
\r
286 FlowLayout flowLayout1 = new FlowLayout();
\r
287 protected Checkbox allGroupsCheck = new Checkbox();
\r
288 BorderLayout borderLayout1 = new BorderLayout();
\r
289 BorderLayout borderLayout2 = new BorderLayout();
\r
290 FlowLayout flowLayout2 = new FlowLayout();
\r
292 private void jbInit() throws Exception {
\r
293 this.setLayout(borderLayout2);
\r
295 // slider.setMajorTickSpacing(10);
\r
296 // slider.setMinorTickSpacing(1);
\r
297 // slider.setPaintTicks(true);
\r
298 slider.setBackground(Color.white);
\r
299 slider.setFont(new java.awt.Font("Verdana", 0, 11));
\r
300 slider.setOrientation(0);
\r
301 valueField.setFont(new java.awt.Font("Verdana", 0, 11));
\r
302 valueField.setText(" ");
\r
303 valueField.addActionListener(this);
\r
304 label.setFont(new java.awt.Font("Verdana", 0, 11));
\r
305 label.setText("set this label text");
\r
306 jPanel1.setLayout(borderLayout1);
\r
307 jPanel2.setLayout(flowLayout1);
\r
308 applyButton.setFont(new java.awt.Font("Verdana", 0, 11));
\r
309 applyButton.setLabel("Apply");
\r
310 applyButton.addActionListener(this);
\r
311 undoButton.setEnabled(false);
\r
312 undoButton.setFont(new java.awt.Font("Verdana", 0, 11));
\r
313 undoButton.setLabel("Undo");
\r
314 undoButton.addActionListener(this);
\r
315 allGroupsCheck.setEnabled(false);
\r
316 allGroupsCheck.setFont(new java.awt.Font("Verdana", 0, 11));
\r
317 allGroupsCheck.setLabel("Apply threshold to all groups");
\r
318 allGroupsCheck.setName("Apply to all Groups");
\r
319 this.setBackground(Color.white);
\r
320 this.setForeground(Color.black);
\r
321 jPanel2.add(label, null);
\r
322 jPanel2.add(applyButton, null);
\r
323 jPanel2.add(undoButton, null);
\r
324 jPanel2.add(allGroupsCheck);
\r
325 jPanel1.add(valueField, java.awt.BorderLayout.EAST);
\r
326 jPanel1.add(slider, java.awt.BorderLayout.CENTER);
\r
327 this.add(jPanel1, java.awt.BorderLayout.SOUTH);
\r
328 this.add(jPanel2, java.awt.BorderLayout.CENTER);
\r
331 protected void applyButton_actionPerformed()
\r
334 protected void undoButton_actionPerformed()
\r
337 public void mousePressed(MouseEvent evt)
\r
340 public void mouseReleased(MouseEvent evt)
\r
342 if (ap.overviewPanel != null)
\r
343 ap.overviewPanel.updateOverviewImage();
\r
345 public void mouseClicked(MouseEvent evt)
\r
347 public void mouseEntered(MouseEvent evt)
\r
349 public void mouseExited(MouseEvent evt)
\r