+ @BeforeMethod(alwaysRun = true)
+ public void setUp() throws IOException
+ {
+ // pin down annotation sort order for test
+ Cache.applicationProperties.setProperty(Preferences.SORT_ANNOTATIONS,
+ SequenceAnnotationOrder.NONE.name());
+ final String TRUE = Boolean.TRUE.toString();
+ Cache.applicationProperties.setProperty(
+ Preferences.SHOW_AUTOCALC_ABOVE, TRUE);
+ Cache.applicationProperties.setProperty("SHOW_QUALITY", TRUE);
+ Cache.applicationProperties.setProperty("SHOW_CONSERVATION", TRUE);
+ Cache.applicationProperties.setProperty("SHOW_IDENTITY", TRUE);
+
+ AlignmentI al = new jalview.io.FormatAdapter().readFile(TEST_DATA,
+ AppletFormatAdapter.PASTE, "FASTA");
+ af = new AlignFrame(al, 700, 500);
+ parentPanel = new AlignmentPanel(af, af.getViewport());
+ addAnnotations();
+ }
+
+ /**
+ * Add 4 annotations, 3 of them sequence-specific.
+ *
+ * <PRE>
+ * ann1 - for sequence 0 - label 'IUPRED'
+ * ann2 - not sequence related - label 'Beauty'
+ * ann3 - for sequence 3 - label 'JMol'
+ * ann4 - for sequence 2 - label 'IUPRED'
+ * ann5 - for sequence 1 - label 'JMol'
+ */
+ private void addAnnotations()
+ {
+ Annotation an = new Annotation(2f);
+ Annotation[] anns = new Annotation[] { an, an, an };
+ AlignmentAnnotation ann0 = new AlignmentAnnotation("IUPRED", "", anns);
+ AlignmentAnnotation ann1 = new AlignmentAnnotation("Beauty", "", anns);
+ AlignmentAnnotation ann2 = new AlignmentAnnotation("JMol", "", anns);
+ AlignmentAnnotation ann3 = new AlignmentAnnotation("IUPRED", "", anns);
+ AlignmentAnnotation ann4 = new AlignmentAnnotation("JMol", "", anns);
+ SequenceI[] seqs = parentPanel.getAlignment().getSequencesArray();
+ ann0.setSequenceRef(seqs[0]);
+ ann2.setSequenceRef(seqs[3]);
+ ann3.setSequenceRef(seqs[2]);
+ ann4.setSequenceRef(seqs[1]);
+ parentPanel.getAlignment().addAnnotation(ann0);
+ parentPanel.getAlignment().addAnnotation(ann1);
+ parentPanel.getAlignment().addAnnotation(ann2);
+ parentPanel.getAlignment().addAnnotation(ann3);
+ parentPanel.getAlignment().addAnnotation(ann4);
+ }
+
+ /**
+ * Test creation of panel with OK and Cancel buttons
+ */
+ @Test(groups = { "Functional" })
+ public void testBuildActionButtonsPanel()
+ {
+ testee = new AnnotationChooser(parentPanel);
+ JPanel jp = testee.buildActionButtonsPanel();
+ assertTrue("Wrong layout", jp.getLayout() instanceof FlowLayout);
+
+ Component[] comps = jp.getComponents();
+ assertEquals("Not 2 action buttons", 2, comps.length);
+
+ final Component jb1 = comps[0];
+ final Component jb2 = comps[1];
+
+ assertEquals("Not 'OK' button", MessageManager.getString("action.ok"),
+ ((JButton) jb1).getText());
+ assertEquals("Wrong button font", JvSwingUtils.getLabelFont(),
+ jb1.getFont());
+
+ assertEquals("Not 'Cancel' button",
+ MessageManager.getString("action.cancel"),
+ ((JButton) jb2).getText());
+ assertEquals("Wrong button font", JvSwingUtils.getLabelFont(),
+ jb2.getFont());
+ }
+
+ /**
+ * Test 'Apply to' has 3 radio buttons enabled, 'Selected Sequences' selected,
+ * when there is a current selection group.
+ */
+ @Test(groups = { "Functional" })
+ public void testBuildApplyToOptionsPanel_withSelectionGroup()
+ {
+ selectSequences(0, 2, 3);
+ testee = new AnnotationChooser(parentPanel);
+
+ JPanel jp = testee.buildApplyToOptionsPanel();
+ Component[] comps = jp.getComponents();
+ assertEquals("Not 3 radio buttons", 3, comps.length);
+
+ final Checkbox cb1 = (Checkbox) comps[0];
+ final Checkbox cb2 = (Checkbox) comps[1];
+ final Checkbox cb3 = (Checkbox) comps[2];
+
+ assertTrue("Not enabled", cb1.isEnabled());
+ assertTrue("Not enabled", cb2.isEnabled());
+ assertTrue("Not enabled", cb3.isEnabled());
+ assertEquals("Option not selected", cb2, cb2.getCheckboxGroup()
+ .getSelectedCheckbox());
+
+ // check state variables match checkbox selection
+ assertTrue(testee.isApplyToSelectedSequences());
+ assertFalse(testee.isApplyToUnselectedSequences());
+ }
+
+ /**
+ * Add a sequence group to the alignment with the specified sequences (base 0)
+ * in it
+ *
+ * @param i
+ * @param more
+ */
+ private void selectSequences(int... selected)
+ {
+ SequenceI[] seqs = parentPanel.getAlignment().getSequencesArray();
+ SequenceGroup sg = new SequenceGroup();
+ for (int i : selected)
+ {
+ sg.addSequence(seqs[i], false);
+ }
+ parentPanel.av.setSelectionGroup(sg);
+ }
+
+ /**
+ * Test 'Apply to' has 1 radio button enabled, 'All Sequences' selected, when
+ * there is no current selection group.
+ */
+ @Test(groups = { "Functional" })
+ public void testBuildApplyToOptionsPanel_noSelectionGroup()
+ {
+ testee = new AnnotationChooser(parentPanel);
+ JPanel jp = testee.buildApplyToOptionsPanel();
+ verifyApplyToOptionsPanel_noSelectionGroup(jp);
+ }
+
+ protected void verifyApplyToOptionsPanel_noSelectionGroup(JPanel jp)
+ {
+ assertTrue("Wrong layout", jp.getLayout() instanceof FlowLayout);
+ Component[] comps = jp.getComponents();
+ assertEquals("Not 3 radio buttons", 3, comps.length);
+
+ final Checkbox cb1 = (Checkbox) comps[0];
+ final Checkbox cb2 = (Checkbox) comps[1];
+ final Checkbox cb3 = (Checkbox) comps[2];
+
+ assertTrue("Not enabled", cb1.isEnabled());
+ assertFalse("Enabled", cb2.isEnabled());
+ assertFalse("Enabled", cb3.isEnabled());
+ assertEquals("Not selected", cb1, cb1.getCheckboxGroup()
+ .getSelectedCheckbox());
+
+ // check state variables match checkbox selection
+ assertTrue(testee.isApplyToSelectedSequences());
+ assertTrue(testee.isApplyToUnselectedSequences());
+
+ assertEquals("Wrong text",
+ MessageManager.getString("label.all_sequences"), cb1.getLabel());
+ assertEquals("Wrong text",
+ MessageManager.getString("label.selected_sequences"),
+ cb2.getLabel());
+ assertEquals("Wrong text",
+ MessageManager.getString("label.except_selected_sequences"),
+ cb3.getLabel());
+ }
+
+ /**
+ * Test Show and Hide radio buttons created, with Hide initially selected.
+ */
+ @Test(groups = { "Functional" })
+ public void testBuildShowHidePanel()
+ {
+ testee = new AnnotationChooser(parentPanel);
+ JPanel jp = testee.buildShowHidePanel();
+ verifyShowHidePanel(jp);
+
+ }
+
+ protected void verifyShowHidePanel(JPanel jp)
+ {
+ assertTrue("Wrong layout", jp.getLayout() instanceof FlowLayout);
+ Component[] comps = jp.getComponents();
+ assertEquals("Not 2 radio buttons", 2, comps.length);
+
+ final Checkbox cb1 = (Checkbox) comps[0];
+ final Checkbox cb2 = (Checkbox) comps[1];
+
+ assertTrue("Show not enabled", cb1.isEnabled());
+ assertTrue("Hide not enabled", cb2.isEnabled());
+
+ // Hide (button 2) selected; note this may change to none (null)
+ assertEquals("Not selected", cb2, cb2.getCheckboxGroup()
+ .getSelectedCheckbox());
+
+ assertTrue("Show is flagged", !testee.isShowSelected());
+
+ assertEquals("Wrong text",
+ MessageManager.getString("label.show_selected_annotations"),
+ cb1.getLabel());
+ assertEquals("Wrong text",
+ MessageManager.getString("label.hide_selected_annotations"),
+ cb2.getLabel());
+ }
+
+ /**
+ * Test construction of panel containing two sub-panels
+ */
+ @Test(groups = { "Functional" })
+ public void testBuildShowHideOptionsPanel()
+ {
+ testee = new AnnotationChooser(parentPanel);
+ JPanel jp = testee.buildShowHideOptionsPanel();
+ assertTrue("Wrong layout", jp.getLayout() instanceof BorderLayout);
+ Component[] comps = jp.getComponents();
+ assertEquals("Not 2 sub-panels", 2, comps.length);
+
+ verifyShowHidePanel((JPanel) comps[0]);
+ verifyApplyToOptionsPanel_noSelectionGroup((JPanel) comps[1]);
+ }
+
+ /**
+ * Test that annotation types are (uniquely) identified.
+ *
+ */
+ @Test(groups = { "Functional" })
+ public void testGetAnnotationTypes()
+ {
+ selectSequences(1);
+ testee = new AnnotationChooser(parentPanel);
+ // selection group should make no difference to the result
+ // as all annotation types for the alignment are considered
+
+ List<String> types = AnnotationChooser.getAnnotationTypes(
+ parentPanel.getAlignment(), true);
+ assertEquals("Not two annotation types", 2, types.size());
+ assertTrue("IUPRED missing", types.contains("IUPRED"));
+ assertTrue("JMol missing", types.contains("JMol"));
+
+ types = AnnotationChooser.getAnnotationTypes(
+ parentPanel.getAlignment(), false);
+ assertEquals("Not six annotation types", 6, types.size());
+ assertTrue("IUPRED missing", types.contains("IUPRED"));
+ assertTrue("JMol missing", types.contains("JMol"));
+ assertTrue("Beauty missing", types.contains("Beauty"));
+ // These are added by viewmodel.AlignViewport.initAutoAnnotation():
+ assertTrue("Consensus missing", types.contains("Consensus"));
+ assertTrue("Quality missing", types.contains("Quality"));
+ assertTrue("Conservation missing", types.contains("Conservation"));
+ }
+
+ /**
+ * Test result of selecting an annotation type, with 'Hide for all sequences'.
+ *
+ * We expect all annotations of that type to be set hidden. Other annotations
+ * should be left visible.
+ */
+ @Test(groups = { "Functional" })
+ public void testSelectType_hideForAll()
+ {
+ selectSequences(1, 2);
+ testee = new AnnotationChooser(parentPanel);
+ final Checkbox hideCheckbox = (Checkbox) getComponent(testee, 1, 0, 1);
+ setSelected(hideCheckbox, true);
+
+ final Checkbox allSequencesCheckbox = (Checkbox) getComponent(testee,
+ 1, 1, 0);
+ setSelected(allSequencesCheckbox, true);
+
+ AlignmentAnnotation[] anns = parentPanel.getAlignment()
+ .getAlignmentAnnotation();
+
+ assertTrue(anns[5].visible); // JMol for seq3
+ assertTrue(anns[7].visible); // JMol for seq1
+
+ setSelected(getTypeCheckbox("JMol"), true);
+ assertTrue(anns[0].visible); // Conservation
+ assertTrue(anns[1].visible); // Quality
+ assertTrue(anns[2].visible); // Consensus
+ assertTrue(anns[3].visible); // IUPred for seq0
+ assertTrue(anns[4].visible); // Beauty
+ assertFalse(anns[5].visible); // JMol for seq3 - not selected but hidden
+ assertTrue(anns[6].visible); // IUPRED for seq2
+ assertFalse(anns[7].visible); // JMol for seq1 - selected and hidden
+ }
+
+ /**
+ * Test result of selecting an annotation type, with 'Hide for selected
+ * sequences'.
+ *
+ * We expect the annotations of that type, linked to the sequence group, to be
+ * set hidden. Other annotations should be left visible.
+ */
+ @Test(groups = { "Functional" })
+ public void testSelectType_hideForSelected()