Ejemplo n.º 1
0
 public void coloriseTokens(Transition t) {
   VisualStg visualStg = (VisualStg) getUnderlyingModel();
   VisualTransition vt = visualStg.getVisualTransition(t);
   if (vt == null) return;
   Color tokenColor = Color.black;
   ColorGenerator tokenColorGenerator = vt.getTokenColorGenerator();
   if (tokenColorGenerator != null) {
     // generate token colour
     tokenColor = tokenColorGenerator.updateColor();
   } else {
     // combine preset token colours
     for (Connection c : visualStg.getConnections(vt)) {
       if ((c.getSecond() == vt) && (c instanceof VisualConnection)) {
         VisualConnection vc = (VisualConnection) c;
         if (vc.isTokenColorPropagator()) {
           if (vc.getFirst() instanceof VisualPlace) {
             VisualPlace vp = (VisualPlace) c.getFirst();
             tokenColor = Coloriser.colorise(tokenColor, vp.getTokenColor());
           } else if (vc instanceof VisualImplicitPlaceArc) {
             VisualImplicitPlaceArc vipa = (VisualImplicitPlaceArc) vc;
             tokenColor = Coloriser.colorise(tokenColor, vipa.getTokenColor());
           }
         }
       }
     }
   }
   // propagate the colour to postset tokens
   for (Connection c : visualStg.getConnections(vt)) {
     if ((c.getFirst() == vt) && (c instanceof VisualConnection)) {
       VisualConnection vc = (VisualConnection) c;
       if (vc.isTokenColorPropagator()) {
         if (vc.getSecond() instanceof VisualPlace) {
           VisualPlace vp = (VisualPlace) c.getSecond();
           vp.setTokenColor(tokenColor);
         } else if (vc instanceof VisualImplicitPlaceArc) {
           VisualImplicitPlaceArc vipa = (VisualImplicitPlaceArc) vc;
           vipa.setTokenColor(tokenColor);
         }
       }
     }
   }
 }
Ejemplo n.º 2
0
  @Test
  public void testHitTest() {
    Place p = new Place();
    VisualPlace vp = new VisualPlace(p);

    Assert.assertTrue(vp.hitTest(new Point2D.Double(0, 0)));
    Assert.assertFalse(vp.hitTest(new Point2D.Double(5, 5)));

    vp.setX(5);
    vp.setY(5);

    Assert.assertTrue(vp.hitTest(new Point2D.Double(5, 5)));
    Assert.assertFalse(vp.hitTest(new Point2D.Double(0, 0)));
  }