Search in sources :

Example 81 with RouteLocation

use of jmri.jmrit.operations.routes.RouteLocation in project JMRI by JMRI.

the class PrintTrainAction method printTrain.

protected void printTrain(HardcopyWriter writer, Train train) {
    try {
        String s = Bundle.getMessage("Name") + ": " + train.getName() + NEW_LINE;
        writer.write(s);
        s = Bundle.getMessage("Description") + ": " + train.getDescription() + NEW_LINE;
        writer.write(s);
        s = Bundle.getMessage("Departs") + ": " + train.getTrainDepartsName() + NEW_LINE;
        writer.write(s);
        s = Bundle.getMessage("DepartTime") + ": " + train.getDepartureTime() + NEW_LINE;
        writer.write(s);
        s = Bundle.getMessage("Terminates") + ": " + train.getTrainTerminatesName() + NEW_LINE;
        writer.write(s);
        s = NEW_LINE;
        writer.write(s);
        s = Bundle.getMessage("Route") + ": " + train.getTrainRouteName() + NEW_LINE;
        writer.write(s);
        Route route = train.getRoute();
        if (route != null) {
            for (RouteLocation rl : route.getLocationsBySequenceList()) {
                s = TAB + rl.getName() + NEW_LINE;
                writer.write(s);
            }
        }
        if (!train.getComment().equals(Train.NONE)) {
            s = Bundle.getMessage("Comment") + ": " + train.getComment() + NEW_LINE;
            writer.write(s);
        }
    } catch (IOException we) {
        log.error("Error printing train report");
    }
}
Also used : RouteLocation(jmri.jmrit.operations.routes.RouteLocation) IOException(java.io.IOException) Route(jmri.jmrit.operations.routes.Route)

Example 82 with RouteLocation

use of jmri.jmrit.operations.routes.RouteLocation in project JMRI by JMRI.

the class ShowCarsInTrainFrame method update.

private void update() {
    log.debug("queue update");
    // use invokeLater to prevent deadlock
    SwingUtilities.invokeLater(new Runnable() {

        @Override
        public void run() {
            log.debug("update");
            if (_train == null || _train.getRoute() == null) {
                return;
            }
            textTrainName.setText(_train.getIconName());
            pCars.removeAll();
            RouteLocation rl = _train.getCurrentLocation();
            if (rl != null) {
                textLocationName.setText(rl.getLocation().getName());
                textNextLocationName.setText(_train.getNextLocationName());
                // add header
                int i = 0;
                addItemLeft(pCars, textPickUp, 0, 0);
                addItemLeft(pCars, textInTrain, 1, 0);
                addItemLeft(pCars, textSetOut, 2, i++);
                // block cars by destination
                // except for passenger cars, use car blocking
                boolean isOnlyPassenger = _train.isOnlyPassengerCars();
                for (RouteLocation rld : _train.getRoute().getLocationsBySequenceList()) {
                    for (Car car : carManager.getByTrainDestinationList(_train)) {
                        if ((car.getTrack() == null || car.getRouteLocation() == rl) && (car.getRouteDestination() == rld || (car.isPassenger() && isOnlyPassenger))) {
                            log.debug("car ({}) routelocation ({}) track ({}) route destination ({})", car.toString(), car.getRouteLocation().getName(), car.getTrackName(), car.getRouteDestination().getName());
                            JCheckBox checkBox = new JCheckBox(TrainCommon.splitString(car.toString()));
                            if (car.getRouteDestination() == rl) {
                                // set out
                                addItemLeft(pCars, checkBox, 2, i++);
                            } else if (car.getRouteLocation() == rl && car.getTrack() != null) {
                                // pick up
                                addItemLeft(pCars, checkBox, 0, i++);
                            } else {
                                // in train
                                addItemLeft(pCars, checkBox, 1, i++);
                            }
                        }
                    }
                    if (isOnlyPassenger) {
                        break;
                    }
                }
                textStatus.setText(getStatus(rl));
            } else {
                textStatus.setText(MessageFormat.format(TrainManifestText.getStringTrainTerminates(), new Object[] { _train.getTrainTerminatesName() }));
            }
            pCars.repaint();
        }
    });
}
Also used : JCheckBox(javax.swing.JCheckBox) Car(jmri.jmrit.operations.rollingstock.cars.Car) RouteLocation(jmri.jmrit.operations.routes.RouteLocation)

Example 83 with RouteLocation

use of jmri.jmrit.operations.routes.RouteLocation in project JMRI by JMRI.

the class ChangeDepartureTimesFrame method buttonActionPerformed.

@Override
public void buttonActionPerformed(java.awt.event.ActionEvent ae) {
    if (ae.getSource() == changeButton) {
        log.debug("change button activated");
        TrainManager trainManager = TrainManager.instance();
        List<Train> trains = trainManager.getTrainsByIdList();
        for (Train train : trains) {
            train.setDepartureTime(adjustHour(train.getDepartureTimeHour()), train.getDepartureTimeMinute());
            // now check the train's route to see if there are any departure times that need to be modified
            if (train.getRoute() == null)
                continue;
            for (RouteLocation rl : train.getRoute().getLocationsBySequenceList()) {
                if (!rl.getDepartureTime().equals(RouteLocation.NONE))
                    rl.setDepartureTime(adjustHour(rl.getDepartureTimeHour()), rl.getDepartureTimeMinute());
            }
        }
    }
}
Also used : RouteLocation(jmri.jmrit.operations.routes.RouteLocation) Train(jmri.jmrit.operations.trains.Train) TrainManager(jmri.jmrit.operations.trains.TrainManager)

Example 84 with RouteLocation

use of jmri.jmrit.operations.routes.RouteLocation in project JMRI by JMRI.

the class HtmlConductor method getLocationComments.

private String getLocationComments() {
    List<Car> carList = CarManager.instance().getByTrainDestinationList(train);
    StringBuilder builder = new StringBuilder();
    RouteLocation routeLocation = train.getCurrentLocation();
    boolean work = isThereWorkAtLocation(train, routeLocation.getLocation());
    // print info only if new location
    String routeLocationName = StringEscapeUtils.escapeHtml4(splitString(routeLocation.getName()));
    if (work) {
        if (!train.isShowArrivalAndDepartureTimesEnabled()) {
            // NOI18N
            builder.append(String.format(locale, strings.getProperty("ScheduledWorkAt"), routeLocationName));
        } else if (routeLocation == train.getRoute().getDepartsRouteLocation()) {
            builder.append(String.format(locale, strings.getProperty("WorkDepartureTime"), routeLocationName, // NOI18N
            train.getFormatedDepartureTime()));
        } else if (!routeLocation.getDepartureTime().equals("")) {
            builder.append(// NOI18N
            String.format(// NOI18N
            locale, // NOI18N
            strings.getProperty("WorkDepartureTime"), // NOI18N
            routeLocationName, // NOI18N
            routeLocation.getFormatedDepartureTime()));
        } else if (Setup.isUseDepartureTimeEnabled() && routeLocation != train.getRoute().getTerminatesRouteLocation() && !train.getExpectedDepartureTime(routeLocation).equals(Train.ALREADY_SERVICED)) {
            builder.append(String.format(locale, strings.getProperty("WorkDepartureTime"), routeLocationName, // NOI18N
            train.getExpectedDepartureTime(routeLocation)));
        } else if (!train.getExpectedArrivalTime(routeLocation).equals(Train.ALREADY_SERVICED)) {
            builder.append(String.format(locale, strings.getProperty("WorkArrivalTime"), routeLocationName, // NOI18N
            train.getExpectedArrivalTime(// NOI18N
            routeLocation)));
        } else {
            // NOI18N
            builder.append(String.format(locale, strings.getProperty("ScheduledWorkAt"), routeLocationName));
        }
        // add route comment
        if (!routeLocation.getComment().trim().equals("")) {
            builder.append(String.format(locale, strings.getProperty("RouteLocationComment"), // NOI18N
            StringEscapeUtils.escapeHtml4(routeLocation.getComment())));
        }
        builder.append(getTrackComments(routeLocation, carList));
        // add location comment
        if (Setup.isPrintLocationCommentsEnabled() && !routeLocation.getLocation().getComment().isEmpty()) {
            builder.append(String.format(locale, strings.getProperty("LocationComment"), // NOI18N
            StringEscapeUtils.escapeHtml4(routeLocation.getLocation().getComment())));
        }
    }
    // engine change or helper service?
    builder.append(this.getEngineChanges(routeLocation));
    if (routeLocation != train.getRoute().getTerminatesRouteLocation()) {
        if (work) {
            if (!Setup.isPrintLoadsAndEmptiesEnabled()) {
                // Message format: Train departs Boston Westbound with 12 cars, 450 feet, 3000 tons
                builder.append(// NOI18N
                String.format(// NOI18N
                strings.getProperty("TrainDepartsCars"), // NOI18N
                routeLocationName, routeLocation.getTrainDirectionString(), train.getTrainLength(routeLocation), Setup.getLengthUnit().toLowerCase(), train.getTrainWeight(routeLocation), train.getNumberCarsInTrain(routeLocation)));
            } else {
                // Message format: Train departs Boston Westbound with 4 loads, 8 empties, 450 feet, 3000 tons
                int emptyCars = train.getNumberEmptyCarsInTrain(routeLocation);
                builder.append(// NOI18N
                String.format(// NOI18N
                strings.getProperty("TrainDepartsLoads"), // NOI18N
                routeLocationName, routeLocation.getTrainDirectionString(), train.getTrainLength(routeLocation), Setup.getLengthUnit().toLowerCase(), train.getTrainWeight(routeLocation), train.getNumberCarsInTrain(routeLocation) - emptyCars, emptyCars));
            }
        } else {
            if (routeLocation.getComment().trim().isEmpty()) {
                // no route comment, no work at this location
                if (train.isShowArrivalAndDepartureTimesEnabled()) {
                    if (routeLocation == train.getRoute().getDepartsRouteLocation()) {
                        builder.append(String.format(locale, strings.getProperty("NoScheduledWorkAtWithDepartureTime"), routeLocationName, // NOI18N
                        train.getFormatedDepartureTime()));
                    } else if (!routeLocation.getDepartureTime().isEmpty()) {
                        builder.append(String.format(locale, strings.getProperty(// NOI18N
                        "NoScheduledWorkAtWithDepartureTime"), // NOI18N
                        routeLocationName, routeLocation.getFormatedDepartureTime()));
                    } else {
                        builder.append(// NOI18N
                        String.format(// NOI18N
                        locale, // NOI18N
                        strings.getProperty("NoScheduledWorkAt"), routeLocationName));
                    }
                } else {
                    builder.append(// NOI18N
                    String.format(// NOI18N
                    locale, // NOI18N
                    strings.getProperty("NoScheduledWorkAt"), routeLocationName));
                }
            } else {
                // route comment, so only use location and route comment (for passenger trains)
                if (train.isShowArrivalAndDepartureTimesEnabled()) {
                    if (routeLocation == train.getRoute().getDepartsRouteLocation()) {
                        builder.append(// NOI18N
                        String.format(// NOI18N
                        locale, // NOI18N
                        strings.getProperty("CommentAtWithDepartureTime"), routeLocationName, train.getFormatedDepartureTime(), StringEscapeUtils.escapeHtml4(routeLocation.getComment())));
                    } else if (!routeLocation.getDepartureTime().isEmpty()) {
                        builder.append(// NOI18N
                        String.format(// NOI18N
                        locale, // NOI18N
                        strings.getProperty("CommentAtWithDepartureTime"), routeLocationName, routeLocation.getFormatedDepartureTime(), StringEscapeUtils.escapeHtml4(routeLocation.getComment())));
                    }
                } else {
                    builder.append(// NOI18N
                    String.format(// NOI18N
                    locale, // NOI18N
                    strings.getProperty("CommentAt"), // NOI18N
                    routeLocationName, // NOI18N
                    null, StringEscapeUtils.escapeHtml4(routeLocation.getComment())));
                }
            }
            // add location comment
            if (Setup.isPrintLocationCommentsEnabled() && !routeLocation.getLocation().getComment().isEmpty()) {
                builder.append(String.format(locale, strings.getProperty("LocationComment"), // NOI18N
                StringEscapeUtils.escapeHtml4(routeLocation.getLocation().getComment())));
            }
        }
    } else {
        // NOI18N
        builder.append(String.format(strings.getProperty("TrainTerminatesIn"), routeLocationName));
    }
    return builder.toString();
}
Also used : Car(jmri.jmrit.operations.rollingstock.cars.Car) RouteLocation(jmri.jmrit.operations.routes.RouteLocation)

Example 85 with RouteLocation

use of jmri.jmrit.operations.routes.RouteLocation in project JMRI by JMRI.

the class HtmlConductor method dropCars.

private String dropCars(boolean local) {
    StringBuilder builder = new StringBuilder();
    RouteLocation location = train.getCurrentLocation();
    List<Car> carList = CarManager.instance().getByTrainDestinationList(train);
    List<Track> tracks = location.getLocation().getTrackByNameList(null);
    List<String> trackNames = new ArrayList<String>();
    List<String> dropped = new ArrayList<String>();
    for (Track track : tracks) {
        if (trackNames.contains(splitString(track.getName()))) {
            continue;
        }
        // use a track name once
        trackNames.add(splitString(track.getName()));
        for (Car car : carList) {
            if (dropped.contains(car.getId()) || (Setup.isSortByTrackNameEnabled() && !splitString(track.getName()).equals(splitString(car.getDestinationTrackName())))) {
                continue;
            }
            if (isLocalMove(car) == local && (car.getRouteDestination() == location && car.getDestinationTrack() != null)) {
                dropped.add(car.getId());
                if (car.isUtility()) {
                    builder.append(setoutUtilityCars(carList, car, local));
                } else {
                    String[] format = (!local) ? Setup.getDropManifestMessageFormat() : Setup.getLocalManifestMessageFormat();
                    builder.append(dropCar(car, format, local));
                }
            }
        }
    }
    return builder.toString();
}
Also used : Car(jmri.jmrit.operations.rollingstock.cars.Car) ArrayList(java.util.ArrayList) RouteLocation(jmri.jmrit.operations.routes.RouteLocation) Track(jmri.jmrit.operations.locations.Track)

Aggregations

RouteLocation (jmri.jmrit.operations.routes.RouteLocation)118 Route (jmri.jmrit.operations.routes.Route)64 Location (jmri.jmrit.operations.locations.Location)55 Track (jmri.jmrit.operations.locations.Track)52 Car (jmri.jmrit.operations.rollingstock.cars.Car)48 Engine (jmri.jmrit.operations.rollingstock.engines.Engine)33 LocationManager (jmri.jmrit.operations.locations.LocationManager)21 RouteManager (jmri.jmrit.operations.routes.RouteManager)20 Consist (jmri.jmrit.operations.rollingstock.engines.Consist)17 Train (jmri.jmrit.operations.trains.Train)16 CarManager (jmri.jmrit.operations.rollingstock.cars.CarManager)13 ArrayList (java.util.ArrayList)12 CarTypes (jmri.jmrit.operations.rollingstock.cars.CarTypes)12 EngineManager (jmri.jmrit.operations.rollingstock.engines.EngineManager)12 RollingStock (jmri.jmrit.operations.rollingstock.RollingStock)11 EngineTypes (jmri.jmrit.operations.rollingstock.engines.EngineTypes)8 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)6 IOException (java.io.IOException)6 TrainManager (jmri.jmrit.operations.trains.TrainManager)6 JCheckBox (javax.swing.JCheckBox)5