X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FSliderPanel.java;h=1d59853b80ce8d37bec6c2e226f724a2b5be5291;hb=155a17a423e980849fd4dc5f857da1a72b0010b9;hp=6a1ae97ee0ddc22ce061d866a76f3257699ea2d3;hpb=29e4005910da86ce71244c274f97a17ee7070d64;p=jalview.git
diff --git a/src/jalview/gui/SliderPanel.java b/src/jalview/gui/SliderPanel.java
index 6a1ae97..1d59853 100755
--- a/src/jalview/gui/SliderPanel.java
+++ b/src/jalview/gui/SliderPanel.java
@@ -1,393 +1,504 @@
-/*
- * Jalview - A Sequence Alignment Editor and Viewer
- * Copyright (C) 2005 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
- */
-package jalview.gui;
-
-import jalview.datamodel.*;
-
-import jalview.jbgui.*;
-
-import jalview.schemes.*;
-
-import java.awt.event.*;
-
-import java.util.*;
-
-import javax.swing.*;
-import javax.swing.event.*;
-
-
-/**
- * DOCUMENT ME!
- *
- * @author $author$
- * @version $Revision$
- */
-public class SliderPanel extends GSliderPanel
-{
- static JInternalFrame conservationSlider;
- static JInternalFrame PIDSlider;
- AlignmentPanel ap;
- boolean forConservation = true;
- boolean forAnnotation = false;
- ColourSchemeI cs;
-
- /**
- * Creates a new SliderPanel object.
- *
- * @param ap DOCUMENT ME!
- * @param value DOCUMENT ME!
- * @param forConserve DOCUMENT ME!
- * @param cs DOCUMENT ME!
- */
- 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(100);
- }
- 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 SliderPanel(final AlignmentAnnotation annotation, final AlignmentPanel ap)
- {
- forAnnotation = true;
- undoButton.setVisible(false);
- applyButton.setVisible(false);
- allGroupsCheck.setVisible(false);
- label.setText("Adjust value - "+annotation.threshold.label);
-
- float range = annotation.graphMax * 1000 - annotation.graphMin * 1000;
-
- slider.setMinimum( (int) (annotation.graphMin * 1000));
- slider.setMaximum( (int) (annotation.graphMax * 1000));
- slider.setValue( (int) (annotation.threshold.value * 1000));
- valueField.setText( annotation.threshold.value + "");
- slider.setMajorTickSpacing( (int) (range / 10f));
- slider.setMinorTickSpacing( (int) (range / 100f));
- slider.setPaintTicks(true);
-
- JInternalFrame slideFrame = new JInternalFrame();
- slideFrame.setLayer(JLayeredPane.PALETTE_LAYER);
- Desktop.addInternalFrame(slideFrame,
- "Adjust " + annotation.label +" value",
- 250, 90);
-
- slideFrame.setContentPane(this);
- slider.addChangeListener(new ChangeListener()
- {
- public void stateChanged(ChangeEvent evt)
- {
- valueField.setText( ((float)slider.getValue()/1000f) + "");
- annotation.threshold.value = (float)slider.getValue()/1000f;
- ap.repaint();
- }
- });
-
- }
-
-
- /**
- * DOCUMENT ME!
- *
- * @param ap DOCUMENT ME!
- * @param cs DOCUMENT ME!
- * @param source DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
- public static int setConservationSlider(AlignmentPanel ap,
- ColourSchemeI cs, String source)
- {
- SliderPanel sp = null;
-
- if (conservationSlider == null)
- {
- sp = new SliderPanel(ap, cs.getConservationInc(), true, cs);
- conservationSlider = new JInternalFrame();
- conservationSlider.setContentPane(sp);
- conservationSlider.setLayer(JLayeredPane.PALETTE_LAYER);
- }
- else
- {
- sp = (SliderPanel) conservationSlider.getContentPane();
- sp.cs = cs;
- }
-
- conservationSlider.setTitle("Conservation Colour Increment (" +
- source + ")");
-
- if (ap.av.alignment.getGroups() != null)
- {
- sp.setAllGroupsCheckEnabled(true);
- }
- else
- {
- sp.setAllGroupsCheckEnabled(false);
- }
-
- return sp.getValue();
- }
-
- /**
- * DOCUMENT ME!
- */
- 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);
- }
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param ap DOCUMENT ME!
- * @param cs DOCUMENT ME!
- * @param source DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
- public static int setPIDSliderSource(AlignmentPanel ap, ColourSchemeI cs,
- String source)
- {
- SliderPanel pid = null;
-
- int threshold = cs.getThreshold();
-
- if (PIDSlider == null)
- {
- pid = new SliderPanel(ap, threshold, 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();
- }
-
- /**
- * DOCUMENT ME!
- */
- 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);
- }
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param i DOCUMENT ME!
- */
- public void valueChanged(int i)
- {
- if (cs == null)
- {System.out.println("cs is 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 (toChange == null)
- {
- groupIndex--;
-
- continue;
- }
- }
-
- if (forConservation)
- {
- if (toChange.conservationApplied())
- {
- toChange.setConservationInc(i);
- }
- }
- else
- {
- toChange.setThreshold(i, ap.av.getIgnoreGapsConsensus());
- }
-
- groupIndex--;
- }
-
- ap.seqPanel.seqCanvas.repaint();
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param b DOCUMENT ME!
- */
- public void setAllGroupsCheckEnabled(boolean b)
- {
- allGroupsCheck.setEnabled(b);
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param e DOCUMENT ME!
- */
- public void valueField_actionPerformed(ActionEvent e)
- {
- try
- {
- if (forAnnotation)
- {
- float f = Float.parseFloat(valueField.getText());
- slider.setValue( (int)( f * 1000 ));
- }
- else
- {
- int i = Integer.parseInt(valueField.getText());
- slider.setValue(i);
- }
- }
- catch (Exception ex)
- {
- valueField.setText(slider.getValue() + "");
- }
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param value DOCUMENT ME!
- */
- public void setValue(int value)
- {
- slider.setValue(value);
- }
-
- /**
- * DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
- public int getValue()
- {
- return Integer.parseInt(valueField.getText());
- }
-}
+/*
+ * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
+ * Copyright (C) $$Year-Rel$$ The Jalview Authors
+ *
+ * This file is part of Jalview.
+ *
+ * Jalview is free software: you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 3
+ * of the License, or (at your option) any later version.
+ *
+ * Jalview is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty
+ * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ * PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Jalview. If not, see .
+ * The Jalview Authors are detailed in the 'AUTHORS' file.
+ */
+package jalview.gui;
+
+import java.awt.event.MouseAdapter;
+import java.awt.event.MouseEvent;
+import java.beans.PropertyVetoException;
+import java.util.List;
+
+import javax.swing.JInternalFrame;
+import javax.swing.JLayeredPane;
+import javax.swing.event.ChangeEvent;
+import javax.swing.event.ChangeListener;
+import javax.swing.event.InternalFrameAdapter;
+import javax.swing.event.InternalFrameEvent;
+
+import jalview.analysis.Conservation;
+import jalview.datamodel.SequenceGroup;
+import jalview.jbgui.GSliderPanel;
+import jalview.renderer.ResidueShaderI;
+import jalview.util.MessageManager;
+
+/**
+ * DOCUMENT ME!
+ *
+ * @author $author$
+ * @version $Revision$
+ */
+public class SliderPanel extends GSliderPanel
+{
+ private static final String BACKGROUND = "Background";
+
+ static JInternalFrame conservationSlider;
+
+ static JInternalFrame PIDSlider;
+
+ AlignmentPanel ap;
+
+ boolean forConservation = true;
+
+ ResidueShaderI cs;
+
+ /**
+ * Returns the currently displayed slider panel (or null if none).
+ *
+ * @return
+ */
+ public static SliderPanel getSliderPanel()
+ {
+ if (conservationSlider != null && conservationSlider.isVisible())
+ {
+ return (SliderPanel) conservationSlider.getContentPane();
+ }
+ if (PIDSlider != null && PIDSlider.isVisible())
+ {
+ return (SliderPanel) PIDSlider.getContentPane();
+ }
+ return null;
+ }
+
+ /**
+ * Creates a new SliderPanel object.
+ *
+ * @param ap
+ * DOCUMENT ME!
+ * @param value
+ * DOCUMENT ME!
+ * @param forConserve
+ * DOCUMENT ME!
+ * @param scheme
+ * DOCUMENT ME!
+ */
+ public SliderPanel(final AlignmentPanel ap, int value,
+ boolean forConserve, ResidueShaderI scheme)
+ {
+ this.ap = ap;
+ this.cs = scheme;
+ forConservation = forConserve;
+ undoButton.setVisible(false);
+ applyButton.setVisible(false);
+
+ if (forConservation)
+ {
+ label.setText(MessageManager.getString(
+ "label.enter_value_increase_conservation_visibility"));
+ slider.setMinimum(0);
+ slider.setMaximum(100);
+ }
+ else
+ {
+ label.setText(MessageManager.getString(
+ "label.enter_percentage_identity_above_which_colour_residues"));
+ slider.setMinimum(0);
+ slider.setMaximum(100);
+ }
+
+ slider.addChangeListener(new ChangeListener()
+ {
+ @Override
+ public void stateChanged(ChangeEvent evt)
+ {
+ valueField.setText(String.valueOf(slider.getValue()));
+ valueChanged(slider.getValue());
+ }
+ });
+
+ slider.addMouseListener(new MouseAdapter()
+ {
+ @Override
+ public void mouseReleased(MouseEvent evt)
+ {
+ ap.paintAlignment(true, true);
+ }
+ });
+
+ slider.setValue(value);
+ valueField.setText(String.valueOf(value));
+ }
+
+ /**
+ * Method to 'set focus' of the Conservation slider panel
+ *
+ * @param ap
+ * the panel to repaint on change of slider
+ * @param rs
+ * the colour scheme to update on change of slider
+ * @param source
+ * a text description for the panel's title
+ *
+ * @return
+ */
+ public static int setConservationSlider(AlignmentPanel ap,
+ ResidueShaderI rs, String source)
+ {
+ SliderPanel sliderPanel = null;
+
+ if (conservationSlider == null)
+ {
+ sliderPanel = new SliderPanel(ap, rs.getConservationInc(), true, rs);
+ conservationSlider = new JInternalFrame();
+ conservationSlider.setFrameIcon(null);
+ conservationSlider.setContentPane(sliderPanel);
+ conservationSlider.setLayer(JLayeredPane.PALETTE_LAYER);
+ }
+ else
+ {
+ sliderPanel = (SliderPanel) conservationSlider.getContentPane();
+ sliderPanel.valueField
+ .setText(String.valueOf(rs.getConservationInc()));
+ sliderPanel.cs = rs;
+ sliderPanel.ap = ap;
+ sliderPanel.slider.setValue(rs.getConservationInc());
+ }
+
+ conservationSlider.setTitle(MessageManager.formatMessage(
+ "label.conservation_colour_increment", new String[]
+ { source == null ? BACKGROUND : source }));
+
+ List groups = ap.av.getAlignment().getGroups();
+ if (groups != null && !groups.isEmpty())
+ {
+ sliderPanel.setAllGroupsCheckEnabled(true);
+ sliderPanel.allGroupsCheck
+ .setSelected(ap.av.getColourAppliesToAllGroups());
+ }
+ else
+ {
+ sliderPanel.setAllGroupsCheckEnabled(false);
+ }
+
+ return sliderPanel.getValue();
+ }
+
+ /**
+ * Hides the PID slider panel if it is shown
+ */
+ public static void hidePIDSlider()
+ {
+ if (PIDSlider != null)
+ {
+ try
+ {
+ PIDSlider.setClosed(true);
+ PIDSlider = null;
+ } catch (PropertyVetoException ex)
+ {
+ }
+ }
+ }
+
+ /**
+ * Hides the conservation slider panel if it is shown
+ */
+ public static void hideConservationSlider()
+ {
+ if (conservationSlider != null)
+ {
+ try
+ {
+ conservationSlider.setClosed(true);
+ conservationSlider = null;
+ } catch (PropertyVetoException ex)
+ {
+ }
+ }
+ }
+
+ /**
+ * DOCUMENT ME!
+ */
+ public static void showConservationSlider()
+ {
+ hidePIDSlider();
+
+ if (!conservationSlider.isVisible())
+ {
+ Desktop.addInternalFrame(conservationSlider,
+ conservationSlider.getTitle(), true, FRAME_WIDTH,
+ FRAME_HEIGHT, false, true);
+ conservationSlider.addInternalFrameListener(new InternalFrameAdapter()
+ {
+ @Override
+ public void internalFrameClosed(InternalFrameEvent e)
+ {
+ conservationSlider = null;
+ }
+ });
+ conservationSlider.setLayer(JLayeredPane.PALETTE_LAYER);
+ }
+ }
+
+ /**
+ * Method to 'set focus' of the PID slider panel
+ *
+ * @param ap
+ * the panel to repaint on change of slider
+ * @param rs
+ * the colour scheme to update on change of slider
+ * @param source
+ * a text description for the panel's title
+ *
+ * @return
+ */
+ public static int setPIDSliderSource(AlignmentPanel ap, ResidueShaderI rs,
+ String source)
+ {
+ int threshold = rs.getThreshold();
+
+ SliderPanel sliderPanel = null;
+
+ if (PIDSlider == null)
+ {
+ sliderPanel = new SliderPanel(ap, threshold, false, rs);
+ PIDSlider = new JInternalFrame();
+ PIDSlider.setFrameIcon(null);
+ PIDSlider.setContentPane(sliderPanel);
+ PIDSlider.setLayer(JLayeredPane.PALETTE_LAYER);
+ }
+ else
+ {
+ sliderPanel = (SliderPanel) PIDSlider.getContentPane();
+ sliderPanel.cs = rs;
+ sliderPanel.ap = ap;
+ sliderPanel.valueField.setText(String.valueOf(rs.getThreshold()));
+ sliderPanel.slider.setValue(rs.getThreshold());
+ }
+
+ PIDSlider.setTitle(MessageManager.formatMessage(
+ "label.percentage_identity_threshold", new String[]
+ { source == null ? BACKGROUND : source }));
+
+ if (ap.av.getAlignment().getGroups() != null)
+ {
+ sliderPanel.setAllGroupsCheckEnabled(true);
+ }
+ else
+ {
+ sliderPanel.setAllGroupsCheckEnabled(false);
+ }
+
+ return sliderPanel.getValue();
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @return
+ */
+ public static JInternalFrame showPIDSlider()
+ {
+ hideConservationSlider();
+
+ if (!PIDSlider.isVisible())
+ {
+ Desktop.addInternalFrame(PIDSlider, PIDSlider.getTitle(), true,
+ FRAME_WIDTH, FRAME_HEIGHT, false, true);
+ PIDSlider.setLayer(JLayeredPane.PALETTE_LAYER);
+ PIDSlider.addInternalFrameListener(new InternalFrameAdapter()
+ {
+ @Override
+ public void internalFrameClosed(InternalFrameEvent e)
+ {
+ PIDSlider = null;
+ }
+ });
+ PIDSlider.setLayer(JLayeredPane.PALETTE_LAYER);
+ }
+ return PIDSlider;
+ }
+
+ /**
+ * Updates the colour scheme with the current (identity threshold or
+ * conservation) percentage value. Also updates all groups if 'apply to all
+ * groups' is selected.
+ *
+ * @param percent
+ */
+ public void valueChanged(int percent)
+ {
+ if (!forConservation)
+ {
+ ap.av.setThreshold(percent);
+ }
+ updateColourScheme(percent, cs, null);
+
+ if (allGroupsCheck.isSelected())
+ {
+ List groups = ap.av.getAlignment().getGroups();
+ for (SequenceGroup sg : groups)
+ {
+ updateColourScheme(percent, sg.getGroupColourScheme(), sg);
+ }
+ }
+
+ ap.getSeqPanel().seqCanvas.repaint();
+ }
+
+ /**
+ * Updates the colour scheme (if not null) with the current (identity
+ * threshold or conservation) percentage value
+ *
+ * @param percent
+ * @param scheme
+ * @param sg
+ */
+ protected void updateColourScheme(int percent, ResidueShaderI scheme,
+ SequenceGroup sg)
+ {
+ if (scheme == null)
+ {
+ return;
+ }
+ if (forConservation)
+ {
+ if (!scheme.conservationApplied() && sg != null)
+ {
+ /*
+ * first time the colour scheme has had Conservation shading applied
+ * - compute conservation
+ */
+ Conservation c = new Conservation("Group", sg.getSequences(null),
+ sg.getStartRes(), sg.getEndRes());
+ c.calculate();
+ c.verdict(false, ap.av.getConsPercGaps());
+ sg.cs.setConservation(c);
+
+ }
+ scheme.setConservationApplied(true);
+ scheme.setConservationInc(percent);
+ }
+ else
+ {
+ scheme.setThreshold(percent, ap.av.isIgnoreGapsConsensus());
+ }
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param b
+ * DOCUMENT ME!
+ */
+ public void setAllGroupsCheckEnabled(boolean b)
+ {
+ allGroupsCheck.setEnabled(b);
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param e
+ * DOCUMENT ME!
+ */
+ @Override
+ public void valueField_actionPerformed()
+ {
+ try
+ {
+ int i = Integer.parseInt(valueField.getText());
+ slider.setValue(i);
+ } catch (NumberFormatException ex)
+ {
+ valueField.setText(slider.getValue() + "");
+ }
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param value
+ * DOCUMENT ME!
+ */
+ public void setValue(int value)
+ {
+ slider.setValue(value);
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public int getValue()
+ {
+ return Integer.parseInt(valueField.getText());
+ }
+
+ @Override
+ public void slider_mouseReleased(MouseEvent e)
+ {
+ if (ap.overviewPanel != null)
+ {
+ ap.overviewPanel.updateOverviewImage();
+ }
+ }
+
+ public static int getConservationValue()
+ {
+ return getValue(conservationSlider);
+ }
+
+ static int getValue(JInternalFrame slider)
+ {
+ return slider == null ? 0
+ : ((SliderPanel) slider.getContentPane()).getValue();
+ }
+
+ public static int getPIDValue()
+ {
+ return getValue(PIDSlider);
+ }
+
+ /**
+ * Answers true if the SliderPanel is for Conservation, false if it is for PID
+ * threshold
+ *
+ * @return
+ */
+ public boolean isForConservation()
+ {
+ return forConservation;
+ }
+
+ /**
+ * Answers the title for the slider panel; this may include 'Background' if
+ * for the alignment, or the group id if for a group
+ *
+ * @return
+ */
+ public String getTitle()
+ {
+ String title = null;
+ if (isForConservation())
+ {
+ if (conservationSlider != null)
+ {
+ title = conservationSlider.getTitle();
+ }
+ }
+ else if (PIDSlider != null)
+ {
+ title = PIDSlider.getTitle();
+ }
+ return title;
+ }
+}