コード例 #1
0
    protected void paintComponent(Graphics g) {
      super.paintComponent(g);
      Graphics gg = g.create();
      if (trainNumber < 0) return;

      TrainModel tm = (TrainModel) w.get(KEY.TRAINS, trainNumber, modelRoot.getPlayerPrincipal());

      trainModelViewer.setTrainModel(tm);
      int waterRemaining = trainModelViewer.getWaterRemaining();

      int maxWater =
          ((EngineType) w.get(KEY.ENGINE_TYPES, tm.getEngineType(), Player.AUTHORITATIVE))
              .getWaterCapacity();

      // draw a dark-blue rectangle and a light blue rectangle
      gg.setColor(Color.BLUE);
      gg.fillRect(0, 0, getWidth() * waterRemaining / maxWater, getHeight());
    }
コード例 #2
0
        /**
         * Cycle through train status in the following order: Priority express, standard, slow,
         * stopped
         */
        public void actionPerformed(ActionEvent e) {
          if (trainNumber == -1) return;

          TrainModel tm =
              (TrainModel) w.get(KEY.TRAINS, trainNumber, modelRoot.getPlayerPrincipal());

          int priority = tm.getPriority();
          int state = tm.getState();

          if (state == TrainModel.STATE_STOPPED) {
            state = TrainModel.STATE_RUNNABLE;
            priority = TrainModel.PRIORITY_EXPRESS;
          } else {
            switch (priority) {
              case TrainModel.PRIORITY_EXPRESS:
                priority = TrainModel.PRIORITY_NORMAL;
                break;
              case TrainModel.PRIORITY_NORMAL:
                priority = TrainModel.PRIORITY_SLOW;
                break;
              case TrainModel.PRIORITY_SLOW:
                state = TrainModel.STATE_STOPPED;
                break;
              default:
                throw new IllegalStateException();
            }
          }
          Move m;
          GameTime now = (GameTime) w.get(ITEM.TIME, Player.AUTHORITATIVE);
          if (tm.getState() != state) {
            m =
                ChangeTrainMove.generateMove(
                    trainNumber, modelRoot.getPlayerPrincipal(), tm, state, now);
            modelRoot.getReceiver().processMove(m);
            tm = (TrainModel) w.get(KEY.TRAINS, trainNumber, modelRoot.getPlayerPrincipal());
          }
          if (tm.getPriority() != priority) {
            m =
                ChangeTrainMove.generatePriorityMove(
                    trainNumber, modelRoot.getPlayerPrincipal(), tm, priority);
            modelRoot.getReceiver().processMove(m);
          }
        }
コード例 #3
0
  public void displayTrain(int trainNumber) {
    this.trainNumber = trainNumber;

    trainViewJPanel1.display(trainNumber);
    String s;
    String destination = "";
    int priority = TrainModel.PRIORITY_NORMAL;
    int state = TrainModel.STATE_STOPPED;
    if (trainNumber >= 0) {
      TrainModel train =
          (TrainModel) w.get(KEY.TRAINS, trainNumber, modelRoot.getPlayerPrincipal());

      trainCargoBundleKey = train.getCargoBundle();
      CargoBundle cb = (CargoBundle) w.get(train.getCargoBundle());
      s = "Train #" + trainNumber + ": ";
      ScheduleIterator si = train.getScheduleIterator();
      TrainOrdersModel tom = si.getCurrentOrder(w);
      if (tom != null) {
        ObjectKey2 ok = tom.getStation();
        StationModel station = (StationModel) w.get(ok);
        destination = station.getStationName();
      }
      priority = train.getPriority();
      state = train.getState();
      setStatusLabel(train);
    } else {
      s = "No trains to display";
      setStatusLabel(null);
    }
    setStatusButton(priority, state);
    nameJLabel.setText(s);
    destinationJLabel.setText(destination);
  }
コード例 #4
0
  private void setStatusLabel(TrainModel trainModel) {
    if (trainModel == null) {
      statusJLabel.setIcon((Icon) null);
      statusJLabel.setToolTipText("");
      return;
    }

    switch (trainModel.getState()) {
      case TrainModel.STATE_RUNNABLE:
        if (trainModel.isBlocked()) {
          statusJLabel.setIcon(blockedIcon);
          statusJLabel.setToolTipText(Resources.get("Track blocked"));
        } else if (trainModel.getTrainMotionModel().isLost()) {
          statusJLabel.setIcon(noRouteIcon);
          statusJLabel.setToolTipText(Resources.get("No route to destination"));
        } else if (trainModel.getTrainMotionModel().isOutOfWater()) {
          statusJLabel.setIcon(outOfWaterIcon);
          statusJLabel.setToolTipText(Resources.get("No water"));
        } else {
          statusJLabel.setIcon((Icon) null);
          statusJLabel.setToolTipText("");
        }
        break;
      case TrainModel.STATE_LOADING:
        statusJLabel.setIcon(loadingIcon);
        statusJLabel.setToolTipText(Resources.get("Loading"));
        break;
      case TrainModel.STATE_UNLOADING:
        statusJLabel.setIcon(unloadingIcon);
        statusJLabel.setToolTipText(Resources.get("Unloading"));
        break;
      default:
        statusJLabel.setIcon((Icon) null);
        statusJLabel.setToolTipText("");
        break;
    }
  }