use of jmri.jmrit.operations.ExceptionDisplayFrame in project JMRI by JMRI.
the class OperationsSetupPanel method save.
@SuppressFBWarnings(value = "BC_UNCONFIRMED_CAST_OF_RETURN_VALUE", justification = "checks for instance of OperationsSetupFrame")
private void save() {
// check input fields
int maxTrainLength;
try {
maxTrainLength = Integer.parseInt(maxLengthTextField.getText());
} catch (NumberFormatException e) {
JOptionPane.showMessageDialog(this, Bundle.getMessage("MaxLength"), Bundle.getMessage("CanNotAcceptNumber"), JOptionPane.ERROR_MESSAGE);
return;
}
try {
Integer.parseInt(maxEngineSizeTextField.getText());
} catch (NumberFormatException e) {
JOptionPane.showMessageDialog(this, Bundle.getMessage("MaxEngine"), Bundle.getMessage("CanNotAcceptNumber"), JOptionPane.ERROR_MESSAGE);
return;
}
try {
Integer.parseInt(hptTextField.getText());
} catch (NumberFormatException e) {
JOptionPane.showMessageDialog(this, Bundle.getMessage("HPT"), Bundle.getMessage("CanNotAcceptNumber"), JOptionPane.ERROR_MESSAGE);
return;
}
try {
Integer.parseInt(switchTimeTextField.getText());
} catch (NumberFormatException e) {
JOptionPane.showMessageDialog(this, Bundle.getMessage("MoveTime"), Bundle.getMessage("CanNotAcceptNumber"), JOptionPane.ERROR_MESSAGE);
return;
}
try {
Integer.parseInt(travelTimeTextField.getText());
} catch (NumberFormatException e) {
JOptionPane.showMessageDialog(this, Bundle.getMessage("TravelTime"), Bundle.getMessage("CanNotAcceptNumber"), JOptionPane.ERROR_MESSAGE);
return;
}
try {
if (!yearTextField.getText().trim().equals("")) {
Integer.parseInt(yearTextField.getText().trim());
}
} catch (NumberFormatException e) {
JOptionPane.showMessageDialog(this, Bundle.getMessage("BorderLayoutYearModeled"), Bundle.getMessage("CanNotAcceptNumber"), JOptionPane.ERROR_MESSAGE);
return;
}
// if max train length has changed, check routes
checkRoutes();
// set car types
if (typeDesc.isSelected() && !Setup.getCarTypes().equals(Setup.DESCRIPTIVE) || typeAAR.isSelected() && !Setup.getCarTypes().equals(Setup.AAR)) {
// backup files before changing car type descriptions
AutoBackup backup = new AutoBackup();
try {
backup.autoBackup();
} catch (Exception ex) {
UnexpectedExceptionContext context = new UnexpectedExceptionContext(ex, // NOI18N
"Auto backup before changing Car types");
new ExceptionDisplayFrame(context);
}
if (typeDesc.isSelected()) {
CarTypes.instance().changeDefaultNames(Setup.DESCRIPTIVE);
Setup.setCarTypes(Setup.DESCRIPTIVE);
} else {
CarTypes.instance().changeDefaultNames(Setup.AAR);
Setup.setCarTypes(Setup.AAR);
}
// save all the modified files
OperationsXml.save();
}
// main menu enabled?
Setup.setMainMenuEnabled(mainMenuCheckBox.isSelected());
Setup.setCloseWindowOnSaveEnabled(closeOnSaveCheckBox.isSelected());
Setup.setAutoSaveEnabled(autoSaveCheckBox.isSelected());
Setup.setAutoBackupEnabled(autoBackupCheckBox.isSelected());
// add panel name to setup
Setup.setPanelName(panelTextField.getText());
// train Icon X&Y
Setup.setTrainIconCordEnabled(iconCheckBox.isSelected());
Setup.setTrainIconAppendEnabled(appendCheckBox.isSelected());
// save train icon colors
Setup.setTrainIconColorNorth((String) northComboBox.getSelectedItem());
Setup.setTrainIconColorSouth((String) southComboBox.getSelectedItem());
Setup.setTrainIconColorEast((String) eastComboBox.getSelectedItem());
Setup.setTrainIconColorWest((String) westComboBox.getSelectedItem());
Setup.setTrainIconColorLocal((String) localComboBox.getSelectedItem());
Setup.setTrainIconColorTerminate((String) terminateComboBox.getSelectedItem());
// set train direction
int direction = 0;
if (eastCheckBox.isSelected()) {
direction = Setup.EAST + Setup.WEST;
}
if (northCheckBox.isSelected()) {
direction += Setup.NORTH + Setup.SOUTH;
}
Setup.setTrainDirection(direction);
Setup.setMaxNumberEngines(Integer.parseInt(maxEngineSizeTextField.getText()));
Setup.setHorsePowerPerTon(Integer.parseInt(hptTextField.getText()));
// set switch time
Setup.setSwitchTime(Integer.parseInt(switchTimeTextField.getText()));
// set travel time
Setup.setTravelTime(Integer.parseInt(travelTimeTextField.getText()));
// set scale
if (scaleZ.isSelected()) {
Setup.setScale(Setup.Z_SCALE);
}
if (scaleN.isSelected()) {
Setup.setScale(Setup.N_SCALE);
}
if (scaleTT.isSelected()) {
Setup.setScale(Setup.TT_SCALE);
}
if (scaleOO.isSelected()) {
Setup.setScale(Setup.OO_SCALE);
}
if (scaleHOn3.isSelected()) {
Setup.setScale(Setup.HOn3_SCALE);
}
if (scaleHO.isSelected()) {
Setup.setScale(Setup.HO_SCALE);
}
if (scaleSn3.isSelected()) {
Setup.setScale(Setup.Sn3_SCALE);
}
if (scaleS.isSelected()) {
Setup.setScale(Setup.S_SCALE);
}
if (scaleOn3.isSelected()) {
Setup.setScale(Setup.On3_SCALE);
}
if (scaleO.isSelected()) {
Setup.setScale(Setup.O_SCALE);
}
if (scaleG.isSelected()) {
Setup.setScale(Setup.G_SCALE);
}
if (!Setup.getRailroadName().equals(WebServerPreferences.getDefault().getRailRoadName())) {
Setup.setRailroadName(railroadNameTextField.getText());
int results = JOptionPane.showConfirmDialog(this, MessageFormat.format(Bundle.getMessage("ChangeRailroadName"), new Object[] { WebServerPreferences.getDefault().getRailRoadName(), Setup.getRailroadName() }), Bundle.getMessage("ChangeJMRIRailroadName"), JOptionPane.YES_NO_OPTION);
if (results == JOptionPane.OK_OPTION) {
WebServerPreferences.getDefault().setRailRoadName(Setup.getRailroadName());
WebServerPreferences.getDefault().save();
}
}
// Set Unit of Length
if (feetUnit.isSelected()) {
Setup.setLengthUnit(Setup.FEET);
}
if (meterUnit.isSelected()) {
Setup.setLengthUnit(Setup.METER);
}
Setup.setYearModeled(yearTextField.getText().trim());
// warn about train length being too short
if (maxTrainLength != Setup.getMaxTrainLength()) {
if (maxTrainLength < 500 && Setup.getLengthUnit().equals(Setup.FEET) || maxTrainLength < 160 && Setup.getLengthUnit().equals(Setup.METER)) {
JOptionPane.showMessageDialog(this, MessageFormat.format(Bundle.getMessage("LimitTrainLength"), new Object[] { maxTrainLength, Setup.getLengthUnit().toLowerCase() }), Bundle.getMessage("WarningTooShort"), JOptionPane.WARNING_MESSAGE);
}
}
// set max train length
Setup.setMaxTrainLength(Integer.parseInt(maxLengthTextField.getText()));
Setup.setComment(commentTextArea.getText());
OperationsSetupXml.instance().writeOperationsFile();
if (Setup.isCloseWindowOnSaveEnabled() && this.getTopLevelAncestor() instanceof OperationsSetupFrame) {
((OperationsSetupFrame) this.getTopLevelAncestor()).dispose();
}
}
Aggregations