use of javax.swing.JFileChooser in project JMRI by JMRI.
the class JythonSigletAction method actionPerformed.
@Override
public void actionPerformed(ActionEvent e) {
// create a SampleAutomaton
JFileChooser fci = jmri.jmrit.XmlFile.userFileChooser("Python script files", "py");
fci.setDialogTitle("Find desired script file");
int retVal = fci.showOpenDialog(_who);
// handle selection or cancel
if (retVal == JFileChooser.APPROVE_OPTION) {
File file = fci.getSelectedFile();
// create an object to handle script and run
(new JythonSiglet(file.toString())).start();
}
}
use of javax.swing.JFileChooser in project JMRI by JMRI.
the class RouteTableAction method setSoundPressed.
/**
* Set the sound file
*/
void setSoundPressed() {
if (soundChooser == null) {
soundChooser = new JFileChooser(FileUtil.getUserFilesPath());
soundChooser.setFileFilter(new jmri.util.NoArchiveFileFilter());
}
soundChooser.rescanCurrentDirectory();
int retVal = soundChooser.showOpenDialog(null);
// handle selection or cancel
if (retVal == JFileChooser.APPROVE_OPTION) {
try {
soundFile.setText(soundChooser.getSelectedFile().getCanonicalPath());
} catch (java.io.IOException e) {
log.error("exception setting sound file: " + e);
}
}
}
use of javax.swing.JFileChooser in project JMRI by JMRI.
the class BackupFilesAction method backUp.
private void backUp() {
// 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();
}
}
BackupBase backup = new DefaultBackup();
// get directory to write to
JFileChooser fc = new JFileChooser(backup.getBackupRoot());
fc.addChoosableFileFilter(new fileFilter());
File fs = new File(backup.suggestBackupSetName());
fc.setSelectedFile(fs);
int retVal = fc.showSaveDialog(null);
if (retVal != JFileChooser.APPROVE_OPTION) {
// Canceled
return;
}
if (fc.getSelectedFile() == null) {
// Canceled
return;
}
File directory = fc.getSelectedFile();
// Fix this later....... UGH!!
try {
backup.backupFilesToDirectory(directory);
} catch (IOException ex) {
log.error("backup failed");
}
}
use of javax.swing.JFileChooser in project JMRI by JMRI.
the class StoreXmlVSDecoderAction method actionPerformed.
/**
* The action is performed. Let the user choose the file to save to. Write
* XML for each ThrottleFrame.
*
* @param e The event causing the action.
*/
@Override
public void actionPerformed(ActionEvent e) {
JFileChooser fileChooser = jmri.jmrit.XmlFile.userFileChooser(Bundle.getMessage("PromptXmlFileTypes"), "xml");
fileChooser.setDialogType(JFileChooser.SAVE_DIALOG);
fileChooser.setCurrentDirectory(new File(VSDecoderPane.getDefaultVSDecoderFolder()));
java.io.File file = StoreXmlConfigAction.getFileName(fileChooser);
if (file == null) {
return;
}
saveVSDecoderProfile(file);
}
use of javax.swing.JFileChooser in project JMRI by JMRI.
the class DccSpeedProfile method openImportFile.
private void openImportFile() {
JFileChooser fileChooser = new JFileChooser(FileUtil.getUserFilesPath());
// get filename
// start at current file, show dialog
int retVal = fileChooser.showOpenDialog(null);
// handle selection or cancel
if (retVal == JFileChooser.APPROVE_OPTION) {
String selectedPath = fileChooser.getSelectedFile().getPath();
Path filePath = Paths.get(selectedPath);
try {
dccProfileData = Files.readAllLines(filePath);
} catch (IOException ex) {
log.error("Failed to read reference profile file " + ex);
}
}
}
Aggregations