/*
- * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.2)
- * Copyright (C) 2014 The Jalview Authors
+ * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
+ * Copyright (C) $$Year-Rel$$ The Jalview Authors
*
* This file is part of Jalview.
*
*/
package jalview.gui;
-import java.util.*;
+import jalview.datamodel.SequenceGroup;
+import jalview.jbgui.GSliderPanel;
+import jalview.schemes.CollectionColourSchemeI;
+import jalview.util.MessageManager;
-import java.awt.event.*;
-import javax.swing.*;
-import javax.swing.event.*;
+import java.awt.event.ActionEvent;
+import java.awt.event.MouseAdapter;
+import java.awt.event.MouseEvent;
-import jalview.datamodel.*;
-import jalview.jbgui.*;
-import jalview.schemes.*;
-import jalview.util.MessageManager;
+import javax.swing.JInternalFrame;
+import javax.swing.JLayeredPane;
+import javax.swing.event.ChangeEvent;
+import javax.swing.event.ChangeListener;
/**
* DOCUMENT ME!
boolean forConservation = true;
- ColourSchemeI cs;
+ CollectionColourSchemeI cs;
/**
* Creates a new SliderPanel object.
* DOCUMENT ME!
* @param forConserve
* DOCUMENT ME!
- * @param cs
+ * @param scheme
* DOCUMENT ME!
*/
public SliderPanel(final AlignmentPanel ap, int value,
- boolean forConserve, ColourSchemeI cs)
+ boolean forConserve, CollectionColourSchemeI scheme)
{
this.ap = ap;
- this.cs = cs;
+ this.cs = scheme;
forConservation = forConserve;
undoButton.setVisible(false);
applyButton.setVisible(false);
slider.addChangeListener(new ChangeListener()
{
+ @Override
public void stateChanged(ChangeEvent evt)
{
valueField.setText(slider.getValue() + "");
slider.addMouseListener(new MouseAdapter()
{
+ @Override
public void mouseReleased(MouseEvent evt)
{
ap.paintAlignment(true);
* @return DOCUMENT ME!
*/
public static int setConservationSlider(AlignmentPanel ap,
- ColourSchemeI cs, String source)
+ CollectionColourSchemeI cs, String source)
{
SliderPanel sp = null;
sp.cs = cs;
}
- conservationSlider.setTitle("Conservation Colour Increment (" + source
- + ")");
+ conservationSlider
+ .setTitle(MessageManager.formatMessage(
+ "label.conservation_colour_increment",
+ new String[] { source }));
if (ap.av.getAlignment().getGroups() != null)
{
conservationSlider
.addInternalFrameListener(new javax.swing.event.InternalFrameAdapter()
{
+ @Override
public void internalFrameClosed(
javax.swing.event.InternalFrameEvent e)
{
*
* @param ap
* DOCUMENT ME!
- * @param cs
+ * @param collectionColourScheme
* DOCUMENT ME!
* @param source
* DOCUMENT ME!
*
* @return DOCUMENT ME!
*/
- public static int setPIDSliderSource(AlignmentPanel ap, ColourSchemeI cs,
+ public static int setPIDSliderSource(AlignmentPanel ap,
+ CollectionColourSchemeI collectionColourScheme,
String source)
{
SliderPanel pid = null;
- int threshold = cs.getThreshold();
+ int threshold = collectionColourScheme.getThreshold();
if (PIDSlider == null)
{
- pid = new SliderPanel(ap, threshold, false, cs);
+ pid = new SliderPanel(ap, threshold, false, collectionColourScheme);
PIDSlider = new JInternalFrame();
PIDSlider.setContentPane(pid);
PIDSlider.setLayer(JLayeredPane.PALETTE_LAYER);
else
{
pid = (SliderPanel) PIDSlider.getContentPane();
- pid.cs = cs;
+ pid.cs = collectionColourScheme;
}
- PIDSlider.setTitle("Percentage Identity Threshold (" + source + ")");
+ PIDSlider
+ .setTitle(MessageManager.formatMessage(
+ "label.percentage_identity_threshold",
+ new String[] { source }));
if (ap.av.getAlignment().getGroups() != null)
{
PIDSlider
.addInternalFrameListener(new javax.swing.event.InternalFrameAdapter()
{
+ @Override
public void internalFrameClosed(
javax.swing.event.InternalFrameEvent e)
{
}
/**
- * DOCUMENT ME!
+ * 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 i
- * DOCUMENT ME!
+ * @param percent
*/
- public void valueChanged(int i)
+ public void valueChanged(int percent)
{
- if (cs == null)
+ if (!forConservation)
{
- return;
+ ap.av.setThreshold(percent);
}
-
- ColourSchemeI toChange = cs;
- Iterator<SequenceGroup> allGroups = null;
+ updateColourScheme(percent, cs);
if (allGroupsCheck.isSelected())
{
- allGroups = ap.av.getAlignment().getGroups().listIterator();
- }
-
- while (toChange != null)
- {
- if (forConservation)
+ for (SequenceGroup sg : ap.av.getAlignment().getGroups())
{
- toChange.setConservationInc(i);
- }
- else
- {
- toChange.setThreshold(i, ap.av.getIgnoreGapsConsensus());
- }
- if (allGroups != null && allGroups.hasNext())
- {
- while ((toChange = allGroups.next().cs) == null
- && allGroups.hasNext())
- ;
- }
- else
- {
- toChange = null;
+ updateColourScheme(percent, sg.getGroupColourScheme());
}
}
- ap.seqPanel.seqCanvas.repaint();
+ ap.getSeqPanel().seqCanvas.repaint();
+ }
+
+ /**
+ * Updates the colour scheme (if not null) with the current (identity
+ * threshold or conservation) percentage value
+ *
+ * @param percent
+ * @param scheme
+ */
+ protected void updateColourScheme(int percent, CollectionColourSchemeI scheme)
+ {
+ if (scheme == null)
+ {
+ return;
+ }
+ if (forConservation)
+ {
+ scheme.setConservationInc(percent);
+ }
+ else
+ {
+ scheme.setThreshold(percent, ap.av.isIgnoreGapsConsensus());
+ }
}
/**
* @param e
* DOCUMENT ME!
*/
+ @Override
public void valueField_actionPerformed(ActionEvent e)
{
try
return Integer.parseInt(valueField.getText());
}
+ @Override
public void slider_mouseReleased(MouseEvent e)
{
if (ap.overviewPanel != null)
}
}
+ 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);
+ }
+
}