Search in sources :

Example 31 with Location

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

the class TrainSwitchListEditFrame method locationCheckBoxActionPerformed.

public void locationCheckBoxActionPerformed(ActionEvent ae) {
    JCheckBox b = (JCheckBox) ae.getSource();
    log.debug("checkbox change " + b.getName());
    Location l = locationManager.getLocationByName(b.getName());
    l.setSwitchListEnabled(b.isSelected());
    // enable the save button whenever a checkbox is changed
    saveButton.setEnabled(true);
}
Also used : JCheckBox(javax.swing.JCheckBox) Location(jmri.jmrit.operations.locations.Location)

Example 32 with Location

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

the class TrainSwitchListEditFrame method updateLocationCheckboxes.

// TODO there's a ConcurrentModificationException when the printer status changes
// when printing. This routine rebuilds the locationCheckBoxes during the update.
// A better solution would only update the status for a location.
// name change or number of locations has changed
private void updateLocationCheckboxes() {
    List<Location> locations = locationManager.getLocationsByNameList();
    synchronized (this) {
        for (Location location : locations) {
            location.removePropertyChangeListener(this);
        }
    }
    locationCheckBoxes.clear();
    // remove printer selection
    locationComboBoxes.clear();
    locationPanelCheckBoxes.removeAll();
    // create header
    addItem(locationPanelCheckBoxes, new JLabel(Bundle.getMessage("Location")), 0, 0);
    addItem(locationPanelCheckBoxes, new JLabel("        "), 1, 0);
    addItem(locationPanelCheckBoxes, new JLabel(Bundle.getMessage("Status")), 2, 0);
    addItem(locationPanelCheckBoxes, new JLabel("        "), 3, 0);
    addItem(locationPanelCheckBoxes, new JLabel(Bundle.getMessage("Comment")), 4, 0);
    addItem(locationPanelCheckBoxes, new JLabel("        "), 5, 0);
    addItem(locationPanelCheckBoxes, new JLabel(Bundle.getMessage("Printer")), 6, 0);
    // vertical position in panel
    int y = 1;
    // user can have multiple locations with the "same" name.
    Location mainLocation = null;
    for (Location location : locations) {
        String name = TrainCommon.splitString(location.getName());
        if (mainLocation != null && TrainCommon.splitString(mainLocation.getName()).equals(name)) {
            location.setSwitchListEnabled(mainLocation.isSwitchListEnabled());
            if (mainLocation.isSwitchListEnabled() && location.getStatus().equals(Location.MODIFIED)) {
                // we need to update the primary location
                mainLocation.setStatus(Location.MODIFIED);
                // and clear the secondaries
                location.setStatus(Location.UPDATED);
            }
            continue;
        }
        mainLocation = location;
    }
    mainLocation = null;
    for (Location location : locations) {
        String name = TrainCommon.splitString(location.getName());
        if (mainLocation != null && TrainCommon.splitString(mainLocation.getName()).equals(name)) {
            continue;
        }
        mainLocation = location;
        JCheckBox checkBox = new JCheckBox();
        locationCheckBoxes.add(checkBox);
        checkBox.setSelected(location.isSwitchListEnabled());
        checkBox.setText(name);
        checkBox.setName(location.getName());
        addLocationCheckBoxAction(checkBox);
        addItemLeft(locationPanelCheckBoxes, checkBox, 0, y);
        JLabel status = new JLabel(location.getStatus());
        addItem(locationPanelCheckBoxes, status, 2, y);
        JButton button = new JButton(Bundle.getMessage("Add"));
        if (!location.getSwitchListComment().equals(Location.NONE)) {
            button.setText(Bundle.getMessage("ButtonEdit"));
        }
        button.setName(location.getName());
        addCommentButtonAction(button);
        addItem(locationPanelCheckBoxes, button, 4, y);
        JComboBox<String> comboBox = TrainPrintUtilities.getPrinterJComboBox();
        locationComboBoxes.add(comboBox);
        comboBox.setSelectedItem(location.getDefaultPrinterName());
        addComboBoxAction(comboBox);
        addItem(locationPanelCheckBoxes, comboBox, 6, y++);
    }
    // restore listeners
    synchronized (this) {
        for (Location location : locations) {
            location.addPropertyChangeListener(this);
        }
    }
    locationPanelCheckBoxes.revalidate();
    pack();
    repaint();
}
Also used : JCheckBox(javax.swing.JCheckBox) JButton(javax.swing.JButton) JLabel(javax.swing.JLabel) Location(jmri.jmrit.operations.locations.Location)

Example 33 with Location

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

the class TrainSwitchListEditFrame method reset.

// Remove all terminated or reset trains from the switch lists for selected locations
private void reset() {
    // this for loop prevents ConcurrentModificationException when printing and status changes
    for (JCheckBox checkbox : new ArrayList<JCheckBox>(locationCheckBoxes)) {
        String locationName = checkbox.getName();
        Location location = locationManager.getLocationByName(locationName);
        if (location.isSwitchListEnabled()) {
            // new switch lists will now be created for the location
            location.setSwitchListState(Location.SW_CREATE);
            location.setStatus(Location.MODIFIED);
        }
    }
    // set trains switch lists unknown, any built trains should remain on the switch lists
    TrainManager.instance().setTrainsSwitchListStatus(Train.UNKNOWN);
}
Also used : JCheckBox(javax.swing.JCheckBox) ArrayList(java.util.ArrayList) Location(jmri.jmrit.operations.locations.Location)

Example 34 with Location

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

the class TrainSwitchListEditFrame method enableChangeButtons.

private void enableChangeButtons() {
    printChangesButton.setEnabled(false);
    csvChangeButton.setEnabled(false);
    runChangeButton.setEnabled(false);
    updateButton.setEnabled(false);
    for (Location location : locationManager.getLocationsByNameList()) {
        if (location.getStatus().equals(Location.MODIFIED) && location.isSwitchListEnabled()) {
            printChangesButton.setEnabled(true);
            csvChangeButton.setEnabled(true);
            runChangeButton.setEnabled(true);
            updateButton.setEnabled(true);
        }
    }
}
Also used : Location(jmri.jmrit.operations.locations.Location)

Example 35 with Location

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

the class TrainSwitchListEditFrame method dispose.

@Override
public void dispose() {
    locationManager.removePropertyChangeListener(this);
    Setup.removePropertyChangeListener(this);
    for (Location location : locationManager.getLocationsByNameList()) {
        location.removePropertyChangeListener(this);
    }
    super.dispose();
}
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