use of javax.swing.JFileChooser in project CFLint by cflint.
the class CFLintMain method ui.
private void ui() {
final JFileChooser chooser = new JFileChooser();
chooser.setDialogTitle("Select target directory");
chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
final int returnVal = chooser.showOpenDialog(null);
if (returnVal == JFileChooser.APPROVE_OPTION) {
folder.add(chooser.getSelectedFile().getAbsolutePath());
} else {
return;
}
final String[] slist = new String[] { "xml", "html", "text", "txt", "json" };
final JList<String> list = new JList<String>(slist);
JOptionPane.showMessageDialog(null, list, "Output Type", JOptionPane.PLAIN_MESSAGE);
final int[] indxs = list.getSelectedIndices();
// If selected set htmlOutput to false
for (final int indx : indxs) {
if (indx == 0) {
xmlOutput = true;
}
if (indx == 1) {
htmlOutput = true;
}
if (indx == 2 || indx == 3) {
textOutput = true;
}
if (indx == 4) {
jsonOutput = true;
}
}
}
use of javax.swing.JFileChooser in project JMRI by JMRI.
the class ProfileManagerDialog method btnUseExistingActionPerformed.
//GEN-LAST:event_btnCreateActionPerformed
private void btnUseExistingActionPerformed(ActionEvent evt) {
//GEN-FIRST:event_btnUseExistingActionPerformed
timer.stop();
countDownLbl.setVisible(false);
JFileChooser chooser = new JFileChooser(FileUtil.getHomePath());
chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
chooser.setFileFilter(new ProfileFileFilter());
chooser.setFileView(new ProfileFileView());
// TODO: Use NetBeans OpenDialog if its availble
if (chooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
try {
Profile p = new Profile(chooser.getSelectedFile());
ProfileManager.getDefault().addProfile(p);
profiles.setSelectedValue(p, true);
} catch (IOException ex) {
log.warn("{} is not a profile directory", chooser.getSelectedFile());
// TODO: Display error dialog - selected file is not a profile directory
}
}
}
use of javax.swing.JFileChooser in project JMRI by JMRI.
the class ProfilePreferencesPanel method btnOpenExistingProfileActionPerformed.
//GEN-LAST:event_btnDeleteProfileActionPerformed
private void btnOpenExistingProfileActionPerformed(ActionEvent evt) {
//GEN-FIRST:event_btnOpenExistingProfileActionPerformed
JFileChooser chooser = new JFileChooser(FileUtil.getHomePath());
chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
chooser.setFileFilter(new ProfileFileFilter());
chooser.setFileView(new ProfileFileView());
// TODO: Use NetBeans OpenDialog if its availble
if (chooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
try {
Profile p = new Profile(chooser.getSelectedFile());
ProfileManager.getDefault().addProfile(p);
int index = ProfileManager.getDefault().getAllProfiles().indexOf(p);
profilesTbl.setRowSelectionInterval(index, index);
} catch (IOException ex) {
log.warn("{} is not a profile directory", chooser.getSelectedFile());
JOptionPane.showMessageDialog(this, Bundle.getMessage("ProfilePreferencesPanel.btnOpenExistingProfile.errorMessage", chooser.getSelectedFile().getPath()), Bundle.getMessage("ProfilePreferencesPanel.btnOpenExistingProfile.errorMessage"), JOptionPane.ERROR_MESSAGE);
}
}
}
use of javax.swing.JFileChooser in project JMRI by JMRI.
the class SetupExcelProgramFrame method selectFile.
/**
* Opens a dialog window in either the csvManifest or csvSwitchLists
* directory
* @param directoryName The string name of the directory
* @return The File selected.
*
*/
protected File selectFile(String directoryName) {
// NOI18N
JFileChooser fc = jmri.jmrit.XmlFile.userFileChooser(Bundle.getMessage("ExcelProgramFiles"), "xls", "xlsm");
fc.setCurrentDirectory(OperationsManager.getInstance().getFile(directoryName));
fc.setDialogTitle(Bundle.getMessage("FindDesiredExcelFile"));
// when reusing the chooser, make sure new files are included
fc.rescanCurrentDirectory();
int retVal = fc.showOpenDialog(null);
// handle selection or cancel
if (retVal == JFileChooser.APPROVE_OPTION) {
File file = fc.getSelectedFile();
// Run the script from it's filename
return file;
}
return null;
}
use of javax.swing.JFileChooser in project JMRI by JMRI.
the class FullBackupExportAction method actionPerformed.
@Override
public void actionPerformed(ActionEvent e) {
Roster roster = Roster.getDefault();
ZipOutputStream zipper = null;
try {
String roster_filename_extension = "roster";
JFileChooser chooser = new JFileChooser();
FileNameExtensionFilter filter = new FileNameExtensionFilter("JMRI full roster files", roster_filename_extension);
chooser.setFileFilter(filter);
int returnVal = chooser.showSaveDialog(_parent);
if (returnVal != JFileChooser.APPROVE_OPTION) {
return;
}
String filename = chooser.getSelectedFile().getAbsolutePath();
if (!filename.endsWith(roster_filename_extension)) {
filename = filename.concat(roster_filename_extension);
}
zipper = new ZipOutputStream(new FileOutputStream(filename));
// create a zip file roster entry for each entry in the main roster
for (RosterEntry entry : roster.getAllEntries()) {
copyFileToStream(entry.getPathName(), "roster", zipper, entry.getId());
}
// Now the full roster entry
copyFileToStream(Roster.getDefault().getRosterIndexPath(), null, zipper, null);
zipper.setComment("Roster file saved from DecoderPro " + jmri.Version.name());
zipper.close();
} catch (FileNotFoundException ex) {
ex.printStackTrace();
} catch (IOException ex) {
ex.printStackTrace();
} finally {
if (zipper != null) {
try {
zipper.close();
} catch (IOException ex) {
ex.printStackTrace();
}
}
}
}
Aggregations