Пример #1
0
  public JPanel createLaneTrafficGenerator(
      Route in, RouteAspect aspect, Engine engine, RouteAspect routes) {
    JPanel controller = vertical();
    TrafficGenerator generator = new TrafficGenerator(in, engine, routes);
    aspect.addTrafficGenerator(generator);
    IntTextField imprecision = new IntTextField();
    IntTextField traffic = new IntTextField();
    JLabel message = new JLabel();
    generator.configure(0, DEFAULT_TRAFFIC_PER_HOUR);
    imprecision.setText("" + 0);
    traffic.setText("" + DEFAULT_TRAFFIC_PER_HOUR);

    JButton validate =
        new JButton("Valider") {
          public TrafficGenerator holder = generator;
        };

    validate.addActionListener(
        (e) -> {
          int imp = imprecision.getValue();
          int traf = traffic.getValue();
          if (traf < 0) traf = 0;
          if (imp < 0) imp = 0;
          if (imp > 100) imp = 100;
          generator.configure(imp, traf);
          message.setText("Modifcation prise en compte");
        });

    controller.add(horizontal(new JLabel("Imprecision (+/-)      "), imprecision));
    controller.add(horizontal(new JLabel("Densite (voiture/heure)"), traffic));
    controller.add(horizontal(validate, message));
    controller.setPreferredSize(new Dimension(100, 100));
    controller.setSize(100, 100);
    return controller;
  }
Пример #2
0
  private void generateRoutes(Vec2 o) {
    routes.clear();
    Vec2 northInStart = o.copy().add(7, -100);
    Vec2 northInEnd = o.copy().add(7, 0);

    Vec2 northOutStart = o.copy().add(33, 0);
    Vec2 northOutEnd = o.copy().add(33, -100);

    Vec2 southInStart = o.copy().add(33, 140);
    Vec2 southInEnd = o.copy().add(33, 40);
    Vec2 southOutStart = o.copy().add(7, 40);
    Vec2 southOutEnd = o.copy().add(7, 140);

    Vec2 eastInStart = o.copy().add(140, 7);
    Vec2 eastInEnd = o.copy().add(40, 7);
    Vec2 eastOutStart = o.copy().add(40, 33);
    Vec2 eastOutEnd = o.copy().add(140, 33);

    Vec2 westInStart = o.copy().add(-100, 33);
    Vec2 westInEnd = o.copy().add(0, 33);
    Vec2 westOutStart = o.copy().add(0, 7);
    Vec2 westOutEnd = o.copy().add(-100, 7);

    inNorth = routes.createRoute(northInStart, northInEnd);
    Route outNorth = routes.createRoute(northOutStart, northOutEnd);

    inSouth = routes.createRoute(southInStart, southInEnd);
    Route outSouth = routes.createRoute(southOutStart, southOutEnd);

    inEast = routes.createRoute(eastInStart, eastInEnd);
    Route outEast = routes.createRoute(eastOutStart, eastOutEnd);

    inWest = routes.createRoute(westInStart, westInEnd);
    Route outWest = routes.createRoute(westOutStart, westOutEnd);
    inNorth.link(outEast);
    inNorth.link(outWest);
    inNorth.link(outSouth);
    inEast.link(outWest);
    inEast.link(outSouth);
    inEast.link(outNorth);
    inWest.link(outEast);
    inWest.link(outNorth);
    inWest.link(outSouth);
    inSouth.link(outNorth);
    inSouth.link(outEast);
    inSouth.link(outWest);

    fNorth = routes.createFeu(inNorth.getEnd().add(0, -10));
    fEast = routes.createFeu(inEast.getEnd().add(10, 0));
    fWest = routes.createFeu(inWest.getEnd().add(-10, 0));
    fSouth = routes.createFeu(inSouth.getEnd().add(0, 10));
  }