package jalview.gui; import jalview.jbgui.*; import jalview.schemes.*; import jalview.datamodel.*; import java.awt.event.*; import javax.swing.event.*; import javax.swing.*; import java.util.*; public class SliderPanel extends GSliderPanel { AlignmentPanel ap; boolean forConservation = true; ColourSchemeI cs; static JInternalFrame conservationSlider; static JInternalFrame PIDSlider; public static int setConservationSlider(AlignmentPanel ap, ColourSchemeI cs, String source) { SliderPanel sp = null; ConservationColourScheme ccs = (ConservationColourScheme)cs; int value = ccs.inc; if(conservationSlider == null) { sp = new SliderPanel(ap, value, true, cs); conservationSlider = new JInternalFrame(); conservationSlider.setContentPane(sp); conservationSlider.setLayer(JLayeredPane.PALETTE_LAYER); } else { sp = (SliderPanel)conservationSlider.getContentPane(); sp.cs = cs; sp.setValue(value); } conservationSlider.setTitle("Conservation Colour Increment ("+source+")"); if(ap.av.alignment.getGroups()!=null) sp.setAllGroupsCheckEnabled( true ); else sp.setAllGroupsCheckEnabled( false); return sp.getValue(); } public static void showConservationSlider() { try{ PIDSlider.setClosed(true); PIDSlider = null; }catch(Exception ex){} if(!conservationSlider.isVisible()) { Desktop.addInternalFrame(conservationSlider, conservationSlider.getTitle(), 420, 90, false); conservationSlider.addInternalFrameListener(new javax.swing.event. InternalFrameAdapter() { public void internalFrameClosed(javax.swing.event.InternalFrameEvent e) { conservationSlider = null; } }); conservationSlider.setLayer(JLayeredPane.PALETTE_LAYER); } } public static int setPIDSliderSource(AlignmentPanel ap, ColourSchemeI cs, String source) { SliderPanel pid = null; if(PIDSlider == null) { pid = new SliderPanel(ap, 50, false, cs); PIDSlider = new JInternalFrame(); PIDSlider.setContentPane(pid); PIDSlider.setLayer(JLayeredPane.PALETTE_LAYER); } else { pid = (SliderPanel)PIDSlider.getContentPane(); pid.cs = cs; } PIDSlider.setTitle("Percentage Identity Threshold ("+source+")"); if (ap.av.alignment.getGroups() != null) pid.setAllGroupsCheckEnabled(true); else pid.setAllGroupsCheckEnabled(false); return pid.getValue(); } public static void showPIDSlider() { try{ conservationSlider.setClosed(true); conservationSlider = null; }catch(Exception ex){} if(!PIDSlider.isVisible()) { Desktop.addInternalFrame(PIDSlider, PIDSlider.getTitle(), 420, 90, false); PIDSlider.setLayer(JLayeredPane.PALETTE_LAYER); PIDSlider.addInternalFrameListener(new javax.swing.event. InternalFrameAdapter() { public void internalFrameClosed(javax.swing.event.InternalFrameEvent e) { PIDSlider = null; } }); PIDSlider.setLayer(JLayeredPane.PALETTE_LAYER); } } public SliderPanel(AlignmentPanel ap, int value, boolean forConserve, ColourSchemeI cs) { this.ap = ap; this.cs = cs; forConservation = forConserve; undoButton.setVisible(false); applyButton.setVisible(false); if(forConservation) { label.setText("Enter value to increase conservation visibility"); slider.setMinimum(0); slider.setMaximum(50); } else { label.setText("Enter % identity above which to colour residues"); slider.setMinimum(0); slider.setMaximum(100); } slider.addChangeListener( new ChangeListener() { public void stateChanged(ChangeEvent evt) { valueField.setText( slider.getValue()+"" ); valueChanged( slider.getValue() ); } }); slider.setValue(value); valueField.setText(value+""); } public void valueChanged(int i) { if(cs == null) return; ColourSchemeI toChange = null; Vector allGroups = null; int groupIndex = 0; if(allGroupsCheck.isSelected()) { allGroups = ap.av.alignment.getGroups(); groupIndex = allGroups.size()-1; } else toChange = cs; while( groupIndex > -1 ) { if(allGroups!=null) toChange = ((SequenceGroup)allGroups.get(groupIndex)).cs; if (forConservation) { if (toChange instanceof ConservationColourScheme) ( (ConservationColourScheme) toChange).inc = i; } else { if (toChange.canThreshold()) ( (ResidueColourScheme) toChange).setThreshold(i); } groupIndex--; } ap.seqPanel.repaint(); } public void setAllGroupsCheckEnabled(boolean b) { allGroupsCheck.setEnabled(b); } public void valueField_actionPerformed(ActionEvent e) { try{ int i = Integer.parseInt(valueField.getText()); slider.setValue(i); } catch(Exception ex) { valueField.setText( slider.getValue()+"" ); } } public void setValue(int value) { slider.setValue(value); } public int getValue() { return Integer.parseInt(valueField.getText()); } }