Search in sources :

Example 6 with Route

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

Example 7 with Route

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();
}
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 8 with Route

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

Example 9 with Route

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

Example 10 with Route

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

Aggregations

Route (jmri.jmrit.operations.routes.Route)87 RouteLocation (jmri.jmrit.operations.routes.RouteLocation)69 Location (jmri.jmrit.operations.locations.Location)51 Track (jmri.jmrit.operations.locations.Track)43 Car (jmri.jmrit.operations.rollingstock.cars.Car)32 Engine (jmri.jmrit.operations.rollingstock.engines.Engine)31 LocationManager (jmri.jmrit.operations.locations.LocationManager)23 RouteManager (jmri.jmrit.operations.routes.RouteManager)23 Train (jmri.jmrit.operations.trains.Train)20 Consist (jmri.jmrit.operations.rollingstock.engines.Consist)19 CarManager (jmri.jmrit.operations.rollingstock.cars.CarManager)14 CarTypes (jmri.jmrit.operations.rollingstock.cars.CarTypes)13 EngineManager (jmri.jmrit.operations.rollingstock.engines.EngineManager)13 RollingStock (jmri.jmrit.operations.rollingstock.RollingStock)11 EngineTypes (jmri.jmrit.operations.rollingstock.engines.EngineTypes)10 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)5 ArrayList (java.util.ArrayList)5 JLabel (javax.swing.JLabel)5 TrainManager (jmri.jmrit.operations.trains.TrainManager)5 Kernel (jmri.jmrit.operations.rollingstock.cars.Kernel)4