Esempio n. 1
0
 public JPanel createLaneController() {
   JPanel controller = new JPanel();
   IntTextField northSouthGREENTimer = new IntTextField();
   IntTextField northSouthREDTimer = new IntTextField();
   JButton validate = new JButton("Valider");
   JLabel message = new JLabel();
   validate.addActionListener(
       (e) -> {
         int greenValue = northSouthGREENTimer.getValue() * 1000;
         int redValue = northSouthREDTimer.getValue() * 1000;
         if (greenValue > 0 && redValue > 0) {
           fNorth.configure(Feu.State.VERT, greenValue, redValue);
           fSouth.configure(Feu.State.VERT, greenValue, redValue);
           fEast.configure(Feu.State.ROUGE, redValue, greenValue);
           fWest.configure(Feu.State.ROUGE, redValue, greenValue);
           message.setText("Modifications prises en compte.");
         } else {
           message.setText("Erreur : valeurs invalides.");
         }
       });
   controller.setLayout(new BoxLayout(controller, BoxLayout.Y_AXIS));
   controller.add(new JLabel("Temps Vert"));
   controller.add(northSouthGREENTimer);
   controller.add(new JLabel("Temps Rouge"));
   controller.add(northSouthREDTimer);
   controller.add(validate);
   controller.add(message);
   return controller;
 }
 private void setWidgetActivation() {
   if (m_text.isEnabled()) {
     final int value = m_text.getValue();
     final int max = m_text.getMax();
     final boolean enableUp = (value != max);
     m_up.setEnabled(enableUp);
     m_max.setEnabled(enableUp);
     final int min = m_text.getMin();
     final boolean enableDown = (value != min);
     m_down.setEnabled(enableDown);
     m_min.setEnabled(enableDown);
   } else {
     m_up.setEnabled(false);
     m_down.setEnabled(false);
     m_max.setEnabled(false);
     m_min.setEnabled(false);
   }
 }
Esempio n. 3
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;
  }
 /** Creates new ScrollableTextField */
 public ScrollableTextField(final int minVal, final int maxVal) {
   super();
   loadImages(this);
   m_text = new IntTextField(minVal, maxVal);
   setLayout(new FlowLayout(FlowLayout.LEFT, 0, 0));
   add(m_text);
   Insets inset = new Insets(0, 0, 0, 0);
   if (GameRunner.isMac()) {
     inset = new Insets(2, 0, 2, 0);
   }
   m_up = new JButton(s_up);
   m_up.addActionListener(m_incrementAction);
   m_up.setMargin(inset);
   m_down = new JButton(s_down);
   m_down.setMargin(inset);
   m_down.addActionListener(m_decrementAction);
   m_max = new JButton(s_max);
   m_max.setMargin(inset);
   m_max.addActionListener(m_maxAction);
   m_min = new JButton(s_min);
   m_min.setMargin(inset);
   m_min.addActionListener(m_minAction);
   final JPanel upDown = new JPanel();
   upDown.setLayout(new BoxLayout(upDown, BoxLayout.Y_AXIS));
   upDown.add(m_up);
   upDown.add(m_down);
   final JPanel maxMin = new JPanel();
   maxMin.setLayout(new BoxLayout(maxMin, BoxLayout.Y_AXIS));
   maxMin.add(m_max);
   maxMin.add(m_min);
   add(upDown);
   add(maxMin);
   // add(new JSpinner());
   m_text.addChangeListener(m_textListener);
   setWidgetActivation();
 }
 @Override
 public void setEnabled(final boolean enabled) {
   m_text.setEnabled(enabled);
   setWidgetActivation();
 }
 public void setValue(final int value) {
   m_text.setValue(value);
   setWidgetActivation();
 }
 public int getValue() {
   return m_text.getValue();
 }
 public void actionPerformed(final ActionEvent e) {
   if (m_text.isEnabled()) {
     m_text.setValue(m_text.getMin());
     setWidgetActivation();
   }
 }
 public void setMin(final int min) {
   m_text.setMin(min);
   setWidgetActivation();
 }
Esempio n. 10
0
 public String getTerr() {
   return m_text.getTerr();
 }
Esempio n. 11
0
 public int getMax() {
   return m_text.getMax();
 }
Esempio n. 12
0
 public void setTerr(final String terr) {
   m_text.setTerr(terr);
 }
Esempio n. 13
0
 public void setMax(final int max) {
   m_text.setMax(max);
   setWidgetActivation();
 }