return builder.toString();
}
@Test
public void testStyleEvents() {
StyleGroupSet sgs = new StyleGroupSet(stylesheet);
populateGroupSet(sgs);
StyleGroup sA = sgs.getStyleForElement(A);
StyleGroup sB = sgs.getStyleForElement(B);
StyleGroup sC = sgs.getStyleForElement(C);
StyleGroup sD = sgs.getStyleForElement(D);
assertEquals(1, sA.getStrokeWidth().value, 0);
assertEquals(1, sB.getStrokeWidth().value, 0);
assertEquals(1, sC.getStrokeWidth().value, 0);
assertEquals(1, sD.getStrokeWidth().value, 0);
// Test global events (events that apply to a whole group or groups).
sgs.pushEvent("clicked"); // This is normally done automatically by the
// GraphicElement
sA = sgs.getStyleForElement(A);
sB = sgs.getStyleForElement(B);
sC = sgs.getStyleForElement(C);
sD = sgs.getStyleForElement(D);
assertEquals(2, sA.getStrokeWidth().value, 0);
assertEquals(3, sB.getStrokeWidth().value, 0);
assertEquals(3, sC.getStrokeWidth().value, 0);
assertEquals(3, sD.getStrokeWidth().value, 0);
sgs.popEvent("clicked"); // This is normally done automatically by the
// GraphicElement
sA = sgs.getStyleForElement(A);
sB = sgs.getStyleForElement(B);
sC = sgs.getStyleForElement(C);
sD = sgs.getStyleForElement(D);
assertEquals(1, sA.getStrokeWidth().value, 0);
assertEquals(1, sB.getStrokeWidth().value, 0);
assertEquals(1, sC.getStrokeWidth().value, 0);
assertEquals(1, sD.getStrokeWidth().value, 0);
sgs.pushEvent("clicked"); // Both events at a time.
sgs.pushEvent("selected"); // They should cascade.
sA = sgs.getStyleForElement(A);
sB = sgs.getStyleForElement(B);
sC = sgs.getStyleForElement(C);
sD = sgs.getStyleForElement(D);
assertEquals(4, sA.getStrokeWidth().value, 0);
assertEquals(3, sB.getStrokeWidth().value, 0);
assertEquals(3, sC.getStrokeWidth().value, 0);
assertEquals(3, sD.getStrokeWidth().value, 0);
sgs.popEvent("clicked"); // This is normally done automatically by the
// GraphicElement
sgs.popEvent("selected"); // This is normally done automatically by the
// GraphicElement
// Now test individual events, that is events that apply to
// an individual element only.
sA = sgs.getStyleForElement(A);
assertFalse(sA.hasEventElements());
sgs.pushEventFor(A, "clicked"); // This is normally done automatically
// by the GraphicElement
sgs.pushEventFor(B, "clicked"); // This is normally done automatically
// by the GraphicElement
sA = sgs.getStyleForElement(A);
sB = sgs.getStyleForElement(B);
sC = sgs.getStyleForElement(C);
sD = sgs.getStyleForElement(D);
assertTrue(sA.hasEventElements());
assertEquals(1, sA.getStrokeWidth().value, 0); // Individual events must be
// activated
assertEquals(1, sB.getStrokeWidth().value, 0); // to work, so just pushing
// them is not
assertEquals(1, sC.getStrokeWidth().value, 0); // sufficient.
assertEquals(1, sD.getStrokeWidth().value, 0);
sA.activateEventsFor(A);
assertEquals(2, sA.getStrokeWidth().value, 0); // Only A should change.
assertEquals(1, sB.getStrokeWidth().value, 0);
assertEquals(1, sC.getStrokeWidth().value, 0);
assertEquals(1, sD.getStrokeWidth().value, 0);
sA.deactivateEvents();
sB.activateEventsFor(B);
assertEquals(1, sA.getStrokeWidth().value, 0);
assertEquals(3, sB.getStrokeWidth().value, 0); // B and all its group
// change.
assertEquals(3, sC.getStrokeWidth().value, 0); // Therefore C also changes.
assertEquals(1, sD.getStrokeWidth().value, 0);
sB.deactivateEvents();
sgs.popEventFor(A, "clicked"); // This is normally done automatically by
// the GraphicElement
sgs.popEventFor(B, "clicked"); // This is normally done automatically by
// the GraphicElement
// Now two individual events at a time.
sgs.pushEventFor(A, "clicked"); // This is normally done automatically
// by the GraphicElement
sgs.pushEventFor(A, "selected"); // This is normally done automatically
// by the GraphicElement
sA = sgs.getStyleForElement(A);
sB = sgs.getStyleForElement(B);
sC = sgs.getStyleForElement(C);
sD = sgs.getStyleForElement(D);
assertEquals(1, sA.getStrokeWidth().value, 0); // Individual events must be
// activated
assertEquals(1, sB.getStrokeWidth().value, 0); // to work, so just pushing
// them is not
assertEquals(1, sC.getStrokeWidth().value, 0); // sufficient.
assertEquals(1, sD.getStrokeWidth().value, 0);
sA.activateEventsFor(A);
assertEquals(4, sA.getStrokeWidth().value, 0); // Only A should change,
// "selected" has
assertEquals(1, sB.getStrokeWidth().value, 0); // precedence over "clicked"
// since added
assertEquals(1, sC.getStrokeWidth().value, 0); // after.
assertEquals(1, sD.getStrokeWidth().value, 0);
sA.deactivateEvents();
sgs.popEventFor(A, "clicked"); // This is normally done automatically by
// the GraphicElement
sgs.popEventFor(A, "selected"); // This is normally done automatically
// by the GraphicElement
sgs.release();
}