Example #1
0
 // combo boxes
 public void comboBoxActionPerformed(java.awt.event.ActionEvent ae) {
   if (ae.getSource() == modelComboBox) {
     if (modelComboBox.getSelectedItem() != null) {
       String model = (String) modelComboBox.getSelectedItem();
       // load the default hp and length for the model selected
       hpTextField.setText(engineModels.getModelHorsepower(model));
       weightTextField.setText(engineModels.getModelWeight(model));
       if (engineModels.getModelLength(model) != null
           && !engineModels.getModelLength(model).equals("")) {
         lengthComboBox.setSelectedItem(engineModels.getModelLength(model));
       }
       if (engineModels.getModelType(model) != null
           && !engineModels.getModelType(model).equals("")) {
         typeComboBox.setSelectedItem(engineModels.getModelType(model));
       }
     }
   }
   if (ae.getSource() == locationBox) {
     if (locationBox.getSelectedItem() == null) {
       trackLocationBox.removeAllItems();
     } else {
       log.debug("EnginesSetFrame sees location: " + locationBox.getSelectedItem());
       Location l = ((Location) locationBox.getSelectedItem());
       l.updateComboBox(trackLocationBox);
     }
   }
 }
Example #2
0
 public void setReturnWhenEmptyDestination(Location destination) {
   Location old = _rweDestination;
   _rweDestination = destination;
   if ((old != null && !old.equals(destination))
       || (destination != null && !destination.equals(old))) {
     setDirtyAndFirePropertyChange(RETURN_WHEN_EMPTY_CHANGED_PROPERTY, null, null);
   }
 }
 @Override
 public void doAction() {
   if (getAutomationItem() != null) {
     boolean isChanged = true;
     if (!Setup.isGenerateCsvSwitchListEnabled()) {
       log.warn("Generate CSV Switch List isn't enabled!");
       finishAction(false);
       return;
     }
     // we do need one of these!
     if (!TrainCustomSwitchList.manifestCreatorFileExists()) {
       log.warn(
           "Manifest creator file not found!, directory name: {}, file name: {}",
           TrainCustomSwitchList.getDirectoryName(),
           TrainCustomSwitchList.getFileName());
       finishAction(false);
       return;
     }
     setRunning(true);
     TrainSwitchLists trainSwitchLists = new TrainSwitchLists();
     TrainCsvSwitchLists trainCsvSwitchLists = new TrainCsvSwitchLists();
     for (Location location : LocationManager.instance().getLocationsByNameList()) {
       if (location.isSwitchListEnabled()
           && (!isChanged || isChanged && location.getStatus().equals(Location.MODIFIED))) {
         // also build the regular switch lists so they can be used
         if (!Setup.isSwitchListRealTime()) {
           trainSwitchLists.buildSwitchList(location);
         }
         File csvFile = trainCsvSwitchLists.buildSwitchList(location);
         if (csvFile == null || !csvFile.exists()) {
           log.error("CSV switch list file was not created for location {}", location.getName());
           finishAction(false);
           return;
         }
         TrainCustomSwitchList.addCVSFile(csvFile);
       }
     }
     // Processes the CSV Manifest files using an external custom program.
     int fileCount = TrainCustomSwitchList.getFileCount();
     boolean status = TrainCustomSwitchList.process();
     if (status) {
       try {
         TrainCustomSwitchList.waitForProcessToComplete(
             Control.excelWaitTime * fileCount); // wait up to 60 seconds per file
       } catch (InterruptedException e) {
         // TODO Auto-generated catch block
         e.printStackTrace();
       }
     }
     // set trains switch lists printed
     TrainManager.instance().setTrainsSwitchListStatus(Train.PRINTED);
     finishAction(status);
   }
 }
 private void updateSwitchListButton() {
   log.debug("update switch list button");
   List<Location> locations = locationManager.getList();
   for (Location location : locations) {
     if (location != null
         && location.isSwitchListEnabled()
         && location.getStatus().equals(Location.MODIFIED)) {
       switchListsButton.setBackground(Color.RED);
       return;
     }
   }
   switchListsButton.setBackground(Color.GREEN);
 }
Example #5
0
 /**
  * Sets the final destination for a car.
  *
  * @param destination The final destination for this car.
  */
 public void setFinalDestination(Location destination) {
   Location old = _finalDestination;
   if (old != null) {
     old.removePropertyChangeListener(this);
   }
   _finalDestination = destination;
   if (_finalDestination != null) {
     _finalDestination.addPropertyChangeListener(this);
   }
   // log.debug("Next destination for car ("+toString()+") old: "+old+" new: "+destination);
   if ((old != null && !old.equals(destination))
       || (destination != null && !destination.equals(old))) {
     setDirtyAndFirePropertyChange(FINAL_DESTINATION_CHANGED_PROPERTY, old, destination);
   }
 }
 public void buildSwitchLists() {
   TrainSwitchLists trainSwitchLists = new TrainSwitchLists();
   String locationName = ""; // only create switch lists once for locations with similar names
   for (Location location : LocationManager.instance().getLocationsByNameList()) {
     if (location.isSwitchListEnabled()
         && !locationName.equals(TrainCommon.splitString(location.getName()))) {
       trainSwitchLists.buildSwitchList(location);
       // print switch lists for locations that have changes
       if (Setup.isSwitchListRealTime() && location.getStatus().equals(Location.MODIFIED)) {
         trainSwitchLists.printSwitchList(
             location, TrainManager.instance().isPrintPreviewEnabled());
         locationName = TrainCommon.splitString(location.getName());
       }
     }
   }
   // set trains switch lists printed
   TrainManager.instance().setTrainsSwitchListStatus(Train.PRINTED);
 }
Example #7
0
 public void printSwitchList(Location location, boolean isPreview) {
   File buildFile = TrainManagerXml.instance().getSwitchListFile(location.getName());
   if (!buildFile.exists()) {
     log.warn("Switch list file missing for location ({})", location.getName());
     return;
   }
   if (isPreview && Setup.isManifestEditorEnabled()) {
     TrainPrintUtilities.openDesktopEditor(buildFile);
   } else {
     TrainPrintUtilities.printReport(
         buildFile,
         location.getName(),
         isPreview,
         Setup.getFontName(),
         false,
         FileUtil.getExternalFilename(Setup.getManifestLogoURL()),
         location.getDefaultPrinterName(),
         Setup.getSwitchListOrientation(),
         Setup.getManifestFontSize());
   }
   if (!isPreview) {
     location.setStatus(Location.PRINTED);
     location.setSwitchListState(Location.SW_PRINTED);
   }
 }
 private void removePropertyChangeLocations() {
   for (Location location : locationManager.getList()) {
     location.removePropertyChangeListener(this);
   }
 }
Example #9
0
 private synchronized void removePropertyChangeLocations() {
   List<Location> locations = locationManager.getList();
   for (Location location : locations) {
     location.removePropertyChangeListener(this);
   }
 }
Example #10
0
  public void loadEngine(Engine engine) {
    _engine = engine;

    if (!CarRoads.instance().containsName(engine.getRoadName())) {
      String msg =
          MessageFormat.format(
              Bundle.getMessage("roadNameNotExist"), new Object[] {engine.getRoadName()});
      if (JOptionPane.showConfirmDialog(
              this, msg, Bundle.getMessage("engineAddRoad"), JOptionPane.YES_NO_OPTION)
          == JOptionPane.YES_OPTION) {
        CarRoads.instance().addName(engine.getRoadName());
      }
    }
    roadComboBox.setSelectedItem(engine.getRoadName());

    roadNumberTextField.setText(engine.getNumber());

    if (!engineModels.containsName(engine.getModel())) {
      String msg =
          MessageFormat.format(
              Bundle.getMessage("modelNameNotExist"), new Object[] {engine.getModel()});
      if (JOptionPane.showConfirmDialog(
              this, msg, Bundle.getMessage("engineAddModel"), JOptionPane.YES_NO_OPTION)
          == JOptionPane.YES_OPTION) {
        engineModels.addName(engine.getModel());
      }
    }
    modelComboBox.setSelectedItem(engine.getModel());

    if (!engineTypes.containsName(engine.getTypeName())) {
      String msg =
          MessageFormat.format(
              Bundle.getMessage("typeNameNotExist"), new Object[] {engine.getTypeName()});
      if (JOptionPane.showConfirmDialog(
              this, msg, Bundle.getMessage("engineAddType"), JOptionPane.YES_NO_OPTION)
          == JOptionPane.YES_OPTION) {
        engineTypes.addName(engine.getTypeName());
      }
    }
    typeComboBox.setSelectedItem(engine.getTypeName());
    bUnitCheckBox.setSelected(engine.isBunit());

    if (!engineLengths.containsName(engine.getLength())) {
      String msg =
          MessageFormat.format(
              Bundle.getMessage("lengthNameNotExist"), new Object[] {engine.getLength()});
      if (JOptionPane.showConfirmDialog(
              this, msg, Bundle.getMessage("engineAddLength"), JOptionPane.YES_NO_OPTION)
          == JOptionPane.YES_OPTION) {
        engineLengths.addName(engine.getLength());
      }
    }
    lengthComboBox.setSelectedItem(engine.getLength());
    weightTextField.setText(engine.getWeightTons());
    hpTextField.setText(engine.getHp());

    locationBox.setSelectedItem(engine.getLocation());
    Location l = locationManager.getLocationById(engine.getLocationId());
    if (l != null) {
      l.updateComboBox(trackLocationBox);
      trackLocationBox.setSelectedItem(engine.getTrack());
    } else {
      trackLocationBox.removeAllItems();
    }

    builtTextField.setText(engine.getBuilt());

    if (!CarOwners.instance().containsName(engine.getOwner())) {
      String msg =
          MessageFormat.format(
              Bundle.getMessage("ownerNameNotExist"), new Object[] {engine.getOwner()});
      if (JOptionPane.showConfirmDialog(
              this, msg, Bundle.getMessage("addOwner"), JOptionPane.YES_NO_OPTION)
          == JOptionPane.YES_OPTION) {
        CarOwners.instance().addName(engine.getOwner());
      }
    }
    consistComboBox.setSelectedItem(engine.getConsistName());

    ownerComboBox.setSelectedItem(engine.getOwner());
    valueTextField.setText(engine.getValue());
    rfidComboBox.setSelectedItem(engine.getIdTag());
    commentTextField.setText(engine.getComment());

    setTitle(Bundle.getMessage("TitleEngineEdit"));
  }
Example #11
0
  /**
   * Construct this Entry from XML. This member has to remain synchronized with the detailed DTD in
   * operations-cars.dtd
   *
   * @param e Car XML element
   */
  public Car(org.jdom2.Element e) {
    super(e);
    loaded = true;
    org.jdom2.Attribute a;
    if ((a = e.getAttribute(Xml.PASSENGER)) != null) {
      _passenger = a.getValue().equals(Xml.TRUE);
    }
    if ((a = e.getAttribute(Xml.HAZARDOUS)) != null) {
      _hazardous = a.getValue().equals(Xml.TRUE);
    }
    if ((a = e.getAttribute(Xml.CABOOSE)) != null) {
      _caboose = a.getValue().equals(Xml.TRUE);
    }
    if ((a = e.getAttribute(Xml.FRED)) != null) {
      _fred = a.getValue().equals(Xml.TRUE);
    }
    if ((a = e.getAttribute(Xml.UTILITY)) != null) {
      _utility = a.getValue().equals(Xml.TRUE);
    }
    if ((a = e.getAttribute(Xml.KERNEL)) != null) {
      Kernel k = CarManager.instance().getKernelByName(a.getValue());
      if (k != null) {
        setKernel(k);
        if ((a = e.getAttribute(Xml.LEAD_KERNEL)) != null && a.getValue().equals(Xml.TRUE)) {
          _kernel.setLead(this);
        }
      } else {
        log.error("Kernel " + a.getValue() + " does not exist");
      }
    }
    if ((a = e.getAttribute(Xml.LOAD)) != null) {
      _loadName = a.getValue();
    }
    if ((a = e.getAttribute(Xml.LOAD_FROM_STAGING)) != null && a.getValue().equals(Xml.TRUE)) {
      setLoadGeneratedFromStaging(true);
    }

    if ((a = e.getAttribute(Xml.WAIT)) != null) {
      try {
        _wait = Integer.parseInt(a.getValue());
      } catch (NumberFormatException nfe) {
        log.error("Wait count ({}) for car ({}) isn't a valid number!", a.getValue(), toString());
      }
    }
    if ((a = e.getAttribute(Xml.PICKUP_SCHEDULE_ID)) != null) {
      _pickupScheduleId = a.getValue();
    }
    if ((a = e.getAttribute(Xml.SCHEDULE_ID)) != null) {
      _scheduleId = a.getValue();
    }
    if ((a = e.getAttribute(Xml.NEXT_LOAD)) != null) {
      _nextLoadName = a.getValue();
    }
    if ((a = e.getAttribute(Xml.NEXT_WAIT)) != null) {
      try {
        _nextWait = Integer.parseInt(a.getValue());
      } catch (NumberFormatException nfe) {
        log.error(
            "Next wait count ({}) for car ({}) isn't a valid number!", a.getValue(), toString());
      }
    }
    if ((a = e.getAttribute(Xml.NEXT_PICKUP_SCHEDULE_ID)) != null) {
      _nextPickupScheduleId = a.getValue();
    }
    if ((a = e.getAttribute(Xml.NEXT_DEST_ID)) != null) {
      setFinalDestination(LocationManager.instance().getLocationById(a.getValue()));
    }
    if (getFinalDestination() != null && (a = e.getAttribute(Xml.NEXT_DEST_TRACK_ID)) != null) {
      setFinalDestinationTrack(getFinalDestination().getTrackById(a.getValue()));
    }
    if ((a = e.getAttribute(Xml.PREVIOUS_NEXT_DEST_ID)) != null) {
      setPreviousFinalDestination(LocationManager.instance().getLocationById(a.getValue()));
    }
    if (getPreviousFinalDestination() != null
        && (a = e.getAttribute(Xml.PREVIOUS_NEXT_DEST_TRACK_ID)) != null) {
      setPreviousFinalDestinationTrack(getPreviousFinalDestination().getTrackById(a.getValue()));
    }
    if ((a = e.getAttribute(Xml.PREVIOUS_SCHEDULE_ID)) != null) {
      setPreviousScheduleId(a.getValue());
    }
    if ((a = e.getAttribute(Xml.RWE_DEST_ID)) != null) {
      _rweDestination = LocationManager.instance().getLocationById(a.getValue());
    }
    if (_rweDestination != null && (a = e.getAttribute(Xml.RWE_DEST_TRACK_ID)) != null) {
      _rweDestTrack = _rweDestination.getTrackById(a.getValue());
    }
    if ((a = e.getAttribute(Xml.RWE_LOAD)) != null) {
      _rweLoadName = a.getValue();
    }
    addPropertyChangeListeners();
  }
Example #12
0
 public String getFinalDestinationName() {
   if (_finalDestination != null) {
     return _finalDestination.getName();
   }
   return NONE;
 }
Example #13
0
  @Override
  @edu.umd.cs.findbugs.annotations.SuppressFBWarnings(
      value = "ST_WRITE_TO_STATIC_FROM_INSTANCE_METHOD",
      justification = "GUI ease of use")
  protected void buttonActionPerformed(java.awt.event.ActionEvent ae) {
    if (ae.getSource() == copyButton) {
      log.debug("copy location button activated");
      if (!checkName()) {
        return;
      }

      if (locationBox.getSelectedItem() == null) {
        JOptionPane.showMessageDialog(
            this,
            Bundle.getMessage("SelectLocationToCopy"),
            MessageFormat.format(
                Bundle.getMessage("CanNotLocation"), new Object[] {Bundle.getMessage("Copy")}),
            JOptionPane.ERROR_MESSAGE);
        return;
      }

      Location location = (Location) locationBox.getSelectedItem();
      // check to see if there are cars scheduled for pickup or set out
      if (moveRollingStockCheckBox.isSelected()) {
        for (Track track : location.getTrackList()) {
          if (track.getPickupRS() > 0) {
            JOptionPane.showMessageDialog(
                this,
                MessageFormat.format(
                    Bundle.getMessage("FoundRollingStockPickUp"),
                    new Object[] {track.getPickupRS()}),
                MessageFormat.format(
                    Bundle.getMessage("TrainsServicingTrack"), new Object[] {track.getName()}),
                JOptionPane.WARNING_MESSAGE);
            return; // can't move rolling stock, some are scheduled for a pick up
          }
          if (track.getDropRS() > 0) {
            JOptionPane.showMessageDialog(
                this,
                MessageFormat.format(
                    Bundle.getMessage("FoundRollingStockDrop"), new Object[] {track.getDropRS()}),
                MessageFormat.format(
                    Bundle.getMessage("TrainsServicingTrack"), new Object[] {track.getName()}),
                JOptionPane.WARNING_MESSAGE);
            return; // can't move rolling stock, some are scheduled for drops
          }
        }
      }
      // now copy all of the tracks
      Location newLocation = locationManager.newLocation(loctionNameTextField.getText());
      location.copyLocation(newLocation);

      // does the user want the cars to also move to the new tracks?
      if (moveRollingStockCheckBox.isSelected()) {
        for (Track track : location.getTrackList()) {
          moveRollingStock(track, newLocation.getTrackByName(track.getName(), null));
          if (deleteTrackCheckBox.isSelected()) {
            location.deleteTrack(track);
          }
        }
      }
    }
    if (ae.getSource() == saveButton) {
      log.debug("save track button activated");
      // save checkbox states
      moveRollingStock = moveRollingStockCheckBox.isSelected();
      deleteTrack = deleteTrackCheckBox.isSelected();
      // save location file
      OperationsXml.save();
    }
  }
Example #14
0
  /**
   * Builds a switch list for a location showing the work by train arrival time. If not running in
   * real time, new train work is appended to the end of the file. User has the ability to modify
   * the text of the messages which can cause an IllegalArgumentException. Some messages have more
   * arguments than the default message allowing the user to customize the message to their liking.
   *
   * <p>There also an option to list all of the car work by track name. This option is only
   * available in real time and is shown after the switch list by train.
   *
   * @param location The Location needing a switch list
   */
  @edu.umd.cs.findbugs.annotations.SuppressFBWarnings(
      value = "BC_UNCONFIRMED_CAST_OF_RETURN_VALUE",
      justification = "CarManager only provides Car Objects") // NOI18N
  public void buildSwitchList(Location location) {
    // Append switch list data if not operating in real time
    boolean newTrainsOnly = !Setup.isSwitchListRealTime();
    boolean append = false; // add text to end of file when true
    boolean checkFormFeed = true; // used to determine if FF needed between trains
    if (newTrainsOnly) {
      if (!location.getStatus().equals(Location.MODIFIED)
          && !Setup.isSwitchListAllTrainsEnabled()) {
        return; // nothing to add
      }
      append = location.getSwitchListState() == Location.SW_APPEND;
      if (location.getSwitchListState() != Location.SW_APPEND) {
        location.setSwitchListState(Location.SW_APPEND);
      }
      location.setStatus(Location.UPDATED);
    }

    log.debug("Append: {} for location ({})", append, location.getName());

    // create switch list file
    File file = TrainManagerXml.instance().createSwitchListFile(location.getName());

    PrintWriter fileOut = null;
    try {
      fileOut =
          new PrintWriter(
              new BufferedWriter(
                  new OutputStreamWriter(new FileOutputStream(file, append), "UTF-8")),
              true); // NOI18N
    } catch (IOException e) {
      log.error("Can not open switchlist file: {}", file.getName());
      return;
    }
    try {
      // build header
      if (!append) {
        newLine(fileOut, Setup.getRailroadName());
        newLine(fileOut);
        newLine(
            fileOut,
            MessageFormat.format(
                messageFormatText = TrainSwitchListText.getStringSwitchListFor(),
                new Object[] {splitString(location.getName())}));
        if (!location.getSwitchListComment().equals(Location.NONE)) {
          newLine(fileOut, location.getSwitchListComment());
        }
      }

      String valid =
          MessageFormat.format(
              messageFormatText = TrainManifestText.getStringValid(), new Object[] {getDate(true)});
      if (Setup.isPrintTimetableNameEnabled()) {
        TrainSchedule sch =
            TrainScheduleManager.instance()
                .getScheduleById(trainManager.getTrainScheduleActiveId());
        if (sch != null) {
          valid = valid + " (" + sch.getName() + ")";
        }
      }

      // get a list of trains sorted by arrival time
      List<Train> trains = trainManager.getTrainsArrivingThisLocationList(location);
      for (Train train : trains) {
        if (!train.isBuilt()) {
          continue; // train wasn't built so skip
        }
        if (newTrainsOnly && train.getSwitchListStatus().equals(Train.PRINTED)) {
          continue; // already printed this train
        }
        Route route = train.getRoute();
        if (route == null) {
          continue; // no route for this train
        } // determine if train works this location
        boolean works = isThereWorkAtLocation(train, location);
        if (!works && !Setup.isSwitchListAllTrainsEnabled()) {
          log.debug("No work for train ({}) at location ({})", train.getName(), location.getName());
          continue;
        }
        // we're now going to add to the switch list
        if (checkFormFeed) {
          if (append && !Setup.getSwitchListPageFormat().equals(Setup.PAGE_NORMAL)) {
            fileOut.write(FORM_FEED);
          }
          if (Setup.isPrintValidEnabled()) {
            newLine(fileOut, valid);
          }
        } else if (!Setup.getSwitchListPageFormat().equals(Setup.PAGE_NORMAL)) {
          fileOut.write(FORM_FEED);
        }
        checkFormFeed = false; // done with FF for this train
        // some cars booleans and the number of times this location get's serviced
        pickupCars = false; // when true there was a car pick up
        dropCars = false; // when true there was a car set out
        int stops = 1;
        boolean trainDone = false;
        // get engine and car lists
        List<Engine> engineList = engineManager.getByTrainBlockingList(train);
        List<Car> carList = carManager.getByTrainDestinationList(train);
        List<RouteLocation> routeList = route.getLocationsBySequenceList();
        RouteLocation rlPrevious = null;
        // does the train stop once or more at this location?
        for (RouteLocation rl : routeList) {
          if (!splitString(rl.getName()).equals(splitString(location.getName()))) {
            rlPrevious = rl;
            continue;
          }
          String expectedArrivalTime = train.getExpectedArrivalTime(rl);
          if (expectedArrivalTime.equals(Train.ALREADY_SERVICED)) {
            trainDone = true;
          }
          // first time at this location?
          if (stops == 1) {
            newLine(fileOut);
            newLine(
                fileOut,
                MessageFormat.format(
                    messageFormatText = TrainSwitchListText.getStringScheduledWork(),
                    new Object[] {train.getName(), train.getDescription()}));
            if (train.isTrainEnRoute()) {
              if (!trainDone) {
                newLine(
                    fileOut,
                    MessageFormat.format(
                        messageFormatText = TrainSwitchListText.getStringDepartedExpected(),
                        new Object[] {
                          splitString(train.getTrainDepartsName()),
                          expectedArrivalTime,
                          rl.getTrainDirectionString()
                        }));
              }
            } else if (!train.isLocalSwitcher()) {
              if (rl == train.getRoute().getDepartsRouteLocation()) {
                newLine(
                    fileOut,
                    MessageFormat.format(
                        messageFormatText = TrainSwitchListText.getStringDepartsAt(),
                        new Object[] {
                          splitString(train.getTrainDepartsName()),
                          rl.getTrainDirectionString(),
                          train.getFormatedDepartureTime()
                        }));
              } else {
                newLine(
                    fileOut,
                    MessageFormat.format(
                        messageFormatText = TrainSwitchListText.getStringDepartsAtExpectedArrival(),
                        new Object[] {
                          splitString(train.getTrainDepartsName()),
                          train.getFormatedDepartureTime(),
                          expectedArrivalTime,
                          rl.getTrainDirectionString()
                        }));
              }
            }
          } else {
            // multiple visits to this location
            // Print visit number only if previous location wasn't the same
            if (rlPrevious == null
                || !splitString(rl.getName()).equals(splitString(rlPrevious.getName()))) {
              if (Setup.getSwitchListPageFormat().equals(Setup.PAGE_PER_VISIT)) {
                fileOut.write(FORM_FEED);
              }
              newLine(fileOut);
              if (train.isTrainEnRoute()) {
                if (expectedArrivalTime.equals(Train.ALREADY_SERVICED)) {
                  newLine(
                      fileOut,
                      MessageFormat.format(
                          messageFormatText = TrainSwitchListText.getStringVisitNumberDone(),
                          new Object[] {stops, train.getName(), train.getDescription()}));
                } else if (rl != train.getRoute().getTerminatesRouteLocation()) {
                  newLine(
                      fileOut,
                      MessageFormat.format(
                          messageFormatText = TrainSwitchListText.getStringVisitNumberDeparted(),
                          new Object[] {
                            stops,
                            train.getName(),
                            expectedArrivalTime,
                            rl.getTrainDirectionString(),
                            train.getDescription()
                          }));
                } else {
                  // message: Visit number {0} for train ({1}) expect to arrive in {2}, terminates
                  // {3}
                  newLine(
                      fileOut,
                      MessageFormat.format(
                          messageFormatText =
                              TrainSwitchListText.getStringVisitNumberTerminatesDeparted(),
                          new Object[] {
                            stops,
                            train.getName(),
                            expectedArrivalTime,
                            splitString(rl.getName()),
                            train.getDescription()
                          }));
                }
              } else {
                // train hasn't departed
                if (rl != train.getRoute().getTerminatesRouteLocation()) {
                  newLine(
                      fileOut,
                      MessageFormat.format(
                          messageFormatText = TrainSwitchListText.getStringVisitNumber(),
                          new Object[] {
                            stops,
                            train.getName(),
                            expectedArrivalTime,
                            rl.getTrainDirectionString(),
                            train.getDescription()
                          }));
                } else {
                  newLine(
                      fileOut,
                      MessageFormat.format(
                          messageFormatText = TrainSwitchListText.getStringVisitNumberTerminates(),
                          new Object[] {
                            stops,
                            train.getName(),
                            expectedArrivalTime,
                            splitString(rl.getName()),
                            train.getDescription()
                          }));
                }
              }
            } else {
              stops--; // don't bump stop count, same location
              // Does the train reverse direction?
              if (rl.getTrainDirection() != rlPrevious.getTrainDirection()
                  && !TrainSwitchListText.getStringTrainDirectionChange().equals("")) {
                newLine(
                    fileOut,
                    MessageFormat.format(
                        messageFormatText = TrainSwitchListText.getStringTrainDirectionChange(),
                        new Object[] {
                          train.getName(),
                          rl.getTrainDirectionString(),
                          train.getDescription(),
                          train.getTrainTerminatesName()
                        }));
              }
            }
          }

          rlPrevious =
              rl; // save current location in case there's back to back location with the same name

          // add route comment
          if (Setup.isSwitchListRouteLocationCommentEnabled()
              && !rl.getComment().trim().equals("")) {
            newLine(fileOut, rl.getComment());
          }

          // now print out the work for this location
          if (Setup.getManifestFormat().equals(Setup.STANDARD_FORMAT)) {
            pickupEngines(fileOut, engineList, rl, !IS_MANIFEST);
            // if switcher show loco drop at end of list
            if (train.isLocalSwitcher()) {
              blockCarsByTrack(
                  fileOut, train, carList, routeList, rl, IS_PRINT_HEADER, !IS_MANIFEST);
              dropEngines(fileOut, engineList, rl, !IS_MANIFEST);
            } else {
              dropEngines(fileOut, engineList, rl, !IS_MANIFEST);
              blockCarsByTrack(
                  fileOut, train, carList, routeList, rl, IS_PRINT_HEADER, !IS_MANIFEST);
            }
          } else if (Setup.getManifestFormat().equals(Setup.TWO_COLUMN_FORMAT)) {
            blockLocosTwoColumn(fileOut, engineList, rl, !IS_MANIFEST);
            blockCarsByTrackTwoColumn(
                fileOut, train, carList, routeList, rl, IS_PRINT_HEADER, !IS_MANIFEST);
          } else {
            blockLocosTwoColumn(fileOut, engineList, rl, !IS_MANIFEST);
            blockCarsByTrackNameTwoColumn(
                fileOut, train, carList, routeList, rl, IS_PRINT_HEADER, !IS_MANIFEST);
          }
          if (Setup.isPrintHeadersEnabled()
              || !Setup.getManifestFormat().equals(Setup.STANDARD_FORMAT)) {
            printHorizontalLine(fileOut, !IS_MANIFEST);
          }

          stops++;

          // done with work, now print summary for this location if we're done
          if (rl != train.getRoute().getTerminatesRouteLocation()) {
            RouteLocation nextRl = train.getRoute().getNextRouteLocation(rl);
            if (splitString(rl.getName()).equals(splitString(nextRl.getName()))) {
              continue; // the current location name is the "same" as the next
            }
            // print departure text if not a switcher
            if (!train.isLocalSwitcher()) {
              String trainDeparts = "";
              if (Setup.isPrintLoadsAndEmptiesEnabled()) {
                int emptyCars = train.getNumberEmptyCarsInTrain(rl);
                // Message format: Train departs Boston Westbound with 4 loads, 8 empties, 450 feet,
                // 3000 tons
                trainDeparts =
                    MessageFormat.format(
                        TrainSwitchListText.getStringTrainDepartsLoads(),
                        new Object[] {
                          TrainCommon.splitString(rl.getName()),
                          rl.getTrainDirectionString(),
                          train.getNumberCarsInTrain(rl) - emptyCars,
                          emptyCars,
                          train.getTrainLength(rl),
                          Setup.getLengthUnit().toLowerCase(),
                          train.getTrainWeight(rl),
                          train.getTrainTerminatesName(),
                          train.getName()
                        });
              } else {
                // Message format: Train departs Boston Westbound with 12 cars, 450 feet, 3000 tons
                trainDeparts =
                    MessageFormat.format(
                        TrainSwitchListText.getStringTrainDepartsCars(),
                        new Object[] {
                          TrainCommon.splitString(rl.getName()),
                          rl.getTrainDirectionString(),
                          train.getNumberCarsInTrain(rl),
                          train.getTrainLength(rl),
                          Setup.getLengthUnit().toLowerCase(),
                          train.getTrainWeight(rl),
                          train.getTrainTerminatesName(),
                          train.getName()
                        });
              }
              newLine(fileOut, trainDeparts);
            }
          }
        }
        if (trainDone && !pickupCars && !dropCars) {
          // Default message: Train ({0}) has serviced this location
          newLine(
              fileOut,
              MessageFormat.format(
                  messageFormatText = TrainSwitchListText.getStringTrainDone(),
                  new Object[] {
                    train.getName(), train.getDescription(), splitString(location.getName())
                  }));
        } else {
          if (stops > 1 && !pickupCars) {
            // Default message: No car pick ups for train ({0}) at this location
            newLine(
                fileOut,
                MessageFormat.format(
                    messageFormatText = TrainSwitchListText.getStringNoCarPickUps(),
                    new Object[] {
                      train.getName(), train.getDescription(), splitString(location.getName())
                    }));
          }
          if (stops > 1 && !dropCars) {
            // Default message: No car set outs for train ({0}) at this location
            newLine(
                fileOut,
                MessageFormat.format(
                    messageFormatText = TrainSwitchListText.getStringNoCarDrops(),
                    new Object[] {
                      train.getName(), train.getDescription(), splitString(location.getName())
                    }));
          }
        }
      }

      // now report car movement by tracks at location
      if (Setup.isTrackSummaryEnabled() && Setup.isSwitchListRealTime()) {
        clearUtilityCarTypes(); // list utility cars by quantity
        if (Setup.getSwitchListPageFormat().equals(Setup.PAGE_NORMAL)) {
          newLine(fileOut);
          newLine(fileOut);
        } else {
          fileOut.write(FORM_FEED);
        }
        newLine(
            fileOut,
            MessageFormat.format(
                messageFormatText = TrainSwitchListText.getStringSwitchListByTrack(),
                new Object[] {splitString(location.getName())}));

        // we only need the cars delivered to or at this location
        List<RollingStock> rsList = carManager.getByTrainList();
        List<Car> carList = new ArrayList<Car>();
        for (RollingStock rs : rsList) {
          if ((rs.getLocation() != null
                  && splitString(rs.getLocation().getName())
                      .equals(splitString(location.getName())))
              || (rs.getDestination() != null
                  && splitString(rs.getDestination().getName())
                      .equals(splitString(location.getName())))) carList.add((Car) rs);
        }

        List<String> trackNames =
            new ArrayList<
                String>(); // locations and tracks can have "similar" names, only list track names
                           // once
        for (Location loc : locationManager.getLocationsByNameList()) {
          if (!splitString(loc.getName()).equals(splitString(location.getName()))) continue;
          for (Track track : loc.getTrackByNameList(null)) {
            String trackName = splitString(track.getName());
            if (trackNames.contains(trackName)) continue;
            trackNames.add(trackName);

            String trainName = ""; // for printing train message once
            newLine(fileOut);
            newLine(fileOut, trackName); // print out just the track name
            // now show the cars pickup and holds for this track
            for (Car car : carList) {
              if (!splitString(car.getTrackName()).equals(trackName)) {
                continue;
              }
              // is the car scheduled for pickup?
              if (car.getRouteLocation() != null) {
                if (splitString(car.getRouteLocation().getLocation().getName())
                    .equals(splitString(location.getName()))) {
                  // cars are sorted by train name, print train message once
                  if (!trainName.equals(car.getTrainName())) {
                    trainName = car.getTrainName();
                    newLine(
                        fileOut,
                        MessageFormat.format(
                            messageFormatText = TrainSwitchListText.getStringScheduledWork(),
                            new Object[] {car.getTrainName(), car.getTrain().getDescription()}));
                    printPickupCarHeader(fileOut, !IS_MANIFEST, !IS_TWO_COLUMN_TRACK);
                  }
                  if (car.isUtility()) {
                    pickupUtilityCars(fileOut, carList, car, !IS_MANIFEST);
                  } else {
                    pickUpCar(fileOut, car, !IS_MANIFEST);
                  }
                }
                // car holds
              } else if (car.isUtility()) {
                String s = pickupUtilityCars(carList, car, !IS_MANIFEST, !IS_TWO_COLUMN_TRACK);
                if (s != null) {
                  newLine(
                      fileOut,
                      TrainSwitchListText.getStringHoldCar().split("\\{")[0] + s.trim()); // NOI18N
                }
              } else {
                newLine(
                    fileOut,
                    MessageFormat.format(
                        messageFormatText = TrainSwitchListText.getStringHoldCar(),
                        new Object[] {
                          padAndTruncateString(
                              car.getRoadName(), CarRoads.instance().getMaxNameLength()),
                          padAndTruncateString(
                              TrainCommon.splitString(car.getNumber()),
                              Control.max_len_string_print_road_number),
                          padAndTruncateString(
                              car.getTypeName().split("-")[0],
                              CarTypes.instance().getMaxNameLength()),
                          padAndTruncateString(
                              car.getLength() + LENGTHABV, Control.max_len_string_length_name),
                          padAndTruncateString(
                              car.getLoadName(), CarLoads.instance().getMaxNameLength()),
                          padAndTruncateString(trackName, locationManager.getMaxTrackNameLength()),
                          padAndTruncateString(
                              car.getColor(), CarColors.instance().getMaxNameLength())
                        }));
              }
            }
            // now do set outs at this location
            for (Car car : carList) {
              if (!splitString(car.getDestinationTrackName()).equals(trackName)) {
                continue;
              }
              if (car.getRouteDestination() != null
                  && splitString(car.getRouteDestination().getLocation().getName())
                      .equals(splitString(location.getName()))) {
                // cars are sorted by train name, print train message once
                if (!trainName.equals(car.getTrainName())) {
                  trainName = car.getTrainName();
                  newLine(
                      fileOut,
                      MessageFormat.format(
                          messageFormatText = TrainSwitchListText.getStringScheduledWork(),
                          new Object[] {car.getTrainName(), car.getTrain().getDescription()}));
                  printDropCarHeader(fileOut, !IS_MANIFEST, !IS_TWO_COLUMN_TRACK);
                }
                if (car.isUtility()) {
                  setoutUtilityCars(fileOut, carList, car, !IS_MANIFEST);
                } else {
                  dropCar(fileOut, car, !IS_MANIFEST);
                }
              }
            }
          }
        }
      }

    } catch (IllegalArgumentException e) {
      newLine(
          fileOut,
          MessageFormat.format(
              Bundle.getMessage("ErrorIllegalArgument"),
              new Object[] {Bundle.getMessage("TitleSwitchListText"), e.getLocalizedMessage()}));
      newLine(fileOut, messageFormatText);
      e.printStackTrace();
    }

    // Are there any cars that need to be found?
    addCarsLocationUnknown(fileOut, !IS_MANIFEST);
    fileOut.flush();
    fileOut.close();
  }