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();
}
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);
}
}
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;
}
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;
}
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;
}
Aggregations