Search in sources :

Example 36 with RollingStock

use of jmri.jmrit.operations.rollingstock.RollingStock in project JMRI by JMRI.

the class PrintEngineRosterAction method actionPerformed.

@Override
@SuppressFBWarnings(value = "BC_UNCONFIRMED_CAST_OF_RETURN_VALUE", justification = "EngineManager only provides Engine Objects")
public void actionPerformed(ActionEvent e) {
    // obtain a HardcopyWriter to do this
    HardcopyWriter writer = null;
    try {
        writer = new HardcopyWriter(mFrame, Bundle.getMessage("TitleEngineRoster"), Control.reportFontSize, .5, .5, .5, .5, isPreview);
    } catch (HardcopyWriter.PrintCanceledException ex) {
        log.debug("Print cancelled");
        return;
    }
    numberCharPerLine = writer.getCharactersPerLine();
    // Loop through the Roster, printing as needed
    String number;
    String road;
    String model;
    String type;
    String length;
    String owner = "";
    String consist = "";
    String built = "";
    String value = "";
    String rfid = "";
    String location;
    List<RollingStock> engines = panel.getSortByList();
    try {
        // header
        String header = padAttribute(Bundle.getMessage("Number"), Control.max_len_string_print_road_number) + padAttribute(Bundle.getMessage("Road"), CarRoads.instance().getMaxNameLength()) + padAttribute(Bundle.getMessage("Model"), EngineModels.instance().getMaxNameLength()) + padAttribute(Bundle.getMessage("Type"), EngineTypes.instance().getMaxNameLength()) + padAttribute(Bundle.getMessage("Len"), Control.max_len_string_length_name) + (panel.sortByConsist.isSelected() ? padAttribute(Bundle.getMessage("Consist"), Control.max_len_string_attibute) : padAttribute(Bundle.getMessage("Owner"), ownerMaxLen)) + (panel.sortByValue.isSelected() ? padAttribute(Setup.getValueLabel(), Control.max_len_string_attibute) : "") + (panel.sortByRfid.isSelected() ? padAttribute(Setup.getRfidLabel(), Control.max_len_string_attibute) : "") + ((!panel.sortByValue.isSelected() && !panel.sortByRfid.isSelected()) ? padAttribute(Bundle.getMessage("Built"), Control.max_len_string_built_name) : "") + Bundle.getMessage("Location") + NEW_LINE;
        writer.write(header);
        for (RollingStock rs : engines) {
            Engine engine = (Engine) rs;
            // loco number
            number = padAttribute(engine.getNumber(), Control.max_len_string_print_road_number);
            road = padAttribute(engine.getRoadName(), CarRoads.instance().getMaxNameLength());
            model = padAttribute(engine.getModel(), EngineModels.instance().getMaxNameLength());
            type = padAttribute(engine.getTypeName(), EngineTypes.instance().getMaxNameLength());
            length = padAttribute(engine.getLength(), Control.max_len_string_length_name);
            if (panel.sortByConsist.isSelected()) {
                consist = padAttribute(engine.getConsistName(), Control.max_len_string_attibute);
            } else {
                owner = padAttribute(engine.getOwner(), ownerMaxLen);
            }
            if (panel.sortByValue.isSelected()) {
                value = padAttribute(engine.getValue(), Control.max_len_string_attibute);
            } else if (panel.sortByRfid.isSelected()) {
                rfid = padAttribute(engine.getRfid(), Control.max_len_string_attibute);
            } else {
                built = padAttribute(engine.getBuilt(), Control.max_len_string_built_name);
            }
            location = "";
            if (!engine.getLocationName().equals(Engine.NONE)) {
                location = engine.getLocationName() + " - " + engine.getTrackName();
            }
            String s = number + road + model + type + length + owner + consist + value + rfid + built + location;
            if (s.length() > numberCharPerLine) {
                s = s.substring(0, numberCharPerLine);
            }
            writer.write(s + NEW_LINE);
        }
    } catch (IOException we) {
        log.error("Error printing ConsistRosterEntry: " + e);
    }
    // and force completion of the printing
    writer.close();
}
Also used : IOException(java.io.IOException) HardcopyWriter(jmri.util.davidflanagan.HardcopyWriter) RollingStock(jmri.jmrit.operations.rollingstock.RollingStock) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Example 37 with RollingStock

use of jmri.jmrit.operations.rollingstock.RollingStock in project JMRI by JMRI.

the class EnginesTableModel method updateList.

private void updateList() {
    // first, remove listeners from the individual objects
    removePropertyChangeEngines();
    sysList = getSelectedEngineList();
    // and add listeners back in
    for (RollingStock rs : sysList) {
        rs.addPropertyChangeListener(this);
    }
}
Also used : RollingStock(jmri.jmrit.operations.rollingstock.RollingStock)

Example 38 with RollingStock

use of jmri.jmrit.operations.rollingstock.RollingStock in project JMRI by JMRI.

the class Train method getNumberEmptyCarsInTrain.

/**
     * Gets the number of empty cars in the train when train departs the route
     * location.
     * @param routeLocation The RouteLocation.
     *
     * @return The number of empty cars in the train departing the route
     *         location.
     */
public int getNumberEmptyCarsInTrain(RouteLocation routeLocation) {
    int number = 0;
    Route route = getRoute();
    if (route != null) {
        for (RouteLocation rl : route.getLocationsBySequenceList()) {
            for (RollingStock rs : CarManager.instance().getList(this)) {
                Car car = (Car) rs;
                if (!car.getLoadType().equals(CarLoad.LOAD_TYPE_EMPTY)) {
                    continue;
                }
                if (car.getRouteLocation() == rl) {
                    number++;
                }
                if (car.getRouteDestination() == rl) {
                    number--;
                }
            }
            if (rl == routeLocation) {
                break;
            }
        }
    }
    return number;
}
Also used : Car(jmri.jmrit.operations.rollingstock.cars.Car) RouteLocation(jmri.jmrit.operations.routes.RouteLocation) Route(jmri.jmrit.operations.routes.Route) RollingStock(jmri.jmrit.operations.rollingstock.RollingStock)

Example 39 with RollingStock

use of jmri.jmrit.operations.rollingstock.RollingStock in project JMRI by JMRI.

the class Train method getTrainHorsePower.

/**
     * Gets the train's locomotive horsepower at the route location specified
     *
     * @param routeLocation The route location
     * @return The train's locomotive horsepower at the route location
     */
public int getTrainHorsePower(RouteLocation routeLocation) {
    int hp = 0;
    Route route = getRoute();
    if (route != null) {
        for (RouteLocation rl : route.getLocationsBySequenceList()) {
            for (RollingStock rs : EngineManager.instance().getList(this)) {
                Engine eng = (Engine) rs;
                if (eng.getRouteLocation() == rl) {
                    hp += eng.getHpInteger();
                }
                if (eng.getRouteDestination() == rl) {
                    hp += -eng.getHpInteger();
                }
            }
            if (rl == routeLocation) {
                break;
            }
        }
    }
    return hp;
}
Also used : RouteLocation(jmri.jmrit.operations.routes.RouteLocation) Route(jmri.jmrit.operations.routes.Route) RollingStock(jmri.jmrit.operations.rollingstock.RollingStock) Engine(jmri.jmrit.operations.rollingstock.engines.Engine)

Example 40 with RollingStock

use of jmri.jmrit.operations.rollingstock.RollingStock in project JMRI by JMRI.

the class Train method getCabooseRoadAndNumber.

/**
     * Gets the current caboose road and number if there's one assigned to the
     * train.
     *
     * @return Road and number of caboose.
     */
@Nonnull
public String getCabooseRoadAndNumber() {
    String cabooseRoadNumber = NONE;
    RouteLocation rl = getCurrentLocation();
    List<RollingStock> cars = CarManager.instance().getByTrainList(this);
    for (RollingStock rs : cars) {
        Car car = (Car) rs;
        if (car.getRouteLocation() == rl && car.getRouteDestination() != rl && car.isCaboose()) {
            cabooseRoadNumber = car.toString();
        }
    }
    return cabooseRoadNumber;
}
Also used : Car(jmri.jmrit.operations.rollingstock.cars.Car) RouteLocation(jmri.jmrit.operations.routes.RouteLocation) RollingStock(jmri.jmrit.operations.rollingstock.RollingStock) Nonnull(javax.annotation.Nonnull)

Aggregations

RollingStock (jmri.jmrit.operations.rollingstock.RollingStock)43 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)13 Car (jmri.jmrit.operations.rollingstock.cars.Car)13 Route (jmri.jmrit.operations.routes.Route)11 RouteLocation (jmri.jmrit.operations.routes.RouteLocation)11 Track (jmri.jmrit.operations.locations.Track)7 IOException (java.io.IOException)6 ArrayList (java.util.ArrayList)5 Location (jmri.jmrit.operations.locations.Location)5 Engine (jmri.jmrit.operations.rollingstock.engines.Engine)5 Train (jmri.jmrit.operations.trains.Train)5 BufferedWriter (java.io.BufferedWriter)4 File (java.io.File)4 FileOutputStream (java.io.FileOutputStream)4 OutputStreamWriter (java.io.OutputStreamWriter)4 PrintWriter (java.io.PrintWriter)4 Dimension (java.awt.Dimension)2 JPanel (javax.swing.JPanel)2 XmlFile (jmri.jmrit.XmlFile)2 HardcopyWriter (jmri.util.davidflanagan.HardcopyWriter)2