Search in sources :

Example 41 with Location

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

the class LocationsByCarLoadFrame method checkBoxActionPerformed.

@Override
public void checkBoxActionPerformed(java.awt.event.ActionEvent ae) {
    if (ae.getSource() == loadAndTypeCheckBox) {
        updateLocations();
        return;
    }
    JCheckBox cb = (JCheckBox) ae.getSource();
    String[] locId = cb.getName().split("-");
    String[] id = locId[0].split("s");
    Location loc = locationManager.getLocationById(id[0]);
    if (loc != null) {
        Track track = loc.getTrackById(locId[0]);
        // if enabled track services this car type
        log.debug("CheckBox : {} track: ({}) isEnabled: {} isSelected: {}", cb.getName(), track.getName(), cb.isEnabled(), cb.isSelected());
        if (cb.isEnabled()) {
            boolean needLoadTrackEditFrame = false;
            String loadName = (String) loadComboBox.getSelectedItem();
            String load = loadName;
            String type = (String) typeComboBox.getSelectedItem();
            log.debug("Selected load ({})", loadName);
            if (loadAndTypeCheckBox.isSelected()) {
                loadName = type + CarLoad.SPLIT_CHAR + loadName;
            }
            if (locId[1].equals("r")) {
                if (cb.isSelected()) {
                    if (track.getLoadOption().equals(Track.ALL_LOADS)) {
                        log.debug("All loads selected for track ({})", track.getName());
                    } else if (track.getLoadOption().equals(Track.INCLUDE_LOADS)) {
                        track.addLoadName(loadName);
                    } else if (track.getLoadOption().equals(Track.EXCLUDE_LOADS)) {
                        track.deleteLoadName(loadName);
                        // need to check if load configuration is to exclude all car types using this load
                        if (!track.acceptsLoadName(load)) {
                            JOptionPane.showMessageDialog(this, MessageFormat.format(Bundle.getMessage("WarningExcludeTrackLoad"), new Object[] { track.getName(), load }), Bundle.getMessage("ErrorTitle"), JOptionPane.WARNING_MESSAGE);
                            needLoadTrackEditFrame = true;
                        } else if (!track.acceptsLoad(load, type)) {
                            JOptionPane.showMessageDialog(this, MessageFormat.format(Bundle.getMessage("WarningExcludeTrackTypeAndLoad"), new Object[] { track.getName(), type, load }), Bundle.getMessage("ErrorTitle"), JOptionPane.WARNING_MESSAGE);
                            needLoadTrackEditFrame = true;
                        }
                    }
                } else {
                    if (track.getLoadOption().equals(Track.INCLUDE_LOADS)) {
                        track.deleteLoadName(loadName);
                        // need to check if load configuration is to accept all car types using this load
                        if (track.acceptsLoadName(load)) {
                            JOptionPane.showMessageDialog(this, MessageFormat.format(Bundle.getMessage("WarningAcceptTrackLoad"), new Object[] { track.getName(), load }), Bundle.getMessage("ErrorTitle"), JOptionPane.WARNING_MESSAGE);
                            needLoadTrackEditFrame = true;
                        } else if (track.acceptsLoad(load, type)) {
                            JOptionPane.showMessageDialog(this, MessageFormat.format(Bundle.getMessage("WarningAcceptTrackTypeAndLoad"), new Object[] { track.getName(), type, load }), Bundle.getMessage("ErrorTitle"), JOptionPane.WARNING_MESSAGE);
                            needLoadTrackEditFrame = true;
                        }
                    } else if (track.getLoadOption().equals(Track.EXCLUDE_LOADS)) {
                        track.addLoadName(loadName);
                    } else if (track.getLoadOption().equals(Track.ALL_LOADS)) {
                        // need to exclude this load
                        track.setLoadOption(Track.EXCLUDE_LOADS);
                        track.addLoadName(loadName);
                    }
                }
            }
            if (locId[1].equals("s")) {
                if (cb.isSelected()) {
                    if (track.getShipLoadOption().equals(Track.ALL_LOADS)) {
                        log.debug("Ship all loads selected for track ({})", track.getName());
                    } else if (track.getShipLoadOption().equals(Track.INCLUDE_LOADS)) {
                        track.addShipLoadName(loadName);
                    } else if (track.getShipLoadOption().equals(Track.EXCLUDE_LOADS)) {
                        track.deleteShipLoadName(loadName);
                        // need to check if load configuration is to exclude all car types using this load
                        if (!track.shipsLoadName(load)) {
                            JOptionPane.showMessageDialog(this, MessageFormat.format(Bundle.getMessage("WarningExcludeTrackShipLoad"), new Object[] { track.getName(), load }), Bundle.getMessage("ErrorTitle"), JOptionPane.WARNING_MESSAGE);
                            needLoadTrackEditFrame = true;
                        } else if (!track.shipsLoad(load, type)) {
                            JOptionPane.showMessageDialog(this, MessageFormat.format(Bundle.getMessage("WarningExcludeTrackShipTypeAndLoad"), new Object[] { track.getName(), type, load }), Bundle.getMessage("ErrorTitle"), JOptionPane.WARNING_MESSAGE);
                            needLoadTrackEditFrame = true;
                        }
                    }
                } else {
                    if (track.getShipLoadOption().equals(Track.INCLUDE_LOADS)) {
                        track.deleteShipLoadName(loadName);
                        // need to check if load configuration is to accept all car types using this load
                        if (track.shipsLoadName(load)) {
                            JOptionPane.showMessageDialog(this, MessageFormat.format(Bundle.getMessage("WarningShipTrackLoad"), new Object[] { track.getName(), load }), Bundle.getMessage("ErrorTitle"), JOptionPane.WARNING_MESSAGE);
                            needLoadTrackEditFrame = true;
                        } else if (track.shipsLoad(load, type)) {
                            JOptionPane.showMessageDialog(this, MessageFormat.format(Bundle.getMessage("WarningShipTrackTypeAndLoad"), new Object[] { track.getName(), type, load }), Bundle.getMessage("ErrorTitle"), JOptionPane.WARNING_MESSAGE);
                            needLoadTrackEditFrame = true;
                        }
                    } else if (track.getShipLoadOption().equals(Track.EXCLUDE_LOADS)) {
                        track.addShipLoadName(loadName);
                    } else if (track.getShipLoadOption().equals(Track.ALL_LOADS)) {
                        // need to exclude this load
                        track.setShipLoadOption(Track.EXCLUDE_LOADS);
                        track.addShipLoadName(loadName);
                    }
                }
            }
            if (needLoadTrackEditFrame) {
                if (tlef != null) {
                    tlef.dispose();
                }
                tlef = new TrackLoadEditFrame();
                tlef.initComponents(track.getLocation(), track);
            }
        }
    }
}
Also used : JCheckBox(javax.swing.JCheckBox) Track(jmri.jmrit.operations.locations.Track) Location(jmri.jmrit.operations.locations.Location)

Example 42 with Location

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

the class LocationsByCarTypeFrame method updateLocations.

private void updateLocations() {
    log.debug("update checkboxes");
    removePropertyChangeLocations();
    locationCheckBoxList.clear();
    trackCheckBoxList.clear();
    int x = 0;
    pLocations.removeAll();
    String carType = (String) typeComboBox.getSelectedItem();
    if (copyCheckBox.isSelected()) {
        carType = textCarType.getText();
    }
    // did the location get deleted?
    if (_location != null && manager.getLocationByName(_location.getName()) == null) {
        _location = null;
    }
    List<Location> locations = manager.getLocationsByNameList();
    for (Location loc : locations) {
        // show only one location?
        if (_location != null && _location != loc) {
            continue;
        }
        loc.addPropertyChangeListener(this);
        JCheckBox cb = new JCheckBox(loc.getName());
        cb.setName(loc.getId());
        cb.setToolTipText(MessageFormat.format(Bundle.getMessage("TipLocCarType"), new Object[] { carType }));
        addCheckBoxAction(cb);
        locationCheckBoxList.add(cb);
        boolean locAcceptsType = loc.acceptsTypeName(carType);
        cb.setSelected(locAcceptsType);
        addItemLeft(pLocations, cb, 0, x++);
        List<Track> tracks = loc.getTrackByNameList(null);
        for (Track track : tracks) {
            track.addPropertyChangeListener(this);
            cb = new JCheckBox(track.getName());
            cb.setName(track.getId());
            cb.setToolTipText(MessageFormat.format(Bundle.getMessage("TipTrackCarType"), new Object[] { carType }));
            addCheckBoxAction(cb);
            trackCheckBoxList.add(cb);
            cb.setSelected(track.acceptsTypeName(carType));
            addItemLeft(pLocations, cb, 1, x++);
        }
    }
    pLocations.revalidate();
    repaint();
}
Also used : JCheckBox(javax.swing.JCheckBox) Track(jmri.jmrit.operations.locations.Track) Location(jmri.jmrit.operations.locations.Location)

Example 43 with Location

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

the class PoolTrackFrame method buttonActionPerformed.

@Override
public void buttonActionPerformed(java.awt.event.ActionEvent ae) {
    if (ae.getSource() == addButton) {
        Location location = _track.getLocation();
        location.addPool(trackPoolNameTextField.getText());
    }
    if (ae.getSource() == saveButton) {
        try {
            _track.setMinimumLength(Integer.parseInt(trackMinLengthTextField.getText()));
        } catch (NumberFormatException e) {
            JOptionPane.showMessageDialog(this, Bundle.getMessage("TrackMustBeNumber"), Bundle.getMessage("ErrorTrackLength"), JOptionPane.ERROR_MESSAGE);
            return;
        }
        if (_pool != null) {
            _pool.removePropertyChangeListener(this);
        }
        _pool = (Pool) comboBoxPools.getSelectedItem();
        if (_pool != null) {
            _pool.addPropertyChangeListener(this);
        }
        // this causes a property change to this frame
        _track.setPool(_pool);
        // save location file
        OperationsXml.save();
        if (Setup.isCloseWindowOnSaveEnabled()) {
            dispose();
        }
    }
}
Also used : Location(jmri.jmrit.operations.locations.Location)

Example 44 with Location

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

the class LocationsByCarTypeFrame method removePropertyChangeLocations.

private void removePropertyChangeLocations() {
    if (locationCheckBoxList != null) {
        for (int i = 0; i < locationCheckBoxList.size(); i++) {
            // checkbox name is the location id
            Location loc = manager.getLocationById(locationCheckBoxList.get(i).getName());
            if (loc != null) {
                loc.removePropertyChangeListener(this);
                List<Track> tracks = loc.getTrackList();
                for (Track track : tracks) {
                    track.removePropertyChangeListener(this);
                }
            }
        }
    }
}
Also used : Track(jmri.jmrit.operations.locations.Track) Location(jmri.jmrit.operations.locations.Location)

Example 45 with Location

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

the class LocationsByCarTypeFrame method save.

/**
     * Update the car types that locations and tracks service. Note that the
     * checkbox name is the id of the location or track.
     */
private void save() {
    if (copyCheckBox.isSelected() && JOptionPane.showConfirmDialog(this, MessageFormat.format(Bundle.getMessage("CopyCarType"), new Object[] { typeComboBox.getSelectedItem(), textCarType.getText() }), Bundle.getMessage("CopyCarTypeTitle"), JOptionPane.YES_NO_OPTION) != JOptionPane.YES_OPTION) {
        return;
    }
    log.debug("save {} locations", locationCheckBoxList.size());
    removePropertyChangeLocations();
    for (JCheckBox cb : locationCheckBoxList) {
        Location loc = manager.getLocationById(cb.getName());
        if (cb.isSelected()) {
            loc.addTypeName((String) typeComboBox.getSelectedItem());
            // save tracks that have the same id as the location
            for (JCheckBox cbt : trackCheckBoxList) {
                String[] id = cbt.getName().split("s");
                if (loc.getId().equals(id[0])) {
                    Track track = loc.getTrackById(cbt.getName());
                    if (cbt.isSelected()) {
                        track.addTypeName((String) typeComboBox.getSelectedItem());
                    } else {
                        track.deleteTypeName((String) typeComboBox.getSelectedItem());
                    }
                }
            }
        } else {
            loc.deleteTypeName((String) typeComboBox.getSelectedItem());
        }
    }
    OperationsXml.save();
    updateLocations();
    if (Setup.isCloseWindowOnSaveEnabled()) {
        dispose();
    }
}
Also used : JCheckBox(javax.swing.JCheckBox) Track(jmri.jmrit.operations.locations.Track) 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