use of jmri.jmrit.operations.routes.RouteLocation in project JMRI by JMRI.
the class TrainIcon method makeTrainRouteMenu.
@SuppressFBWarnings(value = "BC_UNCONFIRMED_CAST_OF_RETURN_VALUE", justification = "CarManager only provides Car Objects")
private JMenu makeTrainRouteMenu() {
JMenu routeMenu = new JMenu(Bundle.getMessage("Route"));
Route route = _train.getRoute();
if (route == null) {
return routeMenu;
}
List<RollingStock> carList = CarManager.instance().getByTrainList(_train);
for (RouteLocation rl : route.getLocationsBySequenceList()) {
int pickupCars = 0;
int dropCars = 0;
String current = " ";
if (_train.getCurrentLocation() == rl) {
// NOI18N
current = "-> ";
}
for (RollingStock rs : carList) {
Car car = (Car) rs;
if (car.getRouteLocation() == rl && !car.getTrackName().equals(Car.NONE)) {
pickupCars++;
}
if (car.getRouteDestination() == rl) {
dropCars++;
}
}
String rText = "";
String pickups = "";
String drops = "";
if (pickupCars > 0) {
pickups = " " + Bundle.getMessage("Pickup") + " " + pickupCars;
if (dropCars > 0) {
drops = ", " + Bundle.getMessage("SetOut") + " " + dropCars;
}
} else if (dropCars > 0) {
drops = " " + Bundle.getMessage("SetOut") + " " + dropCars;
}
if (pickupCars > 0 || dropCars > 0) {
rText = current + rl.getName() + " (" + pickups + drops + " )";
} else {
rText = current + rl.getName();
}
routeMenu.add(new RouteAction(rText, rl));
}
return routeMenu;
}
use of jmri.jmrit.operations.routes.RouteLocation in project JMRI by JMRI.
the class TrainIcon method doMouseDragged.
// route
/**
* Determine if user moved the train icon to next location in a train's
* route.
*/
@Override
public void doMouseDragged(MouseEvent event) {
log.debug("Mouse dragged, X=" + getX() + " Y=" + getY());
if (_train != null) {
RouteLocation next = _train.getNextLocation(_train.getCurrentLocation());
if (next != null) {
Point nextPoint = next.getTrainIconCoordinates();
log.debug("Next location (" + next.getName() + "), X=" + nextPoint.x + " Y=" + nextPoint.y);
if (Math.abs(getX() - nextPoint.x) < range && Math.abs(getY() - nextPoint.y) < range) {
log.debug("Train icon (" + _train.getName() + ") within range of (" + next.getName() + ")");
if (JOptionPane.showConfirmDialog(null, MessageFormat.format(Bundle.getMessage("MoveTrainTo"), new Object[] { next.getName() }), MessageFormat.format(Bundle.getMessage("MoveTrain"), new Object[] { _train.getIconName() }), JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
_train.move();
}
}
}
}
}
use of jmri.jmrit.operations.routes.RouteLocation 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.RouteLocation in project JMRI by JMRI.
the class TrainEditFrame method updateDepartureTime.
private void updateDepartureTime() {
hourBox.setSelectedItem(_train.getDepartureTimeHour());
minuteBox.setSelectedItem(_train.getDepartureTimeMinute());
// check to see if route has a departure time from the 1st location
RouteLocation rl = _train.getTrainDepartsRouteLocation();
if (rl != null && !rl.getDepartureTime().equals(NONE)) {
hourBox.setEnabled(false);
minuteBox.setEnabled(false);
} else {
hourBox.setEnabled(true);
minuteBox.setEnabled(true);
}
}
use of jmri.jmrit.operations.routes.RouteLocation in project JMRI by JMRI.
the class PrintTrainsAction method actionPerformed.
@Override
public void actionPerformed(ActionEvent e) {
// obtain a HardcopyWriter to do this
HardcopyWriter writer = null;
try {
writer = new HardcopyWriter(mFrame, Bundle.getMessage("TitleTrainsTable"), Control.reportFontSize, .5, .5, .5, .5, isPreview);
} catch (HardcopyWriter.PrintCanceledException ex) {
log.debug("Print cancelled");
return;
}
List<Train> trains = trainsTableFrame.getSortByList();
printSummaryTrains(writer, trains);
try {
// new page
writer.write(FORM_FEED);
int numberOfLines = writer.getLinesPerPage();
// now do the details for each train
for (Train train : trains) {
if ((train.isBuildEnabled() || trainsTableFrame.showAllBox.isSelected()) && train.getRoute() != null) {
List<RouteLocation> route = train.getRoute().getLocationsBySequenceList();
// determine if another detailed summary can fit on the same page
if (numberOfLines - writer.getCurrentLineNumber() < route.size() + NUMBER_OF_HEADER_LINES) {
writer.write(FORM_FEED);
} else if (writer.getCurrentLineNumber() > 0) {
writer.write(NEW_LINE);
}
printTrain(writer, train);
}
}
} catch (IOException e1) {
log.error("Exception in print train details");
}
// and force completion of the printing
writer.close();
}
Aggregations