use of javax.swing.JFileChooser in project JMRI by JMRI.
the class SymbolicProgFrame method selectFileButtonActionPerformed.
protected void selectFileButtonActionPerformed(java.awt.event.ActionEvent e) {
if (fci == null) {
fci = new JFileChooser("xml" + File.separator + "decoders" + File.separator);
fci.setFileFilter(new jmri.util.NoArchiveFileFilter());
}
// show dialog
fci.rescanCurrentDirectory();
int retVal = fci.showOpenDialog(this);
// handle selection or cancel
if (retVal == JFileChooser.APPROVE_OPTION) {
File file = fci.getSelectedFile();
if (log.isDebugEnabled()) {
log.debug("selectFileButtonActionPerformed: located file " + file + " for XML processing");
}
progStatus.setText("Reading file...");
// handle the file (later should be outside this thread?)
readAndParseConfigFile(file);
progStatus.setText("OK");
if (log.isDebugEnabled()) {
log.debug("selectFileButtonActionPerformed: parsing complete");
}
}
}
use of javax.swing.JFileChooser in project JMRI by JMRI.
the class LoadVSDFileAction method actionPerformed.
/**
* The action is performed. Let the user choose the file to load from. Read
* XML for each VSDecoder Profile.
*
* @param e The event causing the action.
*/
@Override
public void actionPerformed(ActionEvent e) {
if (fileChooser == null) {
// Need to somehow give the user a history...
// Must investigate JFileChooser...
String start_dir = VSDecoderManager.instance().getVSDecoderPreferences().getDefaultVSDFilePath();
if (last_path != null) {
start_dir = last_path;
}
log.debug("Using path: " + start_dir);
fileChooser = new JFileChooser(start_dir);
jmri.util.FileChooserFilter filt = new jmri.util.FileChooserFilter(Bundle.getMessage("LoadVSDFileChooserFilterLabel"));
filt.addExtension("vsd");
filt.addExtension("zip");
fileChooser.setFileFilter(filt);
fileChooser.setDialogType(JFileChooser.OPEN_DIALOG);
fileChooser.setCurrentDirectory(new File(start_dir));
}
int retVal = fileChooser.showOpenDialog(null);
if (retVal != JFileChooser.APPROVE_OPTION) {
return;
// give up if no file selected
}
loadVSDFile(fileChooser.getSelectedFile());
// Store the last used directory
try {
last_path = fileChooser.getCurrentDirectory().getCanonicalPath();
} catch (java.io.IOException err) {
log.debug("Error getting current directory: " + err);
last_path = VSDecoderManager.instance().getVSDecoderPreferences().getDefaultVSDFilePath();
}
}
use of javax.swing.JFileChooser in project JMRI by JMRI.
the class StoreXmlUserAction method actionPerformed.
@Override
public void actionPerformed(ActionEvent e) {
JFileChooser userFileChooser = getUserFileChooser();
userFileChooser.setDialogType(javax.swing.JFileChooser.SAVE_DIALOG);
userFileChooser.setApproveButtonText(rb.getString("StorePanelTitle"));
userFileChooser.setDialogTitle(rb.getString("StorePanelTitle"));
java.io.File file = getFileCustom(userFileChooser);
if (file == null) {
return;
}
// make a backup file
ConfigureManager cm = InstanceManager.getNullableDefault(jmri.ConfigureManager.class);
if (cm == null) {
log.error("Failed to make backup due to unable to get default configure manager");
} else {
cm.makeBackup(file);
// and finally store
boolean results = cm.storeUser(file);
log.debug(results ? "store was successful" : "store failed");
if (!results) {
JOptionPane.showMessageDialog(null, rb.getString("StoreHasErrors") + "\n" + rb.getString("StoreIncomplete") + "\n" + rb.getString("ConsoleWindowHasInfo"), rb.getString("StoreError"), JOptionPane.ERROR_MESSAGE);
}
}
}
use of javax.swing.JFileChooser in project JMRI by JMRI.
the class LoadXmlUserAction method actionPerformed.
@Override
public void actionPerformed(ActionEvent e) {
JFileChooser userFileChooser = getUserFileChooser();
userFileChooser.setDialogType(javax.swing.JFileChooser.OPEN_DIALOG);
userFileChooser.setApproveButtonText(rb.getString("LoadPanelTitle"));
userFileChooser.setDialogTitle(rb.getString("LoadPanelTitle"));
boolean results = loadFile(userFileChooser);
if (results) {
log.debug("load was successful");
setCurrentFile(userFileChooser.getSelectedFile());
} else {
log.debug("load failed");
JOptionPane.showMessageDialog(null, rb.getString("PanelHasErrors") + "\n" + rb.getString("CheckPreferences") + "\n" + rb.getString("ConsoleWindowHasInfo"), rb.getString("PanelLoadError"), JOptionPane.ERROR_MESSAGE);
setCurrentFile(null);
}
}
use of javax.swing.JFileChooser in project JMRI by JMRI.
the class JythonAutomatonAction 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 JythonAutomaton(file.toString())).start();
}
}
Aggregations