use of jmri.jmrit.operations.ExceptionDisplayFrame in project JMRI by JMRI.
the class RestoreDialog method do_restoreButton_actionPerformed.
protected void do_restoreButton_actionPerformed(ActionEvent e) {
log.debug("restore button activated");
// check to see if files are dirty
if (OperationsXml.areFilesDirty()) {
if (JOptionPane.showConfirmDialog(this, Bundle.getMessage("OperationsFilesModified"), Bundle.getMessage("SaveOperationFiles"), JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
OperationsXml.save();
}
}
// first backup the users data in case they forgot
try {
AutoBackup auto = new AutoBackup();
auto.autoBackup();
// now delete the current operations files in case the restore isn't a full set of files
backup.deleteOperationsFiles();
setName = ((BackupSet) comboBox.getSelectedItem()).getSetName();
// The restore method should probably be overloaded to accept a
// BackupSet instead of a simple string. Later.
backup.restoreFilesFromSetName(setName);
// now deregister shut down task
// If Trains window was opened, then task is active
// otherwise it is normal to not have the task running
OperationsManager.getInstance().setShutDownTask(null);
JOptionPane.showMessageDialog(this, Bundle.getMessage("YouMustRestartAfterRestore"), Bundle.getMessage("RestoreSuccessful"), JOptionPane.INFORMATION_MESSAGE);
dispose();
Apps.handleRestart();
}// auto or default.
catch (IOException ex) {
ExceptionContext context = new ExceptionContext(ex, Bundle.getMessage("RestoreDialog.restoring") + " " + setName, // NOI18N
"Hint about checking valid names, etc.");
new ExceptionDisplayFrame(context);
} catch (Exception ex) {
log.error("Doing restore from " + setName, ex);
UnexpectedExceptionContext context = new UnexpectedExceptionContext(ex, Bundle.getMessage("RestoreDialog.restoring") + " " + setName);
new ExceptionDisplayFrame(context);
}
}
use of jmri.jmrit.operations.ExceptionDisplayFrame in project JMRI by JMRI.
the class BackupDialog method do_backupButton_actionPerformed.
protected void do_backupButton_actionPerformed(ActionEvent e) {
// Do the backup of the files...
String setName = null;
try {
log.debug("backup button activated");
setName = setNameTextField.getText();
if (!OperationsXml.checkFileName(setName)) {
// NOI18N
log.error("Back up set name must not contain reserved characters");
JOptionPane.showMessageDialog(this, // NOI18N
Bundle.getMessage("NameResChar") + "\n" + Bundle.getMessage("ReservedChar"), Bundle.getMessage("CanNotUseName"), JOptionPane.ERROR_MESSAGE);
return;
}
// check to see if files are dirty
if (OperationsXml.areFilesDirty()) {
if (JOptionPane.showConfirmDialog(this, Bundle.getMessage("OperationsFilesModified"), Bundle.getMessage("SaveOperationFiles"), JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
OperationsXml.save();
}
}
// check to see if directory already exists
if (backup.checkIfBackupSetExists(setName)) {
int result = JOptionPane.showConfirmDialog(this, MessageFormat.format(Bundle.getMessage("DirectoryAreadyExists"), new Object[] { setName }), Bundle.getMessage("OverwriteBackupDirectory"), JOptionPane.OK_CANCEL_OPTION);
if (result != JOptionPane.OK_OPTION) {
return;
}
}
backup.backupFilesToSetName(setName);
dispose();
} catch (IOException ex) {
ExceptionContext context = new ExceptionContext(ex, Bundle.getMessage("BackupDialog.BackingUp") + " " + setName, Bundle.getMessage("BackupDialog.Ensure"));
new ExceptionDisplayFrame(context);
} catch (RuntimeException ex) {
// ex.printStackTrace();
log.error("Doing backup...", ex);
UnexpectedExceptionContext context = new UnexpectedExceptionContext(ex, Bundle.getMessage("BackupDialog.BackingUp") + " " + setName);
new ExceptionDisplayFrame(context);
} catch (Exception ex) {
// ex.printStackTrace();
log.error("Doing backup...", ex);
UnexpectedExceptionContext context = new UnexpectedExceptionContext(ex, Bundle.getMessage("BackupDialog.BackingUp") + " " + setName);
new ExceptionDisplayFrame(context);
}
}
use of jmri.jmrit.operations.ExceptionDisplayFrame in project JMRI by JMRI.
the class LoadDemoAction method actionPerformed.
@Override
public void actionPerformed(ActionEvent e) {
// check to see if files are dirty
if (OperationsXml.areFilesDirty()) {
if (JOptionPane.showConfirmDialog(null, Bundle.getMessage("OperationsFilesModified"), Bundle.getMessage("SaveOperationFiles"), JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
OperationsXml.save();
}
}
int results = JOptionPane.showConfirmDialog(null, Bundle.getMessage("AreYouSureDemoFiles"), Bundle.getMessage("LoadDemo"), JOptionPane.OK_CANCEL_OPTION);
if (results != JOptionPane.OK_OPTION) {
return;
}
AutoBackup backup = new AutoBackup();
try {
backup.autoBackup();
backup.loadDemoFiles();
// now deregister shut down task
// If Trains window was opened, then task is active
// otherwise it is normal to not have the task running
OperationsManager.getInstance().setShutDownTask(null);
JOptionPane.showMessageDialog(null, Bundle.getMessage("YouMustRestartAfterLoadDemo"), Bundle.getMessage("LoadDemoSuccessful"), JOptionPane.INFORMATION_MESSAGE);
Apps.handleRestart();
} catch (IOException ex) {
ExceptionContext context = new ExceptionContext(ex, Bundle.getMessage("LoadingDemoFiles"), Bundle.getMessage("LoadingDemoMakeSure"));
new ExceptionDisplayFrame(context);
}
}
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();
}
}
use of jmri.jmrit.operations.ExceptionDisplayFrame in project JMRI by JMRI.
the class RestoreFilesAction method restore.
private void restore() {
// check to see if files are dirty
if (OperationsXml.areFilesDirty()) {
if (JOptionPane.showConfirmDialog(null, Bundle.getMessage("OperationsFilesModified"), Bundle.getMessage("SaveOperationFiles"), JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
OperationsXml.save();
}
}
// first backup the users data in case they forgot
BackupBase backup = new DefaultBackup();
// get file to write to
JFileChooser fc = new JFileChooser(backup.getBackupRoot());
fc.addChoosableFileFilter(new fileFilter());
fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
int retVal = fc.showOpenDialog(null);
if (retVal != JFileChooser.APPROVE_OPTION) {
// Canceled
return;
}
if (fc.getSelectedFile() == null) {
// Canceled
return;
}
// now backup files
AutoBackup autoBackup = new AutoBackup();
try {
autoBackup.autoBackup();
File directory = fc.getSelectedFile();
// now delete the current operations files in case the restore isn't a full set of files
backup.deleteOperationsFiles();
backup.restoreFilesFromDirectory(directory);
JOptionPane.showMessageDialog(null, Bundle.getMessage("YouMustRestartAfterRestore"), Bundle.getMessage("RestoreSuccessful"), JOptionPane.INFORMATION_MESSAGE);
// now deregister shut down task
// If Trains window was opened, then task is active
// otherwise it is normal to not have the task running
OperationsManager.getInstance().setShutDownTask(null);
Apps.handleRestart();
} catch (IOException ex) {
ExceptionContext context = new ExceptionContext(ex, Bundle.getMessage("RestoreDialog.restore.files"), Bundle.getMessage("RestoreDialog.makeSure"));
new ExceptionDisplayFrame(context);
}
}
Aggregations