+ 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();
+
+ final Checkbox typeCheckbox = getTypeCheckbox("JMol");
+
+ // select JMol - all hidden
+ setSelected(typeCheckbox, true);
+ int autocalc = countAutocalc(anns);
+ assertFalse(anns[autocalc + 2].visible); // JMol for seq3
+ assertFalse(anns[autocalc + 4].visible); // JMol for seq1
+
+ // deselect JMol - all unhidden
+ setSelected(typeCheckbox, false);
+ for (AlignmentAnnotation ann : anns)
+ {
+ assertTrue(ann.visible);
+ }
+ }
+
+ /**
+ * Returns a count of autocalculated annotations in the set provided
+ *
+ * @param anns
+ * @return
+ */
+ private int countAutocalc(AlignmentAnnotation[] anns)
+ {
+ int count = 0;
+ for (AlignmentAnnotation ann : anns)
+ {
+ if (ann.autoCalculated)
+ {
+ count++;
+ }
+ }
+ return count;
+ }
+
+ /**
+ * Test result of deselecting an annotation type, with 'Hide for selected
+ * sequences'.
+ *
+ * We expect the annotations of that type, linked to the sequence group, to be
+ * set visible. Other annotations should be left unchanged.
+ */
+ @Test(groups = { "Functional" })
+ public void testDeselectType_hideForSelected()
+ {
+ selectSequences(1, 2);
+ testee = new AnnotationChooser(parentPanel);
+ final Checkbox hideCheckbox = (Checkbox) getComponent(testee, 1, 0, 1);
+ setSelected(hideCheckbox, true);
+
+ /*
+ * Don't set the 'selected sequences' radio button since this would trigger
+ * an update, including unselected sequences / annotation types
+ */
+ // setSelected(getSelectedSequencesCheckbox());
+
+ setSelected(getTypeCheckbox("JMol"), true);
+ setSelected(getTypeCheckbox("JMol"), false);
+
+ AlignmentAnnotation[] anns = parentPanel.getAlignment()
+ .getAlignmentAnnotation();
+ 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
+ assertTrue(anns[5].visible); // JMol for seq3 not in selection group
+ assertTrue(anns[6].visible); // IUPRED for seq2
+ assertTrue(anns[7].visible); // JMol for seq1 in selection group
+ }
+
+ /**
+ * Test result of selecting an annotation type, with 'Show for all sequences'.
+ *
+ * We expect all annotations of that type to be set visible. Other annotations
+ * should be left unchanged
+ */
+ @Test(groups = { "Functional" })
+ public void testSelectType_showForAll()
+ {
+ selectSequences(1, 2);
+ testee = new AnnotationChooser(parentPanel);
+ final Checkbox showCheckbox = (Checkbox) getComponent(testee, 1, 0, 0);
+ final Checkbox hideCheckbox = (Checkbox) getComponent(testee, 1, 0, 1);
+
+ final Checkbox allSequencesCheckbox = (Checkbox) getComponent(testee,
+ 1, 1, 0);
+
+ AlignmentAnnotation[] anns = parentPanel.getAlignment()
+ .getAlignmentAnnotation();
+
+ // hide all JMol annotations
+ setSelected(allSequencesCheckbox, true);
+ setSelected(hideCheckbox, true);
+ setSelected(getTypeCheckbox("JMol"), true);
+ int autocalc = countAutocalc(anns);
+ assertFalse(anns[autocalc + 2].visible); // JMol for seq3
+ assertFalse(anns[autocalc + 4].visible); // JMol for seq1
+ // ...now show them...
+ setSelected(showCheckbox, true);
+ for (AlignmentAnnotation ann : anns)
+ {
+ assertTrue(ann.visible);
+ }
+ }
+
+ /**
+ * Test result of selecting an annotation type, with 'Show for selected
+ * sequences'.
+ *
+ * We expect all annotations of that type, linked to the sequence group, to be
+ * set visible. Other annotations should be left unchanged
+ */
+ @Test(groups = { "Functional" })
+ public void testSelectType_showForSelected()
+ {
+ // sequences 1 and 2 have annotations IUPred and Jmol
+ selectSequences(1, 2);
+ testee = new AnnotationChooser(parentPanel);
+ final Checkbox showCheckbox = (Checkbox) getComponent(testee, 1, 0, 0);
+ final Checkbox hideCheckbox = (Checkbox) getComponent(testee, 1, 0, 1);
+
+ final Checkbox selectedSequencesCheckbox = (Checkbox) getComponent(
+ testee, 1, 1, 1);
+
+ AlignmentAnnotation[] anns = parentPanel.getAlignment()
+ .getAlignmentAnnotation();
+
+ // hide all JMol annotations in the selection region (== annotation 7)
+ setSelected(selectedSequencesCheckbox, true);
+ setSelected(hideCheckbox, true);
+ setSelected(getTypeCheckbox("JMol"), true);
+
+ int autocalc = countAutocalc(anns);
+ assertTrue(anns[autocalc + 2].visible); // JMol for seq3
+ assertFalse(anns[autocalc + 4].visible); // JMol for seq1
+ // ...now show them...
+ setSelected(showCheckbox, true);
+
+ for (AlignmentAnnotation ann : anns)
+ {
+ assertTrue(ann.visible);
+ }
+ }
+
+ /**
+ * Test result of deselecting an annotation type, with 'Show for all
+ * sequences'.
+ *
+ * We expect all annotations of that type to be set hidden. Other annotations
+ * should be left unchanged.
+ */
+ @Test(groups = { "Functional" })
+ public void testDeselectType_showForAll()
+ {
+ selectSequences(1, 2);
+ testee = new AnnotationChooser(parentPanel);
+
+ final Checkbox showCheckbox = (Checkbox) getComponent(testee, 1, 0, 0);
+ setSelected(showCheckbox, true);
+
+ final Checkbox allSequencesCheckbox = (Checkbox) getComponent(testee,
+ 1, 1, 0);
+ setSelected(allSequencesCheckbox, true);
+
+ AlignmentAnnotation[] anns = parentPanel.getAlignment()
+ .getAlignmentAnnotation();
+
+ final Checkbox typeCheckbox = getTypeCheckbox("JMol");
+ // select JMol - all shown
+ setSelected(typeCheckbox, true);
+ int autocalc = countAutocalc(anns);
+ assertTrue(anns[autocalc + 2].visible); // JMol for seq3
+ assertTrue(anns[autocalc + 4].visible); // JMol for seq1
+
+ // deselect JMol - all hidden
+ setSelected(typeCheckbox, false);
+ assertTrue(anns[0].visible); // Conservation
+ assertTrue(anns[1].visible); // Quality
+ assertTrue(anns[2].visible); // Consensus
+ assertTrue(anns[3].visible); // Occupancy
+ assertTrue(anns[4].visible); // IUPred for seq0
+ assertTrue(anns[5].visible); // Beauty
+ assertFalse(anns[6].visible); // JMol for seq3
+ assertTrue(anns[7].visible); // IUPRED for seq2
+ assertFalse(anns[8].visible); // JMol for seq1
+ }
+
+ /**
+ * Test result of deselecting an annotation type, with 'Show for selected
+ * sequences'.
+ *
+ * We expect the annotations of that type, linked to the sequence group, to be
+ * set hidden. Other annotations should be left unchanged.
+ */
+ @Test(groups = { "Functional" })
+ public void testDeselectType_showForSelected()
+ {
+ selectSequences(1, 2);
+ testee = new AnnotationChooser(parentPanel);
+ final Checkbox showCheckbox = (Checkbox) getComponent(testee, 1, 0, 0);
+ setSelected(showCheckbox, true);
+
+ /*
+ * Don't set the 'selected sequences' radio button since this would trigger
+ * an update, including unselected sequences / annotation types
+ */
+ // setSelected(getSelectedSequencesCheckbox());
+
+ AlignmentAnnotation[] anns = parentPanel.getAlignment()
+ .getAlignmentAnnotation();
+
+ // select JMol - should remain visible
+ setSelected(getTypeCheckbox("JMol"), true);
+ int autocalc = countAutocalc(anns);
+ assertTrue(anns[autocalc + 2].visible); // JMol for seq3
+ assertTrue(anns[autocalc + 4].visible); // JMol for seq1
+
+ // deselect JMol - should be hidden for selected sequences only
+ setSelected(getTypeCheckbox("JMol"), false);
+ assertTrue(anns[0].visible); // Conservation
+ assertTrue(anns[1].visible); // Quality
+ assertTrue(anns[2].visible); // Consensus
+ assertTrue(anns[3].visible); // Occupancy
+ assertTrue(anns[4].visible); // IUPred for seq0
+ assertTrue(anns[5].visible); // Beauty
+ assertTrue(anns[6].visible); // JMol for seq3 not in selection group
+ assertTrue(anns[7].visible); // IUPRED for seq2
+ assertFalse(anns[8].visible); // JMol for seq1 in selection group
+ }
+
+ /**
+ * Helper method to drill down to a sub-component in a Container hierarchy.
+ *
+ * @param cont
+ * @param i
+ * @param j
+ * @param k
+ * @return
+ */
+ public static Component getComponent(Container cont, int... positions)
+ {
+ Component comp = cont;
+ for (int i : positions)
+ {
+ comp = ((Container) comp).getComponent(i);
+ }
+ return comp;
+ }
+
+ /**
+ * Helper method to set or unset a checkbox and fire its action listener.
+ *
+ * @param cb
+ * @param select
+ */
+ protected void setSelected(Checkbox cb, boolean select)
+ {
+ // TODO refactor to a test utility class
+ cb.setState(select);
+ // have to manually fire the action listener
+ cb.getItemListeners()[0].itemStateChanged(new ItemEvent(cb,
+ ItemEvent.ITEM_STATE_CHANGED, cb, select ? ItemEvent.SELECTED
+ : ItemEvent.DESELECTED));
+ }
+
+ /**
+ * Helper method to drill down to the 'Annotation type' checkbox with given
+ * label.
+ *
+ * @return
+ */
+ private Checkbox getTypeCheckbox(String forLabel)
+ {
+ Component[] cbs = ((JPanel) testee.getComponent(0)).getComponents();
+ for (Component comp : cbs)
+ {
+ final Checkbox cb = (Checkbox) comp;
+ if (cb.getLabel().equals(forLabel))
+ {
+ return cb;
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Test isInActionScope for the case where the scope is selected sequences.
+ * Test cases include sequences in the selection group, and others not in the
+ * group.
+ */
+ @Test(groups = { "Functional" })
+ public void testIsInActionScope_selectedScope()
+ {
+ // sequences 1 and 2 have annotations 4 and 3 respectively
+ selectSequences(1, 2);
+ testee = new AnnotationChooser(parentPanel);
+
+ final Checkbox selectedSequencesCheckbox = (Checkbox) getComponent(
+ testee, 1, 1, 1);
+ setSelected(selectedSequencesCheckbox, true);
+
+ AlignmentAnnotation[] anns = parentPanel.getAlignment()
+ .getAlignmentAnnotation();
+ int autocalc = countAutocalc(anns);
+ assertFalse(testee.isInActionScope(anns[autocalc]));
+ assertFalse(testee.isInActionScope(anns[autocalc + 1]));
+ assertFalse(testee.isInActionScope(anns[autocalc + 2]));
+ assertTrue(testee.isInActionScope(anns[autocalc + 3]));
+ assertTrue(testee.isInActionScope(anns[autocalc + 4]));
+ }
+
+ /**
+ * Test isInActionScope for the case where the scope is unselected sequences.
+ * Test cases include sequences in the selection group, and others not in the
+ * group.
+ */
+ @Test(groups = { "Functional" })
+ public void testIsInActionScope_unselectedScope()
+ {
+ // sequences 1 and 2 have annotations 4 and 3 respectively
+ selectSequences(1, 2);
+ testee = new AnnotationChooser(parentPanel);
+
+ final Checkbox unselectedSequencesCheckbox = (Checkbox) getComponent(
+ testee, 1, 1, 2);
+ setSelected(unselectedSequencesCheckbox, true);
+
+ AlignmentAnnotation[] anns = parentPanel.getAlignment()
+ .getAlignmentAnnotation();
+ int autocalc = countAutocalc(anns);
+ assertTrue(testee.isInActionScope(anns[autocalc]));
+ assertTrue(testee.isInActionScope(anns[autocalc + 1]));
+ assertTrue(testee.isInActionScope(anns[autocalc + 2]));
+ assertFalse(testee.isInActionScope(anns[autocalc + 3]));
+ assertFalse(testee.isInActionScope(anns[autocalc + 4]));
+ }
+
+ /**
+ * Test that the reset method restores previous visibility flags.
+ */
+ @Test(groups = { "Functional" })
+ public void testResetOriginalState()
+ {
+ testee = new AnnotationChooser(parentPanel);
+
+ AlignmentAnnotation[] anns = parentPanel.getAlignment()
+ .getAlignmentAnnotation();
+ // all start visible
+ for (int i = 0; i < anns.length; i++)
+ {
+ assertTrue(i + "'th sequence not visible", anns[i].visible);
+ }
+
+ /*
+ * check options to hide JMol and IUPRED annotations for all sequences
+ */
+ final Checkbox hideCheckbox = (Checkbox) getComponent(testee, 1, 0, 1);
+ setSelected(hideCheckbox, true);
+
+ final Checkbox allSequencesCheckbox = (Checkbox) getComponent(testee,
+ 1, 1, 0);
+ setSelected(allSequencesCheckbox, true);
+
+ setSelected(getTypeCheckbox("JMol"), true);
+ setSelected(getTypeCheckbox("IUPRED"), true);
+
+ assertTrue(anns[0].visible); // Conservation
+ assertTrue(anns[1].visible); // Quality
+ assertTrue(anns[2].visible); // Consensus
+ assertTrue(anns[3].visible); // Occupancy
+ assertFalse(anns[4].visible); // IUPRED
+ assertTrue(anns[5].visible); // Beauty (not seq-related)
+ assertFalse(anns[6].visible); // JMol
+ assertFalse(anns[7].visible); // IUPRED
+ assertFalse(anns[8].visible); // JMol