use of javax.swing.filechooser.FileNameExtensionFilter in project JMRI by JMRI.
the class ScriptFileChooser method init.
private void init() {
List<String> allExtensions = new ArrayList<>();
HashMap<String, FileFilter> filters = new HashMap<>();
List<String> filterNames = new ArrayList<>();
JmriScriptEngineManager.getDefault().getManager().getEngineFactories().stream().forEach((ScriptEngineFactory factory) -> {
List<String> extensions = factory.getExtensions();
allExtensions.addAll(extensions);
String name = this.fileForLanguage(factory.getLanguageName());
filterNames.add(name);
filters.put(name, new FileNameExtensionFilter(name, extensions.toArray(new String[extensions.size()])));
});
FileFilter allScripts = new FileNameExtensionFilter(Bundle.getMessage("allScripts"), allExtensions.toArray(new String[allExtensions.size()]));
this.addChoosableFileFilter(allScripts);
filterNames.stream().sorted().forEach((filter) -> {
this.addChoosableFileFilter(filters.get(filter));
});
this.setFileFilter(allScripts);
this.setFileSelectionMode(JFileChooser.FILES_ONLY);
}
use of javax.swing.filechooser.FileNameExtensionFilter 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();
}
}
}
}
use of javax.swing.filechooser.FileNameExtensionFilter in project beast-mcmc by beast-dev.
the class BeautiFrame method doImportTraits.
public final boolean doImportTraits() {
if (options.taxonList != null) {
// validation of check empty taxonList
File[] files = selectImportFiles("Import Traits File...", false, new FileNameExtensionFilter[] { new FileNameExtensionFilter("Tab-delimited text files", "txt", "tab", "dat") });
if (files != null && files.length != 0) {
try {
BEAUTiImporter beautiImporter = new BEAUTiImporter(this, options);
beautiImporter.importTraits(files[0]);
} catch (FileNotFoundException fnfe) {
JOptionPane.showMessageDialog(this, "Unable to open file: File not found", "Unable to open file", JOptionPane.ERROR_MESSAGE);
return false;
} catch (IOException ioe) {
JOptionPane.showMessageDialog(this, "Unable to read file: " + ioe.getMessage(), "Unable to read file", JOptionPane.ERROR_MESSAGE);
return false;
} catch (Exception ex) {
ex.printStackTrace(System.err);
JOptionPane.showMessageDialog(this, "Fatal exception: " + ex, "Error reading file", JOptionPane.ERROR_MESSAGE);
ex.printStackTrace();
return false;
}
} else {
return false;
}
traitsPanel.fireTraitsChanged();
setAllOptions();
tabbedPane.setSelectedComponent(traitsPanel);
return true;
} else {
JOptionPane.showMessageDialog(this, "No taxa loaded yet, please import Alignment file.", "No taxa loaded", JOptionPane.ERROR_MESSAGE);
return false;
}
}
use of javax.swing.filechooser.FileNameExtensionFilter in project beast-mcmc by beast-dev.
the class BeautiFrame method doGenerate.
public final boolean doGenerate() {
try {
generator.checkOptions();
} catch (Generator.GeneratorException ge) {
ge.printStackTrace(System.err);
JOptionPane.showMessageDialog(this, ge.getMessage(), "Invalid BEAUti setting : ", JOptionPane.ERROR_MESSAGE);
if (ge.getSwitchToPanel() != null) {
switchToPanel(ge.getSwitchToPanel());
}
return false;
}
DefaultPriorTableDialog defaultPriorDialog = new DefaultPriorTableDialog(this);
if (!defaultPriorDialog.showDialog(options)) {
return false;
}
File file = selectExportFile("Generate BEAST XML File...", new FileNameExtensionFilter("BEAST XML File", "xml", "beast"));
if (file != null) {
try {
getAllOptions();
generator.generateXML(file);
} catch (IOException ioe) {
ioe.printStackTrace(System.err);
JOptionPane.showMessageDialog(this, "Unable to generate file due to I/O issue: " + ioe.getMessage(), "Unable to generate file", JOptionPane.ERROR_MESSAGE);
return false;
} catch (Generator.GeneratorException e) {
e.printStackTrace(System.err);
JOptionPane.showMessageDialog(this, "The BEAST XML is incomplete because :\n" + e.getMessage(), "The BEAST XML is incomplete", JOptionPane.ERROR_MESSAGE);
return false;
} catch (Exception e) {
e.printStackTrace(System.err);
JOptionPane.showMessageDialog(this, "Unable to generate file: " + e.getMessage(), "Unable to generate file", JOptionPane.ERROR_MESSAGE);
return false;
}
clearDirty();
return true;
}
return false;
}
use of javax.swing.filechooser.FileNameExtensionFilter in project beast-mcmc by beast-dev.
the class TreeSpaceFrame method initializeComponents.
public void initializeComponents() {
tabbedPane.addTab("Input", inputPanel);
tabbedPane.addTab("Trees", treePanel);
tabbedPane.addTab("Clades", cladePanel);
tabbedPane.addTab("Graph", cladePlotter);
tabbedPane.addTab("Plot", plotterPanel);
JPanel panel = new JPanel(new BorderLayout(6, 6));
panel.setBorder(new BorderUIResource.EmptyBorderUIResource(new java.awt.Insets(12, 12, 12, 12)));
panel.add(tabbedPane, BorderLayout.CENTER);
panel.setPreferredSize(new java.awt.Dimension(800, 600));
// getExportAction().setEnabled(false);
// JButton generateButton = new JButton(getExportAction());
// generateButton.putClientProperty("JButton.buttonType", "roundRect");
JPanel panel2 = new JPanel(new BorderLayout(6, 6));
panel2.add(statusLabel, BorderLayout.NORTH);
// panel2.add(generateButton, BorderLayout.EAST);
panel.add(panel2, BorderLayout.SOUTH);
getContentPane().setLayout(new java.awt.BorderLayout(0, 0));
getContentPane().add(panel, BorderLayout.CENTER);
// setAllOptions();
setSize(new java.awt.Dimension(1024, 768));
setMinimumSize(new java.awt.Dimension(800, 600));
// make JFileChooser chooser remember previous path
exportChooser = new JFileChooser(Utils.getCWD());
exportChooser.setDialogTitle("Generate File...");
importChooser = new JFileChooser(Utils.getCWD());
importChooser.setMultiSelectionEnabled(true);
importChooser.setFileFilter(new FileNameExtensionFilter("NEXUS (*.nex) & BEAST Tree (*.trees) Files", "nex", "nexus", "nx", "tree", "tre", "trees"));
importChooser.setDialogTitle("Import Data Files...");
}
Aggregations