use of jmri.jmrit.operations.trains.timetable.TrainSchedule in project JMRI by JMRI.
the class Track method checkScheduleItem.
private String checkScheduleItem(ScheduleItem si, Car car) {
if (!si.getSetoutTrainScheduleId().equals(ScheduleItem.NONE) && !TrainManager.instance().getTrainScheduleActiveId().equals(si.getSetoutTrainScheduleId())) {
TrainSchedule sch = TrainScheduleManager.instance().getScheduleById(si.getSetoutTrainScheduleId());
if (sch != null) {
return SCHEDULE + " (" + getScheduleName() + ") " + Bundle.getMessage("requestCarOnly") + " (" + sch.getName() + ")";
}
}
// Check for correct car type, road, load
if (!car.getTypeName().equals(si.getTypeName())) {
return SCHEDULE + " (" + getScheduleName() + ") " + Bundle.getMessage("requestCar") + " " + TYPE + " (" + si.getTypeName() + ")";
}
if (!si.getRoadName().equals(ScheduleItem.NONE) && !car.getRoadName().equals(si.getRoadName())) {
return SCHEDULE + " (" + getScheduleName() + ") " + Bundle.getMessage("requestCar") + " " + TYPE + " (" + si.getTypeName() + ") " + ROAD + " (" + si.getRoadName() + ")";
}
if (!si.getReceiveLoadName().equals(ScheduleItem.NONE) && !car.getLoadName().equals(si.getReceiveLoadName())) {
return SCHEDULE + " (" + getScheduleName() + ") " + Bundle.getMessage("requestCar") + " " + TYPE + " (" + si.getTypeName() + ") " + LOAD + " (" + si.getReceiveLoadName() + ")";
}
if (car.getFinalDestinationTrack() != this && !si.getRandom().equals(ScheduleItem.NONE)) {
try {
int value = Integer.parseInt(si.getRandom());
double random = 100 * Math.random();
log.debug("Selected random {}, created random {}", si.getRandom(), random);
if (random > value) {
return MessageFormat.format(Bundle.getMessage("scheduleRandom"), new Object[] { SCHEDULE, getScheduleName(), si.getId(), value, random });
}
} catch (NumberFormatException e) {
log.error("Random value {} isn't a number", si.getRandom());
}
}
return OKAY;
}
use of jmri.jmrit.operations.trains.timetable.TrainSchedule in project JMRI by JMRI.
the class Action method getFormatedMessage.
/**
* Formats a message using fixed arguments in the following order:
* <p>
* action name, train name, route location name, automation name, goto item id,
* train schedule day.
* @param message the string to be formated
*
* @return formated message
*/
public String getFormatedMessage(String message) {
String trainName = "";
Train train = getAutomationItem().getTrain();
if (train != null) {
trainName = " " + train.getName();
}
String routeLocationName = "";
RouteLocation rl = getAutomationItem().getRouteLocation();
if (rl != null) {
routeLocationName = " " + rl.getName();
}
String automationName = "";
Automation automation = getAutomationItem().getAutomationToRun();
if (automation != null) {
automationName = " " + automation.getName();
}
String itemId = "";
AutomationItem item = getAutomationItem().getGotoAutomationItem();
if (item != null) {
itemId = " " + item.getId();
}
String day = "";
TrainSchedule trainSchedule = getAutomationItem().getTrainSchedule();
if (trainSchedule != null) {
day = " " + trainSchedule.getName();
}
return MessageFormat.format(message, new Object[] { getName(), trainName, routeLocationName, automationName, itemId, day });
}
use of jmri.jmrit.operations.trains.timetable.TrainSchedule in project JMRI by JMRI.
the class ScheduleTableModel method getPickupDayComboBox.
private JComboBox<TrainSchedule> getPickupDayComboBox(ScheduleItem si) {
JComboBox<TrainSchedule> cb = TrainScheduleManager.instance().getSelectComboBox();
TrainSchedule sch = TrainScheduleManager.instance().getScheduleById(si.getPickupTrainScheduleId());
if (sch != null) {
cb.setSelectedItem(sch);
} else if (!si.getPickupTrainScheduleId().equals(ScheduleItem.NONE)) {
// error user deleted this pick up day
String notValid = MessageFormat.format(Bundle.getMessage("NotValid"), new Object[] { si.getPickupTrainScheduleId() });
TrainSchedule errorSchedule = new TrainSchedule(si.getSetoutTrainScheduleId(), notValid);
cb.addItem(errorSchedule);
cb.setSelectedItem(errorSchedule);
}
return cb;
}
use of jmri.jmrit.operations.trains.timetable.TrainSchedule in project JMRI by JMRI.
the class TrainBuilder method checkScheduleItem.
/**
* Checks a schedule item to see if the car type matches, and the train and
* track can service the schedule item's load. This code doesn't check to
* see if the car's load can be serviced by the schedule. Instead a schedule
* item is returned that allows the program to assign a custom load to the
* car that matches a schedule item. Therefore, schedule items that request
* don't request a custom load are ignored.
*
* @param si the schedule item
* @param car the car to check
* @param track the destination track
* @return Schedule item si if okay, null otherwise.
*/
private ScheduleItem checkScheduleItem(ScheduleItem si, Car car, Track track) {
if (!car.getTypeName().equals(si.getTypeName()) || si.getReceiveLoadName().equals(ScheduleItem.NONE) || si.getReceiveLoadName().equals(CarLoads.instance().getDefaultEmptyName()) || si.getReceiveLoadName().equals(CarLoads.instance().getDefaultLoadName())) {
log.debug("Not using track ({}) schedule request type ({}) road ({}) load ({})", track.getName(), si.getTypeName(), si.getRoadName(), // NOI18N
si.getReceiveLoadName());
if (!Setup.getRouterBuildReportLevel().equals(Setup.BUILD_REPORT_NORMAL)) {
addLine(_buildReport, SEVEN, MessageFormat.format(Bundle.getMessage("buildSpurScheduleNotUsed"), new Object[] { track.getLocation().getName(), track.getName(), track.getScheduleName(), si.getId(), si.getTypeName(), si.getRoadName(), si.getReceiveLoadName() }));
}
return null;
}
if (!si.getRoadName().equals(ScheduleItem.NONE) && !car.getRoadName().equals(si.getRoadName())) {
log.debug("Not using track ({}) schedule request type ({}) road ({}) load ({})", track.getName(), si.getTypeName(), si.getRoadName(), // NOI18N
si.getReceiveLoadName());
if (!Setup.getRouterBuildReportLevel().equals(Setup.BUILD_REPORT_NORMAL)) {
addLine(_buildReport, SEVEN, MessageFormat.format(Bundle.getMessage("buildSpurScheduleNotUsed"), new Object[] { track.getName(), track.getScheduleName(), si.getId(), si.getTypeName(), si.getRoadName(), si.getReceiveLoadName() }));
}
return null;
}
if (!_train.acceptsLoad(si.getReceiveLoadName(), si.getTypeName())) {
addLine(_buildReport, SEVEN, MessageFormat.format(Bundle.getMessage("buildTrainNotNewLoad"), new Object[] { _train.getName(), si.getReceiveLoadName(), track.getLocation().getName(), track.getName() }));
return null;
}
// does the departure track allow this load?
if (!car.getTrack().shipsLoad(si.getReceiveLoadName(), car.getTypeName())) {
addLine(_buildReport, SEVEN, MessageFormat.format(Bundle.getMessage("buildTrackNotNewLoad"), new Object[] { car.getTrackName(), si.getReceiveLoadName(), track.getLocation().getName(), track.getName() }));
return null;
}
if (!si.getSetoutTrainScheduleId().equals(ScheduleItem.NONE) && !TrainManager.instance().getTrainScheduleActiveId().equals(si.getSetoutTrainScheduleId())) {
log.debug("Schedule item isn't active");
// build the status message
TrainSchedule aSch = TrainScheduleManager.instance().getScheduleById(TrainManager.instance().getTrainScheduleActiveId());
TrainSchedule tSch = TrainScheduleManager.instance().getScheduleById(si.getSetoutTrainScheduleId());
String aName = "";
String tName = "";
if (aSch != null) {
aName = aSch.getName();
}
if (tSch != null) {
tName = tSch.getName();
}
addLine(_buildReport, SEVEN, MessageFormat.format(Bundle.getMessage("buildScheduleNotActive"), new Object[] { track.getName(), si.getId(), tName, aName }));
return null;
}
if (!si.getRandom().equals(ScheduleItem.NONE)) {
try {
int value = Integer.parseInt(si.getRandom());
double random = 100 * Math.random();
log.debug("Selected random {}, created random {}", si.getRandom(), random);
if (random > value) {
addLine(_buildReport, SEVEN, MessageFormat.format(Bundle.getMessage("buildScheduleRandom"), new Object[] { track.getName(), track.getScheduleName(), si.getId(), value, random }));
return null;
}
} catch (NumberFormatException e) {
log.error("Random value {} isn't a number", si.getRandom());
}
}
log.debug("Found track ({}) schedule item id ({}) for car ({})", track.getName(), si.getId(), car.toString());
car.setScheduleItemId(si.getId());
return si;
}
use of jmri.jmrit.operations.trains.timetable.TrainSchedule in project JMRI by JMRI.
the class Car method getPickupScheduleName.
public String getPickupScheduleName() {
TrainSchedule sch = TrainScheduleManager.instance().getScheduleById(getPickupScheduleId());
String name = NONE;
if (sch != null) {
name = sch.getName();
}
return name;
}
Aggregations