Search in sources :

Example 6 with RouteLocation

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;
}
Also used : Car(jmri.jmrit.operations.rollingstock.cars.Car) RouteLocation(jmri.jmrit.operations.routes.RouteLocation) JMenu(javax.swing.JMenu) Route(jmri.jmrit.operations.routes.Route) RollingStock(jmri.jmrit.operations.rollingstock.RollingStock) Point(java.awt.Point) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Example 7 with RouteLocation

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();
                }
            }
        }
    }
}
Also used : RouteLocation(jmri.jmrit.operations.routes.RouteLocation) Point(java.awt.Point)

Example 8 with RouteLocation

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();
}
Also used : JCheckBox(javax.swing.JCheckBox) RouteLocation(jmri.jmrit.operations.routes.RouteLocation) Route(jmri.jmrit.operations.routes.Route) Location(jmri.jmrit.operations.locations.Location) RouteLocation(jmri.jmrit.operations.routes.RouteLocation)

Example 9 with RouteLocation

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);
    }
}
Also used : RouteLocation(jmri.jmrit.operations.routes.RouteLocation)

Example 10 with RouteLocation

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();
}
Also used : RouteLocation(jmri.jmrit.operations.routes.RouteLocation) IOException(java.io.IOException) Train(jmri.jmrit.operations.trains.Train) HardcopyWriter(jmri.util.davidflanagan.HardcopyWriter)

Aggregations

RouteLocation (jmri.jmrit.operations.routes.RouteLocation)118 Route (jmri.jmrit.operations.routes.Route)64 Location (jmri.jmrit.operations.locations.Location)55 Track (jmri.jmrit.operations.locations.Track)52 Car (jmri.jmrit.operations.rollingstock.cars.Car)48 Engine (jmri.jmrit.operations.rollingstock.engines.Engine)33 LocationManager (jmri.jmrit.operations.locations.LocationManager)21 RouteManager (jmri.jmrit.operations.routes.RouteManager)20 Consist (jmri.jmrit.operations.rollingstock.engines.Consist)17 Train (jmri.jmrit.operations.trains.Train)16 CarManager (jmri.jmrit.operations.rollingstock.cars.CarManager)13 ArrayList (java.util.ArrayList)12 CarTypes (jmri.jmrit.operations.rollingstock.cars.CarTypes)12 EngineManager (jmri.jmrit.operations.rollingstock.engines.EngineManager)12 RollingStock (jmri.jmrit.operations.rollingstock.RollingStock)11 EngineTypes (jmri.jmrit.operations.rollingstock.engines.EngineTypes)8 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)6 IOException (java.io.IOException)6 TrainManager (jmri.jmrit.operations.trains.TrainManager)6 JCheckBox (javax.swing.JCheckBox)5