Search in sources :

Example 6 with Location

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

the class Car method setReturnWhenEmptyDestination.

public void setReturnWhenEmptyDestination(Location destination) {
    Location old = _rweDestination;
    _rweDestination = destination;
    if ((old != null && !old.equals(destination)) || (destination != null && !destination.equals(old))) {
        setDirtyAndFirePropertyChange(RETURN_WHEN_EMPTY_CHANGED_PROPERTY, null, null);
    }
}
Also used : Location(jmri.jmrit.operations.locations.Location)

Example 7 with Location

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

the class RollingStockSetFrame method updateDestinationTrackComboBox.

protected void updateDestinationTrackComboBox() {
    log.debug("update destination track combobox");
    if (destinationBox.getSelectedItem() == null) {
        trackDestinationBox.removeAllItems();
    } else {
        log.debug("RollingStockFrame sees destination: {}", destinationBox.getSelectedItem());
        Location loc = (Location) destinationBox.getSelectedItem();
        Track track = null;
        if (trackDestinationBox.getSelectedItem() != null) {
            track = (Track) trackDestinationBox.getSelectedItem();
        }
        loc.updateComboBox(trackDestinationBox, _rs, autoDestinationTrackCheckBox.isSelected(), true);
        // check for staging, add track if train is built and terminates into staging
        if (autoDestinationTrackCheckBox.isSelected() && trainBox.getSelectedItem() != null) {
            Train train = (Train) trainBox.getSelectedItem();
            if (train.isBuilt() && train.getTerminationTrack() != null && train.getTerminationTrack().getLocation() == loc) {
                trackDestinationBox.addItem(train.getTerminationTrack());
            }
        }
        if (_rs != null && _rs.getDestination() != null && _rs.getDestination().equals(loc)) {
            if (_rs.getDestinationTrack() != null) {
                trackDestinationBox.setSelectedItem(_rs.getDestinationTrack());
            } else if (track != null) {
                trackDestinationBox.setSelectedItem(track);
            }
        }
    }
}
Also used : Train(jmri.jmrit.operations.trains.Train) Track(jmri.jmrit.operations.locations.Track) RouteLocation(jmri.jmrit.operations.routes.RouteLocation) Location(jmri.jmrit.operations.locations.Location)

Example 8 with Location

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

the class ImportCars method run.

// we use a thread so the status frame will work!
@Override
public void run() {
    File file = getFile();
    if (file == null) {
        return;
    }
    BufferedReader in = getBufferedReader(file);
    if (in == null) {
        return;
    }
    createStatusFrame(Bundle.getMessage("ImportCars"));
    // Now read the input file
    boolean importOkay = false;
    boolean comma = false;
    boolean importKernel = false;
    int lineNum = 0;
    int carsAdded = 0;
    String line = " ";
    String carNumber;
    String carRoad;
    String carType;
    String carLength;
    String carWeight;
    String carColor = "";
    String carOwner = "";
    String carBuilt = "";
    String carLocation = "";
    String carTrack = "";
    String carLoad = "";
    String carKernel = "";
    int carMoves = 0;
    String carValue = "";
    String carComment = "";
    String[] inputLine;
    // does the file name end with .csv?
    if (file.getAbsolutePath().endsWith(".csv")) {
        // NOI18N
        log.info("Using comma as delimiter for import cars");
        comma = true;
    }
    while (true) {
        lineNumber.setText(Bundle.getMessage("LineNumber") + " " + Integer.toString(++lineNum));
        try {
            line = in.readLine();
        } catch (IOException e) {
            break;
        }
        if (line == null) {
            importOkay = true;
            break;
        }
        // has user canceled import?
        if (!fstatus.isShowing()) {
            break;
        }
        line = line.trim();
        log.debug("Import: {}", line);
        importLine.setText(line);
        if (line.startsWith(Bundle.getMessage("Number"))) {
            // skip header
            continue;
        }
        if (line.equalsIgnoreCase("kernel")) {
            // NOI18N
            log.info("Importing kernel names");
            importKernel = true;
            continue;
        }
        if (line.equalsIgnoreCase("comma")) {
            // NOI18N
            log.info("Using comma as delimiter for import cars");
            comma = true;
            continue;
        }
        // use comma as delimiter if found otherwise use spaces
        if (comma) {
            inputLine = parseCommaLine(line, MAXIMUM_NUMBER_FIELDS);
        } else {
            // NOI18N
            inputLine = line.split("\\s+");
        }
        if (inputLine.length < 1 || line.equals("")) {
            log.debug("Skipping blank line");
            continue;
        }
        int base = 1;
        if (comma || !inputLine[0].equals("")) {
            // skip over any spaces at start of line
            base--;
        }
        // The minimum import is car number, road, type and length
        if (inputLine.length > base + 3) {
            carNumber = inputLine[base + CAR_NUMBER];
            carRoad = inputLine[base + CAR_ROAD];
            carType = inputLine[base + CAR_TYPE];
            carLength = inputLine[base + CAR_LENGTH];
            carWeight = "0";
            carColor = "";
            carOwner = "";
            carBuilt = "";
            carLocation = "";
            carTrack = "";
            carLoad = CarLoads.instance().getDefaultEmptyName();
            carKernel = "";
            carMoves = 0;
            carValue = "";
            carComment = "";
            if (inputLine.length > base + CAR_WEIGHT) {
                carWeight = inputLine[base + CAR_WEIGHT];
            }
            if (inputLine.length > base + CAR_COLOR) {
                carColor = inputLine[base + CAR_COLOR];
            }
            log.debug("Checking car number ({}) road ({}) type ({}) length ({}) weight ({}) color ({})", carNumber, carRoad, carType, carLength, carWeight, // NOI18N
            carColor);
            if (carNumber.length() > Control.max_len_string_road_number) {
                JOptionPane.showMessageDialog(null, MessageFormat.format(Bundle.getMessage("CarRoadNumberTooLong"), new Object[] { (carRoad + " " + carNumber), carNumber }), MessageFormat.format(Bundle.getMessage("carRoadNum"), new Object[] { Control.max_len_string_road_number + 1 }), JOptionPane.ERROR_MESSAGE);
                break;
            }
            if (carRoad.length() > Control.max_len_string_attibute) {
                JOptionPane.showMessageDialog(null, MessageFormat.format(Bundle.getMessage("CarRoadNameTooLong"), new Object[] { (carRoad + " " + carNumber), carRoad }), MessageFormat.format(Bundle.getMessage("carAttribute"), new Object[] { Control.max_len_string_attibute }), JOptionPane.ERROR_MESSAGE);
                break;
            }
            if (carType.length() > Control.max_len_string_attibute) {
                JOptionPane.showMessageDialog(null, MessageFormat.format(Bundle.getMessage("CarTypeNameTooLong"), new Object[] { (carRoad + " " + carNumber), carType }), MessageFormat.format(Bundle.getMessage("carAttribute"), new Object[] { Control.max_len_string_attibute }), JOptionPane.ERROR_MESSAGE);
                break;
            }
            if (!CarTypes.instance().containsName(carType)) {
                if (autoCreateTypes) {
                    log.debug("Adding car type ({})", carType);
                    CarTypes.instance().addName(carType);
                } else {
                    int results = JOptionPane.showConfirmDialog(null, Bundle.getMessage("Car") + " (" + carRoad + " " + carNumber + ")" + NEW_LINE + MessageFormat.format(Bundle.getMessage("typeNameNotExist"), new Object[] { carType }), Bundle.getMessage("carAddType"), JOptionPane.YES_NO_CANCEL_OPTION);
                    if (results == JOptionPane.YES_OPTION) {
                        CarTypes.instance().addName(carType);
                        if (askAutoCreateTypes) {
                            results = JOptionPane.showConfirmDialog(null, Bundle.getMessage("DoYouWantToAutoAddCarTypes"), Bundle.getMessage("OnlyAskedOnce"), JOptionPane.YES_NO_OPTION);
                            if (results == JOptionPane.YES_OPTION) {
                                autoCreateTypes = true;
                            }
                        }
                        askAutoCreateTypes = false;
                    } else if (results == JOptionPane.CANCEL_OPTION) {
                        break;
                    }
                }
            }
            if (carLength.length() > Control.max_len_string_length_name) {
                JOptionPane.showMessageDialog(null, MessageFormat.format(Bundle.getMessage("CarLengthNameTooLong"), new Object[] { (carRoad + " " + carNumber), carLength }), MessageFormat.format(Bundle.getMessage("carAttribute"), new Object[] { Control.max_len_string_length_name }), JOptionPane.ERROR_MESSAGE);
                break;
            }
            if (carLength.equals("")) {
                log.debug("Car ({} {}) length not specified", carRoad, carNumber);
                JOptionPane.showMessageDialog(null, MessageFormat.format(Bundle.getMessage("CarLengthNotSpecified"), new Object[] { (carRoad + " " + carNumber) }), Bundle.getMessage("CarLengthMissing"), JOptionPane.ERROR_MESSAGE);
                break;
            }
            try {
                Integer.parseInt(carLength);
            } catch (NumberFormatException e) {
                JOptionPane.showMessageDialog(null, MessageFormat.format(Bundle.getMessage("CarLengthNameNotNumber"), new Object[] { (carRoad + " " + carNumber), carLength }), Bundle.getMessage("CarLengthMissing"), JOptionPane.ERROR_MESSAGE);
                break;
            }
            if (carWeight.length() > Control.max_len_string_weight_name) {
                JOptionPane.showMessageDialog(null, MessageFormat.format(Bundle.getMessage("CarWeightNameTooLong"), new Object[] { (carRoad + " " + carNumber), carWeight }), MessageFormat.format(Bundle.getMessage("carAttribute"), new Object[] { Control.max_len_string_weight_name }), JOptionPane.ERROR_MESSAGE);
                break;
            }
            if (carColor.length() > Control.max_len_string_attibute) {
                JOptionPane.showMessageDialog(null, MessageFormat.format(Bundle.getMessage("CarColorNameTooLong"), new Object[] { (carRoad + " " + carNumber), carColor }), MessageFormat.format(Bundle.getMessage("carAttribute"), new Object[] { Control.max_len_string_attibute }), JOptionPane.ERROR_MESSAGE);
                break;
            }
            // calculate car weight if "0"
            if (carWeight.equals("0")) {
                try {
                    double doubleCarLength = Double.parseDouble(carLength) * 12 / Setup.getScaleRatio();
                    double doubleCarWeight = (Setup.getInitalWeight() + doubleCarLength * Setup.getAddWeight()) / 1000;
                    NumberFormat nf = NumberFormat.getNumberInstance();
                    nf.setMaximumFractionDigits(1);
                    // car weight in ounces.
                    carWeight = nf.format(doubleCarWeight);
                } catch (NumberFormatException e) {
                    JOptionPane.showMessageDialog(null, Bundle.getMessage("carLengthMustBe"), Bundle.getMessage("carWeigthCanNot"), JOptionPane.ERROR_MESSAGE);
                }
            }
            Car existingCar = manager.getByRoadAndNumber(carRoad, carNumber);
            if (existingCar != null) {
                // NOI18N
                log.info("Can not add, car number (" + carNumber + ") road (" + carRoad + ") already exists!");
            } else {
                if (inputLine.length > base + CAR_OWNER) {
                    carOwner = inputLine[base + CAR_OWNER];
                    if (carOwner.length() > Control.max_len_string_attibute) {
                        JOptionPane.showMessageDialog(null, MessageFormat.format(Bundle.getMessage("CarOwnerNameTooLong"), new Object[] { (carRoad + " " + carNumber), carOwner }), MessageFormat.format(Bundle.getMessage("carAttribute"), new Object[] { Control.max_len_string_attibute }), JOptionPane.ERROR_MESSAGE);
                        break;
                    }
                }
                if (inputLine.length > base + CAR_BUILT) {
                    carBuilt = inputLine[base + CAR_BUILT];
                    if (carBuilt.length() > Control.max_len_string_built_name) {
                        JOptionPane.showMessageDialog(null, MessageFormat.format(Bundle.getMessage("CarBuiltNameTooLong"), new Object[] { (carRoad + " " + carNumber), carBuilt }), MessageFormat.format(Bundle.getMessage("carAttribute"), new Object[] { Control.max_len_string_built_name }), JOptionPane.ERROR_MESSAGE);
                        break;
                    }
                }
                if (inputLine.length > base + CAR_LOCATION) {
                    carLocation = inputLine[base + CAR_LOCATION];
                }
                // Location name can be one to three words
                if (inputLine.length > base + CAR_LOCATION_TRACK_SEPARATOR) {
                    if (!inputLine[base + CAR_LOCATION_TRACK_SEPARATOR].equals(LOCATION_TRACK_SEPARATOR)) {
                        carLocation = carLocation + " " + inputLine[base + 9];
                        if (inputLine.length > base + 10) {
                            if (!inputLine[base + 10].equals(LOCATION_TRACK_SEPARATOR)) {
                                carLocation = carLocation + " " + inputLine[base + 10];
                            }
                        }
                    }
                    log.debug("Car ({} {}) has location ({})", carRoad, carNumber, carLocation);
                    // now get the track name
                    boolean foundLocationTrackSeparator = false;
                    for (int i = base + CAR_LOCATION_TRACK_SEPARATOR; i < inputLine.length; i++) {
                        if (inputLine[i].equals(LOCATION_TRACK_SEPARATOR)) {
                            foundLocationTrackSeparator = true;
                            if (inputLine.length > i + 1) {
                                carTrack = inputLine[++i];
                            }
                        } else if (foundLocationTrackSeparator && !comma) {
                            carTrack = carTrack + " " + inputLine[i];
                        }
                    }
                    if (carTrack == null) {
                        carTrack = "";
                    }
                    log.debug("Car ({} {}) has track ({})", carRoad, carNumber, carTrack);
                }
                // is there a load name?
                if (comma && inputLine.length > base + CAR_LOAD) {
                    carLoad = inputLine[CAR_LOAD];
                    log.debug("Car ({} {}) has load ({})", carRoad, carNumber, carLoad);
                }
                // is there a kernel name?
                if (comma && inputLine.length > base + CAR_KERNEL) {
                    carKernel = inputLine[CAR_KERNEL];
                    log.debug("Car ({} {}) has kernel name ({})", carRoad, carNumber, carKernel);
                }
                // is the a move count?
                if (comma && inputLine.length > base + CAR_MOVES) {
                    try {
                        carMoves = Integer.parseInt(inputLine[CAR_MOVES]);
                        log.debug("Car ({} {}) has move count ({})", carRoad, carNumber, carMoves);
                    } catch (NumberFormatException e) {
                        log.error("Car ({} {}) has move count ({}) not a number", carRoad, carNumber, carMoves);
                    }
                }
                // is there a car value?
                if (comma && inputLine.length > base + CAR_VALUE) {
                    carValue = inputLine[CAR_VALUE];
                }
                // is there a car comment?
                if (comma && inputLine.length > base + CAR_COMMENT) {
                    carComment = inputLine[CAR_COMMENT];
                }
                if (carLocation.length() > Control.max_len_string_location_name) {
                    JOptionPane.showMessageDialog(null, MessageFormat.format(Bundle.getMessage("CarLocationNameTooLong"), new Object[] { (carRoad + " " + carNumber), carLocation }), MessageFormat.format(Bundle.getMessage("carAttribute"), new Object[] { Control.max_len_string_location_name }), JOptionPane.ERROR_MESSAGE);
                    break;
                }
                if (carTrack.length() > Control.max_len_string_track_name) {
                    JOptionPane.showMessageDialog(null, MessageFormat.format(Bundle.getMessage("CarTrackNameTooLong"), new Object[] { (carRoad + " " + carNumber), carTrack }), MessageFormat.format(Bundle.getMessage("carAttribute"), new Object[] { Control.max_len_string_track_name }), JOptionPane.ERROR_MESSAGE);
                    break;
                }
                Location location = LocationManager.instance().getLocationByName(carLocation);
                Track track = null;
                if (location == null && !carLocation.equals("")) {
                    if (autoCreateLocations) {
                        log.debug("Create location ({})", carLocation);
                        location = LocationManager.instance().newLocation(carLocation);
                    } else {
                        JOptionPane.showMessageDialog(null, MessageFormat.format(Bundle.getMessage("CarLocationDoesNotExist"), new Object[] { (carRoad + " " + carNumber), carLocation }), Bundle.getMessage("carLocation"), JOptionPane.ERROR_MESSAGE);
                        int results = JOptionPane.showConfirmDialog(null, MessageFormat.format(Bundle.getMessage("DoYouWantToCreateLoc"), new Object[] { carLocation }), Bundle.getMessage("carLocation"), JOptionPane.YES_NO_OPTION);
                        if (results == JOptionPane.YES_OPTION) {
                            log.debug("Create location ({})", carLocation);
                            location = LocationManager.instance().newLocation(carLocation);
                            if (askAutoCreateLocations) {
                                results = JOptionPane.showConfirmDialog(null, Bundle.getMessage("DoYouWantToAutoCreateLoc"), Bundle.getMessage("OnlyAskedOnce"), JOptionPane.YES_NO_OPTION);
                                if (results == JOptionPane.YES_OPTION) {
                                    autoCreateLocations = true;
                                }
                            }
                            askAutoCreateLocations = false;
                        } else {
                            break;
                        }
                    }
                }
                if (location != null && !carTrack.equals("")) {
                    track = location.getTrackByName(carTrack, null);
                    if (track == null) {
                        if (autoCreateTracks) {
                            if (location.getLocationOps() == Location.NORMAL) {
                                log.debug("Create 1000 foot yard track ({})", carTrack);
                                track = location.addTrack(carTrack, Track.YARD);
                            } else {
                                log.debug("Create 1000 foot staging track ({})", carTrack);
                                track = location.addTrack(carTrack, Track.STAGING);
                            }
                            track.setLength(1000);
                        } else {
                            JOptionPane.showMessageDialog(null, MessageFormat.format(Bundle.getMessage("CarTrackDoesNotExist"), new Object[] { (carRoad + " " + carNumber), carTrack, carLocation }), Bundle.getMessage("carTrack"), JOptionPane.ERROR_MESSAGE);
                            int results = JOptionPane.showConfirmDialog(null, MessageFormat.format(Bundle.getMessage("DoYouWantToCreateTrack"), new Object[] { carTrack, carLocation }), Bundle.getMessage("carTrack"), JOptionPane.YES_NO_OPTION);
                            if (results == JOptionPane.YES_OPTION) {
                                if (location.getLocationOps() == Location.NORMAL) {
                                    log.debug("Create 1000 foot yard track ({})", carTrack);
                                    track = location.addTrack(carTrack, Track.YARD);
                                } else {
                                    log.debug("Create 1000 foot staging track ({})", carTrack);
                                    track = location.addTrack(carTrack, Track.STAGING);
                                }
                                track.setLength(1000);
                                if (askAutoCreateTracks) {
                                    results = JOptionPane.showConfirmDialog(null, Bundle.getMessage("DoYouWantToAutoCreateTrack"), Bundle.getMessage("OnlyAskedOnce"), JOptionPane.YES_NO_OPTION);
                                    if (results == JOptionPane.YES_OPTION) {
                                        autoCreateTracks = true;
                                    }
                                    askAutoCreateTracks = false;
                                }
                            } else {
                                break;
                            }
                        }
                    }
                }
                log.debug("Add car ({} {}) owner ({}) built ({}) location ({}, {})", carRoad, carNumber, carOwner, carBuilt, carLocation, carTrack);
                Car car = manager.newCar(carRoad, carNumber);
                car.setTypeName(carType);
                car.setLength(carLength);
                car.setWeight(carWeight);
                car.setColor(carColor);
                car.setOwner(carOwner);
                car.setBuilt(carBuilt);
                car.setLoadName(carLoad);
                car.setKernel(manager.newKernel(carKernel));
                car.setMoves(carMoves);
                car.setValue(carValue);
                car.setComment(carComment);
                carsAdded++;
                // if the car's type name is "Caboose" then make it a caboose
                car.setCaboose(carType.equals("Caboose"));
                // determine if there are any car extensions
                if (comma && inputLine.length > base + CAR_EXTENSIONS) {
                    String extensions = inputLine[CAR_EXTENSIONS];
                    log.debug("Car ({} {}) has extension ({})", carRoad, carNumber, extensions);
                    String[] ext = extensions.split(Car.EXTENSION_REGEX);
                    for (int i = 0; i < ext.length; i++) {
                        if (ext[i].equals(Car.CABOOSE_EXTENSION)) {
                            car.setCaboose(true);
                        }
                        if (ext[i].equals(Car.FRED_EXTENSION)) {
                            car.setFred(true);
                        }
                        if (ext[i].equals(Car.PASSENGER_EXTENSION)) {
                            car.setPassenger(true);
                            car.setBlocking(Integer.parseInt(ext[i + 1]));
                        }
                        if (ext[i].equals(Car.UTILITY_EXTENSION)) {
                            car.setUtility(true);
                        }
                        if (ext[i].equals(Car.HAZARDOUS_EXTENSION)) {
                            car.setHazardous(true);
                        }
                    }
                }
                // add new roads
                if (!CarRoads.instance().containsName(carRoad)) {
                    if (autoCreateRoads) {
                        log.debug("add car road {}", carRoad);
                        CarRoads.instance().addName(carRoad);
                    }
                }
                // add new lengths
                if (!CarLengths.instance().containsName(carLength)) {
                    if (autoCreateLengths) {
                        log.debug("add car length {}", carLength);
                        CarLengths.instance().addName(carLength);
                    }
                }
                // add new colors
                if (!CarColors.instance().containsName(carColor)) {
                    if (autoCreateColors) {
                        log.debug("add car color {}", carColor);
                        CarColors.instance().addName(carColor);
                    }
                }
                // add new owners
                if (!CarOwners.instance().containsName(carOwner)) {
                    if (autoCreateOwners) {
                        log.debug("add car owner {}", carOwner);
                        CarOwners.instance().addName(carOwner);
                    }
                }
                if (car.getWeight().equals("")) {
                    log.debug("Car ({} {}) weight not specified", carRoad, carNumber);
                    if (weightResults != JOptionPane.CANCEL_OPTION) {
                        weightResults = JOptionPane.showOptionDialog(null, MessageFormat.format(Bundle.getMessage("CarWeightNotFound"), new Object[] { (carRoad + " " + carNumber) }), Bundle.getMessage("CarWeightMissing"), JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.INFORMATION_MESSAGE, null, new Object[] { Bundle.getMessage("ButtonYes"), Bundle.getMessage("ButtonNo"), Bundle.getMessage("ButtonDontShow") }, autoCalculate ? Bundle.getMessage("ButtonYes") : Bundle.getMessage("ButtonNo"));
                    }
                    if (weightResults == JOptionPane.NO_OPTION) {
                        autoCalculate = false;
                    }
                    if (weightResults == JOptionPane.YES_OPTION || autoCalculate == true && weightResults == JOptionPane.CANCEL_OPTION) {
                        autoCalculate = true;
                        try {
                            double carLen = Double.parseDouble(car.getLength()) * 12 / Setup.getScaleRatio();
                            double carWght = (Setup.getInitalWeight() + carLen * Setup.getAddWeight()) / 1000;
                            NumberFormat nf = NumberFormat.getNumberInstance();
                            nf.setMaximumFractionDigits(1);
                            // car weight in ounces.
                            car.setWeight(nf.format(carWght));
                            int tons = (int) (carWght * Setup.getScaleTonRatio());
                            // adjust weight for caboose
                            if (car.isCaboose()) {
                                // .9 tons/foot
                                tons = (int) (Double.parseDouble(car.getLength()) * .9);
                            }
                            car.setWeightTons(Integer.toString(tons));
                        } catch (NumberFormatException e) {
                            JOptionPane.showMessageDialog(null, Bundle.getMessage("carLengthMustBe"), Bundle.getMessage("carWeigthCanNot"), JOptionPane.ERROR_MESSAGE);
                        }
                    }
                }
                if (location != null && track != null) {
                    String status = car.setLocation(location, track);
                    if (!status.equals(Track.OKAY)) {
                        log.debug("Can't set car's location because of {}", status);
                        if (status.startsWith(Track.TYPE)) {
                            if (autoAdjustLocationType) {
                                location.addTypeName(carType);
                                track.addTypeName(carType);
                                status = car.setLocation(location, track);
                            } else {
                                JOptionPane.showMessageDialog(null, MessageFormat.format(Bundle.getMessage("CanNotSetCarAtLocation"), new Object[] { (carRoad + " " + carNumber), carType, carLocation, carTrack, status }), Bundle.getMessage("rsCanNotLoc"), JOptionPane.ERROR_MESSAGE);
                                int results = JOptionPane.showConfirmDialog(null, MessageFormat.format(Bundle.getMessage("DoYouWantToAllowService"), new Object[] { carLocation, carTrack, (carRoad + " " + carNumber), carType }), Bundle.getMessage("ServiceCarType"), JOptionPane.YES_NO_OPTION);
                                if (results == JOptionPane.YES_OPTION) {
                                    location.addTypeName(carType);
                                    track.addTypeName(carType);
                                    status = car.setLocation(location, track);
                                    log.debug("Set car's location status: {}", status);
                                    if (askAutoLocationType) {
                                        results = JOptionPane.showConfirmDialog(null, Bundle.getMessage("DoYouWantToAutoAdjustLocations"), Bundle.getMessage("OnlyAskedOnce"), JOptionPane.YES_NO_OPTION);
                                        if (results == JOptionPane.YES_OPTION) {
                                            autoAdjustLocationType = true;
                                        }
                                        askAutoLocationType = false;
                                    }
                                } else {
                                    break;
                                }
                            }
                        }
                        if (status.startsWith(Track.LENGTH)) {
                            if (autoAdjustTrackLength) {
                                track.setLength(track.getLength() + 1000);
                                status = car.setLocation(location, track);
                                log.debug("Set track length status: {}", status);
                            } else {
                                JOptionPane.showMessageDialog(null, MessageFormat.format(Bundle.getMessage("CanNotSetCarAtLocation"), new Object[] { (carRoad + " " + carNumber), carType, carLocation, carTrack, status }), Bundle.getMessage("rsCanNotLoc"), JOptionPane.ERROR_MESSAGE);
                                int results = JOptionPane.showConfirmDialog(null, MessageFormat.format(Bundle.getMessage("DoYouWantIncreaseLength"), new Object[] { carTrack }), Bundle.getMessage("TrackLength"), JOptionPane.YES_NO_OPTION);
                                if (results == JOptionPane.YES_OPTION) {
                                    track.setLength(track.getLength() + 1000);
                                    status = car.setLocation(location, track);
                                    log.debug("Set track length status: {}", status);
                                    if (askAutoIncreaseTrackLength) {
                                        results = JOptionPane.showConfirmDialog(null, Bundle.getMessage("DoYouWantToAutoAdjustTrackLength"), Bundle.getMessage("OnlyAskedOnce"), JOptionPane.YES_NO_OPTION);
                                        if (results == JOptionPane.YES_OPTION) {
                                            autoAdjustTrackLength = true;
                                        }
                                        askAutoIncreaseTrackLength = false;
                                    }
                                } else {
                                    break;
                                }
                            }
                        }
                        if (!status.equals(Track.OKAY)) {
                            if (autoForceCar) {
                                // force car
                                car.setLocation(location, track, RollingStock.FORCE);
                            } else {
                                JOptionPane.showMessageDialog(null, MessageFormat.format(Bundle.getMessage("CanNotSetCarAtLocation"), new Object[] { (carRoad + " " + carNumber), carType, carLocation, carTrack, status }), Bundle.getMessage("rsCanNotLoc"), JOptionPane.ERROR_MESSAGE);
                                int results = JOptionPane.showConfirmDialog(null, MessageFormat.format(Bundle.getMessage("DoYouWantToForceCar"), new Object[] { (carRoad + " " + carNumber), carLocation, carTrack }), Bundle.getMessage("OverRide"), JOptionPane.YES_NO_OPTION);
                                if (results == JOptionPane.YES_OPTION) {
                                    // force car
                                    car.setLocation(location, track, true);
                                    if (askAutoForceCar) {
                                        results = JOptionPane.showConfirmDialog(null, Bundle.getMessage("DoYouWantToAutoForceCar"), Bundle.getMessage("OnlyAskedOnce"), JOptionPane.YES_NO_OPTION);
                                        if (results == JOptionPane.YES_OPTION) {
                                            autoForceCar = true;
                                        }
                                        askAutoForceCar = false;
                                    }
                                } else {
                                    break;
                                }
                            }
                        }
                    }
                } else {
                // log.debug("No location for car ("+carRoad+" "+carNumber+")");
                }
            }
        } else if (importKernel && inputLine.length == base + 3) {
            carNumber = inputLine[base + 0];
            carRoad = inputLine[base + 1];
            String kernelName = inputLine[base + 2];
            Car car = manager.getByRoadAndNumber(carRoad, carNumber);
            if (car != null) {
                Kernel kernel = manager.newKernel(kernelName);
                car.setKernel(kernel);
                carsAdded++;
            } else {
                // NOI18N
                log.info("Car number (" + carNumber + ") road (" + carRoad + ") does not exist!");
                break;
            }
        } else if (!line.equals("")) {
            log.info("Car import line " + lineNum + " missing attributes: " + line);
            JOptionPane.showMessageDialog(null, MessageFormat.format(Bundle.getMessage("ImportMissingAttributes"), new Object[] { lineNum }) + NEW_LINE + line + NEW_LINE + Bundle.getMessage("ImportMissingAttributes2"), Bundle.getMessage("CarAttributeMissing"), JOptionPane.ERROR_MESSAGE);
            break;
        }
    }
    try {
        in.close();
    } catch (IOException e) {
    }
    // kill status panel
    fstatus.dispose();
    if (importOkay) {
        JOptionPane.showMessageDialog(null, MessageFormat.format(Bundle.getMessage("ImportCarsAdded"), new Object[] { carsAdded }), Bundle.getMessage("SuccessfulImport"), JOptionPane.INFORMATION_MESSAGE);
    } else {
        JOptionPane.showMessageDialog(null, MessageFormat.format(Bundle.getMessage("ImportCarsAdded"), new Object[] { carsAdded }), Bundle.getMessage("ImportFailed"), JOptionPane.ERROR_MESSAGE);
    }
}
Also used : IOException(java.io.IOException) BufferedReader(java.io.BufferedReader) File(java.io.File) Track(jmri.jmrit.operations.locations.Track) NumberFormat(java.text.NumberFormat) Location(jmri.jmrit.operations.locations.Location)

Example 9 with Location

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

the class EngineEditFrame method loadEngine.

public void loadEngine(Engine engine) {
    _engine = engine;
    // enable delete and save buttons
    deleteButton.setEnabled(true);
    saveButton.setEnabled(true);
    if (!CarRoads.instance().containsName(engine.getRoadName())) {
        String msg = MessageFormat.format(Bundle.getMessage("roadNameNotExist"), new Object[] { engine.getRoadName() });
        if (JOptionPane.showConfirmDialog(this, msg, Bundle.getMessage("rsAddRoad"), JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
            CarRoads.instance().addName(engine.getRoadName());
        }
    }
    roadComboBox.setSelectedItem(engine.getRoadName());
    roadNumberTextField.setText(engine.getNumber());
    if (!engineModels.containsName(engine.getModel())) {
        String msg = MessageFormat.format(Bundle.getMessage("modelNameNotExist"), new Object[] { engine.getModel() });
        if (JOptionPane.showConfirmDialog(this, msg, Bundle.getMessage("engineAddModel"), JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
            engineModels.addName(engine.getModel());
        }
    }
    modelComboBox.setSelectedItem(engine.getModel());
    if (!engineTypes.containsName(engine.getTypeName())) {
        String msg = MessageFormat.format(Bundle.getMessage("typeNameNotExist"), new Object[] { engine.getTypeName() });
        if (JOptionPane.showConfirmDialog(this, msg, Bundle.getMessage("engineAddType"), JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
            engineTypes.addName(engine.getTypeName());
        }
    }
    typeComboBox.setSelectedItem(engine.getTypeName());
    bUnitCheckBox.setSelected(engine.isBunit());
    if (!engineLengths.containsName(engine.getLength())) {
        String msg = MessageFormat.format(Bundle.getMessage("lengthNameNotExist"), new Object[] { engine.getLength() });
        if (JOptionPane.showConfirmDialog(this, msg, Bundle.getMessage("engineAddLength"), JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
            engineLengths.addName(engine.getLength());
        }
    }
    lengthComboBox.setSelectedItem(engine.getLength());
    weightTextField.setText(engine.getWeightTons());
    hpTextField.setText(engine.getHp());
    locationBox.setSelectedItem(engine.getLocation());
    Location l = locationManager.getLocationById(engine.getLocationId());
    if (l != null) {
        l.updateComboBox(trackLocationBox);
        trackLocationBox.setSelectedItem(engine.getTrack());
    } else {
        trackLocationBox.removeAllItems();
    }
    builtTextField.setText(engine.getBuilt());
    if (!CarOwners.instance().containsName(engine.getOwner())) {
        String msg = MessageFormat.format(Bundle.getMessage("ownerNameNotExist"), new Object[] { engine.getOwner() });
        if (JOptionPane.showConfirmDialog(this, msg, Bundle.getMessage("addOwner"), JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
            CarOwners.instance().addName(engine.getOwner());
        }
    }
    consistComboBox.setSelectedItem(engine.getConsistName());
    ownerComboBox.setSelectedItem(engine.getOwner());
    valueTextField.setText(engine.getValue());
    rfidComboBox.setSelectedItem(engine.getIdTag());
    commentTextField.setText(engine.getComment());
    setTitle(Bundle.getMessage("TitleEngineEdit"));
}
Also used : Location(jmri.jmrit.operations.locations.Location)

Example 10 with Location

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

the class EngineEditFrame method comboBoxActionPerformed.

// combo boxes
@Override
public void comboBoxActionPerformed(java.awt.event.ActionEvent ae) {
    if (ae.getSource() == modelComboBox) {
        if (modelComboBox.getSelectedItem() != null) {
            String model = (String) modelComboBox.getSelectedItem();
            // load the default hp and length for the model selected
            hpTextField.setText(engineModels.getModelHorsepower(model));
            weightTextField.setText(engineModels.getModelWeight(model));
            if (engineModels.getModelLength(model) != null && !engineModels.getModelLength(model).equals("")) {
                lengthComboBox.setSelectedItem(engineModels.getModelLength(model));
            }
            if (engineModels.getModelType(model) != null && !engineModels.getModelType(model).equals("")) {
                typeComboBox.setSelectedItem(engineModels.getModelType(model));
            }
        }
    }
    if (ae.getSource() == locationBox) {
        if (locationBox.getSelectedItem() == null) {
            trackLocationBox.removeAllItems();
        } else {
            log.debug("EnginesSetFrame sees location: " + locationBox.getSelectedItem());
            Location l = ((Location) locationBox.getSelectedItem());
            l.updateComboBox(trackLocationBox);
        }
    }
}
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