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