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());
}
}
}
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;
}
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;
}
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());
}
}
}
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);
}
}
Aggregations