{
FileFormatI format = fileFormat;
cap.setText(new FormatAdapter(alignPanel, exportData.getSettings())
- .formatSequences(format,
- exportData.getAlignment(),
+ .formatSequences(format, exportData.getAlignment(),
exportData.getOmitHidden(),
exportData.getStartEndPostions(),
viewport.getColumnSelection()));
}
String output = new FormatAdapter().formatSequences(FileFormat.Fasta,
- seqs,
- omitHidden, null);
+ seqs, omitHidden, null);
StringSelection ss = new StringSelection(output);
* colour scheme to all groups. If unchecked, groups may have their own
* independent colour schemes.
*
+ * @param selected
*/
@Override
- protected void applyToAllGroups_actionPerformed()
+ protected void applyToAllGroups_actionPerformed(boolean selected)
{
- viewport.setColourAppliesToAllGroups(applyToAllGroups.isSelected());
+ viewport.setColourAppliesToAllGroups(selected);
}
/**
@Override
protected void modifyPID_actionPerformed()
{
- if (viewport.getAbovePIDThreshold())
- {
- SliderPanel.setPIDSliderSource(alignPanel,
- viewport.getViewportColourScheme(), "Background");
- SliderPanel.showPIDSlider();
- }
+ SliderPanel.setPIDSliderSource(alignPanel,
+ viewport.getViewportColourScheme(), "Background");
+ SliderPanel.showPIDSlider();
}
/**
@Override
protected void modifyConservation_actionPerformed()
{
- if (viewport.getConservationSelected()
- && viewport.getGlobalColourScheme() != null)
- {
- SliderPanel.setConservationSlider(alignPanel,
- viewport.getViewportColourScheme(), "Background");
- SliderPanel.showConservationSlider();
- }
+ SliderPanel.setConservationSlider(alignPanel,
+ viewport.getViewportColourScheme(), "Background");
+ SliderPanel.showConservationSlider();
}
/**
* Action on selecting or deselecting (Colour) By Conservation
*/
@Override
- protected void conservationMenuItem_actionPerformed()
+ protected void conservationMenuItem_actionPerformed(boolean selected)
{
- boolean selected = conservationMenuItem.isSelected();
modifyConservation.setEnabled(selected);
viewport.setConservationSelected(selected);
viewport.getViewportColourScheme().setConservationApplied(selected);
* Action on selecting or deselecting (Colour) Above PID Threshold
*/
@Override
- public void abovePIDThreshold_actionPerformed()
+ public void abovePIDThreshold_actionPerformed(boolean selected)
{
- boolean selected = abovePIDThreshold.isSelected();
modifyPID.setEnabled(selected);
viewport.setAbovePIDThreshold(selected);
}
if (FileFormat.Jnet.equals(format))
{
- JPredFile predictions = new JPredFile(
- file, sourceType);
+ JPredFile predictions = new JPredFile(file, sourceType);
new JnetAnnotationMaker();
JnetAnnotationMaker.add_annotation(predictions,
viewport.getAlignment(), 0, false);
@Override
public void actionPerformed(ActionEvent e)
{
- abovePIDColour_actionPerformed();
+ abovePIDColour_actionPerformed(abovePIDColour.isSelected());
}
});
@Override
public void actionPerformed(ActionEvent e)
{
- conservationMenuItem_actionPerformed();
+ conservationMenuItem_actionPerformed(conservationMenuItem
+ .isSelected());
}
});
/**
* DOCUMENT ME!
*
+ * @param selected
+ *
* @param e
* DOCUMENT ME!
*/
- protected void abovePIDColour_actionPerformed()
+ protected void abovePIDColour_actionPerformed(boolean selected)
{
SequenceGroup sg = getGroup();
if (sg.cs == null)
return;
}
- boolean selected = abovePIDColour.isSelected();
if (selected)
{
sg.cs.setConsensus(AAFrequency.calculate(
* @param e
* DOCUMENT ME!
*/
- protected void conservationMenuItem_actionPerformed()
+ protected void conservationMenuItem_actionPerformed(boolean selected)
{
SequenceGroup sg = getGroup();
if (sg.cs == null)
return;
}
- boolean selected = conservationMenuItem.isSelected();
if (selected)
{
// JBPNote: Conservation name shouldn't be i18n translated
/**
* Action on user selecting an item from the colour menu (that does not have
* its bespoke action handler)
+ *
+ * @return
*/
@Override
public void changeColour_actionPerformed(String colourSchemeName)
CollectionColourSchemeI cs;
+ private static SliderPanel sliderPanel;
+
+ /**
+ * Returns the currently active slider panel (or null if none).
+ *
+ * @return
+ */
+ public static SliderPanel getSliderPanel()
+ {
+ return sliderPanel;
+ }
+
/**
* Creates a new SliderPanel object.
*
public static int setConservationSlider(AlignmentPanel ap,
CollectionColourSchemeI ccs, String source)
{
- SliderPanel sp = null;
+ sliderPanel = null;
if (conservationSlider == null)
{
- sp = new SliderPanel(ap, ccs.getConservationInc(), true, ccs);
+ sliderPanel = new SliderPanel(ap, ccs.getConservationInc(), true, ccs);
conservationSlider = new JInternalFrame();
- conservationSlider.setContentPane(sp);
+ conservationSlider.setContentPane(sliderPanel);
conservationSlider.setLayer(JLayeredPane.PALETTE_LAYER);
}
else
{
- sp = (SliderPanel) conservationSlider.getContentPane();
- sp.valueField.setText(String.valueOf(ccs.getConservationInc()));
- sp.cs = ccs;
+ sliderPanel = (SliderPanel) conservationSlider.getContentPane();
+ sliderPanel.valueField.setText(String.valueOf(ccs.getConservationInc()));
+ sliderPanel.cs = ccs;
}
conservationSlider
if (ap.av.getAlignment().getGroups() != null)
{
- sp.setAllGroupsCheckEnabled(true);
+ sliderPanel.setAllGroupsCheckEnabled(true);
}
else
{
- sp.setAllGroupsCheckEnabled(false);
+ sliderPanel.setAllGroupsCheckEnabled(false);
}
- return sp.getValue();
+ return sliderPanel.getValue();
}
/**
public static int setPIDSliderSource(AlignmentPanel ap,
CollectionColourSchemeI ccs, String source)
{
- SliderPanel pid = null;
-
int threshold = ccs.getThreshold();
if (PIDSlider == null)
{
- pid = new SliderPanel(ap, threshold, false, ccs);
+ sliderPanel = new SliderPanel(ap, threshold, false, ccs);
PIDSlider = new JInternalFrame();
- PIDSlider.setContentPane(pid);
+ PIDSlider.setContentPane(sliderPanel);
PIDSlider.setLayer(JLayeredPane.PALETTE_LAYER);
}
else
{
- pid = (SliderPanel) PIDSlider.getContentPane();
- pid.cs = ccs;
- pid.valueField.setText(String.valueOf(ccs.getThreshold()));
+ sliderPanel = (SliderPanel) PIDSlider.getContentPane();
+ sliderPanel.cs = ccs;
+ sliderPanel.valueField.setText(String.valueOf(ccs.getThreshold()));
}
PIDSlider
if (ap.av.getAlignment().getGroups() != null)
{
- pid.setAllGroupsCheckEnabled(true);
+ sliderPanel.setAllGroupsCheckEnabled(true);
}
else
{
- pid.setAllGroupsCheckEnabled(false);
+ sliderPanel.setAllGroupsCheckEnabled(false);
}
- return pid.getValue();
+ return sliderPanel.getValue();
}
/**
* DOCUMENT ME!
+ *
+ * @return
*/
- public static void showPIDSlider()
+ public static JInternalFrame showPIDSlider()
{
hideConservationSlider();
});
PIDSlider.setLayer(JLayeredPane.PALETTE_LAYER);
}
+ return PIDSlider;
}
/**
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;
+ }
}
};
addMenuActionAndAccelerator(keyStroke, redoMenuItem, al);
- conservationMenuItem.setText(MessageManager
- .getString("action.by_conservation"));
- conservationMenuItem.addActionListener(new ActionListener()
- {
- @Override
- public void actionPerformed(ActionEvent e)
- {
- conservationMenuItem_actionPerformed();
- }
- });
-
wrapMenuItem.setText(MessageManager.getString("label.wrap"));
wrapMenuItem.addActionListener(new ActionListener()
{
};
addMenuActionAndAccelerator(keyStroke, findMenuItem, al);
- abovePIDThreshold.setText(MessageManager
- .getString("label.above_identity_threshold"));
- abovePIDThreshold.addActionListener(new ActionListener()
- {
- @Override
- public void actionPerformed(ActionEvent e)
- {
- abovePIDThreshold_actionPerformed();
- }
- });
-
showSeqFeatures.setText(MessageManager
.getString("label.show_sequence_features"));
showSeqFeatures.addActionListener(new ActionListener()
});
- modifyPID = new JMenuItem(
- MessageManager.getString("label.modify_identity_threshold"));
- modifyPID.addActionListener(new ActionListener()
- {
- @Override
- public void actionPerformed(ActionEvent e)
- {
- modifyPID_actionPerformed();
- }
- });
- modifyConservation.setText(MessageManager
- .getString("label.modify_conservation_threshold"));
- modifyConservation.addActionListener(new ActionListener()
- {
- @Override
- public void actionPerformed(ActionEvent e)
- {
- modifyConservation_actionPerformed();
- }
- });
-
sortByTreeMenu
.setText(MessageManager.getString("action.by_tree_order"));
sort.setText(MessageManager.getString("action.sort"));
@Override
public void actionPerformed(ActionEvent e)
{
- applyToAllGroups_actionPerformed();
+ applyToAllGroups_actionPerformed(applyToAllGroups.isSelected());
}
});
@Override
public void actionPerformed(ActionEvent e)
{
- conservationMenuItem_actionPerformed();
+ conservationMenuItem_actionPerformed(conservationMenuItem
+ .isSelected());
}
});
@Override
public void actionPerformed(ActionEvent e)
{
- abovePIDThreshold_actionPerformed();
+ abovePIDThreshold_actionPerformed(abovePIDThreshold.isSelected());
}
});
modifyPID = new JMenuItem(
{
}
- protected void conservationMenuItem_actionPerformed()
+ protected void conservationMenuItem_actionPerformed(boolean selected)
{
}
{
}
- protected void abovePIDThreshold_actionPerformed()
+ protected void abovePIDThreshold_actionPerformed(boolean selected)
{
}
{
}
- protected void applyToAllGroups_actionPerformed()
+ protected void applyToAllGroups_actionPerformed(boolean selected)
{
}
|| cs instanceof Blosum62ColourScheme)
{
globalColourScheme.setConservation(hconservation);
+ globalColourScheme
+ .setConservationApplied(getConservationSelected());
}
globalColourScheme.alignmentChanged(alignment, hiddenRepSequences);
}
import static org.testng.AssertJUnit.assertEquals;
import static org.testng.AssertJUnit.assertFalse;
+import static org.testng.AssertJUnit.assertSame;
import static org.testng.AssertJUnit.assertTrue;
import jalview.datamodel.Alignment;
import jalview.datamodel.AlignmentI;
import jalview.datamodel.Sequence;
import jalview.datamodel.SequenceFeature;
+import jalview.datamodel.SequenceGroup;
import jalview.datamodel.SequenceI;
+import jalview.io.DataSourceType;
+import jalview.io.FileLoader;
+import jalview.schemes.BuriedColourScheme;
+import jalview.schemes.HelixColourScheme;
+import jalview.schemes.JalviewColourScheme;
+import jalview.schemes.StrandColourScheme;
+import jalview.schemes.TurnColourScheme;
+import jalview.util.MessageManager;
import java.util.List;
import org.testng.annotations.BeforeClass;
+import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
public class AlignFrameTest
{
+ AlignFrame af;
@BeforeClass(alwaysRun = true)
public void setUpJvOptionPane()
assertEquals(6, hidden.get(1)[0]);
assertEquals(8, hidden.get(1)[1]);
}
+
+ @BeforeMethod
+ public void setUp()
+ {
+ af = new FileLoader().LoadFileWaitTillLoaded("examples/uniref50.fa",
+ DataSourceType.FILE);
+ }
+
+ /**
+ * Test that changing background (alignment) colour scheme
+ * <ul>
+ * <li>with Apply Colour to All Groups not selected, does not change group
+ * colours</li>
+ * <li>with Apply Colour to All Groups selected, does change group colours</li>
+ * <li>in neither case, changes alignment or group colour thresholds (PID or
+ * Conservation)</li>
+ * </ul>
+ */
+ @Test
+ public void testChangeColour_background_groupsAndThresholds()
+ {
+ AlignViewport av = af.getViewport();
+ AlignmentI al = av.getAlignment();
+
+ /*
+ * Colour alignment by Buried Index
+ */
+ af.applyToAllGroups_actionPerformed(false);
+ af.changeColour_actionPerformed(JalviewColourScheme.Buried.toString());
+ assertTrue(av.getGlobalColourScheme() instanceof BuriedColourScheme);
+ assertFalse(av.getViewportColourScheme().conservationApplied());
+ assertEquals(av.getViewportColourScheme().getThreshold(), 0);
+
+ /*
+ * Apply Conservation 20%
+ */
+ af.conservationMenuItem_actionPerformed(true);
+ SliderPanel sp = SliderPanel.getSliderPanel();
+ assertEquals(sp.getTitle(), MessageManager.formatMessage(
+ "label.conservation_colour_increment",
+ new String[] { "Background" }));
+ assertTrue(sp.isForConservation());
+ sp.valueChanged(20);
+ assertTrue(av.getViewportColourScheme().conservationApplied());
+ assertEquals(av.getViewportColourScheme().getConservationInc(), 20);
+
+ /*
+ * Apply PID threshold 10% (conservation still applies as well)
+ */
+ af.abovePIDThreshold_actionPerformed(true);
+ sp = SliderPanel.getSliderPanel();
+ assertFalse(sp.isForConservation());
+ assertEquals(sp.getTitle(), MessageManager.formatMessage(
+ "label.percentage_identity_threshold",
+ new String[] { "Background" }));
+ sp.valueChanged(10);
+ assertEquals(av.getViewportColourScheme().getThreshold(), 10);
+ assertTrue(av.getViewportColourScheme().conservationApplied());
+ assertEquals(av.getViewportColourScheme().getConservationInc(), 20);
+
+ /*
+ * create a group with Strand colouring, 30% Conservation
+ * and 40% PID threshold
+ */
+ SequenceGroup sg = new SequenceGroup();
+ sg.addSequence(al.getSequenceAt(0), false);
+ sg.setStartRes(15);
+ sg.setEndRes(25);
+ av.setSelectionGroup(sg);
+
+ /*
+ * apply 30% Conservation to group
+ */
+ PopupMenu popupMenu = new PopupMenu(af.alignPanel, null, null);
+ popupMenu.changeColour_actionPerformed(JalviewColourScheme.Strand
+ .toString());
+ assertTrue(sg.getColourScheme() instanceof StrandColourScheme);
+ assertEquals(al.getGroups().size(), 1);
+ assertSame(al.getGroups().get(0), sg);
+ popupMenu.conservationMenuItem_actionPerformed(true);
+ sp = SliderPanel.getSliderPanel();
+ assertTrue(sp.isForConservation());
+ assertEquals(sp.getTitle(), MessageManager.formatMessage(
+ "label.conservation_colour_increment",
+ new String[] { sg.getName() }));
+ sp.valueChanged(30);
+ assertTrue(sg.getGroupColourScheme().conservationApplied());
+ assertEquals(sg.getGroupColourScheme().getConservationInc(), 30);
+
+ /*
+ * apply 40% PID threshold to group
+ */
+ popupMenu.abovePIDColour_actionPerformed(true);
+ sp = SliderPanel.getSliderPanel();
+ assertFalse(sp.isForConservation());
+ assertEquals(sp.getTitle(), MessageManager.formatMessage(
+ "label.percentage_identity_threshold",
+ new String[] { sg.getName() }));
+ sp.valueChanged(40);
+ assertEquals(sg.getGroupColourScheme().getThreshold(), 40);
+ // conservation threshold is unchanged:
+ assertTrue(sg.getGroupColourScheme().conservationApplied());
+ assertEquals(sg.getGroupColourScheme().getConservationInc(), 30);
+
+ /*
+ * change alignment colour - group colour, and all thresholds,
+ * should be unaffected
+ */
+ af.changeColour_actionPerformed(JalviewColourScheme.Turn.toString());
+ assertTrue(av.getGlobalColourScheme() instanceof TurnColourScheme);
+ assertTrue(av.getViewportColourScheme().conservationApplied());
+ assertEquals(av.getViewportColourScheme().getConservationInc(), 20);
+ assertEquals(av.getViewportColourScheme().getThreshold(), 10);
+ assertTrue(sg.getColourScheme() instanceof StrandColourScheme);
+ assertTrue(sg.getGroupColourScheme().conservationApplied());
+ assertEquals(sg.getGroupColourScheme().getConservationInc(), 30);
+ assertEquals(sg.getGroupColourScheme().getThreshold(), 40);
+
+ /*
+ * Now change alignment colour with Apply Colour To All Groups
+ * - group colour should change, but not colour thresholds
+ */
+ af.applyToAllGroups_actionPerformed(true);
+ af.changeColour_actionPerformed(JalviewColourScheme.Helix.toString());
+ assertTrue(av.getGlobalColourScheme() instanceof HelixColourScheme);
+ assertTrue(av.getViewportColourScheme().conservationApplied());
+ assertEquals(av.getViewportColourScheme().getConservationInc(), 20);
+ assertEquals(av.getViewportColourScheme().getThreshold(), 10);
+ assertTrue(sg.getColourScheme() instanceof HelixColourScheme);
+ assertTrue(sg.getGroupColourScheme().conservationApplied());
+ assertEquals(sg.getGroupColourScheme().getConservationInc(), 30);
+ assertEquals(sg.getGroupColourScheme().getThreshold(), 40);
+ }
}