Search in sources :

Example 1 with Location

use of jmri.jmrit.operations.locations.Location in project JMRI by JMRI.

the class SimpleOperationsServer method sendLocationList.

/**
     * send a list of locations known by Operations to the client
     */
@Override
public void sendLocationList() {
    List<Location> locationList = lm.getLocationsByNameList();
    ArrayList<Attribute> location;
    for (Location loc : locationList) {
        location = new ArrayList<Attribute>(1);
        location.add(new Attribute(LOCATIONS, loc));
        try {
            sendMessage(location);
        } catch (IOException ioe) {
            log.debug("could not send train " + loc.getName());
        }
    }
}
Also used : Attribute(javax.management.Attribute) IOException(java.io.IOException) Location(jmri.jmrit.operations.locations.Location)

Example 2 with Location

use of jmri.jmrit.operations.locations.Location in project JMRI by JMRI.

the class RollingStock method setLocation.

/**
     * Sets rolling stock location on the layout
     * @param location The Location.
     *
     * @param track (yard, spur, staging, or interchange track)
     * @param force when true place rolling stock ignore track length, type,
     *            {@literal &} road
     * @return "okay" if successful, "type" if the rolling stock's type isn't
     *         acceptable, "road" if rolling stock road isn't acceptable, or
     *         "length" if the rolling stock length didn't fit.
     */
public String setLocation(Location location, Track track, boolean force) {
    // first determine if rolling stock can be move to the new location
    if (!force) {
        String status = testLocation(location, track);
        if (!status.equals(Track.OKAY)) {
            return status;
        }
    }
    // now update
    Location oldLocation = _location;
    _location = location;
    Track oldTrack = _trackLocation;
    _trackLocation = track;
    if (oldLocation != location || oldTrack != track) {
        // first remove rolling stock from existing location
        if (oldLocation != null) {
            oldLocation.deleteRS(this);
            oldLocation.removePropertyChangeListener(this);
            // if track is null, then rolling stock is in a train
            if (oldTrack != null) {
                oldTrack.deleteRS(this);
                oldTrack.removePropertyChangeListener(this);
                // if there's a destination then pickup complete
                if (_destination != null) {
                    oldLocation.deletePickupRS();
                    oldTrack.deletePickupRS(this);
                    // don't update rs's previous location if just re-staging
                    if (getTrain() != null && getTrain().getRoute() != null && getTrain().getRoute().size() > 2) {
                        setLastLocationId(oldLocation.getId());
                    }
                }
            }
        }
        if (_location != null) {
            _location.addRS(this);
            // Need to know if location name changes so we can forward to listeners
            _location.addPropertyChangeListener(this);
        }
        if (_trackLocation != null) {
            _trackLocation.addRS(this);
            // Need to know if location name changes so we can forward to listeners
            _trackLocation.addPropertyChangeListener(this);
            // if there's a destination then there's a pick up
            if (_destination != null) {
                _location.addPickupRS();
                _trackLocation.addPickupRS(this);
            }
        }
        setDirtyAndFirePropertyChange(TRACK_CHANGED_PROPERTY, oldTrack, track);
    }
    return Track.OKAY;
}
Also used : Track(jmri.jmrit.operations.locations.Track) RouteLocation(jmri.jmrit.operations.routes.RouteLocation) Location(jmri.jmrit.operations.locations.Location)

Example 3 with Location

use of jmri.jmrit.operations.locations.Location in project JMRI by JMRI.

the class RollingStock method setDestination.

/**
     * Sets rolling stock destination on the layout
     * @param destination The Location.
     *
     * @param track (yard, spur, staging, or interchange track)
     * @param force when true ignore track length, type, {@literal &} road when
     *            setting destination
     * @return "okay" if successful, "type" if the rolling stock's type isn't
     *         acceptable, or "length" if the rolling stock length didn't fit.
     */
public String setDestination(Location destination, Track track, boolean force) {
    // first determine if rolling stock can be move to the new destination
    if (!force) {
        String status = rsTestDestination(destination, track);
        if (!status.equals(Track.OKAY)) {
            return status;
        }
    }
    // now set the rolling stock destination!
    Location oldDestination = _destination;
    _destination = destination;
    Track oldTrack = _trackDestination;
    _trackDestination = track;
    if (oldDestination != destination || oldTrack != track) {
        if (oldDestination != null) {
            oldDestination.deleteDropRS();
            oldDestination.removePropertyChangeListener(this);
            // delete pick up in case destination is null
            if (_location != null && _trackLocation != null) {
                _location.deletePickupRS();
                _trackLocation.deletePickupRS(this);
            }
        }
        if (oldTrack != null) {
            oldTrack.deleteDropRS(this);
            oldTrack.removePropertyChangeListener(this);
        }
        if (_destination != null) {
            _destination.addDropRS();
            if (_location != null && _trackLocation != null) {
                _location.addPickupRS();
                _trackLocation.addPickupRS(this);
            }
            // Need to know if destination name changes so we can forward to listeners
            _destination.addPropertyChangeListener(this);
        }
        if (_trackDestination != null) {
            _trackDestination.addDropRS(this);
            // Need to know if destination name changes so we can forward to listeners
            _trackDestination.addPropertyChangeListener(this);
        } else {
            // rolling stock has been terminated or reset, bump rolling stock moves
            if (getTrain() != null && getTrain().getRoute() != null) {
                setLastRouteId(getTrain().getRoute().getId());
            }
            if (getRouteDestination() != null) {
                setMoves(getMoves() + 1);
                setLastDate(java.util.Calendar.getInstance().getTime());
            }
            setRouteLocation(null);
            setRouteDestination(null);
        }
        setDirtyAndFirePropertyChange(DESTINATION_CHANGED_PROPERTY, oldDestination, destination);
        setDirtyAndFirePropertyChange(DESTINATION_TRACK_CHANGED_PROPERTY, oldTrack, track);
    }
    return Track.OKAY;
}
Also used : Track(jmri.jmrit.operations.locations.Track) RouteLocation(jmri.jmrit.operations.routes.RouteLocation) Location(jmri.jmrit.operations.locations.Location)

Example 4 with Location

use of jmri.jmrit.operations.locations.Location in project JMRI by JMRI.

the class RollingStockSetFrame method updateLocationTrackComboBox.

protected void updateLocationTrackComboBox() {
    log.debug("update location track combobox");
    if (locationBox.getSelectedItem() == null) {
        trackLocationBox.removeAllItems();
    } else {
        log.debug("RollingStockFrame sees location: {}", locationBox.getSelectedItem());
        Location l = (Location) locationBox.getSelectedItem();
        l.updateComboBox(trackLocationBox, _rs, autoTrackCheckBox.isSelected(), false);
        if (_rs != null && _rs.getLocation() != null && _rs.getLocation().equals(l) && _rs.getTrack() != null) {
            trackLocationBox.setSelectedItem(_rs.getTrack());
        }
    }
}
Also used : RouteLocation(jmri.jmrit.operations.routes.RouteLocation) Location(jmri.jmrit.operations.locations.Location)

Example 5 with Location

use of jmri.jmrit.operations.locations.Location in project JMRI by JMRI.

the class Car method setFinalDestination.

/**
     * Sets the final destination for a car.
     *
     * @param destination The final destination for this car.
     */
public void setFinalDestination(Location destination) {
    Location old = _finalDestination;
    if (old != null) {
        old.removePropertyChangeListener(this);
    }
    _finalDestination = destination;
    if (_finalDestination != null) {
        _finalDestination.addPropertyChangeListener(this);
    }
    // log.debug("Next destination for car ("+toString()+") old: "+old+" new: "+destination);
    if ((old != null && !old.equals(destination)) || (destination != null && !destination.equals(old))) {
        setDirtyAndFirePropertyChange(FINAL_DESTINATION_CHANGED_PROPERTY, old, destination);
    }
}
Also used : Location(jmri.jmrit.operations.locations.Location)

Aggregations

Location (jmri.jmrit.operations.locations.Location)186 Track (jmri.jmrit.operations.locations.Track)108 RouteLocation (jmri.jmrit.operations.routes.RouteLocation)82 Route (jmri.jmrit.operations.routes.Route)51 LocationManager (jmri.jmrit.operations.locations.LocationManager)43 Car (jmri.jmrit.operations.rollingstock.cars.Car)41 Engine (jmri.jmrit.operations.rollingstock.engines.Engine)29 RouteManager (jmri.jmrit.operations.routes.RouteManager)21 CarManager (jmri.jmrit.operations.rollingstock.cars.CarManager)20 Consist (jmri.jmrit.operations.rollingstock.engines.Consist)19 Test (org.junit.Test)18 JCheckBox (javax.swing.JCheckBox)13 EngineManager (jmri.jmrit.operations.rollingstock.engines.EngineManager)13 Train (jmri.jmrit.operations.trains.Train)13 CarTypes (jmri.jmrit.operations.rollingstock.cars.CarTypes)12 Schedule (jmri.jmrit.operations.locations.schedules.Schedule)11 EngineTypes (jmri.jmrit.operations.rollingstock.engines.EngineTypes)10 File (java.io.File)9 ScheduleItem (jmri.jmrit.operations.locations.schedules.ScheduleItem)9 TrainManager (jmri.jmrit.operations.trains.TrainManager)8