Example #1
0
 /**
  * Block cars by track (optional), then pick up and set out for each location in a train's route.
  * This shows each car with a check box or with a set button. The set button is displayed when the
  * checkbox isn't selected and the display is in "set" mode. If the car is a utility. Show the
  * number of cars that have the same attributes, and not the car's road and number. Each car is
  * displayed only once in one of three panes. The three panes are pick up, set out, or local move.
  * To keep track of each car and which pane to use, they are placed in the list "rollingStock"
  * with the prefix "p", "s" or "m" and the car's unique id.
  */
 protected void blockCars(RouteLocation rl, boolean isManifest) {
   if (Setup.isPrintHeadersEnabled()) {
     JLabel header =
         new JLabel(
             Tab + trainCommon.getPickupCarHeader(isManifest, !TrainCommon.IS_TWO_COLUMN_TRACK));
     setLabelFont(header);
     pPickups.add(header);
     header =
         new JLabel(
             Tab + trainCommon.getDropCarHeader(isManifest, !TrainCommon.IS_TWO_COLUMN_TRACK));
     setLabelFont(header);
     pSetouts.add(header);
     header = new JLabel(Tab + trainCommon.getLocalMoveHeader(isManifest));
     setLabelFont(header);
     pMoves.add(header);
   }
   List<Track> tracks = rl.getLocation().getTrackByNameList(null);
   List<RouteLocation> routeList = _train.getRoute().getLocationsBySequenceList();
   List<Car> carList = carManager.getByTrainDestinationList(_train);
   for (Track track : tracks) {
     for (RouteLocation rld : routeList) {
       for (Car car : carList) {
         // determine if car is a pick up from the right track
         // caboose or FRED is placed at end of the train
         // passenger trains are already blocked in the car list
         if (car.getTrack() != null
             && car.getRouteLocation() == rl
             && car.getRouteDestination() != rl
             && (!Setup.isSortByTrackEnabled() || car.getTrackName().equals(track.getName()))
             && ((car.getRouteDestination() == rld && !car.isCaboose() && !car.hasFred())
                 || (rld == routeList.get(routeList.size() - 1)
                     && (car.isCaboose() || car.hasFred()))
                 || car.isPassenger())) {
           // yes we have a pick up
           pWorkPanes.setVisible(true);
           pickupPane.setVisible(true);
           if (!rollingStock.contains(car)) {
             rollingStock.add(car);
             car.addPropertyChangeListener(this);
           }
           // did we already process this car?
           if (checkBoxes.containsKey("p" + car.getId())) {
             if (isSetMode && !checkBoxes.get("p" + car.getId()).isSelected()) {
               // change to set button so user can remove car from train
               pPickups.add(addSet(car));
             } else {
               pPickups.add(checkBoxes.get("p" + car.getId()));
             }
             // figure out the checkbox text, either single car or utility
           } else {
             String text;
             if (car.isUtility()) {
               text =
                   trainCommon.pickupUtilityCars(
                       carList, car, isManifest, !TrainCommon.IS_TWO_COLUMN_TRACK);
               if (text == null) {
                 continue; // this car type has already been processed
               }
             } else {
               text = trainCommon.pickupCar(car, isManifest, !TrainCommon.IS_TWO_COLUMN_TRACK);
             }
             JCheckBox checkBox = new JCheckBox(text);
             setCheckBoxFont(checkBox);
             addCheckBoxAction(checkBox);
             pPickups.add(checkBox);
             checkBoxes.put("p" + car.getId(), checkBox);
           }
         }
       }
     }
     // set outs and local moves
     for (Car car : carList) {
       if (car.getRouteDestination() != rl || car.getDestinationTrack() == null) {
         continue;
       }
       // car in train if track null, second check is for yard master window
       if (car.getTrack() == null || car.getTrack() != null && (car.getRouteLocation() != rl)) {
         if (Setup.isSortByTrackEnabled()
             && !car.getDestinationTrack().getName().equals(track.getName())) {
           continue;
         }
         // we have set outs
         pWorkPanes.setVisible(true);
         setoutPane.setVisible(true);
         if (!rollingStock.contains(car)) {
           rollingStock.add(car);
           car.addPropertyChangeListener(this);
         }
         if (checkBoxes.containsKey("s" + car.getId())) {
           if (isSetMode && !checkBoxes.get("s" + car.getId()).isSelected()) {
             // change to set button so user can remove car from train
             pSetouts.add(addSet(car));
           } else {
             pSetouts.add(checkBoxes.get("s" + car.getId()));
           }
         } else {
           String text;
           if (car.isUtility()) {
             text = trainCommon.setoutUtilityCars(carList, car, !TrainCommon.LOCAL, isManifest);
             if (text == null) {
               continue; // this car type has already been processed
             }
           } else {
             text = trainCommon.dropCar(car, isManifest, !TrainCommon.IS_TWO_COLUMN_TRACK);
           }
           JCheckBox checkBox = new JCheckBox(text);
           setCheckBoxFont(checkBox);
           addCheckBoxAction(checkBox);
           pSetouts.add(checkBox);
           checkBoxes.put("s" + car.getId(), checkBox);
         }
         // local move?
       } else if (car.getTrack() != null
           && car.getRouteLocation() == rl
           && (!Setup.isSortByTrackEnabled()
               || car.getTrack().getName().equals(track.getName()))) {
         movePane.setVisible(true);
         if (!rollingStock.contains(car)) {
           rollingStock.add(car);
           car.addPropertyChangeListener(this);
         }
         if (checkBoxes.containsKey("m" + car.getId())) {
           if (isSetMode && !checkBoxes.get("m" + car.getId()).isSelected()) {
             // change to set button so user can remove car from train
             pMoves.add(addSet(car));
           } else {
             pMoves.add(checkBoxes.get("m" + car.getId()));
           }
         } else {
           String text;
           if (car.isUtility()) {
             text = trainCommon.setoutUtilityCars(carList, car, TrainCommon.LOCAL, isManifest);
             if (text == null) {
               continue; // this car type has already been processed
             }
           } else {
             text = trainCommon.localMoveCar(car, isManifest);
           }
           JCheckBox checkBox = new JCheckBox(text);
           setCheckBoxFont(checkBox);
           addCheckBoxAction(checkBox);
           pMoves.add(checkBox);
           checkBoxes.put("m" + car.getId(), checkBox);
         }
       }
     }
     // if not sorting by track, we're done
     if (!Setup.isSortByTrackEnabled()) {
       break;
     }
   }
   // pad the panels in case the horizontal scroll bar appears
   pPickups.add(new JLabel(Space));
   pSetouts.add(new JLabel(Space));
   pMoves.add(new JLabel(Space));
 }