use of jmri.jmrit.operations.routes.Route in project JMRI by JMRI.
the class TrainEditFrame method editAddRoute.
private void editAddRoute() {
log.debug("Edit/add route");
// warn user if train is built that they shouldn't edit the train's route
if (_train != null && _train.isBuilt()) {
JOptionPane.showMessageDialog(this, Bundle.getMessage("DoNotModifyRoute"), Bundle.getMessage("BuiltTrain"), JOptionPane.WARNING_MESSAGE);
}
if (ref != null) {
ref.dispose();
}
ref = new RouteEditFrame();
setChildFrame(ref);
Object selected = routeBox.getSelectedItem();
if (selected != null) {
Route route = (Route) selected;
ref.initComponents(route);
} else {
ref.initComponents(null, _train);
}
}
use of jmri.jmrit.operations.routes.Route in project JMRI by JMRI.
the class TrainEditFrame method updateLocationCheckboxes.
// the train's route shown as locations with checkboxes
private void updateLocationCheckboxes() {
locationCheckBoxes.clear();
locationPanelCheckBoxes.removeAll();
// vertical position in panel
int y = 0;
Route route = null;
// clear out previous status
textRouteStatus.setText(NONE);
if (_train != null) {
route = _train.getRoute();
}
if (route != null) {
if (!route.getStatus().equals(Route.OKAY)) {
textRouteStatus.setText(route.getStatus());
textRouteStatus.setForeground(Color.RED);
}
List<RouteLocation> routeList = route.getLocationsBySequenceList();
for (int i = 0; i < routeList.size(); i++) {
RouteLocation rl = routeList.get(i);
JCheckBox checkBox = new javax.swing.JCheckBox();
locationCheckBoxes.add(checkBox);
checkBox.setText(rl.toString());
checkBox.setName(rl.getId());
addItemLeft(locationPanelCheckBoxes, checkBox, 0, y++);
Location loc = LocationManager.instance().getLocationByName(rl.getName());
// does the location exist?
if (loc != null) {
// need to listen for name and direction changes
loc.removePropertyChangeListener(this);
loc.addPropertyChangeListener(this);
boolean services = false;
// does train direction service location?
if ((rl.getTrainDirection() & loc.getTrainDirections()) != 0) {
services = true;
} else // train must service last location or single location
if (i == routeList.size() - 1) {
services = true;
}
// check can drop and pick up, and moves > 0
if (services && (rl.isDropAllowed() || rl.isPickUpAllowed()) && rl.getMaxCarMoves() > 0) {
checkBox.setSelected(!_train.skipsLocation(rl.getId()));
} else {
checkBox.setEnabled(false);
}
addLocationCheckBoxAction(checkBox);
} else {
checkBox.setEnabled(false);
}
}
}
locationPanelCheckBoxes.revalidate();
}
use of jmri.jmrit.operations.routes.Route in project JMRI by JMRI.
the class PrintLocationsAction method getPickUpTrains.
private String getPickUpTrains(Track track) {
if (track.getPickupOption().equals(Track.ANY)) {
return TAB + TAB + Bundle.getMessage("PickUpAllTrains") + NEW_LINE;
}
StringBuffer buf;
int charCount = 0;
String[] ids = track.getPickupIds();
if (track.getPickupOption().equals(Track.TRAINS) || track.getPickupOption().equals(Track.EXCLUDE_TRAINS)) {
String trainType = Bundle.getMessage("TrainsPickUpTrack");
if (track.getPickupOption().equals(Track.EXCLUDE_TRAINS)) {
trainType = Bundle.getMessage("ExcludeTrainsPickUpTrack");
}
buf = new StringBuffer(TAB + TAB + trainType + NEW_LINE + TAB + TAB);
for (String id : ids) {
Train train = TrainManager.instance().getTrainById(id);
if (train == null) {
log.info("Could not find a train for id: " + id + " track (" + track.getName() + ")");
continue;
}
charCount += train.getName().length() + 2;
if (charCount > charactersPerLine - 2 * TAB_LENGTH) {
buf.append(NEW_LINE + TAB + TAB);
charCount = train.getName().length() + 2;
}
buf.append(train.getName() + ", ");
}
} else {
String routeType = Bundle.getMessage("RoutesPickUpTrack");
if (track.getPickupOption().equals(Track.EXCLUDE_ROUTES)) {
routeType = Bundle.getMessage("ExcludeRoutesPickUpTrack");
}
buf = new StringBuffer(TAB + TAB + routeType + NEW_LINE + TAB + TAB);
for (String id : ids) {
Route route = RouteManager.instance().getRouteById(id);
if (route == null) {
log.info("Could not find a route for id: " + id + " location (" + track.getLocation().getName() + ") track (" + track.getName() + // NOI18N
")");
continue;
}
charCount += route.getName().length() + 2;
if (charCount > charactersPerLine - 2 * TAB_LENGTH) {
buf.append(NEW_LINE + TAB + TAB);
charCount = route.getName().length() + 2;
}
buf.append(route.getName() + ", ");
}
}
if (buf.length() > 2) {
// remove trailing separators
buf.setLength(buf.length() - 2);
}
buf.append(NEW_LINE);
return buf.toString();
}
use of jmri.jmrit.operations.routes.Route in project JMRI by JMRI.
the class ShowTrainsServingLocationFrame method updateTrainPane.
private void updateTrainPane() {
pTrains.removeAll();
int y = 0;
for (Train train : TrainManager.instance().getTrainsByNameList()) {
Route route = train.getRoute();
if (route == null) {
continue;
}
for (RouteLocation rl : route.getLocationsBySequenceList()) {
if (rl.getName().equals(_location.getName())) {
boolean pickup = false;
boolean setout = false;
// monitor move count in the route for this location
train.getRoute().removePropertyChangeListener(this);
train.getRoute().addPropertyChangeListener(this);
if (rl.isPickUpAllowed() && rl.getMaxCarMoves() > 0 && !train.skipsLocation(rl.getId()) && (typeComboBox.getSelectedItem() == null || typeComboBox.getSelectedItem().equals(NONE) || train.acceptsTypeName((String) typeComboBox.getSelectedItem())) && (train.isLocalSwitcher() || (rl.getTrainDirection() & _location.getTrainDirections()) != 0) && (train.isLocalSwitcher() || _track == null || ((rl.getTrainDirection() & _track.getTrainDirections()) != 0)) && (_track == null || _track.acceptsPickupTrain(train))) {
pickup = true;
}
if (rl.isDropAllowed() && rl.getMaxCarMoves() > 0 && !train.skipsLocation(rl.getId()) && (typeComboBox.getSelectedItem() == null || typeComboBox.getSelectedItem().equals(NONE) || train.acceptsTypeName((String) typeComboBox.getSelectedItem())) && (train.isLocalSwitcher() || (rl.getTrainDirection() & _location.getTrainDirections()) != 0) && (train.isLocalSwitcher() || _track == null || ((rl.getTrainDirection() & _track.getTrainDirections()) != 0)) && (_track == null || _track.acceptsDropTrain(train))) {
setout = true;
}
// now display results
if (showAllTrainsCheckBox.isSelected() || pickup || setout) {
addItemLeft(pTrains, new JLabel(train.getName()), 0, y);
if (pickup) {
addItem(pTrains, new JLabel(Bundle.getMessage("OkayPickUp")), 1, y);
} else {
addItem(pTrains, new JLabel(Bundle.getMessage("NoPickUp")), 1, y);
}
if (setout) {
addItem(pTrains, new JLabel(Bundle.getMessage("OkaySetOut")), 2, y);
} else {
addItem(pTrains, new JLabel(Bundle.getMessage("NoSetOut")), 2, y);
}
}
y++;
}
}
}
pTrains.repaint();
pTrains.revalidate();
}
use of jmri.jmrit.operations.routes.Route in project JMRI by JMRI.
the class Train method getTrainWeight.
public int getTrainWeight(RouteLocation routeLocation) {
int weight = 0;
Route route = getRoute();
if (route != null) {
for (RouteLocation rl : route.getLocationsBySequenceList()) {
for (RollingStock rs : EngineManager.instance().getList(this)) {
if (rs.getRouteLocation() == rl) {
weight += rs.getAdjustedWeightTons();
}
if (rs.getRouteDestination() == rl) {
weight += -rs.getAdjustedWeightTons();
}
}
for (RollingStock rs : CarManager.instance().getList(this)) {
Car car = (Car) rs;
if (car.getRouteLocation() == rl) {
// weight depends on car load
weight += car.getAdjustedWeightTons();
}
if (car.getRouteDestination() == rl) {
weight += -car.getAdjustedWeightTons();
}
}
if (rl == routeLocation) {
break;
}
}
}
return weight;
}
Aggregations